/* ============================================
   CARD BROWSER
   ============================================ */

.cb-filter-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.18s, transform 0.18s;
    pointer-events: none;
    z-index: 400;
    white-space: nowrap;
}
.cb-filter-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.cb-page-layout {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px);
    overflow-x: hidden; /* prevent wide filter conditions from creating page-level horizontal scroll */
}

.cb-filter-group {
    margin-bottom: 14px;
}
.cb-filter-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cb-input {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
}
.cb-input:focus { outline: none; border-color: var(--accent); }

.cb-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    cursor: pointer;
}
.cb-select:focus { outline: none; border-color: var(--accent); }

.cb-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cb-range span { color: var(--text-muted); font-size: 12px; }
.cb-range-in { width: 0; flex: 1; }

/* ── Results panel ── */
.cb-results {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cb-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 56px;
    z-index: 10;
}
.cb-count { font-size: 14px; color: var(--text-muted); }
.cb-results-controls { display: flex; align-items: center; gap: 10px; }
.cb-page-size-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.cb-select-sm {
    padding: 4px 8px;
    font-size: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

/* ── Table ── */
.cb-table-wrap {
    overflow-x: auto;
    flex: 1;
}
.cb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.cb-th-img { width: 44px; }
.cb-th {
    padding: 8px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    white-space: nowrap;
}
.cb-th-sort { cursor: pointer; user-select: none; }
.cb-th-sort:hover { color: var(--text); }
.cb-th-active { color: var(--gold); }

.cb-row {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}
.cb-row:hover { background: var(--surface2); }

.cb-td-img { padding: 4px 6px; width: 60px; }
.cb-thumb {
    max-width: 56px;
    max-height: 56px;
    width: auto;
    height: auto;
    border-radius: 3px;
    display: block;
    background: var(--surface2);
}
.cb-td { padding: 8px 10px; color: var(--text); }
.cb-td-name { font-weight: 600; }
.cb-num    { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.cb-th-num { text-align: right; width: 52px; }
.cb-sort-rank { font-size: 0.65em; vertical-align: super; opacity: 0.7; margin-left: 1px; }

/* ── Quick-add buttons (build mode) ── */
.cb-th-add { width: 1px; padding: 0 6px; }
.cb-td-add { padding: 4px 6px; white-space: nowrap; width: 1px; }
.cb-quick-add {
    display: inline-block;
    padding: 2px 6px;
    font-size: 11px;
    line-height: 1.5;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.cb-quick-add:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.cb-row[draggable] { cursor: grab; }
.cb-row[draggable]:active { cursor: grabbing; }

/* ── Pagination ── */
.cb-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px;
    flex-wrap: wrap;
}
.cb-pagination--inline {
    padding: 0;
    flex-wrap: nowrap;
}
.cb-pg-ellipsis { color: var(--text-muted); padding: 0 4px; }

/* ── Modal ── */
.cb-modal-inner {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.cb-modal-img-col { flex-shrink: 0; }
.cb-modal-img {
    width: 300px;
    border-radius: 8px;
    display: block;
}
.cb-modal-img--landscape {
    width: auto;
    height: 300px;
}
.cb-modal-info { flex: 1; min-width: 0; }
.cb-modal-name { font-size: 26px; margin-bottom: 12px; }
.cb-modal-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 16px;
    font-size: 17px;
    color: var(--text);
}
.cb-modal-meta .badge {
    font-size: 13px;
    padding: 3px 10px;
}
.cb-stats-table { border-collapse: collapse; font-size: 16px; margin-bottom: 14px; width: 100%; }
.cb-stat-label { color: var(--text-muted); padding-right: 16px; padding-bottom: 5px; white-space: nowrap; }
.cb-stats-table td { padding-bottom: 5px; vertical-align: top; overflow-wrap: break-word; word-break: break-word; }
.cb-card-text {
    font-size: 16px;
    color: var(--text);
    line-height: 1.6;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-bottom: 12px;
}
.cb-card-text p {
    margin: 0 0 0.38em;
}
.cb-card-text p:last-child {
    margin-bottom: 0;
}
.cb-add-btn { width: 100%; margin-top: 8px; }
.cb-modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.cb-modal-actions .btn { padding: 8px 18px; font-size: 14px; }

/* ── Compact mode (deck builder) ── */
.cb-compact-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.cb-compact-layout .cb-results {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.cb-filter-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
    flex-shrink: 0;
    overflow-y: auto;
}
.cb-compact-layout .cb-filter-bar {
    max-height: 45vh;
}

.cf-bar-footer {
    display: flex;
    gap: 6px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}
.cf-view-btn {
    color: var(--text-muted);
}
.cf-view-btn:hover {
    color: var(--text);
}
.cf-danger-text {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.cf-danger-text:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* ── Filter condition list ── */

/* OR-group: conditions sharing the same implicit OR relationship */
.cf-or-group {
    border: 1px solid rgba(74, 158, 255, 0.5);
    border-radius: 6px;
    padding: 6px 8px;
    background: var(--surface2);
    display: flex;
    flex-direction: column;
}

/* AND connector badge between OR-groups (clickable to merge groups into OR) */
.cf-connector-and,
.cf-connector-or {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    color: var(--text-muted);
    transition: color 0.15s;
    padding: 0;
}
.cf-connector-and { margin: 10px 0; }
.cf-connector-or  { margin: 3px 0; }
.cf-connector-and::before,
.cf-connector-and::after,
.cf-connector-or::before,
.cf-connector-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    transition: background 0.15s;
}
.cf-connector-and span,
.cf-connector-or span {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    transition: border-color 0.15s, background 0.15s;
}
.cf-connector-and:hover,
.cf-connector-or:hover { color: var(--accent); }
.cf-connector-and:hover::before,
.cf-connector-and:hover::after,
.cf-connector-or:hover::before,
.cf-connector-or:hover::after { background: var(--accent); }
.cf-connector-and:hover span,
.cf-connector-or:hover span {
    border-color: var(--accent);
    background: var(--surface2);
}

/* "+ Add condition" button below the list */
.cf-footer {
    margin-top: 10px;
}
.cf-footer .btn {
    width: 100%;
}

/* Pinned (locked) conditions from deck builder */
.cf-pinned {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    padding: 6px 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.cf-pin-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: pointer;
}
.cf-pin-group:hover {
    border-color: var(--accent, #5b8dd9);
    color: var(--text);
}
.cf-pin-group--inactive {
    opacity: 0.45;
    text-decoration: line-through;
}
.cf-pin-group--inactive:hover {
    opacity: 0.75;
}
.cf-pin-connector {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* ── Query box ── */

.cb-query-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}
.cb-query-input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    font-size: 14px;
    font-family: monospace;
    background: var(--surface2);
    border: 1px solid rgba(74, 158, 255, 0.35);
    border-radius: 5px;
    color: var(--text);
    height: 36px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cb-query-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15);
}
.cb-query-help-btn {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    background: none;
    border: 2px solid #3b9eff;
    border-radius: 50%;
    color: #3b9eff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: color 0.1s, border-color 0.1s;
}
.cb-query-help-btn:hover {
    color: #6db8ff;
    border-color: #6db8ff;
}
.cb-query-complex-note {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    margin-bottom: 8px;
    line-height: 1.4;
}
.cb-query-errors {
    margin-bottom: 6px;
}
.cb-query-error {
    display: block;
    font-size: 12px;
    color: var(--danger);
    padding: 2px 0;
}
.cb-query-help-panel {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.5;
    margin-bottom: 8px;
}
.cb-query-help-panel strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.cb-query-help-panel strong + strong {
    margin-top: 8px;
}
.cb-help-table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 4px;
}
.cb-help-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.04);
}
.cb-help-table td {
    padding: 2px 6px 2px 4px;
    vertical-align: top;
    color: var(--text-muted);
}
.cb-help-table td:first-child {
    white-space: nowrap;
    padding-right: 10px;
}
.cb-help-table code {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 11px;
    color: var(--text);
}

/* ── Condition rows ── */

.cf-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 0;
}

/* Compact mode (deck builder) — narrower fields */
.cb-compact-layout .cf-group {
    padding: 4px 6px;
}
.cb-compact-layout .cf-field { width: 90px; flex-shrink: 0; }
.cb-compact-layout .cf-op    { width: 82px; flex-shrink: 0; }

/* Full-page browser — wider fields */
.cb-page-layout .cf-field { width: 120px; flex-shrink: 0; }
.cb-page-layout .cf-op    { width: 100px; flex-shrink: 0; }

.cb-filter-bar-header {
    display: flex;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}
#cb-mode-toggle {
    border-color: var(--accent);
    color: var(--accent);
}
#cb-mode-toggle:hover {
    background: rgba(74, 158, 255, 0.1);
    border-color: var(--accent-hover);
    color: var(--accent-hover);
}

/* ── Filter presets dropdown ── */

.cb-presets-wrap {
    position: relative;
    display: inline-block;
    margin-left: 6px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}
.cb-presets-backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
}
.cb-presets-btn {
    border-color: var(--gold, #c9a84c);
    color: var(--gold, #c9a84c);
}
.cb-presets-btn:hover,
.cb-presets-btn--open {
    background: rgba(201, 168, 76, 0.1);
    border-color: var(--gold, #c9a84c);
    color: var(--gold, #c9a84c);
}
.cb-presets-dropdown {
    position: fixed;
    z-index: 200;
    min-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
.cb-presets-save-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.cb-preset-name-input {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    font-size: 13px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    height: 28px;
}
.cb-preset-name-input:focus {
    outline: none;
    border-color: var(--gold, #c9a84c);
}
.cb-presets-save-btn {
    flex-shrink: 0;
    border-color: var(--gold, #c9a84c);
    color: var(--gold, #c9a84c);
}
.cb-presets-save-btn:not(:disabled):hover {
    background: rgba(201, 168, 76, 0.15);
}
.cb-presets-list-header {
    padding: 6px 10px 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}
.cb-presets-list {
    max-height: 220px;
    overflow-y: auto;
    padding: 2px 0 4px;
}
.cb-presets-empty {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}
.cb-preset-row {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 6px 3px 10px;
    cursor: default;
}
.cb-preset-row:hover {
    background: var(--surface2);
}
.cb-preset-name {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: 3px 0;
}
.cb-preset-name:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.cb-preset-name-edit {
    flex: 1;
    min-width: 0;
    padding: 2px 6px;
    font-size: 13px;
    background: var(--surface2);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text);
    height: 24px;
}
.cb-preset-name-edit:focus {
    outline: none;
}
.cb-preset-actions {
    display: flex;
    gap: 1px;
    opacity: 0;
    transition: opacity 0.12s;
    flex-shrink: 0;
}
.cb-preset-row:hover .cb-preset-actions,
.cb-preset-row:focus-within .cb-preset-actions {
    opacity: 1;
}
.cb-preset-icon-btn {
    background: none;
    border: none;
    width: 22px;
    height: 22px;
    padding: 0;
    font-size: 13px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.1s, background 0.1s;
}
.cb-preset-icon-btn:hover {
    color: var(--text);
    background: var(--border);
}
.cb-preset-icon-btn--danger:hover {
    color: var(--danger);
    background: rgba(255, 80, 80, 0.1);
}

/* Field and op selects */
.cf-sel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 13px;
    padding: 3px 5px;
    height: 28px;
    cursor: pointer;
}
.cf-sel:focus { outline: none; border-color: var(--accent); }

/* Value inputs */
.cf-val {
    flex: 1;
    min-width: 60px;
    height: 28px;
    padding: 3px 7px;
    font-size: 13px;
}
.cf-val-num    { width: 70px; flex: 0 0 70px; text-align: right; }
.cf-val-select { flex: 1; }

/* Text/number inputs get a darker background and a slightly brighter border
   so they read clearly against the blue-bordered group container */
.cf-val-text,
.cf-val-num {
    background: var(--surface);
    border-color: #3d3d60;
}
.cf-val-text:focus,
.cf-val-num:focus { border-color: var(--accent); }

/* Hide number input spinners */
.cf-val-num::-webkit-outer-spin-button,
.cf-val-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cf-val-num { -moz-appearance: textfield; }

/* Condition action buttons (clone + remove) */
.cf-cond-clone,
.cf-remove {
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 3px;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.1s, color 0.1s;
}
.cf-cond-clone { color: var(--text-muted); }
.cf-cond-clone:hover { opacity: 1; color: var(--accent); }
.cf-remove { color: var(--danger); }
.cf-remove:hover { opacity: 1; }
