:root {
    --bg: #ccd2d9;
    --panel: #e7ecf1;
    --panel-2: #dbe2e9;
    --panel-3: #cfd7e0;
    --line: #9eabb8;
    --text: #0f1720;
    --muted: #4b5966;
    --accent: #347fc1;
    --accent-2: #1e5f97;
    --link: #0f6cbf;
    --link-hover: #0a4f8f;
    --danger: #c23a3a;
    --success: #167f4a;
    --warning: #a26400;
    --btn-bg: linear-gradient(180deg, #edf2f6 0%, #d2dbe4 100%);
    --btn-text: #0b0d10;
    --btn-border: #8998a8;
    --btn-ghost-bg: linear-gradient(180deg, #e6edf3 0%, #d5dde6 100%);
    --btn-ghost-text: var(--text);
    --btn-ghost-border: var(--line);
    --nav-bg: linear-gradient(180deg, #e8edf2 0%, #d6dee7 100%);
    --nav-hover-bg: linear-gradient(180deg, #f0f4f7 0%, #d0d9e3 100%);
    --nav-hover-border: #8ea5bb;
    --input-bg: #f0f4f7;
    --input-border: #8f9daa;
    --label-text: #3f4e5b;
    --panel-contrast: #eaf0f5;
    --workspace-bg: linear-gradient(180deg, #d3d9e0 0%, #c5cdd6 100%);
    --workspace-border: #8e9dab;
    --shadow-soft: 0 10px 24px rgba(34, 43, 53, 0.1);
    --shadow-panel: 0 8px 18px rgba(34, 43, 53, 0.13);
    --chart-bg: var(--panel);
    --chart-surface: var(--panel);
    --chart-line: var(--workspace-border);
    --chart-text: var(--text);
    --green: #7dff7d;
    --red: #f07d7d;
    --white: #ffffff;
    --font: "Segoe UI", "Tahoma", sans-serif;
    --mono: "Consolas", "Courier New", monospace;
}
body[data-theme="dark"] {
    --bg: #0a0c0f;
    --panel: #0b0d10;
    --panel-2: #101318;
    --panel-3: #151922;
    --line: #2a313b;
    --text: #f2f2f2;
    --muted: #bcc3cb;
    --accent: #63b3ff;
    --accent-2: #8cc8ff;
    --link: #8cc8ff;
    --link-hover: #b8dcff;
    --danger: #f07d7d;
    --success: #7dffb0;
    --warning: #ffd37d;
    --btn-bg: #d7dce1;
    --btn-text: #0b0d10;
    --btn-border: #8c98a6;
    --btn-ghost-bg: var(--panel-2);
    --btn-ghost-text: var(--text);
    --btn-ghost-border: var(--line);
    --nav-bg: #151920;
    --nav-hover-bg: #1a2029;
    --nav-hover-border: #39424f;
    --input-bg: #0c1015;
    --input-border: #495463;
    --label-text: #c8d0d8;
    --panel-contrast: #12171d;
    --workspace-bg: #151a21;
    --workspace-border: #313944;
    --chart-bg: #090d12;
    --chart-surface: #0f1318;
    --chart-line: #2f3741;
    --chart-text: #dce3ea;
    --shadow-soft: 0 14px 32px rgba(0, 0, 0, 0.3);
    --shadow-panel: 0 12px 24px rgba(0, 0, 0, 0.38);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); }
.layout-shell { display: flex; height: 100vh; overflow: hidden; }
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 2px; }
.topbar strong { font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.chip.value-up { background: rgba(22,127,74,0.12); color: var(--success); border-color: rgba(22,127,74,0.25); }
.chip.value-down { background: rgba(194,58,58,0.12); color: var(--danger); border-color: rgba(194,58,58,0.25); }
.desktop-app-tabs { display: flex; background: var(--panel-2); border-bottom: 1px solid var(--line); padding: 0 10px; }
.desktop-app-tab { padding: 8px 16px; color: var(--muted); font-size: 12px; text-decoration: none; border-bottom: 2px solid transparent; }
.desktop-app-tab.active { color: var(--text); border-color: var(--accent); font-weight: 700; }
.desktop-trading-app { flex: 1; overflow: auto; padding: 16px; }
.mt5-layout { display: flex; gap: 16px; }
.mt5-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.mt5-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow-panel); }
.mt5-chart-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow-panel); }
.mt5-panel-title { padding: 8px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; justify-content: space-between; }
.mt5-panel-title-with-badges { gap: 8px; }
.chart-stage { padding: 10px; background: var(--chart-bg); }

/* Chart slots */
.chart-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; background: var(--chart-bg); }
.chart-slot { background: var(--chart-surface); border: 1px solid var(--chart-line); border-radius: 6px; display: flex; flex-direction: column; height: 320px; }
.slot-header { padding: 8px 10px; font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--chart-line); color: var(--chart-text); background: rgba(0,0,0,0.03); flex-shrink: 0; }
.slot-header .slot-token { color: var(--accent); text-transform: uppercase; }
.chart-slot-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.slot-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 13px; font-style: italic; }
.slot-legend { display: flex; gap: 12px; padding: 6px 10px; font-size: 11px; border-top: 1px solid var(--chart-line); background: rgba(0,0,0,0.03); }
.slot-legend .legend-item { display: flex; align-items: center; gap: 4px; }
.slot-legend .dot { width: 8px; height: 8px; border-radius: 50%; }
.slot-legend .entry { background: #2563eb; }
.slot-legend .tp { background: #10b981; }
.slot-legend .sl { background: #ef4444; }
.slot-legend .current { background: #f59e0b; }

@media (max-width: 1100px) {
    .chart-slots { grid-template-columns: 1fr; }
}

.chart-grid-panels { display: grid; grid-template-columns: 1fr 280px; gap: 14px; }
.chart-panel-main { min-width: 0; }
.chart-side-panel { display: flex; flex-direction: column; }
.mt5-watch-header { display: grid; grid-template-columns: 1fr 1fr 0.5fr; gap: 6px; padding: 6px 10px; font-size: 10px; color: var(--muted); border-bottom: 1px solid var(--line); }
.mt5-watchlist { max-height: 200px; overflow: auto; font-size: 12px; }
.mt5-watch-row { display: grid; grid-template-columns: 1fr 1fr 0.5fr; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.mt5-watch-row .symbol { font-weight: 700; }
.mt5-watch-row .meta { color: var(--muted); }
.mt5-watch-row .score { text-align: right; font-weight: 700; color: var(--accent); }
.toolbox-grid { display: grid; grid-template-columns: 1fr 280px; gap: 14px; }
.trading-primary-grid { }
.mt5-toolbox { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow-panel); }
.groupbox-body { padding: 12px; }
.groupbox-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.groupbox-line:last-child { border-bottom: none; }
.dial-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.dial-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.dial-caption { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.dial { width: 72px; height: 72px; margin: 0 auto; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--value) * 360deg), var(--line) 0); padding: 5px; }
.dial-inner { width: 100%; height: 100%; border-radius: 50%; background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.dial-inner strong { font-size: 13px; line-height: 1; }
.dial-inner span { font-size: 9px; color: var(--muted); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 4px; border: 1px solid var(--btn-border); background: var(--btn-bg); color: var(--btn-text); font-weight: 600; cursor: pointer; font-size: 12px; }
.btn.value-up { background: rgba(22,127,74,0.12); color: var(--success); border-color: rgba(22,127,74,0.35); }
.btn.value-down { background: rgba(194,58,58,0.12); color: var(--danger); border-color: rgba(194,58,58,0.35); }
.btn.ghost { background: var(--btn-ghost-bg); color: var(--btn-ghost-text); border-color: var(--btn-ghost-border); }
.btn.mode-live { background: rgba(194,58,58,0.12); color: var(--danger); border-color: rgba(194,58,58,0.45); }
.btn.mode-dryrun { background: rgba(52,127,193,0.12); color: var(--accent); border-color: rgba(52,127,193,0.35); }
.btn.mode-live:hover, .btn.mode-dryrun:hover { filter: brightness(0.95); }
.btn-close { background: rgba(194,58,58,0.08); color: var(--danger); border-color: rgba(194,58,58,0.25); font-size: 10px; padding: 3px 6px; }
.btn-close:hover { background: rgba(194,58,58,0.18); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th { text-align: left; padding: 8px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: none; }
.value-up { color: var(--success); font-weight: 700; }
.value-down { color: var(--danger); font-weight: 700; }
.trades-history-table-shell { max-height: 280px; overflow: auto; }
#logs-box { white-space: pre-wrap; }
.ai-badges { display: flex; gap: 6px; }
.ai-badge { font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 6px; border-radius: 10px; background: rgba(52,127,193,0.12); color: var(--accent); border: 1px solid rgba(52,127,193,0.2); }

.slot-pnl-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    pointer-events: none;
    min-width: 90px;
}
.slot-pnl-badge strong { font-size: 16px; line-height: 1.2; }
.slot-pnl-badge span { font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 900px) {
    .chart-grid-panels { grid-template-columns: 1fr; }
    .chart-side-panel { max-height: none; }
    .toolbox-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    html, body { height: auto; overflow: auto; }
    .layout-shell { display: block; height: auto; }
    .content { overflow: visible; }
    .topbar { flex-direction: column; gap: 8px; align-items: flex-start; }
    .topbar-actions { width: 100%; justify-content: space-between; }
    .desktop-trading-app { padding: 8px; }
    .mt5-layout { display: block; }
    .chart-slots { grid-template-columns: 1fr; }
    .chart-slot { height: 280px; }
    .chart-slot-stage { min-height: 0; }
    .slot-header { font-size: 11px; }
    .slot-legend { flex-wrap: wrap; gap: 8px; font-size: 10px; }
    .dial-grid { grid-template-columns: repeat(2, 1fr); }
    .dial { width: 64px; height: 64px; }
    .dial-inner strong { font-size: 12px; }
    .mt5-watch-header { font-size: 9px; }
    .mt5-watch-row { font-size: 11px; }
    .table { font-size: 10px; }
    .table th, .table td { padding: 5px 6px; }
    .groupbox-line { font-size: 12px; }
    .btn { font-size: 11px; padding: 5px 8px; }
    .mt5-panel-title { font-size: 11px; }
    #logs-box { font-size: 10px; }
    .slot-pnl-badge { padding: 4px 8px; min-width: 70px; }
    .slot-pnl-badge strong { font-size: 13px; }
    .slot-pnl-badge span { font-size: 8px; }
}

@media (max-width: 420px) {
    .dial-grid { grid-template-columns: repeat(2, 1fr); }
    .dial { width: 58px; height: 58px; padding: 4px; }
    .dial-inner strong { font-size: 11px; }
    .dial-inner span { font-size: 8px; }
    .chart-slot { height: 240px; }
    .chart-slot-stage { min-height: 0; }
    .slot-legend .legend-item:nth-child(n+4) { display: none; }
    .slot-legend { justify-content: space-between; }
    .topbar strong { font-size: 15px; }
    .chip { font-size: 10px; padding: 2px 5px; }
}
