/* ═══════════════════════════════════════════════════════════
   ASB Investment Calculator — Modern Design System
   Refined Emerald theme + Tailwind-compatible custom styles
   ═══════════════════════════════════════════════════════════ */

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
    --bg: #f0fdf4;
    --surface: #ffffff;
    --surface-alt: #f7fcf9;
    --surface-hover: #f0fdf4;
    --text: #14532d;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --primary: #059669;
    --primary-dark: #047857;
    --primary-darker: #065f46;
    --primary-light: #d1fae5;
    --primary-lighter: #ecfdf5;
    --primary-glow: rgba(5, 150, 105, 0.15);
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --success: #10b981;
    --info: #3b82f6;
    --line: #d1fae5;
    --line-strong: #a7f3d0;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

[data-theme="dark"] {
    --bg: #052e16;
    --surface: #0f2a1a;
    --surface-alt: #163a24;
    --surface-hover: #1a4030;
    --text: #86efac;
    --text-primary: #f0fdf4;
    --text-secondary: #a7f3d0;
    --text-muted: #6ee7b7;
    --primary: #34d399;
    --primary-dark: #10b981;
    --primary-darker: #059669;
    --primary-light: #064e3b;
    --primary-lighter: #022c22;
    --primary-glow: rgba(52, 211, 153, 0.12);
    --danger: #f87171;
    --danger-light: #3b1818;
    --warning: #fbbf24;
    --warning-light: #3b3220;
    --success: #34d399;
    --info: #60a5fa;
    --line: #064e3b;
    --line-strong: #065f46;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.45);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* ─── Base ──────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition-slow), color var(--transition-slow);
}

/* ─── App Container ─────────────────────────────────────────── */
.app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 24px 32px;
}

/* ─── Header ────────────────────────────────────────────────── */
.header {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px 32px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    transition: background var(--transition-slow), box-shadow var(--transition-slow);
    border: 1px solid var(--line);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark), var(--primary));
    opacity: 0.8;
}

.header-info h1 {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.header-info p {
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-top: 4px;
    max-width: 600px;
}

.header-info .shortcuts {
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 500;
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-lighter);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--line);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-toggles {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Version Badge ─────────────────────────────────────────── */
.status-badge {
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-lighter), var(--primary-light));
    color: var(--primary-dark);
    border: 1px solid var(--line-strong);
    letter-spacing: 0.02em;
}

/* ─── Simple Mode Toggle ────────────────────────────────────── */
.simple-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 20px;
    transition: background var(--transition);
}

.simple-mode-toggle:hover {
    background: var(--surface-hover);
}

.simple-mode-toggle input[type="checkbox"] {
    display: none;
}

.simple-mode-slider {
    width: 38px;
    height: 22px;
    background: var(--line-strong);
    border-radius: 11px;
    position: relative;
    transition: background var(--transition);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.simple-mode-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform var(--transition), background var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.simple-mode-toggle input:checked + .simple-mode-slider {
    background: var(--primary);
}

.simple-mode-toggle input:checked + .simple-mode-slider::after {
    transform: translateX(16px);
}

/* ─── Toggle Buttons (Lang, Theme) ──────────────────────────── */
.lang-toggle,
.theme-toggle {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    min-width: 44px;
    justify-content: center;
    font-family: inherit;
}

.lang-toggle:hover,
.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-lighter);
}

/* ─── Tab Navigation ────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    transition: background var(--transition-slow);
    border: 1px solid var(--line);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
    font-family: inherit;
    position: relative;
}

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

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* ─── Tab Content ───────────────────────────────────────────── */
.tab-content {
    display: none;
    animation: fadeSlideIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    transition: background var(--transition-slow), box-shadow var(--transition-slow);
    border: 1px solid var(--line);
    position: relative;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 4px;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: var(--primary);
    border-radius: 2px;
    flex-shrink: 0;
}

.card-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    padding-left: 12px;
}

.card-section {
    margin-bottom: 20px;
}

.card-section:last-child {
    margin-bottom: 0;
}

/* ─── Form Elements ─────────────────────────────────────────── */
.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.form-row label {
    min-width: 200px;
    font-size: 0.88rem;
    color: var(--text-primary);
    font-weight: 500;
}

.form-row .input-group {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 160px;
}

.form-row select,
.start-month-select {
    background: var(--surface-alt);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.88rem;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
    min-width: 140px;
    cursor: pointer;
    transition: all var(--transition);
}

.form-row select:focus,
.start-month-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row input[type="number"],
.form-row input[type="text"] {
    background: var(--surface-alt);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.92rem;
    color: var(--text-primary);
    width: 100%;
    max-width: 200px;
    transition: all var(--transition);
    font-family: inherit;
    outline: none;
}

.form-row input[type="number"]:focus,
.form-row input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row input[type="number"]::placeholder,
.form-row input[type="text"]::placeholder {
    color: var(--text-muted);
}

/* ─── Radio Group ───────────────────────────────────────────── */
.form-row .radio-group {
    display: inline-flex;
    gap: 2px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1.5px solid var(--line);
}

.radio-group label {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
    font-weight: 500;
    min-width: auto;
}

.radio-group input[type="radio"] {
    display: none;
}

.radio-group input[type="radio"]:checked + label {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px var(--primary-glow);
}

/* ─── Checkbox Row ──────────────────────────────────────────── */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--primary-lighter);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    transition: background var(--transition);
}

.checkbox-row:hover {
    background: var(--primary-light);
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
}

.checkbox-row label {
    font-size: 0.88rem;
    cursor: pointer;
    user-select: none;
    color: var(--text-primary);
    font-weight: 500;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    line-height: 1.4;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-darker));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px var(--primary-glow);
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text-primary);
    border: 1.5px solid var(--line);
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-lighter);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: #fff;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.78rem;
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--line);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-lighter);
}

/* ─── Separator ─────────────────────────────────────────────── */
.separator {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
    margin: 20px 0;
}

/* ─── Disclosure Link ───────────────────────────────────────── */
.disclosure-link {
    color: var(--primary);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.disclosure-link:hover {
    background: var(--primary-lighter);
    text-decoration: none;
}

/* ─── Collapsible ───────────────────────────────────────────── */
.collapsible-content {
    display: none;
    margin-top: 16px;
    animation: fadeSlideIn 0.25s ease;
}

.collapsible-content.open {
    display: block;
}

/* ─── Action Bar ────────────────────────────────────────────── */
.action-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

/* ─── Results Dashboard ─────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.verdict-card {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 24px;
    background: linear-gradient(135deg, var(--primary-lighter), var(--surface));
    position: relative;
    overflow: hidden;
    transition: all var(--transition-slow);
}

.verdict-card::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: var(--primary-glow);
    opacity: 0.3;
    pointer-events: none;
}

.verdict-card.favors-loan {
    border-left-color: var(--primary);
}

.verdict-card.favors-direct {
    border-left-color: var(--warning);
}

.verdict-card .verdict-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.verdict-card .verdict-value {
    font-size: 2rem;
    font-weight: 800;
    margin: 6px 0;
    letter-spacing: -0.02em;
}

.verdict-card.favors-loan .verdict-value {
    color: var(--primary-dark);
}

.verdict-card.favors-direct .verdict-value {
    color: var(--warning);
}

.verdict-card .verdict-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.strategy-card {
    padding: 20px;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid var(--line);
    transition: all var(--transition);
}

.strategy-card:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-sm);
}

.strategy-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.strategy-card .metric {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--line);
}

.strategy-card .metric:last-child {
    border-bottom: none;
}

.strategy-card .metric .label {
    color: var(--text-secondary);
    font-weight: 500;
}

.strategy-card .metric .value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ─── Details Box (supplementary notes) ─────────────────────── */
.details-box {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    max-height: 240px;
    overflow-y: auto;
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--text-secondary);
}

.details-box p {
    margin: 0 0 8px;
}

.details-box p:last-child {
    margin-bottom: 0;
}

.details-box::-webkit-scrollbar {
    width: 6px;
}

.details-box::-webkit-scrollbar-track {
    background: transparent;
}

.details-box::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 3px;
}

.details-box .header-line {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.85rem;
}

.details-box .bold-line {
    font-weight: 600;
}

/* ─── Metric Cards Grid ─────────────────────────────────────── */
.metric-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 20px 0;
}

.metric-card {
    padding: 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface-alt);
    transition: all var(--transition);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.metric-card .metric-label {
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-card .metric-value {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.metric-card.blue {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #bfdbfe;
}
.metric-card.blue .metric-label { color: #1e40af; }
.metric-card.blue .metric-value { color: #1e3a8a; }

.metric-card.green {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-color: #bbf7d0;
}
.metric-card.green .metric-label { color: #166534; }
.metric-card.green .metric-value { color: #14532d; }

.metric-card.amber {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border-color: #fde68a;
}
.metric-card.amber .metric-label { color: #92400e; }
.metric-card.amber .metric-value { color: #78350f; }

.metric-card.purple {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    border-color: #e9d5ff;
}
.metric-card.purple .metric-label { color: #6b21a8; }
.metric-card.purple .metric-value { color: #581c87; }

.metric-card.teal {
    background: linear-gradient(135deg, #f0fdfa 0%, #ccfbf1 100%);
    border-color: #99f6e4;
}
.metric-card.teal .metric-label { color: #0f766e; }
.metric-card.teal .metric-value { color: #115e59; }

.metric-card.sky {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-color: #bae6fd;
}
.metric-card.sky .metric-label { color: #0369a1; }
.metric-card.sky .metric-value { color: #075985; }

[data-theme="dark"] .metric-card.blue {
    background: linear-gradient(135deg, #172554 0%, #1e3a8a 100%);
    border-color: #3b82f6;
}
[data-theme="dark"] .metric-card.blue .metric-label { color: #93c5fd; }
[data-theme="dark"] .metric-card.blue .metric-value { color: #bfdbfe; }

[data-theme="dark"] .metric-card.green {
    background: linear-gradient(135deg, #052e16 0%, #14532d 100%);
    border-color: #22c55e;
}
[data-theme="dark"] .metric-card.green .metric-label { color: #86efac; }
[data-theme="dark"] .metric-card.green .metric-value { color: #bbf7d0; }

[data-theme="dark"] .metric-card.amber {
    background: linear-gradient(135deg, #451a03 0%, #78350f 100%);
    border-color: #f59e0b;
}
[data-theme="dark"] .metric-card.amber .metric-label { color: #fcd34d; }
[data-theme="dark"] .metric-card.amber .metric-value { color: #fef3c7; }

[data-theme="dark"] .metric-card.purple {
    background: linear-gradient(135deg, #3b0764 0%, #581c87 100%);
    border-color: #a855f7;
}
[data-theme="dark"] .metric-card.purple .metric-label { color: #d8b4fe; }
[data-theme="dark"] .metric-card.purple .metric-value { color: #f3e8ff; }

[data-theme="dark"] .metric-card.teal {
    background: linear-gradient(135deg, #042f2e 0%, #134e4a 100%);
    border-color: #14b8a6;
}
[data-theme="dark"] .metric-card.teal .metric-label { color: #5eead4; }
[data-theme="dark"] .metric-card.teal .metric-value { color: #99f6e4; }

[data-theme="dark"] .metric-card.sky {
    background: linear-gradient(135deg, #082f49 0%, #155e75 100%);
    border-color: #0ea5e9;
}
[data-theme="dark"] .metric-card.sky .metric-label { color: #7dd3fc; }
[data-theme="dark"] .metric-card.sky .metric-value { color: #bae6fd; }

/* ─── Chart Card ────────────────────────────────────────────── */
.chart-card {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 20px;
    transition: all var(--transition);
}

.chart-card .chart-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-container {
    position: relative;
    height: 340px;
}

/* ─── Cashflow Editor ───────────────────────────────────────── */
.cashflow-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    flex-wrap: wrap;
    transition: all var(--transition);
}

.cashflow-item:hover {
    border-color: var(--line-strong);
}

.cashflow-item input[type="number"] {
    background: var(--surface-alt);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-xs);
    padding: 8px 10px;
    font-size: 0.88rem;
    color: var(--text-primary);
    width: 110px;
    font-family: inherit;
    outline: none;
    transition: border var(--transition);
}

.cashflow-item input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.cashflow-item .cf-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.cashflow-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 20px;
}

/* ─── Cashflow Headers ──────────────────────────────────────── */
.cashflow-grid h4 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ─── Tree Table ────────────────────────────────────────────── */
.tree-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.tree-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.tree-table th {
    background: var(--surface);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--line-strong);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tree-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    transition: background var(--transition);
}

.tree-table tr:hover td {
    background: var(--primary-lighter);
}

.tree-table tr.highlight td {
    background: var(--warning-light);
    font-weight: 600;
}

.tree-container {
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    scrollbar-width: thin;
}

.tree-container::-webkit-scrollbar {
    width: 6px;
}

.tree-container::-webkit-scrollbar-track {
    background: transparent;
}

.tree-container::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 3px;
}

/* ─── Year Rates Table ──────────────────────────────────────── */
.year-rates-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.year-rates-table th {
    background: var(--surface);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--line-strong);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.year-rates-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    transition: background var(--transition);
}

.year-rates-table td.editable {
    cursor: pointer;
    position: relative;
}

.year-rates-table td.editable:hover {
    background: var(--primary-lighter);
}

.year-rates-table td.editable::after {
    content: '✎';
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 6px;
    opacity: 0.4;
}

.year-rates-table tr.historical td {
    background: var(--warning-light);
}

/* ─── Progress Bar ──────────────────────────────────────────── */
.progress-bar {
    height: 6px;
    background: var(--line);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
    position: relative;
}

.progress-bar .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    border-radius: 3px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

/* ─── Status Bar ────────────────────────────────────────────── */
.status-bar {
    margin-top: 20px;
    padding: 14px 24px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    transition: background var(--transition-slow);
    border: 1px solid var(--line);
}

.status-bar .status-text {
    color: var(--text-secondary);
    font-weight: 500;
}

.status-bar .status-version {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.78rem;
}

.status-bar .status-text.success {
    color: var(--primary);
    font-weight: 600;
}

.status-bar .status-text.error {
    color: var(--danger);
    font-weight: 600;
}

/* ─── Mode Indicator ────────────────────────────────────────── */
.mode-indicator {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 12px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.mode-indicator.forecast {
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid var(--line-strong);
}

.mode-indicator.historical {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ─── Graph Buttons ─────────────────────────────────────────── */
.graph-btn {
    position: relative;
    transition: all var(--transition);
}

.graph-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px var(--primary-glow);
}

.graph-btn.active:hover {
    box-shadow: 0 4px 12px var(--primary-glow);
    transform: translateY(-1px);
}

/* ─── Help Icons & Popover ──────────────────────────────────── */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-muted);
    opacity: 0.65;
    transition: all var(--transition);
    margin-left: 2px;
    vertical-align: middle;
    -webkit-tap-highlight-color: transparent;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    line-height: 1;
}

.help-icon:hover,
.help-icon:focus-visible {
    opacity: 1;
    color: var(--primary);
    background: var(--primary-lighter);
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.help-icon.is-open {
    opacity: 1;
    color: #fff;
    background: var(--primary);
}

.help-popover {
    position: fixed;
    z-index: 1000;
    max-width: min(320px, calc(100vw - 24px));
    padding: 14px 40px 14px 16px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 0.86rem;
    line-height: 1.5;
}

.help-popover[hidden] {
    display: none;
}

.help-popover-text {
    margin: 0;
}

.help-popover-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-xs);
    background: var(--surface-alt);
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
}

.help-popover-close:hover,
.help-popover-close:focus-visible {
    background: var(--primary-lighter);
    color: var(--primary-dark);
    outline: none;
}

/* ─── Results breakdown table ───────────────────────────────── */
.breakdown-summary {
    margin: 20px 0 8px;
}

.breakdown-summary-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 10px;
}

.breakdown-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
}

.breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.breakdown-table th,
.breakdown-table td {
    padding: 10px 14px;
    text-align: right;
    border-bottom: 1px solid var(--line);
}

.breakdown-table th:first-child,
.breakdown-table td:first-child {
    text-align: left;
    font-weight: 500;
    color: var(--text-secondary);
}

.breakdown-table thead th {
    background: var(--primary-lighter);
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.breakdown-table tbody tr:last-child td {
    border-bottom: none;
}

.breakdown-table .row-emphasis td {
    font-weight: 700;
    color: var(--text-primary);
    background: var(--surface);
}

.breakdown-table td.col-favored {
    color: var(--primary-dark);
    font-weight: 700;
}

.same-as-loan {
    font-size: 0.75em;
    opacity: 0.6;
    font-weight: 400;
    white-space: nowrap;
}

.chart-actions {
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.chart-actions-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    width: 100%;
    flex: 0 0 100%;
}

@media (min-width: 640px) {
    .chart-actions-label {
        width: auto;
        flex: 0 0 auto;
        margin-right: 4px;
    }
}

/* ─── Inline Field Validation ───────────────────────────────── */
input.field-invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}

[data-theme="dark"] input.field-invalid {
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.2) !important;
}

.field-error {
    display: block;
    font-size: 0.7rem;
    color: var(--danger);
    margin-top: 2px;
    line-height: 1.3;
    font-weight: 500;
}

/* ─── Error Message ─────────────────────────────────────────── */
.error-msg {
    background: var(--danger-light);
    color: var(--danger);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-top: 12px;
    display: none;
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-weight: 500;
}

/* ─── Export Buttons Row ────────────────────────────────────── */
.export-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* ─── Print-Friendly Mode ──────────────────────────────────── */
@media print {
    body { background: #fff !important; }
    .app { max-width: 100%; padding: 0; }
    .header { box-shadow: none; border-bottom: 1px solid #ccc; border-radius: 0; }
    .header::before { display: none; }
    .header-toggles, .theme-toggle, .lang-toggle, .simple-mode-toggle { display: none !important; }
    .tabs { display: none !important; }
    .tab-content:not(#tab-results) { display: none !important; }
    #tab-results { display: block !important; }
    #tab-surrender { display: block !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .card:hover { box-shadow: none; }
    .action-bar { display: none !important; }
    .status-bar { display: none !important; }
    .btn { display: none !important; }
    #detailsDisclosure { display: none !important; }
    #detailsPanel { display: block !important; }
    .chart-card { break-inside: avoid; }
    .dashboard-grid { break-inside: avoid; }
    .tree-container { max-height: none; overflow: visible; }
    #surrenderDisclosure { display: none !important; }
    #surrenderPanel { display: block !important; }
    .collapsible-content { display: block !important; }
    .export-row button { display: none !important; }
    .mode-indicator { display: none; }
    .shortcuts { display: none; }
    .metric-card:hover { transform: none; box-shadow: none; }
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 12px));
    }

    .header {
        flex-direction: column;
        padding: 20px;
    }

    .header::before {
        height: 3px;
    }

    .header-info h1 {
        font-size: 1.3rem;
    }

    .header-info .shortcuts {
        display: none;
    }

    .card {
        padding: 20px;
        border-radius: var(--radius-md);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .metric-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .cashflow-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
    }

    .form-row label {
        min-width: auto;
    }

    .form-row input[type="number"],
    .form-row input[type="text"] {
        max-width: 100%;
    }

    .form-row .radio-group {
        align-self: flex-start;
    }

    .tab-btn {
        padding: 12px 16px;
        font-size: 0.82rem;
        min-height: 44px;
    }

    .radio-group label {
        padding: 8px 16px;
    }

    .checkbox-row {
        padding: 10px 12px;
    }

    .checkbox-row label {
        font-size: 0.88rem;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.88rem;
        min-height: 44px;
        justify-content: center;
    }

    .btn-sm {
        padding: 10px 14px;
        font-size: 0.82rem;
        min-height: 40px;
    }

    .verdict-card .verdict-value {
        font-size: 1.5rem;
    }

    .strategy-card .metric {
        font-size: 0.82rem;
    }

    .tree-table th,
    .tree-table td {
        padding: 8px;
        font-size: 0.82rem;
    }

    .year-rates-table th,
    .year-rates-table td {
        padding: 8px;
        font-size: 0.82rem;
    }

    .chart-container {
        height: 260px;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ─── Utility ───────────────────────────────────────────────── */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }

/* ─── Scenario Comparison ───────────────────────────────────── */
.comparison-section {
    margin-top: 16px;
    padding: 16px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 8px;
}

.scenario-column {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    border: 1px solid var(--line);
}

.scenario-header {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
    color: var(--primary-dark);
}

.scenario-label-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    margin-bottom: 6px;
}

.scenario-status {
    font-size: 0.82rem;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    margin-bottom: 8px;
    word-break: break-word;
}
.scenario-status.empty {
    color: var(--text-muted);
    font-style: italic;
}
.scenario-status.saved {
    background: var(--primary-light);
    color: var(--primary-darker);
    border: 1px solid var(--line);
}

.scenario-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.scenario-actions .btn {
    font-size: 0.78rem;
    padding: 4px 10px;
}

/* ─── Comparison Dashboard ──────────────────────────────────── */
.comparison-dashboard {
    margin-top: 16px;
}

.comparison-dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}
.comparison-dashboard-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.comp-verdicts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.comp-strategies-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.comp-strategy-col {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.comp-col-header {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary-dark);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.comp-strategy-col .metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}
.comp-strategy-col .metric .label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.comp-strategy-col .metric .value {
    font-size: 0.82rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.comp-breakdown-table th:first-child,
.comp-breakdown-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
    min-width: 100px;
}
.comp-breakdown-table th,
.comp-breakdown-table td {
    min-width: 120px;
}
.comp-breakdown-table th:not(:first-child) {
    font-size: 0.78rem;
    text-align: right;
}
.comp-breakdown-table td:not(:first-child) {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

@media (max-width: 768px) {
    .comparison-grid {
        grid-template-columns: 1fr;
    }
    .comp-strategies-grid {
        grid-template-columns: 1fr 1fr;
    }
    .comp-verdicts-grid {
        grid-template-columns: 1fr;
    }
}
