/* ============================================================
   theme.css — System-wide light/dark theme variables
   Dark is the default (:root); light overrides via
   html[data-theme="light"].
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;1,600&display=swap');

/* ── System font: Segoe UI everywhere ─────────────────────────
   Enforced with !important so it beats every per-template inline
   `body { font-family: ... }` rule regardless of load order. */
html {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Logo wordmark: ⚡ RAYVAT — R in yellow, italic Poppins, slightly larger */
html body .sidebar-logo h2 {
    font-family: 'Poppins', 'Trebuchet MS', system-ui, sans-serif !important;
    font-size: 1.6rem !important;
    font-style: italic !important;
    font-weight: 600 !important;
}
html body .sidebar-logo h2 .logo-r {
    color: #FFD400 !important;
    font-size: inherit !important;
    font-style: italic !important;
}
html body,
html body button,
html body input,
html body select,
html body textarea {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
}
html body .mono {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
    font-variant-numeric: tabular-nums;
}

:root {
    --bg-body: #0f0f1a;
    --bg-sidebar-top: #1a1a2e;
    --bg-sidebar-bottom: #16213e;
    --bg-panel: #1a1a2e;
    --bg-card: rgba(255,255,255,0.05);
    --bg-input: #14142a;
    --bg-hover: rgba(255,255,255,0.05);
    --bg-soft: rgba(255,255,255,0.04);
    --bg-strong: #0a0a14;

    --border: #2a2a4e;
    --border-alt: #2a2a4a;
    --border-strong: #3a3a5e;
    --border-row: #26264a;
    --border-soft: #1a1a30;

    --text: #e0e0e0;
    --text-strong: #ffffff;
    --text-muted: #aaa;
    --text-dim: #888;
    --text-faint: #666;
    --text-faintest: #444;

    --accent: #10ADDB;
    --accent-dark: #0C8FB8;
    --accent-light: #3FC3E8;
    --accent-soft: #6FCFEA;
    --indigo: #667eea;
    --indigo-dark: #764ba2;
    --purple: #8e44ad;
    --purple-soft: #a569bd;
    --purple-light: #d8b4fe;

    --green: #2ecc71;
    --green-strong: #27ae60;
    --green-soft: #4caf50;
    --red: #e74c3c;
    --red-strong: #c0392b;
    --red-soft: #ec7063;
    --blue: #3498db;
    --blue-strong: #2980b9;
    --blue-soft: #5dade2;
    --amber: #f39c12;

    --bg-green-soft: #1a3a1a;
    --bg-red-soft: #3a1a1a;
    --bg-yellow-soft: #3a3a1a;
    --bg-blue-soft: #1a2a3a;
    --bg-purple-soft: rgba(142,68,173,0.15);

    --shadow: 0 4px 12px rgba(0,0,0,0.3);
    --toggle-bg: #1a1a2e;
    --toggle-border: #3a3a5e;
    --toggle-color: #10ADDB;

    --bg-ghost: rgba(255,255,255,0.08);
    --bg-accent-soft: rgba(16,173,219,0.15);
    --bg-blue-soft2: rgba(102,126,234,0.15);
    --bg-black-soft: rgba(0,0,0,0.2);
    --grid-line: rgba(255,255,255,0.05);

    --glass-bg: rgba(255,255,255,0.08);
    --glass-bg-2: rgba(255,255,255,0.04);
    --glass-hover: rgba(255,255,255,0.12);
    --glass-hover-strong: rgba(255,255,255,0.16);
    --glass-border: rgba(255,255,255,0.14);
    --glass-border-strong: rgba(255,255,255,0.26);
    --glass-shadow: 0 8px 32px rgba(0,0,0,0.28);
    --glass-blur: 16px;
    --glass-sat: 140%;
    --glass-radius: 14px;
}

html[data-theme="light"] {
    --bg-body: #FCFCFC;
    --bg-sidebar-top: #ffffff;
    --bg-sidebar-bottom: #e2e8f0;
    --bg-panel: #ffffff;
    --bg-card: rgba(255,255,255,0.9);
    --bg-input: #ffffff;
    --bg-hover: rgba(15,23,42,0.06);
    --bg-soft: rgba(15,23,42,0.04);
    --bg-strong: #f4f6fa;

    --border: #cfd8e3;
    --border-alt: #d3dbe6;
    --border-strong: #b8c2cf;
    --border-row: #e3e9f0;
    --border-soft: #e9eef4;

    --text: #1c2333;
    --text-strong: #0f1420;
    --text-muted: #4a5163;
    --text-dim: #6b7280;
    --text-faint: #9aa1b0;
    --text-faintest: #b6bdca;

    --accent: #10ADDB;
    --accent-dark: #0C8FB8;
    --accent-light: #3FC3E8;
    --accent-soft: #0E9BC4;
    --indigo: #4f46e5;
    --indigo-dark: #6d28d9;
    --purple: #7c3aed;
    --purple-soft: #8b5cf6;
    --purple-light: #c4b5fd;

    --green: #16a34a;
    --green-strong: #15803d;
    --green-soft: #22c55e;
    --red: #dc2626;
    --red-strong: #b91c1c;
    --red-soft: #f87171;
    --blue: #2563eb;
    --blue-strong: #1d4ed8;
    --blue-soft: #60a5fa;
    --amber: #d97706;

    --bg-green-soft: #d1fae5;
    --bg-red-soft: #fee2e2;
    --bg-yellow-soft: #fef3c7;
    --bg-blue-soft: #dbeafe;
    --bg-purple-soft: rgba(124,58,237,0.12);

    --shadow: 0 4px 12px rgba(15,23,42,0.08);
    --toggle-bg: #ffffff;
    --toggle-border: #cfd8e3;
    --toggle-color: #10ADDB;

    --bg-ghost: rgba(15,23,42,0.08);
    --bg-accent-soft: rgba(16,173,219,0.12);
    --bg-blue-soft2: rgba(79,70,229,0.10);
    --bg-black-soft: rgba(15,23,42,0.10);
    --grid-line: rgba(15,23,42,0.08);

    --glass-bg: rgba(255,255,255,0.50);
    --glass-bg-2: rgba(255,255,255,0.30);
    --glass-hover: rgba(255,255,255,0.80);
    --glass-hover-strong: rgba(255,255,255,0.92);
    --glass-border: rgba(255,255,255,0.70);
    --glass-border-strong: rgba(255,255,255,0.90);
    --glass-shadow: 0 8px 32px rgba(15,23,42,0.10);
    --glass-blur: 18px;
    --glass-sat: 150%;
    --glass-radius: 14px;
}

/* ── Global theme toggle button (sidebar bottom) ─────────── */
#theme-toggle {
    position: static;
    margin-top: auto;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--toggle-border);
    background: var(--toggle-bg);
    color: var(--toggle-color);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
#theme-toggle:hover { transform: translateY(-1px); }

/* ============================================================
   GLASSMORPHISM — translucent panels + visible blur
   High-specificity (html body / !important) so these beat the
   per-template inline <style> skins across all pages.
   ============================================================ */

/* Flat solid body background */
html body {
    background: var(--bg-body) !important;
}
html[data-theme="light"] body {
    background: var(--bg-body) !important;
}

/* ── Shared glass recipe ── */
html body .sidebar,
html body .header,
html body .topbar,
html body .section,
html body .card,
html body .session-card,
html body .modal {
    background: var(--bg-panel) !important;
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    box-shadow: var(--glass-shadow);
}

/* Sidebar: floating full glass box with padding around it */
html body .sidebar {
    display: flex;
    flex-direction: column;
    top: 12px;
    left: 12px;
    bottom: 12px;
    width: 220px;
    min-height: 0 !important;
    padding: 18px 8px !important;
    border-radius: 18px !important;
    border: 1px solid var(--glass-border) !important;
}
html body .main-content {
    margin-left: 244px !important;
}

/* Main heading: rounded glass box with gap from sidebar/top */
html body .header,
html body .topbar {
    border-radius: var(--glass-radius) !important;
    margin-top: 12px !important;
    margin-right: 20px !important;
    margin-left: 14px !important;
}

/* Paper-trade headers (live/dashboard/monitor/signals): cancel the extra
   main-content horizontal padding so the box spans the same width as the
   run-history/backtest headers (14-30 and 20-30 container inset). */
html body .header:has(.header-right) {
    margin-left: -16px !important;
    margin-right: -10px !important;
}

/* Page boxes: rounded glass */
html body .section,
html body .card,
html body .session-card {
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--glass-radius) !important;
}

/* Table heading rows: frosted glass band */
html body thead th {
    background: var(--bg-panel) !important;
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    border-bottom: 1px solid var(--glass-border) !important;
    box-shadow: var(--glass-shadow);
}

/* Modals: frosted overlay + glass body */
html body .modal-overlay {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
html body .modal {
    border: 1px solid var(--glass-border-strong) !important;
    border-radius: var(--glass-radius) !important;
}

/* Hover: boxes brighten to glass highlight */
html body .section:hover,
html body .card:hover,
html body .session-card:hover {
    background: var(--bg-hover) !important;
    border-color: var(--glass-border-strong) !important;
}

/* Sidebar nav: hover + selected glass highlight */
html body .sidebar-nav a:hover,
html body .sidebar-nav a.active {
    background: var(--glass-hover) !important;
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    border-radius: 8px;
}

/* Live Trading nav: pulsing green live dot right after the label text */
html body .sidebar-nav a[href="/paper-trade/live"]::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 6px;
    flex-shrink: 0;
    align-self: center;
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(46,204,113,0.7);
    animation: dbt-live-pulse 2s infinite;
}
@keyframes dbt-live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(46,204,113,0.7); }
    70%  { box-shadow: 0 0 0 6px rgba(46,204,113,0); }
    100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}

/* Compact mode: collapse sidebar inside its rounded box */
@media (max-width: 900px) {
    html body .sidebar {
        width: 60px;
        left: 8px;
        top: 8px;
        bottom: 8px;
        border-radius: 14px !important;
        padding: 16px 4px !important;
    }
    html body .sidebar-logo h2,
    html body .sidebar-logo span,
    html body .sidebar-nav a span:not(.icon) {
        display: none;
    }
    html body .main-content {
        margin-left: 76px !important;
    }
    html body .header,
    html body .topbar {
        margin-left: 8px !important;
        margin-right: 8px !important;
    }
    html body .header:has(.header-right) {
        margin-left: -2px !important;
        margin-right: -2px !important;
    }
    #theme-toggle {
        width: 44px;
        min-height: 44px;
        padding: 0;
        margin-top: 12px;
        align-self: center;
    }
    #theme-toggle .tgl-label {
        display: none;
    }
}

/* ===== RESPONSIVE PASS START ===== */
/* Fluid base + box model */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: clamp(14px, 0.35vw + 13px, 16px); }
img, video, canvas, iframe { max-width: 100%; }
:root {
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
    --tap: 40px;
}

/* Touch-friendly form fields (buttons keep their own sizing) */
input, select, textarea { min-height: var(--tap); }

/* ---- Tables: rely on per-page scroll wrappers (do NOT use display:block,
   which would break position:sticky headers). Add overflow-x:auto to any
   container that lacks a wrapper so wide tables scroll internally. ---- */
html body .table-scroll,
html body .table-wrapper,
html body .sheet-content,
html body .card,
html body #feed-body,
html body #sched-body,
html body #sess-body,
html body #alerts-body,
html body #signals-body { overflow-x: auto; }

/* Tighter table density on phones */
@media (max-width: 768px) {
    table th, table td { padding: 6px 8px !important; font-size: 0.82rem; }
}
@media (max-width: 480px) {
    table th, table td { padding: 5px 6px !important; font-size: 0.78rem; }
}

/* ---- Modals / dialogs fit viewport ---- */
html body .modal,
html body .modal-content,
html body .dialog,
html body .dlg {
    max-width: min(960px, 94vw) !important;
    max-height: 90vh !important;
    overflow: auto !important;
}

/* ---- Layout helpers ---- */
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--sp-4); }
.stack-sm { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
@media (max-width: 768px) { .stack-sm { flex-direction: column; align-items: stretch; } }
.hide-xs { display: inline; }
@media (max-width: 480px) { .hide-xs { display: none !important; } }

/* ---- Sidebar drawer on small screens (off-canvas toggle) ---- */
html body .sidebar-toggle { display: none; }
#sidebar-backdrop { display: none; }
@media (max-width: 900px) {
    html body .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        width: 240px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 2000;
        overflow-y: auto;
    }
    html body .sidebar.open { transform: none; }
    html body .main-content { margin-left: 0 !important; }
    html body .sidebar-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 40px; height: 40px; margin-right: 10px;
        border: 1px solid var(--border, #3a3f4b); border-radius: 8px;
        background: var(--card, #1c1f26); color: inherit;
        cursor: pointer; font-size: 20px; flex: 0 0 auto;
    }
    #sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(0,0,0,0.45);
        z-index: 1500; display: none;
    }
    #sidebar-backdrop.show { display: block; }
}

/* ---- Header / topbar never overflow ---- */
html body .header-right,
html body .topbar { flex-wrap: wrap; min-width: 0; }

/* ---- Forms / grids stack on tablets/phones ---- */
@media (max-width: 900px) {
    .form-grid, .param-grid, .config-grid { grid-template-columns: 1fr !important; }
    html body div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    html body div[style*="repeat(5, 1fr)"] { grid-template-columns: repeat(2, 1fr) !important; }
    .modal-source-fields { grid-template-columns: 1fr !important; }
    .form-group { min-width: 0 !important; }
}

/* Action rows wrap */
html body .action-group,
html body .pf-actions,
html body .pf-left,
html body .pf-inline,
html body #daemon-panel { flex-wrap: wrap; }

/* ===== Per-page specifics ===== */

/* paper_trade/dashboard.html */
@media (max-width: 600px) {
    .session-cols { grid-template-columns: 1fr !important; }
}
html body .metrics-row[style*="repeat(3"] { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important; }

/* paper_trade/live.html */
@media (max-width: 768px) {
    #deployed-sessions td.text-right { white-space: normal !important; }
    #deployed-sessions .action-btn { margin: 2px; }
}

/* backtest_lab/configure.html */
@media (max-width: 768px) {
    .db-status-row { min-width: 0; }
    .db-name { min-width: 0; }
    .condition-row { flex-wrap: wrap; }
    .condition-field, .condition-operator, .condition-value {
        width: auto !important; flex: 1 1 120px; min-width: 0;
    }
    .condition-row .btn { flex: 0 0 auto; }
    .pf-sample-popup { min-width: 0 !important; max-width: calc(100vw - 16px) !important; }
    .query-suggestions { max-width: calc(100vw - 16px) !important; }
}

/* backtest_lab/generate_signals.html */
@media (max-width: 768px) {
    #daily-source-sqlite .form-group,
    #daily-source-mongodb .form-group,
    .form-group { min-width: 0 !important; }
}

/* backtest_lab/history.html */
.strategy-tooltip { width: auto !important; max-width: calc(100vw - 16px) !important; }
.tip-cols { flex-wrap: wrap; }
@media (max-width: 768px) { .action-group { flex-wrap: wrap; } }

/* backtest_lab/daywise_summary.html */
.search-box input { width: 100%; max-width: 220px; }

/* backtest_lab/excel_viewer.html */
@media (max-width: 768px) {
    .sheet-tabs-container { top: 0; }
    .filter-bar { top: auto; position: static; }
}

/* backtest_lab/charts.html */
@media (max-width: 480px) { .chart-wrap { height: 200px; } }

/* ===== RESPONSIVE PASS END ===== */
