:root {
    --bg: #f7f9fc;
    --bg-elev: #ffffff;
    --bg-muted: #eef2f7;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.08);
    --accent-strong: #1d4ed8;
    --teal: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --plot-text: #1e293b;
    --plot-grid: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ===== Top bar ===== */
.topbar {
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logos {
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-logo {
    height: 34px;
    width: auto;
    object-fit: contain;
    border-radius: 4px;
}
.brand-text h1 {
    font-size: 18px; font-weight: 700; letter-spacing: -0.015em;
}
.brand-text p { font-size: 12px; color: var(--text-muted); }
.topbar-meta { display: flex; align-items: center; gap: 16px; }
.api-status {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-muted);
    padding: 6px 12px; border-radius: 999px;
    background: var(--bg-muted); border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot.success { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,0.15); }
.dot.warning { background: var(--warning); box-shadow: 0 0 0 3px rgba(245,158,11,0.15); }
.dot.error   { background: var(--danger);  box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }
.ghost-link {
    color: var(--text-muted); text-decoration: none; font-size: 13px;
    padding: 6px 10px; border-radius: var(--radius-sm);
    transition: color .15s, background .15s;
}
.ghost-link:hover { color: var(--accent); background: var(--accent-soft); }

/* ===== Config tabs ===== */
.config-tabs {
    display: flex; gap: 4px; padding: 0 24px;
    border-top: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: thin;
}
.tab {
    flex-shrink: 0;
    background: transparent; border: none;
    padding: 14px 16px;
    font: inherit; color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
    position: relative; top: 1px;
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    min-width: 160px;
}
.tab .tab-label { font-weight: 600; font-size: 13px; color: inherit; }
.tab .tab-sub { font-size: 11px; color: var(--text-soft); }
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.tab.active .tab-sub { color: var(--text-muted); }

/* ===== Layout ===== */
.layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 20px;
    padding: 20px 24px 40px;
    max-width: 1700px; margin: 0 auto;
}

@media (max-width: 1000px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        max-height: none;
        overflow-y: visible;
        padding-right: 0;
    }
}

/* ===== Sidebar ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-self: start;
    position: sticky;
    top: 96px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
}
.glass {}
.panel {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px;
}
.panel-head h2 { font-size: 15px; }
.panel-head p { font-size: 12px; margin-top: 2px; }
.panel-h3 {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); margin-bottom: 12px; font-weight: 600;
}
.cfg-desc { font-size: 13px; color: var(--text-muted); margin-top: 10px; }

.controls { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.control { display: flex; flex-direction: column; gap: 6px; }
.control-label {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 12px; font-weight: 500; color: var(--text);
}
.control-value {
    font-family: var(--mono); font-size: 12px;
    color: var(--accent); font-weight: 500;
}
.control input[type=range] {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px; background: var(--bg-muted);
    border-radius: 999px; outline: none;
}
.control input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; border-radius: 999px;
    background: var(--accent); border: 2px solid var(--bg-elev);
    box-shadow: 0 0 0 1px var(--accent);
    cursor: pointer; transition: transform .1s;
}
.control input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.1); }
.control input[type=range]::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 999px;
    background: var(--accent); border: 2px solid var(--bg-elev); cursor: pointer;
}

.btn-primary {
    appearance: none; border: none; cursor: pointer;
    background: var(--accent); color: white;
    padding: 11px 16px; border-radius: var(--radius-sm);
    font: inherit; font-weight: 600; font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%;
    transition: background .15s, transform .05s;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary.running .btn-label::after { content: 'ing…'; }
.spinner {
    display: none; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.45);
    border-top-color: white; border-radius: 999px;
    animation: spin 0.8s linear infinite;
}
.btn-primary.running .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ===== Suggestions ===== */
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestion {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 12px; background: var(--bg);
    display: flex; flex-direction: column; gap: 4px;
}
.suggestion-head {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; font-size: 13px;
}
.suggestion-tag {
    font-family: var(--mono); font-size: 11px;
    background: var(--accent-soft); color: var(--accent);
    padding: 2px 8px; border-radius: 999px;
}
.suggestion-body { font-size: 12px; color: var(--text-muted); font-family: var(--mono); }

/* ===== Content area ===== */
.content { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.content-head h2 { font-size: 22px; }
.content-head p { font-size: 13px; margin-top: 4px; }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.chart-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 14px 8px;
    min-height: 500px;
    display: flex; flex-direction: column;
}
.chart-card.wide { grid-column: 1 / -1; min-height: 600px; }
.chart-card.tall { min-height: 600px; }
.chart-card .plot-host { flex: 1; min-height: 0; }
.chart-card .card-title {
    font-size: 15px; font-weight: 600;
    color: var(--text); margin-bottom: 4px;
}
.chart-card .card-sub {
    font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
}

.content-foot {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; color: var(--text-muted);
    padding-top: 8px; border-top: 1px solid var(--border);
}
.content-foot .muted { font-family: var(--mono); font-size: 11px; }

/* ===== Toast ===== */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: #0f172a; color: white;
    padding: 12px 16px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
    pointer-events: none; z-index: 50;
    max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

/* ===== Legend Panel ===== */
.legend-panel {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-muted);
}
.legend-panel strong {
    color: var(--text);
    font-weight: 600;
}

/* ===== Suggestions Count Selector ===== */
.sug-count-selector {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--bg-muted);
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.sug-count-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all .15s;
}
.sug-count-btn:hover {
    color: var(--text);
}
.sug-count-btn.active {
    background: var(--bg-elev);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

/* ===== Card Description ===== */
.card-desc {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
}
.card-desc strong {
    color: var(--text);
    font-weight: 600;
}

/* ===== Model Training Data Table ===== */
.training-panel {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-top: 28px;
}
.training-panel-head {
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}
.training-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 20px;
}
.training-desc code {
    font-family: var(--mono);
    background: var(--bg-muted);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--accent);
}
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
    background: var(--bg-elev);
}
.data-table th, .data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    background: var(--bg-muted);
    color: var(--text);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-table tr:last-child td {
    border-bottom: none;
}
.data-table tbody tr:hover {
    background: var(--bg-muted);
}

/* ===== Visualization Control Slider ===== */
.visualization-control {
    background: var(--accent-soft);
    border-radius: var(--radius-sm);
    padding: 10px;
}
.visualization-control input[type="range"] {
    accent-color: var(--accent);
}

/* ===== Custom Toggle Switch ===== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-toggle {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-strong);
    transition: .3s;
    border-radius: 20px;
}

.slider-toggle:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .slider-toggle {
    background-color: var(--accent);
}

.toggle-switch input:focus + .slider-toggle {
    box-shadow: 0 0 1px var(--accent);
}

.toggle-switch input:checked + .slider-toggle:before {
    transform: translateX(18px);
}

/* ===== Citation Card ===== */
.citation-card {
    background: rgba(124, 58, 237, 0.05);
    border: 1px solid rgba(124, 58, 237, 0.2);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-top: 8px;
    animation: fadeIn 0.25s ease-out;
}

.citation-text {
    font-size: 11px;
    color: #6d28d9;
    line-height: 1.4;
    margin: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Theme Toggle ===== */
.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.15s, border-color 0.15s;
}
.theme-toggle-btn:hover {
    background: var(--bg-muted);
    border-color: var(--border-strong);
}

/* ===== Warning Banner ===== */
.warning-banner {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-left: 4px solid var(--danger);
    color: #b91c1c;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    animation: fadeIn 0.25s ease-out;
}
body.dark-theme .warning-banner {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
}

/* ===== Secondary Button ===== */
.btn-secondary {
    appearance: none;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg-elev);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    transition: background 0.15s, border-color 0.15s;
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
    background: var(--bg-muted);
    border-color: var(--border-strong);
}

/* ===== Dynamic Table Styling ===== */
.data-table .delete-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-soft);
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.data-table .delete-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}
.table-input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 4px 8px;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.15s;
}
.table-input:focus {
    border-color: var(--accent);
}
.btn-add-table {
    border: none;
    background: var(--success);
    color: white;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
    transition: opacity 0.15s;
}
.btn-add-table:hover {
    opacity: 0.9;
}
.table-actions-cell {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

/* ===== Reset Button style inside training header ===== */
.btn-reset-data {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
}
.btn-reset-data:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.05);
}

/* ===== Mode Selector for 3D Plot ===== */
.mode-selector {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--bg-muted);
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.mode-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all .15s;
}
.mode-btn:hover {
    color: var(--text);
}
.mode-btn.active {
    background: var(--bg-elev);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

/* ===== Dark Mode Variables ===== */
body.dark-theme {
    --bg: #0f172a;
    --bg-elev: #1e293b;
    --bg-muted: #334155;
    --border: #334155;
    --border-strong: #475569;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --text-soft: #64748b;
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --accent-strong: #2563eb;
    --plot-text: #f8fafc;
    --plot-grid: #334155;
}
