/* ═══════════════════════════════════════════════════════════════
   Trading Dashboard — Dark theme matching WinForms palette
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: rgb(30, 30, 35);
    --panel: rgb(40, 44, 52);
    --card: rgb(50, 55, 65);
    --border: rgb(70, 75, 85);
    --fg: rgb(230, 230, 235);
    --fg2: rgb(160, 165, 175);
    --green: rgb(16, 185, 129);
    --red: rgb(239, 68, 68);
    --teal: rgb(20, 184, 166);
    --blue: rgb(59, 130, 246);
    --yellow: rgb(251, 191, 36);
    --row-active: rgb(22, 48, 42);
    --row-waiting: rgb(30, 38, 55);
    --row-allocating: rgb(30, 45, 50);
    --row-completed: rgb(38, 38, 42);
    --row-cancelled: rgb(50, 32, 32);
    --row-suspended: rgb(50, 45, 28);
    --row-manual: rgb(35, 50, 42);
    --selection: rgb(45, 55, 72);
    --accent: var(--teal);
    color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--fg);
    overflow: hidden;
    /* GPU-accelerated font rendering — eliminates subpixel fringing on dark backgrounds */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Header ── */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}
.header-left { display: flex; align-items: baseline; gap: 12px; }
.header-left h1 { font-size: 15px; font-weight: 600; white-space: nowrap; color: var(--teal); }
.subtitle { font-size: 11px; color: var(--fg2); white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.hdr-btn {
    padding: 5px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.hdr-btn:hover { background: var(--border); }
.hdr-btn:active { transform: scale(0.97); }
.hdr-btn.accent { background: var(--teal); color: #fff; border-color: var(--teal); }
.hdr-btn.accent:hover { filter: brightness(1.15); }
.hdr-btn.accent:active { filter: brightness(0.92); }
.hdr-btn.danger { color: var(--red); border-color: var(--red); }
.hdr-btn.danger:hover { background: rgba(239, 68, 68, 0.15); }

.clock { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--fg2); min-width: 60px; text-align: right; }
.conn-status { font-size: 12px; color: var(--yellow); }
.conn-status.connected { color: var(--green); }
.conn-status.disconnected { color: var(--red); }

/* ── KPI Bar ── */
#kpi-bar {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg);
    flex-shrink: 0;
    overflow-x: auto;
}
.kpi-card {
    flex: 1;
    min-width: 100px;
    padding: 8px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-align: center;
}
.kpi-label { font-size: 10px; color: var(--fg2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.kpi-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11px; color: var(--fg2); margin-top: 2px; }

/* ── Filter Bar ── */
#filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.filter-buttons { display: flex; gap: 4px; }
.filter-btn {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg2);
    cursor: pointer;
    transition: all 0.15s;
}
.filter-btn:hover { background: var(--border); }
.filter-btn:active { transform: scale(0.97); }
.filter-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }

.search-input {
    flex: 1;
    min-width: 180px;
    max-width: 300px;
    padding: 5px 10px;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    outline: none;
}
.search-input:focus { border-color: var(--teal); }
.search-input::placeholder { color: var(--fg2); }

.risk-status { font-size: 12px; margin-left: auto; white-space: nowrap; }

/* ── Trade Grid ── */
#grid-container {
    flex: 1;
    overflow: auto;
    position: relative;
}

#tradeGrid {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    table-layout: fixed;
    min-width: 600px;
}

#tradeGrid thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

#tradeGrid th {
    background: var(--card);
    color: var(--fg2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
    position: relative;
}

#tradeGrid th.sortable { cursor: pointer; }
#tradeGrid th.sortable:hover { color: var(--fg); }
#tradeGrid th.num { text-align: right; }
#tradeGrid th .sort-arrow { font-size: 10px; margin-left: 3px; }

#tradeGrid td {
    padding: 5px 8px;
    border-bottom: 1px solid rgba(70, 75, 85, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

#tradeGrid td.num { text-align: right; font-variant-numeric: tabular-nums; }

#tradeGrid tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}
#tradeGrid tbody tr:hover { filter: brightness(1.15); }
#tradeGrid tbody tr.selected {
    outline: 1px solid var(--teal);
    outline-offset: -1px;
    box-shadow: inset 3px 0 0 var(--teal);
}

/* Column widths */
#tradeGrid th:nth-child(1), #tradeGrid td:nth-child(1) { width: 75px; }
#tradeGrid th:nth-child(2), #tradeGrid td:nth-child(2) { width: 42px; }
#tradeGrid th:nth-child(3), #tradeGrid td:nth-child(3) { width: 50px; }
#tradeGrid th:nth-child(4), #tradeGrid td:nth-child(4) { width: 110px; }
#tradeGrid th:nth-child(5), #tradeGrid td:nth-child(5) { width: 45px; }
#tradeGrid th:nth-child(6), #tradeGrid td:nth-child(6) { width: 75px; }
#tradeGrid th:nth-child(7), #tradeGrid td:nth-child(7) { width: 80px; }
#tradeGrid th:nth-child(8), #tradeGrid td:nth-child(8) { width: 80px; }
#tradeGrid th:nth-child(9), #tradeGrid td:nth-child(9) { width: 80px; }
#tradeGrid th:nth-child(10), #tradeGrid td:nth-child(10) { width: 65px; }
#tradeGrid th:nth-child(11), #tradeGrid td:nth-child(11) { width: 80px; }
#tradeGrid th:nth-child(12), #tradeGrid td:nth-child(12) { width: 80px; }
#tradeGrid th:nth-child(13), #tradeGrid td:nth-child(13) { width: auto; min-width: 120px; }
#tradeGrid th:nth-child(14), #tradeGrid td:nth-child(14) { width: 75px; }
#tradeGrid th:nth-child(15), #tradeGrid td:nth-child(15) { width: 55px; }

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--fg2);
    font-size: 14px;
}
.hidden { display: none !important; }

/* State colors */
.state-active { color: var(--green); }
.state-waiting, .state-registering, .state-initialized { color: var(--blue); }
.state-allocating, .state-adjusting, .state-manualbuying, .state-manualclosing { color: var(--teal); }
.state-completed { color: var(--fg2); }
.state-cancelled, .state-error { color: var(--red); }
.state-suspended, .state-paused { color: var(--yellow); }

.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }
.pnl-zero { color: var(--fg2); }

.dir-long, .dir-call { color: var(--green); }
.dir-short, .dir-put { color: var(--red); }

.type-cell { color: var(--fg2); }

/* ── Visual Hierarchy ── */
.cell-ticker { font-weight: 700; }
.cell-dim { color: var(--fg2); }
.cell-type-stk { color: var(--teal); font-size: 11px; font-weight: 600; }
.cell-type-opt { color: #8b5cf6; font-size: 11px; font-weight: 600; }
.cell-risk-low { color: var(--green); }
.cell-risk-medium { color: var(--yellow); }
.cell-risk-high { color: var(--red); }

/* ── Detail Panel ── */
#detail-panel {
    flex-shrink: 0;
    background: var(--panel);
    position: relative;
    /* Collapsible: hidden until trade selected */
    max-height: 0;
    overflow: hidden;
    padding: 0 16px;
    border-top: 1px solid transparent;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#detail-panel.panel-open {
    max-height: 320px;
    padding: 10px 16px 8px;
    border-top-color: var(--border);
    overflow: visible;
}
.detail-info {
    display: flex;
    gap: 16px;
    margin-bottom: 0;
    flex-wrap: wrap;
    align-items: flex-start;
}
.detail-col { min-width: 140px; }
.detail-ticker { font-size: 16px; font-weight: 700; }
.detail-ticker-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
    border-radius: 3px;
    transition: color 0.15s;
}
.detail-ticker-link:hover .detail-ticker {
    color: var(--teal);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.detail-ticker-link[href="#"] { pointer-events: none; }
.detail-state { font-size: 12px; color: var(--fg2); margin-top: 1px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.detail-sub { font-size: 11px; color: var(--fg2); }
.detail-pnl { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-signal { font-size: 11px; color: var(--fg2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; }
.detail-col-targets { flex: 1 1 200px; min-width: 200px; }
.detail-col-targets .detail-sub { font-variant-numeric: tabular-nums; }
#detail-panel div:not(.detail-actions) > div { margin-bottom: 1px; font-size: 12px; }

/* Inline detail-panel chips — uses picker-badge vocabulary but with flex-row context */
.dash-chip { display: inline-flex; align-items: center; padding: 1px 6px; font-size: 9px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; border-radius: 3px; white-space: nowrap; }
.dash-chip-type { background: rgba(20,184,166,0.12); color: var(--teal); }
.dash-chip-type.cell-type-opt { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.dash-chip-long { background: rgba(34,197,94,0.12); color: var(--green); }
.dash-chip-short { background: rgba(239,68,68,0.12); color: #f87171; }
.dash-chip-bi { background: rgba(59,130,246,0.12); color: var(--blue); }
.dash-chip-dim { background: rgba(255,255,255,0.06); color: var(--fg2); }

.detail-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 6px;
    margin-top: 6px;
    border-top: 1px solid rgba(70, 75, 85, 0.4);
}

.action-btn {
    padding: 5px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.action-btn:hover:not(:disabled) { background: var(--border); }
.action-btn:active:not(:disabled) { transform: scale(0.97); transition: transform 0.1s; }
.action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.action-btn.buy { border-color: var(--green); color: var(--green); }
.action-btn.buy:hover:not(:disabled) { background: rgba(34, 197, 94, 0.15); }
.action-btn.sell { border-color: var(--red); color: var(--red); }
.action-btn.sell:hover:not(:disabled) { background: rgba(239, 68, 68, 0.15); }
.action-btn.close { border-color: var(--yellow); color: var(--yellow); }
.action-btn.close:hover:not(:disabled) { background: rgba(251, 191, 36, 0.15); }
.action-btn.danger { border-color: var(--red); color: var(--red); }
.action-btn.danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.15); }
.action-btn.accent {
    background: rgba(20, 184, 166, 0.15);
    color: var(--teal);
    border-color: rgba(20, 184, 166, 0.4);
}
.action-btn.accent:hover:not(:disabled) {
    background: rgba(20, 184, 166, 0.28);
    border-color: var(--teal);
}

/* Push danger group right — aligned with sparkline above */
.action-btn:not(.danger) + .action-btn.danger { margin-left: auto; }

/* ── Confirmation Bar ── */
#confirmation-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: rgba(251, 191, 36, 0.12);
    border-top: 1px solid var(--yellow);
}
#confirmMessage { flex: 1; font-size: 13px; font-weight: 500; }
.confirm-yes {
    padding: 5px 18px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    background: var(--green);
    color: #fff;
    cursor: pointer;
    transition: filter 0.15s, box-shadow 0.15s;
}
.confirm-yes:hover:not(:disabled) { filter: brightness(1.1); box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3); }
.confirm-yes:active:not(:disabled) { filter: brightness(0.92); transform: scale(0.97); }
.confirm-no {
    padding: 5px 18px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    transition: background 0.15s;
}
.confirm-no:hover:not(:disabled) { background: var(--border); }
.confirm-no:active:not(:disabled) { filter: brightness(0.9); transform: scale(0.97); }

/* ── Footer ── */
#footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--fg2);
    flex-shrink: 0;
}

/* ── Toast Notifications ── */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    position: relative;
    padding: 14px 38px 14px 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-left: 5px solid var(--teal);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 0 1px rgba(255,255,255,0.06);
    animation: toastIn 0.3s ease-out;
    transition: opacity 0.3s, transform 0.3s;
    overflow: hidden;
    min-width: 300px;
}
.toast.dismissing { opacity: 0; transform: translateX(80px); pointer-events: none; }
.toast.info { border-left-color: var(--blue); }
.toast.warning { border-left-color: var(--yellow); background: rgb(55, 52, 40); }
.toast.critical { border-left-color: var(--red); background: rgb(58, 40, 44); }
.toast.success { border-left-color: var(--green); background: rgb(30, 50, 38); }
.toast.success .toast-progress { background: var(--green); }
.toast-header { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.toast-icon { font-size: 14px; flex-shrink: 0; }
.toast-title { font-size: 13px; font-weight: 600; }
.toast-body { font-size: 12px; color: var(--fg2); line-height: 1.4; }
.toast-close {
    position: absolute; top: 8px; right: 8px;
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent;
    color: var(--fg2); font-size: 16px; cursor: pointer;
    border-radius: 4px; line-height: 1; opacity: 0.5;
    transition: opacity 0.15s, background 0.15s;
}
.toast-close:hover { opacity: 1; background: rgba(255,255,255,0.08); }
.toast-progress {
    position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
    border-radius: 0 0 0 8px;
    background: var(--teal);
    transform-origin: left;
    animation: toastProgress linear forwards;
}
.toast.info .toast-progress { background: var(--blue); }
.toast.warning .toast-progress { background: var(--yellow); }
.toast.critical .toast-progress { background: var(--red); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastProgress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ── Context Menu ── */
#context-menu {
    position: fixed;
    z-index: 9000;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    min-width: 220px;
    padding: 4px 0;
}
.ctx-item {
    padding: 6px 16px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.ctx-item:hover { background: rgba(55, 65, 85, 0.8); }
.ctx-item.disabled { opacity: 0.35; pointer-events: none; }
.ctx-separator { height: 1px; background: var(--border); margin: 4px 8px; }

/* ── Scale Dialog ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
}
.modal-content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px 24px;
    min-width: 320px;
    max-width: 90vw;
}
.modal-content h3 { font-size: 16px; margin-bottom: 8px; }
.modal-content p { font-size: 13px; color: var(--fg2); margin-bottom: 12px; }
.scale-options { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.scale-btn {
    padding: 8px 16px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    transition: all 0.15s;
}
.scale-btn:hover { background: var(--border); }
.scale-btn.selected { background: var(--teal); color: #fff; border-color: var(--teal); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Trade Card Modal ── */
.tradecard-content { min-width: 380px; max-width: 460px; max-height: 80vh; overflow-y: auto; }
.tradecard-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tradecard-header h3 { font-size: 16px; margin: 0; }
.modal-close-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent;
    color: var(--fg2); font-size: 20px; cursor: pointer;
    border-radius: 4px; transition: background 0.15s;
}
.modal-close-btn:hover { background: rgba(255,255,255,0.08); }
.tradecard-body { display: flex; flex-direction: column; }
.tradecard-row {
    display: flex; justify-content: space-between;
    padding: 6px 0; font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.tradecard-row:last-child { border-bottom: none; }
.tradecard-label { color: var(--fg2); }
.tradecard-val { font-variant-numeric: tabular-nums; text-align: right; }

/* ── Parameter Editor Modal ── */
.params-content { min-width: 440px; max-width: 660px; width: 90vw; max-height: 82vh; display: flex; flex-direction: column; }
.params-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.params-header h3 { font-size: 16px; margin: 0; font-weight: 700; }
.params-loading { text-align: center; padding: 24px; color: var(--fg2); font-size: 13px; }
.params-body { overflow-y: auto; flex: 1; padding-right: 4px; min-height: 0; }
.params-body::-webkit-scrollbar { width: 5px; }
.params-body::-webkit-scrollbar-track { background: transparent; }
.params-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.params-body::-webkit-scrollbar-thumb:hover { background: var(--fg2); }
.params-group { margin-bottom: 10px; background: rgba(50, 55, 65, 0.5); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.params-group-label { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; padding: 5px 12px; border-bottom: 1px solid var(--border); }
.params-group-fields { padding: 6px 12px; }
.params-field { display: flex; align-items: center; padding: 4px 0; gap: 12px; }
.params-field label { font-size: 12px; color: var(--fg2); flex-shrink: 0; min-width: 150px; }
.params-field input, .params-field select {
    background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    color: var(--fg); padding: 5px 10px; font-size: 12px; flex: 1; min-width: 80px;
    font-family: inherit;
}
.params-field input:focus, .params-field select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.15); }
.params-field input[type="checkbox"] {
    width: 16px; height: 16px; min-width: 16px; flex: none;
    padding: 0; background: none; border: none; border-radius: 0;
    accent-color: var(--teal); cursor: pointer;
}
.params-content .modal-actions { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; flex-shrink: 0; }

/* ── Sparkline ── */
.detail-col-spark {
    flex: 0 1 240px;
    min-width: 160px;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-left: auto;
}
.spark-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0 2px;
}
.spark-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--fg2);
}
.spark-delta {
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.spark-container {
    position: relative;
    width: 100%;
    height: 38px;
    background: rgba(30, 30, 35, 0.5);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    transform: translateZ(0);
}
.spark-container svg {
    display: block;
    width: 100%;
    height: 100%;
    shape-rendering: geometricPrecision;
}
.spark-entry-line {
    stroke: var(--fg2);
    stroke-width: 0.5;
    stroke-dasharray: 3 2;
    opacity: 0.4;
}
.spark-line {
    fill: none;
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}
.spark-line.up   { stroke: var(--green); }
.spark-line.down { stroke: var(--red); }
.spark-line.flat { stroke: var(--fg2); }
.spark-area {
    opacity: 1;
}
.spark-dot {
    fill: var(--fg);
    opacity: 0;
    transition: opacity 0.3s;
}
.spark-container:hover .spark-dot { opacity: 1; }
.spark-bounds {
    position: absolute;
    top: 0;
    right: 4px;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    padding: 2px 0;
}
.spark-bound {
    font-size: 9px;
    font-variant-numeric: tabular-nums;
    color: var(--fg2);
    opacity: 0.7;
    line-height: 1;
}
.spark-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--fg2);
    opacity: 0.5;
    pointer-events: none;
}

/* ── Confirmation Loading State ── */
.confirm-yes:disabled, .confirm-no:disabled { opacity: 0.6; cursor: wait; }

/* ── Scale button feedback ── */
.scale-btn:active { transform: scale(0.97); }

/* ── Keyboard Accessibility — Focus-visible rings ── */
.hdr-btn:focus-visible,
.filter-btn:focus-visible,
.action-btn:focus-visible,
.scale-btn:focus-visible,
.confirm-yes:focus-visible,
.confirm-no:focus-visible,
.modal-close-btn:focus-visible,
.toast-close:focus-visible,
.search-input:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Responsive — Tablet (<1024px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .hide-tablet { display: none; }
    #tradeGrid th:nth-child(13), #tradeGrid td:nth-child(13) { display: none; }
    #tradeGrid th:nth-child(15), #tradeGrid td:nth-child(15) { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   Accessibility — Reduced Motion
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Trade Control Panel  —  Full operator console modal
   ═══════════════════════════════════════════════════════════════ */

.tcp-modal {
    position: fixed;
    inset: 0;
    z-index: 9600;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
}
.tcp-modal.hidden { display: none; }

.tcp-content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: min(820px, 96vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0,0,0,0.7);
    position: relative;
}

/* ── Header ── */
.tcp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
}
.tcp-header-left  { display: flex; align-items: center; gap: 8px; }
.tcp-header-right { display: flex; align-items: center; gap: 4px; }

.tcp-ticker { font-size: 20px; font-weight: 800; letter-spacing: 0.5px; color: var(--fg); }

.tcp-badge { font-size: 10px; font-weight: 700; letter-spacing: 0.5px; padding: 2px 7px; border-radius: 3px; text-transform: uppercase; }
.tcp-badge-stk { background: rgba(20, 184, 166, 0.15); color: var(--teal); border: 1px solid rgba(20, 184, 166, 0.3); }
.tcp-badge-opt { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }

.tcp-dir { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 3px; }
.dir-long  { background: rgba(16, 185, 129, 0.12); color: var(--green); }
.dir-short { background: rgba(239,  68,  68, 0.12); color: var(--red); }
.dir-bi    { background: rgba(251, 191,  36, 0.12); color: var(--yellow); }

.tcp-state-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-active  { background: var(--green); box-shadow: 0 0 6px var(--green); animation: tcp-pulse 2s ease-in-out infinite; }
.dot-waiting { background: var(--yellow); }
.dot-other   { background: var(--fg2); }
@keyframes tcp-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.tcp-state-label { font-size: 12px; color: var(--fg2); font-weight: 600; }

.tcp-icon-btn {
    width: 28px; height: 28px;
    border: none; background: transparent;
    color: var(--fg2); font-size: 16px;
    cursor: pointer; border-radius: 5px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.tcp-icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--fg); }
.tcp-icon-close:hover { background: rgba(239,68,68,0.15); color: var(--red); }

/* ── Tab bar ── */
.tcp-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 14px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: rgba(0,0,0,0.1);
}
.tcp-tab {
    font-size: 12px; font-weight: 600;
    padding: 7px 16px 8px;
    border: none; background: transparent; color: var(--fg2);
    cursor: pointer; border-radius: 5px 5px 0 0;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.tcp-tab:hover  { color: var(--fg); background: rgba(255,255,255,0.04); }
.tcp-tab.active { color: var(--teal); border-bottom-color: var(--teal); background: rgba(20,184,166,0.06); }

/* ── Tab panels ── */
.tcp-tab-panel { display: none; flex: 1; overflow-y: auto; padding: 14px 18px; min-height: 0; }
.tcp-tab-panel.active { display: flex; flex-direction: column; gap: 14px; }
.tcp-tab-panel::-webkit-scrollbar { width: 5px; }
.tcp-tab-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tcp-tab-panel::-webkit-scrollbar-thumb:hover { background: var(--fg2); }

/* ── Section headers ── */
.tcp-section { display: flex; flex-direction: column; gap: 8px; }
.tcp-section-title {
    font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
    color: var(--fg2); padding: 0 0 4px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.tcp-section-title.teal   { color: var(--teal); }
.tcp-section-title.cyan   { color: #22d3ee; }
.tcp-section-title.yellow { color: var(--yellow); }
.tcp-section-title.red    { color: var(--red); }
.tcp-section-title.muted  { color: var(--fg2); }

.tcp-ro-badge {
    font-size: 9px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase;
    padding: 1px 5px; background: rgba(100,110,130,0.2); color: var(--fg2);
    border: 1px solid var(--border); border-radius: 3px;
}

/* ── Snapshot strip ── */
.tcp-snapshot-row {
    display: flex; gap: 6px; flex-wrap: wrap;
    padding: 10px 12px; background: rgba(0,0,0,0.2);
    border: 1px solid var(--border); border-radius: 6px;
}
.tcp-snap-tile { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 80px; }
.tcp-snap-lbl  { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--fg2); margin-bottom: 3px; }
.tcp-snap-val  { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg); }
.tcp-snap-dim  { font-size: 10px; color: var(--fg2); font-weight: 400; }
.snap-pos  { color: var(--green); }
.snap-neg  { color: var(--red); }
.snap-warn { color: #f59e0b; }
.tcp-snap-rr { cursor: default; border-left: 1px solid var(--border); padding-left: 10px; margin-left: 2px; }
.tcp-snap-candle { cursor: default; min-width: 48px; justify-content: flex-end; gap: 4px; }

/* ── Read-only grid ── */
.tcp-ro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.tcp-ro-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px; font-size: 12px; border-bottom: 1px solid rgba(70,75,85,0.4); }
.tcp-ro-row:last-child { border-bottom: none; }
.tcp-ro-lbl { color: var(--fg2); flex-shrink: 0; }
.tcp-ro-val { font-weight: 600; text-align: right; color: var(--fg); font-variant-numeric: tabular-nums; }

/* ── Quick actions bar ── */
.tcp-actions-row { display: flex; gap: 6px; flex-wrap: wrap; }

.tcp-action-btn {
    flex: 1; min-width: 90px;
    padding: 9px 12px; font-size: 12px; font-weight: 700;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--card); color: var(--fg);
    cursor: pointer; transition: all 0.15s;
    white-space: nowrap;
}
.tcp-action-btn:hover:not(:disabled) { filter: brightness(1.2); }
.tcp-action-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.tcp-btn-buy        { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.4); color: var(--green); }
.tcp-btn-buy:hover:not(:disabled) { background: rgba(16, 185, 129, 0.22); }
.tcp-btn-sell       { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.35); color: var(--red); }
.tcp-btn-sell:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); }
.tcp-btn-close      { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: var(--red); font-weight: 800; }
.tcp-btn-close:hover:not(:disabled) { background: rgba(239, 68, 68, 0.3); }
.tcp-btn-scale-down { background: rgba(251, 191, 36, 0.1); border-color: rgba(251, 191, 36, 0.3); color: var(--yellow); }
.tcp-btn-scale-down:hover:not(:disabled) { background: rgba(251, 191, 36, 0.18); }
.tcp-btn-scale-up   { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); color: #60a5fa; }
.tcp-btn-scale-up:hover:not(:disabled)   { background: rgba(59, 130, 246, 0.18); }

/* ── Scale picker ── */
.tcp-scale-picker {
    margin-top: 8px; padding: 12px 14px;
    background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 6px;
    display: flex; flex-direction: column; gap: 10px;
}
.tcp-scale-label { font-size: 12px; color: var(--fg2); font-weight: 600; }
.tcp-scale-opts  { display: flex; gap: 6px; flex-wrap: wrap; }
.tcp-scale-opt {
    padding: 6px 14px; font-size: 12px; font-weight: 600;
    border: 1px solid var(--border); border-radius: 4px;
    background: var(--card); color: var(--fg); cursor: pointer; transition: all 0.15s;
}
.tcp-scale-opt:hover    { background: var(--border); }
.tcp-scale-opt.selected { background: var(--teal); color: #fff; border-color: var(--teal); }
.tcp-scale-confirm-row  { display: flex; gap: 8px; }

/* ── Generic buttons ── */
.tcp-btn {
    padding: 8px 16px; font-size: 12px; font-weight: 600;
    border: 1px solid var(--border); border-radius: 5px;
    background: var(--card); color: var(--fg);
    cursor: pointer; transition: all 0.15s;
    white-space: nowrap;
}
.tcp-btn:hover:not(:disabled) { background: var(--border); }
.tcp-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tcp-btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.tcp-btn-primary:hover:not(:disabled) { background: rgb(13, 158, 143); }
.tcp-btn-green { background: rgba(16,185,129,0.15); color: var(--green); border-color: rgba(16,185,129,0.4); }
.tcp-btn-green:hover:not(:disabled) { background: rgba(16,185,129,0.28); }
.tcp-btn-danger { background: rgba(239,68,68,0.12); color: var(--red); border-color: rgba(239,68,68,0.4); }
.tcp-btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.24); }
.tcp-btn-disabled { opacity: 0.3; cursor: not-allowed !important; }

/* ── Edit grid (controls tab) ── */
.tcp-edit-grid { display: flex; flex-direction: column; gap: 6px; }
.tcp-edit-row  { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.tcp-edit-lbl  { font-size: 12px; color: var(--fg2); flex-shrink: 0; min-width: 150px; }
.tcp-edit-inp  {
    flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    color: var(--fg); padding: 6px 10px; font-size: 12px; font-family: inherit;
}
.tcp-edit-inp:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(20,184,166,0.12); }

/* ── Toggle grid ── */
.tcp-toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.tcp-toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 7px 10px; background: rgba(50,55,65,0.5);
    border: 1px solid var(--border); border-radius: 6px;
    cursor: pointer; transition: background 0.15s;
}
.tcp-toggle-row:hover { background: rgba(50,55,65,0.9); }
.tcp-toggle-lbl { font-size: 12px; color: var(--fg); font-weight: 500; }

/* Toggle switch */
.tcp-toggle { display: none; }
.tcp-switch {
    position: relative; width: 36px; height: 20px; flex-shrink: 0;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; transition: background 0.2s;
}
.tcp-switch::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--fg2); transition: all 0.2s;
}
.tcp-toggle:checked + .tcp-switch { background: var(--teal); border-color: var(--teal); }
.tcp-toggle:checked + .tcp-switch::after { left: 19px; background: #fff; }
label.tcp-toggle-row input.tcp-toggle + .tcp-switch { pointer-events: none; }

/* Inline param toggle (All Params tab) — fully self-contained, no js needed for visual */
.tcp-param-toggle { display: flex; align-items: center; cursor: pointer; }
.tcp-param-toggle .tcp-param-chk { display: none; }
.tcp-param-toggle .tcp-param-chk + .tcp-switch { pointer-events: none; }
.tcp-param-toggle .tcp-param-chk:checked + .tcp-switch { background: var(--teal); border-color: var(--teal); }
.tcp-param-toggle .tcp-param-chk:checked + .tcp-switch::after { left: 19px; background: #fff; }
/* keep legacy class working too */
.tcp-inline-toggle { display: flex; align-items: center; cursor: pointer; }
.tcp-inline-toggle input { display: none; }
.tcp-inline-toggle input:checked + .tcp-switch { background: var(--teal); border-color: var(--teal); }
.tcp-inline-toggle input:checked + .tcp-switch::after { left: 19px; background: #fff; }

/* Profile row (Overview tab) */
.tcp-profile-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 10px 12px;
    background: rgba(20,184,166,.06); border: 1px solid rgba(20,184,166,.18);
    border-radius: 6px;
}
.tcp-profile-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.tcp-profile-name-row,
.tcp-profile-signal-row { display: flex; align-items: center; gap: 8px; }
.tcp-pf-pill-label {
    font-size: 9px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase;
    color: rgba(20,184,166,0.7); background: rgba(20,184,166,0.1);
    border: 1px solid rgba(20,184,166,0.2); border-radius: 3px;
    padding: 1px 5px; flex-shrink: 0;
}
.tcp-profile-name { font-size: 13px; font-weight: 700; color: var(--teal); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcp-profile-signal { font-size: 12px; color: var(--fg); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcp-btn-profile {
    flex-shrink: 0; background: transparent;
    border: 1px solid var(--teal); color: var(--teal);
    border-radius: 5px; padding: 5px 12px; font-size: 11px;
    cursor: pointer; transition: background .15s, color .15s;
    white-space: nowrap;
}
.tcp-btn-profile:hover { background: var(--teal); color: #0f1318; }

/* Profile modal inside the panel */
.tcp-profile-box { max-width: 420px; width: 90%; }
.tcp-profile-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; font-size: 14px; font-weight: 600; color: var(--fg);
}

/* ── Save bar ── */
.tcp-save-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0 2px; border-top: 1px solid var(--border);
    margin-top: auto; flex-shrink: 0;
}
/* BSL config save bar sits inside a section, not at panel footer */
.tcp-bsl-cfg-save-bar { margin-top: 10px; border-top: none; padding-top: 0; }

/* Inline toggle inside an edit-row (no full-width card) */
.tcp-toggle-inline { padding: 0; background: none; border: none; cursor: pointer; }
.tcp-toggle-inline:hover { background: none; }

/* Select input in edit rows */
.tcp-select {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px;
}

/* ── All Params: read-only field display ── */
.tcp-pf-ro .tcp-pf-val {
    font-size: 12px; font-weight: 500; color: var(--fg2);
    font-variant-numeric: tabular-nums;
    padding: 6px 10px;
    background: rgba(0,0,0,0.15);
    border: 1px solid rgba(70,75,85,0.3);
    border-radius: 4px;
    flex: 1; display: block;
    opacity: 0.75;
    font-style: italic;
}
.tcp-pf-ro .tcp-pf-lbl { opacity: 0.65; }
/* Locked field (BSL active) */
.tcp-pf-dimmed { opacity: 0.45; }
.tcp-pf-dimmed .tcp-edit-inp,
.tcp-pf-dimmed .tcp-pf-sel {
    background: rgba(0,0,0,0.2);
    color: var(--fg2);
    cursor: not-allowed;
}
.tcp-save-status { font-size: 12px; font-weight: 600; }
.tcp-save-status.ok  { color: var(--green); }
.tcp-save-status.err { color: var(--red); }

/* ── Broker SL tab ── */
.tcp-bsl-status-card {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; border-radius: 8px;
    border: 1px solid var(--border); background: rgba(0,0,0,0.2);
}
.tcp-bsl-indicator { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.bsl-active   { background: var(--green); box-shadow: 0 0 10px rgba(16,185,129,0.6); animation: tcp-pulse 2s ease-in-out infinite; }
.bsl-inactive { background: var(--fg2); }
.tcp-bsl-info { flex: 1; }
.tcp-bsl-status-label { font-size: 14px; font-weight: 700; }
.tcp-bsl-price        { font-size: 12px; color: var(--fg2); margin-top: 2px; }
.tcp-bsl-refresh-btn {
    width: 30px; height: 30px; border: 1px solid var(--border);
    background: var(--card); border-radius: 5px; cursor: pointer;
    color: var(--fg2); font-size: 16px; display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.tcp-bsl-refresh-btn:hover { background: var(--border); color: var(--fg); }

.tcp-bsl-override { margin-bottom: 8px; }
.tcp-bsl-actions {
    display: flex; gap: 8px; flex-wrap: wrap;
}
.tcp-bsl-note {
    margin-top: 10px; padding: 10px 12px; font-size: 11px;
    line-height: 1.6; color: var(--fg2);
    background: rgba(239,68,68,0.05); border: 1px solid rgba(239,68,68,0.2); border-radius: 5px;
}

/* ── All Params tab ── */
.tcp-loading { padding: 24px; text-align: center; color: var(--fg2); font-size: 13px; }
.tcp-params-body { display: flex; flex-direction: column; gap: 10px; }
.tcp-pg { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tcp-pg-disabled { border-color: #333; opacity: 0.6; }
.tcp-pg-disabled-hint {
    font-size: 11px; color: #f59e0b; background: rgba(245,158,11,0.08);
    padding: 5px 12px; border-bottom: 1px solid #333; display: flex; align-items: center; gap: 6px;
}
.tcp-pg-na-badge {
    font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
    background: #3a3020; color: #f59e0b; border: 1px solid #f59e0b44;
    border-radius: 3px; padding: 1px 5px; margin-left: 6px; vertical-align: middle;
}
.tcp-pg-fields-dimmed { pointer-events: none; }
.tcp-pg-label {
    font-size: 10px; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase;
    padding: 6px 12px; border-bottom: 1px solid var(--border);
}
.tcp-pg-fields { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.tcp-pf { display: flex; align-items: center; padding: 4px 0; gap: 12px; }
.tcp-pf-ro { pointer-events: none; }
.tcp-pf-lbl { font-size: 12px; color: var(--fg2); flex-shrink: 0; min-width: 155px; }
.tcp-pf-val { font-size: 12px; color: var(--fg); font-variant-numeric: tabular-nums; }
.tcp-pf-sel { min-width: 120px; }

/* ── Confirm overlay ── */
.tcp-confirm-overlay {
    position: absolute; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.65); border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}
.tcp-confirm-box {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 22px 28px; max-width: 380px; width: 90%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.tcp-confirm-box p { font-size: 13px; color: var(--fg); margin-bottom: 16px; line-height: 1.55; white-space: pre-line; }
.tcp-confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Responsive ── */
@media (max-width: 640px) {
    .tcp-toggle-grid { grid-template-columns: 1fr; }
    .tcp-ro-grid     { grid-template-columns: 1fr; }
    .tcp-content     { width: 100vw; max-height: 100vh; border-radius: 0; }
    .tcp-bsl-actions { flex-direction: column; }
    .tcp-action-btn  { min-width: 70px; font-size: 11px; padding: 8px 8px; }
}
