/* Shared components — used by Pairs / Exchanges / Positions / Exchange Detail.
   Mirrors Dashboard V2 palette so the entire admin surface speaks one
   visual language (live blue · dry lavender · accent indigo · gold premium).

   Mode language note: all `--live-*` and `--dry-*` colours come from
   dashboard.css. This file expects those variables to be in scope on
   the page that imports it.
*/

:root {
    --live: #3b82f6;
    --live-bg: rgba(59, 130, 246, 0.12);
    --dry: #a78bfa;
    --dry-bg: rgba(167, 139, 250, 0.12);
    --gold: #d4af37;
    --gold-bg: rgba(212, 175, 55, 0.10);
    --panel: #0f1018;
    --panel-2: #14151f;
    --border-soft: #1f2030;
}

/* ───────────────────────────────────────── KPI ribbon */
/* Compact top strip — used by Pairs / Exchanges / Positions to surface
   the "is this page healthy" answer above the table. Sticky so the
   operator never loses sight of the count + risk numbers while
   scrolling through long lists. */
.kpi-ribbon {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    background: linear-gradient(180deg, #0f1019 0%, #0c0d14 100%);
    border: 1px solid var(--border);
    border-radius: 10px;
    position: sticky;
    top: 64px;
    z-index: 9;
    backdrop-filter: blur(6px);
    margin-bottom: 12px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.kpi-ribbon .kr-cell {
    padding: 10px 16px;
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 64px;
    min-width: 0;
}
.kpi-ribbon .kr-cell:last-child { border-right: none; }
.kpi-ribbon .kr-label {
    font-size: 10px;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}
.kpi-ribbon .kr-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    margin-top: 2px;
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
}
.kpi-ribbon .kr-sub {
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}
.kpi-ribbon .kr-value .pos { color: var(--green); }
.kpi-ribbon .kr-value .neg { color: var(--red); }
.kpi-ribbon .kr-value .m-live { color: var(--live); }
.kpi-ribbon .kr-value .m-dry { color: var(--dry); }
.kpi-ribbon .kr-value .sep { color: var(--text-muted); padding: 0 2px; }

/* ───────────────────────────────────────── Filter chip bar */
.filter-chip-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    position: sticky;
    top: 134px;
    z-index: 8;
}
.filter-chip-bar .fb-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.filter-chip-bar .fb-group + .fb-group {
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px dashed var(--border-soft);
}
.filter-chip-bar .fb-spacer { margin-left: auto; }
.filter-chip-bar .chip {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s ease;
    display: inline-flex; align-items: center; gap: 6px;
    line-height: 1.1;
}
.filter-chip-bar .chip:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}
.filter-chip-bar .chip.is-active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}
.filter-chip-bar .chip-mode .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.filter-chip-bar .dot-both { background: var(--accent); }
.filter-chip-bar .dot-live { background: var(--live); }
.filter-chip-bar .dot-dry { background: var(--dry); }
.filter-chip-bar .chip-mode.is-active[data-mode="live"] {
    background: var(--live); border-color: var(--live);
}
.filter-chip-bar .chip-mode.is-active[data-mode="dry"] {
    background: var(--dry); border-color: var(--dry);
    color: #1a1a28;
}
.filter-chip-bar .fb-select {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.filter-chip-bar .fb-select select {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 5px;
    font-size: 12px;
    min-width: 110px;
    max-width: 220px;
}
.filter-chip-bar .fb-search {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 12px;
    min-width: 180px;
}
.filter-chip-bar .fb-search:focus {
    outline: none;
    border-color: var(--accent);
}

/* ───────────────────────────────────────── View toggle (card / table) */
.view-toggle {
    display: inline-flex;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.view-toggle button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    cursor: pointer;
    font-weight: 600;
}
.view-toggle button.is-active {
    background: var(--accent);
    color: #fff;
}

/* ───────────────────────────────────────── Section group heading */
/* Used to group cards under their type / data-source banner. */
.section-group {
    margin-top: 16px;
    margin-bottom: 8px;
}
.section-group:first-child { margin-top: 0; }
.section-group-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0 6px 2px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 8px;
}
.section-group-head h4 {
    font-size: 11px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.section-group-head .count {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.section-group-head .badge-cluster {
    margin-left: auto;
    display: flex;
    gap: 6px;
    font-size: 10px;
}

/* ───────────────────────────────────────── Entity card / grid */
/* Pair card & Exchange card share this base so future "list of things"
   pages can plug in. Grid is auto-fit so it scales down to phones. */
.entity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 12px;
}
.entity-card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 14px 12px;
    overflow: hidden;
    transition: transform 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.entity-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 60%; height: 60%;
    background: radial-gradient(circle at top left, rgba(99,102,241,0.08), transparent 70%);
    pointer-events: none;
}
.entity-card:hover {
    transform: translateY(-1px);
    border-color: rgba(99,102,241,0.45);
}
.entity-card.is-dimmed { opacity: 0.55; }
.entity-card.is-dimmed:hover { opacity: 0.85; }
.entity-card .ec-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.entity-card .ec-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: 0.005em;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.entity-card .ec-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}
.entity-card .ec-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    flex-wrap: wrap;
}
.entity-card .ec-row .label {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 600;
}
.entity-card .ec-stat {
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    font-weight: 600;
}
.entity-card .ec-stat.pos { color: var(--green); }
.entity-card .ec-stat.neg { color: var(--red); }
.entity-card .ec-stat .muted {
    color: var(--text-muted);
    font-weight: 400;
}
.entity-card .ec-actions {
    margin-top: auto;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 6px;
    border-top: 1px dashed var(--border-soft);
}
.entity-card .ec-actions .btn {
    flex: 0 0 auto;
}

/* ───────────────────────────────────────── Mode tag + binding chip */
.mode-tag {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}
.mode-tag.mt-live { color: var(--live); background: var(--live-bg); }
.mode-tag.mt-dry  { color: var(--dry);  background: var(--dry-bg); }
.mode-tag.mt-stopped { color: var(--text-muted); background: var(--bg-tertiary); }
.mode-tag.mt-l1l2 { color: var(--green); background: rgba(34,197,94,0.10); }
.mode-tag.mt-l1   { color: var(--yellow); background: rgba(250,204,21,0.10); }
.mode-tag.mt-l2   { color: var(--accent); background: rgba(99,102,241,0.10); }

.dot-mode { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-mode.dot-live { background: var(--live); }
.dot-mode.dot-dry  { background: var(--dry); }
.dot-mode.dot-stop { background: var(--text-muted); }

.binding-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-soft);
    font-variant-numeric: tabular-nums;
}
.binding-chip .dot-mode { width: 6px; height: 6px; }
.binding-chip[data-mode="live"] { border-color: rgba(59,130,246,0.4); color: var(--live); }
.binding-chip[data-mode="dry"]  { border-color: rgba(167,139,250,0.4); color: var(--dry); }
.binding-chip[data-mode="stopped"] { opacity: 0.5; }

.slot-counter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    background: rgba(99,102,241,0.08);
    color: var(--accent);
    border: 1px solid rgba(99,102,241,0.18);
    font-variant-numeric: tabular-nums;
}
.slot-counter.empty {
    opacity: 0.45;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border-color: var(--border-soft);
}
.slot-counter b { font-weight: 700; }

/* ───────────────────────────────────────── Capacity bar */
/* Stacked horizontal bar: live | dry | free. Used in exchange grid +
   exchange detail to surface where the pool is currently allocated. */
.capacity-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--border-soft);
}
.capacity-bar > span { display: block; height: 100%; }
.capacity-bar .seg-live { background: var(--live); }
.capacity-bar .seg-dry  { background: var(--dry); }
.capacity-bar .seg-free { background: transparent; }
.capacity-meta {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-top: 3px;
    gap: 6px;
    flex-wrap: wrap;
}
.capacity-meta .m-live { color: var(--live); }
.capacity-meta .m-dry  { color: var(--dry); }

/* ───────────────────────────────────────── Stop-loss distance bar */
/* Used in positions table to show entry → current → SL distance.
   Promoted from dashboard.css so the positions page can share it. */
.sl-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.sl-bar .bar {
    width: 70px; height: 4px;
    background: var(--border-soft);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}
.sl-bar .bar > i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--green) 0%, #5a5a5a 50%, var(--red) 100%);
}
.sl-bar .bar > .marker {
    position: absolute;
    top: -2px; bottom: -2px;
    width: 2px;
    background: var(--text-primary);
    box-shadow: 0 0 0 1px #000;
}

/* ───────────────────────────────────────── Mini sparkline cell */
.cell-spark {
    width: 100%;
    max-width: 110px;
    height: 22px;
}

/* ───────────────────────────────────────── Run-mode pill */
.runmode-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1.3;
    border: 1px solid;
}
.runmode-pill.rm-stopped { color: var(--text-muted); background: var(--bg-tertiary); border-color: var(--border); }
.runmode-pill.rm-dry     { color: var(--dry);  background: var(--dry-bg);  border-color: var(--dry); }
.runmode-pill.rm-live    { color: var(--live); background: var(--live-bg); border-color: var(--live); }
.runmode-pill.rm-both    { color: var(--green); background: rgba(34,197,94,0.10); border-color: var(--green); }
.runmode-pill.rm-l1_only,
.runmode-pill.rm-l1      { color: var(--yellow); background: rgba(250,204,21,0.10); border-color: var(--yellow); }
.runmode-pill.rm-l2_only,
.runmode-pill.rm-l2      { color: var(--accent); background: rgba(99,102,241,0.10); border-color: var(--accent); }

/* ───────────────────────────────────────── Skeleton card / row */
.skeleton-card {
    background: linear-gradient(90deg, var(--panel-2) 0%, var(--bg-hover) 50%, var(--panel-2) 100%);
    background-size: 200% 100%;
    animation: tbl-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
    height: 130px;
    border: 1px solid var(--border);
}
@keyframes tbl-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ───────────────────────────────────────── Tab bar — segmented (positions) */
.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 12px;
    gap: 0;
}
.tab-bar .tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    display: inline-flex; align-items: center; gap: 8px;
    line-height: 1.2;
}
.tab-bar .tab-btn:hover { color: var(--text-primary); }
.tab-bar .tab-btn.is-active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}
.tab-bar .tab-count {
    background: var(--bg-tertiary);
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}
.tab-bar .tab-btn.is-active .tab-count { background: var(--accent); color: #fff; }

/* ───────────────────────────────────────── Live indicator */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.live-indicator .pulse {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(34,197,94,0);
    animation: lv-pulse 1.6s infinite;
}
.live-indicator.is-paused .pulse {
    background: var(--text-muted);
    animation: none;
}
@keyframes lv-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ───────────────────────────────────────── Pro table (Positions) */
.pro-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.pro-table thead th {
    text-align: left;
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 10px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-soft);
    background: var(--panel-2);
    position: sticky;
    top: 0;
    z-index: 2;
}
.pro-table thead th.sortable { cursor: pointer; user-select: none; }
.pro-table thead th.sortable:hover { color: var(--text-primary); }
.pro-table thead th .arrow { opacity: 0.4; margin-left: 4px; }
.pro-table thead th.sort-active .arrow { opacity: 1; color: var(--accent); }
.pro-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-soft);
    color: #b7bccd;
    vertical-align: middle;
}
.pro-table tbody tr:hover { background: var(--bg-hover); }
.pro-table tbody tr:hover td { color: #d7dae6; }
.pro-table tbody tr.is-expanded { background: rgba(99,102,241,0.05); }
.pro-table .num { text-align: right; color: #cdd1de; }
.pro-table .num.pos { color: var(--green); }
.pro-table .num.neg { color: var(--red); }
.pro-table .side-long  { color: var(--green); font-weight: 600; }
.pro-table .side-short { color: var(--red);   font-weight: 600; }
.pro-table .sym {
    color: #e5e7ee;
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.pro-table .sym:hover { color: var(--accent); }
.pro-table .pnl-cell { line-height: 1.2; }
.pro-table .pnl-cell .pct { font-size: 10px; color: var(--text-muted); }
.pro-table .row-expand-pane {
    background: var(--panel-2);
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 11px;
    color: var(--text-secondary);
}
.pro-table .row-expand-pane dl {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 6px 16px;
    margin: 0;
}
.pro-table .row-expand-pane dt {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.pro-table .row-expand-pane dd {
    margin: 0;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Pager bar */
.pager-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--border-soft);
    background: var(--panel-2);
    flex-wrap: wrap;
}
.pager-bar .spacer { flex: 1 1 auto; }
.pager-bar .count-pill {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.pager-bar .btn.is-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.pager-bar .gap {
    padding: 4px 6px;
    color: var(--text-muted);
}

/* ───────────────────────────────────────── Empty state */
.empty-state-pro {
    padding: 36px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}
.empty-state-pro .es-title {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

/* ───────────────────────────────────────── Page header — quant fund */
.qf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.qf-header h1 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.005em;
    color: var(--text-primary);
}
.qf-header .qf-lede {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 680px;
    margin-top: 2px;
}
.qf-header .qf-right { display: flex; gap: 6px; align-items: center; }

/* Responsive tweaks — sticky offsets relax on narrow screens to keep
   filters reachable when the header wraps onto two rows. */
@media (max-width: 880px) {
    .kpi-ribbon { position: static; box-shadow: none; }
    .filter-chip-bar { position: static; }
    .filter-chip-bar .fb-group + .fb-group {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .live-indicator .pulse,
    .skeleton-card,
    .entity-card {
        animation: none !important;
        transition: none !important;
    }
}
