/* Retirement Planning Dashboard — Base Styles */

/* ── Color tokens ────────────────────────────────────────────────────── */
:root {
    --bg-page: #f5f6fa;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8f9fb;
    --bg-table-header: #f5f5f5;
    --bg-table-hover: #f0f7ff;
    --bg-secondary-btn: #e5e7eb;
    --bg-progress: #e5e7eb;
    --bg-tag: #e8e8e8;

    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #666;
    --text-caption: #888;
    --text-faint: #999;
    --text-secondary-btn: #374151;
    --text-label: #374151;
    --text-tag: #333;

    --border-main: #e0e0e0;
    --border-light: #eee;
    --border-input: #d1d5db;
    --border-card-alt: #e8eaed;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-link: #4a90d9;
    --accent-info: #3498db;

    --color-success: #27ae60;
    --color-warning: #f39c12;
    --color-warning-end: #e67e22;
    --color-error: #e74c3c;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-page: #0f1117;
        --bg-surface: #1a1b26;
        --bg-surface-alt: #21222e;
        --bg-table-header: #21222e;
        --bg-table-hover: #1e2a3a;
        --bg-secondary-btn: #2d2f3b;
        --bg-progress: #2d2f3b;
        --bg-tag: #2d2f3b;

        --text-primary: #e0e0e8;
        --text-secondary: #a0a4b0;
        --text-muted: #8a8e9a;
        --text-caption: #707480;
        --text-faint: #606470;
        --text-secondary-btn: #c0c4d0;
        --text-label: #c0c4d0;
        --text-tag: #d0d0d8;

        --border-main: #2d2f3b;
        --border-light: #252738;
        --border-input: #3a3c4e;
        --border-card-alt: #2d2f3b;

        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --accent-link: #60a5fa;
        --accent-info: #60a5fa;

        --color-success: #34d058;
        --color-warning: #f5a623;
        --color-warning-end: #e8913a;
        --color-error: #f85149;
    }
}

/* ── Reset ───────────────────────────────────────────────────────────── */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-page);
    line-height: 1.5;
}

/* Layout: sidebar + main content */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar — pinned to viewport, never scrolls with page */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-main);
    padding: 20px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Sidebar resize handle — sticky like sidebar */
.sidebar-resize-handle {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 10;
    margin-left: -3px;
    margin-right: -2px;
    transition: background 0.15s;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle:active {
    background: var(--accent);
}

.sidebar h2 {
    font-size: 1.1em;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.sidebar h3 {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.sidebar-section {
    padding: 12px 0;
    border-top: 1px solid var(--border-light);
}

.sidebar-section:first-of-type {
    border-top: none;
}

/* Main content */
.content {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
}

.content h1 {
    font-size: 1.6em;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Tab navigation */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-main);
    margin-bottom: 24px;
}

.tab {
    padding: 10px 20px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.95em;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Tab content area */
.tab-content {
    min-height: 400px;
}

/* Utility classes */
.caption {
    font-size: 0.82em;
    color: var(--text-caption);
}

.help-text {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
}

.muted {
    color: var(--text-faint);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 20px;
    font-size: 0.95em;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-secondary-btn);
    color: var(--text-secondary-btn);
}

.btn-secondary:hover {
    background: var(--border-input);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

th {
    font-weight: 600;
    font-size: 0.85em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 16px;
}

/* Metric display */
.metrics-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.metric {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: 8px;
    padding: 12px 16px;
    min-width: 160px;
    flex: 1;
}

.metric-label {
    font-size: 0.8em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.metric-value {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--text-primary);
}

/* Chart containers */
.chart-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-progress);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s;
}

/* Button loading state (HTMX) */
.btn.htmx-request {
    opacity: 0.65;
    pointer-events: none;
    cursor: wait;
}
.btn.htmx-request::after {
    content: " ...";
}

/* Form elements */
input[type="number"],
select {
    padding: 6px 10px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-size: 0.9em;
    width: 100%;
    background: var(--bg-surface);
    color: var(--text-primary);
}

label {
    display: block;
    font-size: 0.85em;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-label);
}

/* Form row (multi-column) */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
}

/* Sidebar: param cards */
.param-card {
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-card-alt);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.param-card-header {
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    margin-bottom: 4px;
}

/* Sidebar: params table */
.params-table {
    width: 100%;
    border-collapse: collapse;
}

.params-table td {
    padding: 2px 4px;
    border: none;
    font-size: 0.85em;
}

.param-label {
    font-weight: 500;
    white-space: nowrap;
    color: var(--text-secondary);
}

.param-value {
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

/* Sidebar: form groups */
.form-group {
    margin-bottom: 10px;
}

/* Sidebar: radio buttons */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    font-weight: normal;
    cursor: pointer;
}

.radio-label input[type="radio"] {
    width: auto;
}

/* Sidebar: small button variant */
.btn-sm {
    padding: 5px 12px;
    font-size: 0.82em;
    margin-top: 8px;
    width: 100%;
}

/* Collapsible sections (HTML <details>) */
.section-collapsible {
    margin-bottom: 16px;
}

.section-collapsible summary {
    cursor: pointer;
    padding: 8px 0;
    user-select: none;
}

.section-collapsible summary:hover {
    color: var(--accent);
}

.section-collapsible[open] summary {
    margin-bottom: 12px;
}

/* Checkbox grid (for sweep parameters) */
.checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.cb-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    cursor: pointer;
}

.cb-label input[type="checkbox"] {
    margin: 0;
}

.bulk-toggle {
    font-size: 0.8em;
    font-weight: normal;
    margin-left: 6px;
}
.bulk-toggle a {
    color: var(--accent-link);
    text-decoration: none;
    margin: 0 2px;
}
.bulk-toggle a:hover {
    text-decoration: underline;
}

/* Data tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88em;
}

.data-table th,
.data-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-main);
}

.data-table th {
    background: var(--bg-table-header);
    font-weight: 600;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: var(--bg-table-hover);
}

/* Responsive: collapse sidebar on small screens */
@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border-main);
    }
    .content {
        padding: 16px;
    }
    .sidebar-resize-handle {
        display: none;
    }
    .tabs {
        overflow-x: auto;
    }
}

/* ── Result expiry banner ──────────────────────────────────────────────── */

.result-expiry-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    margin-bottom: 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-light);
}

.result-expiry-banner.warning {
    color: var(--color-warning-end);
    background: color-mix(in srgb, var(--color-warning) 10%, var(--bg-surface));
    border-color: var(--color-warning);
}

.result-expiry-banner.expired {
    color: var(--color-error);
    background: color-mix(in srgb, var(--color-error) 10%, var(--bg-surface));
    border-color: var(--color-error);
}

.result-expiry-banner .expiry-timer {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
