/* Material Design 3 — Dark Dashboard */
:root {
    --md-primary: #90caf9;
    --md-primary-container: #1565c0;
    --md-on-primary: #0d47a1;
    --md-surface: #0f1419;
    --md-surface-container: #1a2332;
    --md-surface-container-high: #212d3d;
    --md-surface-container-highest: #2a3848;
    --md-outline: rgba(255, 255, 255, 0.1);
    --md-outline-variant: rgba(255, 255, 255, 0.06);
    --md-text: #e8edf4;
    --md-text-secondary: #9aa8b8;
    --md-success: #66bb6a;
    --md-danger: #ef5350;
    --md-warning: #ffb74d;
    --md-elevation-1: 0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);
    --md-elevation-2: 0 3px 8px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.3);
    --md-elevation-3: 0 6px 16px rgba(0,0,0,.45);
    --side-width: 200px;
    --app-bar-h: 48px;
    --trades-h: 110px;
    --radius: 12px;
    --radius-sm: 8px;
    --scrollbar-size: 8px;
    --scrollbar-track: var(--md-surface-container);
    --scrollbar-thumb: rgba(144, 202, 249, 0.28);
    --scrollbar-thumb-hover: rgba(144, 202, 249, 0.48);
    --scrollbar-thumb-border: var(--md-surface-container);
}

* { box-sizing: border-box; }

html, body.dashboard-body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: IRANYekanXFaNum, IRANYekanX, Tahoma, sans-serif;
    background: var(--md-surface);
    color: var(--md-text);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-body strong,
.dashboard-body .stat-card strong,
.dashboard-body .symbol-chip,
.dashboard-body .live-chip,
.dashboard-body input,
.dashboard-body select,
.dashboard-body button,
.dashboard-body table,
.dashboard-body .md-chip {
    font-family: IRANYekanXFaNum, IRANYekanX, Tahoma, sans-serif;
}

/* ── Themed scrollbars ── */
.dashboard-body,
.dashboard-body * {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.dashboard-body ::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

.dashboard-body ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 999px;
}

.dashboard-body ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
    border: 2px solid var(--scrollbar-thumb-border);
    min-height: 40px;
}

.dashboard-body ::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

.dashboard-body ::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

.toolbar-controls {
    scrollbar-width: none;
}

.toolbar-controls::-webkit-scrollbar {
    display: none;
}

/* ── Shell Grid (flush panels) ── */
.dashboard-shell {
    display: grid;
    grid-template-columns: var(--side-width) 1fr var(--side-width);
    grid-template-rows: var(--app-bar-h) 1fr var(--trades-h);
    height: 100vh;
    gap: 0;
    padding: 0;
    background: var(--md-outline-variant);
    overflow: hidden;
}

.dashboard-main {
    display: contents;
}

.app-bar {
    grid-column: 1 / -1;
}

.trades-panel {
    grid-column: 1 / -1;
}

.elevation-1,
.elevation-2 {
    box-shadow: none;
}

/* ── App Bar ── */
.app-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: var(--md-surface-container);
    border: none;
    border-bottom: 1px solid var(--md-outline-variant);
    border-radius: 0;
    min-height: var(--app-bar-h);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #1565c0, #42a5f5);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(21, 101, 192, 0.4);
}

.brand-icon .material-icons-round { font-size: 18px; color: #fff; }

.brand-text {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.02em;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 0;
}

.toolbar-controls::-webkit-scrollbar { display: none; }

.toolbar-status {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* ── Main: side panels + chart (grid cells) ── */
.side-panel {
    width: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--md-surface-container);
    border: none;
    border-inline-start: 1px solid var(--md-outline-variant);
    border-radius: 0;
    overflow: hidden;
    min-height: 0;
}

#panelSignal {
    border-inline-start: none;
}

.chart-panel {
    flex: none;
    min-width: 0;
    min-height: 0;
    background: var(--md-surface-container);
    border: none;
    border-inline-start: 1px solid var(--md-outline-variant);
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chart-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    background: radial-gradient(ellipse at 30% 20%, #141c28 0%, #0c1018 60%, #080b10 100%);
    overflow: hidden;
}

#tradingChart {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
}

.chart-host,
.tv-chart-host {
    background: #0c1018;
}

.tv-chart-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.tv-chart-container {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

.trade-zone-overlay {
    position: absolute;
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
    top: 0;
    left: 0;
    will-change: transform;
}

.trade-zone-overlay .zone-profit {
    fill-opacity: 1;
    stroke-width: 1;
}

.trade-zone-overlay .zone-profit-glass,
.trade-zone-overlay .zone-loss-glass {
    fill-opacity: 1;
    stroke-width: 0.75;
    stroke-dasharray: 4 3;
}

.trade-zone-overlay .zone-profit-filled,
.trade-zone-overlay .zone-loss-filled {
    fill-opacity: 1;
    stroke-width: 1;
}

.trade-zone-overlay .zone-loss {
    fill-opacity: 1;
    stroke-width: 1;
}

.trade-zone-overlay .zone-entry-h {
    stroke-width: 1.5;
    stroke-dasharray: 6 4;
}

.trade-zone-overlay .zone-entry-v {
    stroke-width: 1;
    stroke-dasharray: 4 4;
    opacity: 0.35;
}

.trade-zone-overlay .zone-dot {
    fill: #f59e0b;
    stroke: #fff;
    stroke-width: 1.5;
}

.trade-zone-overlay .trade-live .zone-entry-h { stroke: #f59e0b; }
.trade-zone-overlay .trade-win .zone-entry-h { stroke: rgba(34, 197, 94, 0.85); }
.trade-zone-overlay .trade-loss .zone-entry-h { stroke: rgba(239, 68, 68, 0.85); }

.trade-zone-overlay .entry-vline {
    stroke: var(--md-warning);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
    opacity: 0.85;
}

.trade-zone-overlay .entry-dot {
    fill: var(--md-warning);
    stroke: #fff;
    stroke-width: 2;
    filter: drop-shadow(0 0 4px rgba(255, 183, 77, 0.7));
}

.trade-zone-overlay .zone-label {
    font-family: IRANYekanXFaNum, IRANYekanX, sans-serif;
    font-size: 10px;
    font-weight: 700;
}

.trade-zone-overlay .label-tp { fill: var(--md-success); }
.trade-zone-overlay .label-sl { fill: var(--md-danger); }
.trade-zone-overlay .label-entry { fill: var(--md-warning); }

/* ── Trades footer ── */
.trades-panel {
    display: flex;
    flex-direction: column;
    background: var(--md-surface-container);
    border: none;
    border-top: 1px solid var(--md-outline-variant);
    border-radius: 0;
    overflow: hidden;
    min-height: 0;
}

.trades-scroll {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* ── Panel internals ── */
.panel-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--md-text-secondary);
    background: var(--md-surface-container-high);
    border-bottom: 1px solid var(--md-outline-variant);
    flex-shrink: 0;
}

.panel-head .material-icons-round { color: var(--md-primary); font-size: 16px !important; }

.panel-head-sub {
    border-top: 1px solid var(--md-outline-variant);
}

.panel-head-row {
    justify-content: space-between;
}

.panel-body {
    padding: 8px 10px;
    font-size: 0.75rem;
    line-height: 1.5;
}

.panel-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.panel-compact { padding: 6px 8px; }

.muted { color: var(--md-text-secondary); margin: 0; font-size: 0.72rem; }

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

.stat-card {
    background: var(--md-surface-container-highest);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: 1px solid var(--md-outline-variant);
}

.stat-card span {
    font-size: 0.65rem;
    color: var(--md-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-card strong {
    font-size: 0.82rem;
    color: var(--md-primary);
    font-weight: 700;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed var(--md-outline-variant);
    font-size: 0.72rem;
}

.stat-item:last-child { border-bottom: none; }
.stat-item strong { color: var(--md-primary); }

/* ── Material inputs ── */
.md-input {
    background: var(--md-surface-container-highest) !important;
    border: 1px solid var(--md-outline-variant) !important;
    color: var(--md-text) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 0.75rem !important;
    min-width: 72px;
    height: 30px;
    padding: 0 8px !important;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.md-input:focus {
    border-color: var(--md-primary) !important;
    box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.2) !important;
    outline: none;
}

#strategySelect {
    min-width: 210px;
    max-width: 300px;
}

/* ── Symbol picker button (toolbar) ── */
.symbol-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 10px 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-highest);
    color: var(--md-text);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
    max-width: 180px;
}

.symbol-picker-btn:hover {
    border-color: var(--md-primary);
    background: rgba(144, 202, 249, 0.08);
    box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.12);
}

.symbol-picker-btn .material-icons-round { color: var(--md-text-secondary); font-size: 18px !important; }

.picked-symbol-icon {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--md-surface-container);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--md-primary);
}

.picked-symbol-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Symbol picker modal ── */
.symbol-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.symbol-modal.open {
    opacity: 1;
    visibility: visible;
}

.symbol-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}

.symbol-modal-panel {
    position: relative;
    width: min(560px, 100%);
    max-height: min(80vh, 640px);
    display: flex;
    flex-direction: column;
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline-variant);
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    transform: translateY(12px) scale(0.98);
    transition: transform 0.22s ease;
}

.symbol-modal.open .symbol-modal-panel {
    transform: translateY(0) scale(1);
}

.symbol-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-high);
}

.symbol-modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.symbol-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--md-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.symbol-modal-close:hover {
    background: var(--md-surface-container-highest);
    color: var(--md-text);
}

.symbol-modal-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px 8px;
}

.symbol-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 100px;
    background: transparent;
    color: var(--md-text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s;
}

.symbol-tab:hover {
    background: var(--md-surface-container-highest);
    color: var(--md-text);
}

.symbol-tab.active {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 4px 12px rgba(21, 101, 192, 0.4);
}

.symbol-modal-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 16px 10px;
    padding: 0 12px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-highest);
}

.symbol-modal-search:focus-within {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.18);
}

.symbol-modal-search .material-icons-round { color: var(--md-text-secondary); }

.symbol-modal-search input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--md-text);
    font-size: 0.85rem;
    outline: none;
}

.symbol-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    padding: 4px 16px 16px;
    min-height: 200px;
}

.symbol-grid-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-high);
    cursor: pointer;
    text-align: right;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.symbol-grid-item:hover {
    border-color: var(--md-primary);
    background: rgba(144, 202, 249, 0.1);
    transform: translateY(-1px);
}

.symbol-grid-item:active { transform: scale(0.98); }

.symbol-grid-item.selected {
    border-color: var(--md-primary);
    background: rgba(144, 202, 249, 0.16);
    box-shadow: 0 0 0 1px rgba(144, 202, 249, 0.3);
}

.symbol-fav-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--md-text-secondary);
    cursor: pointer;
    transition: color 0.15s, background 0.15s, transform 0.1s;
}

.symbol-fav-btn:hover {
    background: rgba(255, 183, 77, 0.12);
    color: var(--md-warning);
}

.symbol-fav-btn.active {
    color: var(--md-warning);
}

.symbol-fav-btn .material-icons-round {
    font-size: 18px !important;
}

.favorites-panel {
    padding: 6px 8px;
    max-height: 140px;
}

.favorites-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.favorites-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--radius-sm);
    background: var(--md-surface-container-high);
    color: var(--md-text);
    cursor: pointer;
    font-size: 0.72rem;
    text-align: right;
    transition: border-color 0.15s, background 0.15s;
}

.favorites-item:hover {
    border-color: var(--md-primary);
    background: rgba(144, 202, 249, 0.08);
}

.favorites-item img,
.favorites-item .symbol-icon-fallback {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
}

.favorites-item strong {
    flex: 1;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorites-item .fav-remove {
    flex-shrink: 0;
    padding: 2px;
    border: none;
    background: transparent;
    color: var(--md-text-secondary);
    cursor: pointer;
    line-height: 1;
}

.favorites-item .fav-remove:hover { color: var(--md-warning); }

.favorites-empty {
    font-size: 0.72rem;
    margin: 0;
    padding: 4px 2px;
}

.symbol-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--md-surface-container);
}

.symbol-item-icon.forex-pair {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.symbol-item-icon.forex-pair img {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--md-outline-variant);
}

.symbol-item-icon.forex-pair img:first-child {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 2;
}

.symbol-item-icon.forex-pair img:last-child {
    position: absolute;
    bottom: 4px;
    right: 4px;
    z-index: 1;
}

.symbol-item-text {
    min-width: 0;
    flex: 1;
}

.symbol-item-text strong {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--md-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.symbol-item-text small {
    display: block;
    font-size: 0.65rem;
    color: var(--md-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.symbol-grid-loading,
.symbol-grid-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 32px;
    color: var(--md-text-secondary);
    font-size: 0.82rem;
}

.symbol-grid-loading.hidden,
.symbol-grid-empty.hidden { display: none; }

.symbol-icon-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #455a64, #607d8b);
    flex-shrink: 0;
}

/* ── Material buttons ── */
.md-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    flex-shrink: 0;
}

.md-btn:active { transform: scale(0.94); }

.md-btn-filled {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    color: #fff;
    box-shadow: 0 2px 6px rgba(21, 101, 192, 0.45);
}

.md-btn-filled:hover { background: linear-gradient(135deg, #1976d2, #1e88e5); }

.md-btn-tonal {
    background: rgba(102, 187, 106, 0.18);
    color: var(--md-success);
    border: 1px solid rgba(102, 187, 106, 0.3);
}

.md-btn-tonal:hover { background: rgba(102, 187, 106, 0.28); }

.md-btn-outlined {
    background: transparent;
    color: var(--md-text-secondary);
    border: 1px solid var(--md-outline);
}

.md-btn-outlined:hover {
    background: var(--md-surface-container-highest);
    color: var(--md-text);
}

.md-btn-icon {
    background: transparent;
    color: var(--md-text-secondary);
}

.md-btn-icon:hover {
    background: var(--md-surface-container-highest);
    color: var(--md-text);
}

/* ── Chips ── */
.md-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.live-chip {
    background: rgba(102, 187, 106, 0.12);
    color: var(--md-success);
    border: 1px solid rgba(102, 187, 106, 0.3);
}

.live-chip .material-icons-round { font-size: 10px !important; animation: pulse 2s infinite; }

.reconnecting {
    background: rgba(255, 183, 77, 0.15) !important;
    color: var(--md-warning) !important;
    border-color: rgba(255, 183, 77, 0.35) !important;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.symbol-chip {
    background: rgba(144, 202, 249, 0.1);
    color: var(--md-primary);
    border: 1px solid rgba(144, 202, 249, 0.25);
}

.open-chip {
    background: rgba(255, 183, 77, 0.15);
    color: var(--md-warning);
    border: 1px solid rgba(255, 183, 77, 0.35);
}

/* ── Signal / trade colors ── */
.signal-buy { color: var(--md-success); font-weight: 700; }
.signal-sell { color: var(--md-danger); font-weight: 700; }
.status-waiting { color: var(--md-warning); }
.status-active { color: var(--md-success); }
.trade-win { color: var(--md-success); }
.trade-loss { color: var(--md-danger); }
.trade-open { color: var(--md-warning); }

.sm, .material-icons-round.sm { font-size: 16px !important; vertical-align: middle; }

/* ── Table ── */
#tradesTable {
    --bs-table-bg: transparent;
    --bs-table-color: var(--md-text);
    --bs-table-hover-bg: rgba(255,255,255,0.04);
    font-size: 0.7rem;
}

#tradesTable thead th {
    position: sticky;
    top: 0;
    background: var(--md-surface-container-high);
    color: var(--md-text-secondary);
    font-weight: 600;
    font-size: 0.65rem;
    padding: 5px 8px;
    border-bottom: 1px solid var(--md-outline-variant);
    white-space: nowrap;
}

#tradesTable tbody td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--md-outline-variant);
    white-space: nowrap;
}

/* ── Chart loading ── */
.chart-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(12, 16, 24, 0.8);
    color: var(--md-text-secondary);
    font-size: 0.78rem;
}

.chart-loading.hidden { display: none; }

.chart-loading.history-loading {
    inset: auto;
    top: 10px;
    left: 10px;
    right: auto;
    bottom: auto;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--md-outline-variant);
    background: rgba(12, 16, 24, 0.88);
    pointer-events: none;
}

.spinner-sm { width: 1.2rem; height: 1.2rem; }

/* ── Backtest progress toast (single line) ── */
.backtest-progress {
    position: fixed;
    left: 50%;
    bottom: calc(var(--trades-h) + 14px);
    transform: translateX(-50%) translateY(120%);
    z-index: 1200;
    width: min(520px, calc(100vw - 32px));
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
}

.backtest-progress.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.backtest-progress-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(145deg, rgba(18, 32, 24, 0.97) 0%, rgba(12, 22, 16, 0.98) 100%);
    border: 1px solid rgba(102, 187, 106, 0.35);
    border-radius: var(--radius);
    padding: 8px 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(46, 160, 67, 0.12);
    backdrop-filter: blur(12px);
}

.backtest-progress.success .backtest-progress-card {
    border-color: rgba(102, 187, 106, 0.65);
    box-shadow: 0 8px 32px rgba(46, 160, 67, 0.2);
}

.backtest-progress.error .backtest-progress-card {
    background: linear-gradient(145deg, rgba(32, 18, 18, 0.97) 0%, rgba(22, 12, 12, 0.98) 100%);
    border-color: rgba(239, 83, 80, 0.45);
}

.backtest-progress-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: rgba(46, 160, 67, 0.2);
    color: #66bb6a;
    flex-shrink: 0;
}

.backtest-progress.error .backtest-progress-icon {
    background: rgba(239, 83, 80, 0.2);
    color: #ef5350;
}

.backtest-progress-step {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 0.78rem;
    font-weight: 500;
    color: #c8e6c9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.backtest-progress.error .backtest-progress-step {
    color: #ffcdd2;
}

.backtest-progress-pct {
    font-size: 0.78rem;
    font-weight: 700;
    color: #81c784;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 2.5em;
    text-align: left;
}

.backtest-progress.error .backtest-progress-pct {
    color: #ef9a9a;
}

.backtest-progress-track {
    width: 64px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    flex-shrink: 0;
}

.backtest-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2ea043 0%, #66bb6a 50%, #81c784 100%);
    transition: width 0.35s ease;
    box-shadow: 0 0 12px rgba(102, 187, 106, 0.5);
}

.backtest-progress.error .backtest-progress-fill {
    background: linear-gradient(90deg, #c62828 0%, #ef5350 100%);
    box-shadow: none;
}

html[data-theme="light"] .backtest-progress-card {
    background: linear-gradient(145deg, rgba(232, 245, 233, 0.98) 0%, rgba(255, 255, 255, 0.99) 100%);
    border-color: rgba(46, 125, 50, 0.35);
}

html[data-theme="light"] .backtest-progress-step { color: #388e3c; }
html[data-theme="light"] .backtest-progress-pct { color: #2e7d32; }

.md-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Light theme ── */
html[data-theme="light"] {
    --md-surface: #f0f4f8;
    --md-surface-container: #ffffff;
    --md-surface-container-high: #f5f7fa;
    --md-surface-container-highest: #e8edf2;
    --md-outline: rgba(0, 0, 0, 0.1);
    --md-outline-variant: rgba(0, 0, 0, 0.06);
    --md-text: #1a2332;
    --md-text-secondary: #5a6a7a;
    --md-primary: #1565c0;
    --scrollbar-track: var(--md-surface-container-high);
    --scrollbar-thumb: rgba(21, 101, 192, 0.28);
    --scrollbar-thumb-hover: rgba(21, 101, 192, 0.45);
    --scrollbar-thumb-border: var(--md-surface-container-high);
}

html[data-theme="light"] .chart-stage {
    background: radial-gradient(ellipse at 30% 20%, #eef2f7 0%, #f8fafc 60%, #fff 100%);
}

/* ── Responsive ── */
@media (max-width: 1100px) {
    :root { --side-width: 175px; --trades-h: 100px; }
}

@media (max-width: 900px) {
    :root { --trades-h: 100px; }

    .dashboard-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto minmax(260px, 1fr) auto var(--trades-h);
    }

    .app-bar {
        flex-wrap: wrap;
        min-height: auto;
        padding: 6px 10px;
    }

    .side-panel {
        border-inline-start: none;
        border-top: 1px solid var(--md-outline-variant);
        max-height: 110px;
    }

    #panelSignal { border-top: none; }

    .chart-panel {
        border-inline-start: none;
        min-height: 260px;
    }

    .panel-scroll { max-height: 72px; }
}
