/* Final layer (loaded last): one type system, System 1 palette for the dashboard in light AND dark,
   a toolbar that collapses instead of cutting items off, and the Bots page as a full tab. */

/* ---------- type + focus + motion ---------- */
:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}
body { font-family: var(--font-sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
.mono, .tb-bot-pnl, .timer-countdown, .bp-row b, .bp-gate em, .dash-kpi-val { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: var(--radius); }
.toolbar :focus-visible { outline-offset: -2px; }
@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; }
}

/* ---------- dashboard palette = System 1 (Quant Bot Command), follows the theme switch ---------- */
html[data-theme="light"] body, html:not([data-theme]) body {
    --bg-dashboard: #f6f9ff; --dash-grid: #e0ebf9;
    --dash-card-bg: #ffffff; --dash-card-border: #c9d7e7; --dash-card-subtle: #f0f5fc;
    --dash-text-head: #0b1c30; --dash-text-body: #2d4157; --dash-text-muted: #54677e;
    --dash-accent-blue: #006398; --dash-accent-bg: #e5f3fc;
    --dash-green: #087e5a; --dash-green-bg: #e8f8f1;
    --dash-red: #c83353; --dash-red-bg: #fff0f3;
    --dash-amber: #a66806; --dash-amber-bg: #fff7e9;
}
html[data-theme="dark"] body {
    --bg-dashboard: #080c14; --dash-grid: #182239;
    --dash-card-bg: #111c2c; --dash-card-border: #273a55; --dash-card-subtle: #142339;
    --dash-text-head: #eaf2ff; --dash-text-body: #c3d2e3; --dash-text-muted: #a4b6ca;
    --dash-accent-blue: #76c6fb; --dash-accent-bg: #102e46;
    --dash-green: #58d5a6; --dash-green-bg: #12382e;
    --dash-red: #ff879d; --dash-red-bg: #40232e;
    --dash-amber: #ffd084; --dash-amber-bg: #44341b;
}
.drawer-body {
    background-color: var(--bg-dashboard); color: var(--dash-text-body);
    background-image: linear-gradient(var(--dash-grid) 1px, transparent 1px), linear-gradient(90deg, var(--dash-grid) 1px, transparent 1px);
    background-size: 48px 48px; background-attachment: local;
}
.drawer-body .dash-container { background: transparent; }
/* pastel bot chips from System 1 become dark surfaces in the dark theme */
html[data-theme="dark"] .bot-status-chip { background: var(--dash-card-subtle); border-color: var(--dash-card-border); }
html[data-theme="dark"] .bot-status-chip.online .bot-status-value { color: var(--dash-green); }
html[data-theme="dark"] .bot-status-chip.offline .bot-status-value { color: var(--dash-red); }
html[data-theme="dark"] .bot-status-name { color: var(--dash-text-muted); }
html[data-theme="dark"] .bot-status-mark { background: var(--dash-accent-bg); color: var(--dash-accent-blue); }
.bot-status-mark svg { width: 18px; height: 18px; }
.btn-tel-action { display: inline-flex; align-items: center; gap: 6px; }
.btn-tel-action svg { width: 14px; height: 14px; flex: 0 0 14px; }

/* ---------- Bots = a full tab (covers charts + side panel), starts at the top ---------- */
#view-chart > .bots-drawer {
    position: absolute; inset: 0; z-index: 35; flex: none; border: 0; background: var(--bg-dashboard);
}
@media (max-width: 860px) {
    #view-chart > .bots-drawer,
    .bots-drawer {
        position: fixed !important;
        top: 42px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 56px !important;
        width: 100vw !important;
        height: calc(100dvh - 42px - 56px) !important;
        max-height: calc(100dvh - 42px - 56px) !important;
        z-index: 9999 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: #f8fafc !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain !important;
    }
    #view-chart > .bots-drawer[hidden],
    .bots-drawer[hidden] {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
    .drawer-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain !important;
        padding-bottom: 24px !important;
    }
}
.drawer-bar { height: 44px; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--border); background: var(--bg); }
.drawer-bar b { font-size: 14px; }
.drawer-back { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); font-weight: 600; font-size: 12.5px; color: var(--text); }
.drawer-back:hover { background: var(--bg-hover); border-color: var(--blue); }
.drawer-back svg { width: 14px; height: 14px; }

/* ---------- toolbar: compact single line, zero horizontal scrolling ---------- */
.toolbar {
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
    flex-wrap: nowrap !important;
    width: 100% !important;
    max-width: 100vw !important;
    gap: 4px !important;
    padding: 0 8px !important;
    height: 40px !important;
}
.toolbar::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
.candle-timer-chip, .candle-timer-chip * { white-space: nowrap; }
.candle-timer-chip { flex: 0 0 auto; height: 28px; padding: 0 8px; gap: 5px; font-size: 11.5px; }
.candle-timer-chip strong { font-size: 11.5px; }
.tb-strategy { flex: 0 0 auto !important; max-width: 155px !important; }
.tb-strategy .btn-text, #strategy-label {
    display: inline-block !important;
    max-width: 110px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 11.5px !important;
}
.toolbar > * { flex-shrink: 0; }
.toolbar .tb-strategy { flex-shrink: 0 !important; }
.tb-bot { height: 28px; padding: 0 7px; font-size: 11px; }
.tb-bot-name { max-width: 60px; overflow: hidden; text-overflow: ellipsis; }
.tb-bot-pnl { font-size: 11px; }
.tb-bot-state { font-size: 10px; }
.tool-btn.tb-nav-tab { padding: 0 8px; }

/* secondary buttons keep only their icon (name in the tooltip) */
#top-tab-option-details .btn-text, .tb-alerts .btn-text, .tb-draw .btn-text,
.tb-layout .btn-text, .tb-theme .btn-text { display: none !important; }
.toolbar .tool-btn:not(#strategy-btn):not(#split-btn) { width: 28px !important; height: 28px !important; padding: 0 !important; justify-content: center !important; }
.toolbar .tool-btn:not(#strategy-btn):not(#split-btn) .btn-text { display: none !important; }
.toolbar #split-btn { height: 28px !important; padding: 0 8px !important; font-size: 11px !important; }

@media (max-width: 1500px) {
    .tb-bot-state, #market-badge { display: none; }
}
@media (max-width: 1280px) {
    .tb-bot-name { max-width: 50px; }
    #data-badge { display: none !important; }
}
@media (max-width: 860px) {
    .tb-bots { display: none; }                   /* phones switch bots from the dropdown */
}

html[data-theme="dark"] .status-line { background: var(--dash-card-bg); border-color: var(--dash-card-border); }
html[data-theme="dark"] .status-line #dash-server-clock, html[data-theme="dark"] .status-line .status-right { color: var(--dash-text-body); }
html[data-theme="dark"] .state-marker { background: var(--dash-accent-bg); color: var(--dash-accent-blue); border-color: var(--dash-card-border); }

.dash-canvas-wrap { position: relative; }
.dash-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-size: 13px; color: var(--dash-text-muted); text-align: center; padding: 16px; }

/* narrow side panel: long gate texts wrap instead of squeezing the label */
.bp-gate { align-items: baseline; }
.bp-gate em { overflow-wrap: anywhere; }
.bp-trade .bp-row { flex-wrap: wrap; row-gap: 0; }
.bp-gate, .bp-row { font-size: 12px; }

@media (max-width: 860px) { .drawer-bar .muted { display: none; } }

.dash-warn { margin: 8px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 12.5px; color: var(--dash-amber); background: var(--dash-amber-bg); border: 1px solid var(--dash-amber); }
#riskCostNote { display: block; font-size: 12px; line-height: 1.5; color: var(--dash-text-muted); }
.pane-option.is-loading .pane-body > :not(.pane-status) { visibility: hidden; }
.pane-status {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 6;
    display: inline-flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 10px;
    background: var(--bg, #fff); border: 1px solid var(--border-strong, #cbd5e1);
    color: var(--text-muted, #475569); font: 600 12.5px var(--font-sans, sans-serif);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}
.pane-status[hidden] { display: none !important; }
.pane-status.is-error { color: var(--red, #dc2626); border-color: rgba(220, 38, 38, 0.35); }
.pane-retry-btn { border: 1px solid var(--border-strong, #cbd5e1); background: var(--paper, #f8fafc); color: var(--text, #0f172a); border-radius: 6px; padding: 3px 10px; font: 700 11.5px var(--font-sans, sans-serif); cursor: pointer; }
.pane-retry-btn[hidden] { display: none; }

.bp-warn { margin: 0; padding: 6px 8px; border-radius: var(--radius); font-size: 12px; line-height: 1.4; color: #8a5a00; background: var(--orange-soft); border: 1px solid var(--orange); }
:root[data-theme="dark"] .bp-warn { color: #ffd084; background: #44341b; border-color: #8a6a2a; }

/* ---------- chart layout like TradingView ---------- */
:root { --sidebar-w: clamp(280px, 20vw, 340px); }
#view-chart .pane-main { flex: 1.35 1 0; }
#view-chart .pane-option { flex: 1 1 0; border-left: 1px solid var(--border-strong); }
.legend { font-size: 12px; line-height: 1.55; top: 4px; left: 8px; }
.legend-title { font-weight: 600; }
.pane-head { height: 30px; padding: 0 4px 0 10px; font-size: 12px; }
.pane-title { font-weight: 600; }
.draw-bar { width: 44px; }
.price-countdown {
    position: absolute !important;
    right: 0 !important;
    z-index: 50 !important;
    pointer-events: none !important;
    height: 18px !important;
    line-height: 18px !important;
    text-align: center !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Inter, Roboto, monospace !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    font-variant-numeric: tabular-nums !important;
    border-radius: 2px !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4) !important;
    display: block !important;
}
.price-countdown[hidden] {
    display: none !important;
}
