:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #334155;
    --border: #475569;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --accent: #38bdf8;
    --accent2: #818cf8;
    --green: #4ade80;
    --red: #f87171;
    --orange: #fb923c;
    --gold: #fbbf24;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.app-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions { display: flex; gap: 0.5rem; }

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn:hover { background: var(--surface2); border-color: var(--accent); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border: none;
    color: #0f172a;
    font-weight: 600;
}

.btn-primary:hover { opacity: 0.9; }

.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 0;
    min-height: calc(100vh - 57px);
}

/* Sidebar inputs */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    max-height: calc(100vh - 57px);
    padding-bottom: 2rem;
}

/* Profile bar */
.profile-bar {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.profile-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.profile-row select,
.profile-row input[type="text"] {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.82rem;
}

.profile-row select:focus,
.profile-row input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    white-space: nowrap;
}

.section {
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.section-header:hover { background: rgba(56, 189, 248, 0.05); }

.section-header h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    font-weight: 600;
}

.section-header .section-total {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 500;
}

.section-header .chevron {
    transition: transform 0.2s;
    color: var(--text-dim);
    font-size: 0.75rem;
}

.section.collapsed .chevron { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }

.section-body {
    padding: 0 1.25rem 1rem;
}

.field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.field label {
    font-size: 0.82rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.field input {
    width: 140px;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    text-align: right;
    transition: border-color 0.2s;
}

.field input:focus {
    outline: none;
    border-color: var(--accent);
}

.field .unit {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 0.25rem;
    width: 20px;
}

/* Main content */
.main {
    padding: 1.5rem 2rem;
    overflow-y: auto;
    max-height: calc(100vh - 57px);
}

/* Summary cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
}

.card-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
}

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

.card-sub {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
}

.card.green .card-value { color: var(--green); }
.card.blue .card-value { color: var(--accent); }
.card.gold .card-value { color: var(--gold); }
.card.orange .card-value { color: var(--orange); }
.card.red .card-value { color: var(--red); }

.fire-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.fire-badge.ready { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.fire-badge.not-ready { background: rgba(248, 113, 113, 0.15); color: var(--red); }

/* Charts */
.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-dim);
}

canvas { max-height: 350px; }

/* Table */
.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 2rem;
}

.table-container h3 {
    font-size: 0.9rem;
    padding: 1rem 1.25rem;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.table-scroll { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

th {
    text-align: right;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    color: var(--text-dim);
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

th:first-child, td:first-child { text-align: center; }

td {
    text-align: right;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
    white-space: nowrap;
}

tr:hover td { background: rgba(56, 189, 248, 0.03); }

.highlight-row td { background: rgba(74, 222, 128, 0.08); }

.year0-row td {
    background: var(--bg);
    font-weight: 600;
    border-bottom: 2px solid var(--accent);
}

/* Breakdown sub-lines inside table cells */
.cell-breakdown {
    font-size: 0.68rem;
    line-height: 1.3;
    margin-top: 2px;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.delta-contrib { color: var(--accent); }
.delta-growth { color: var(--green); }
.delta-nw { color: var(--gold); }

/* Responsive */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .main { max-height: none; }
}

/* Spinner */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
    color: var(--text-dim);
}

.loading.active { display: block; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
