/* retirement.css — Retirement page, phase summary, scenario editor, planning, tax strategy */

        /* Line item breakdowns */
        .li-category-label { cursor: pointer; user-select: none; }
        .li-category-label:hover { color: #2563eb; }
        .li-expand-arrow { display: inline-block; width: 12px; font-size: 9px; color: #94a3b8; transition: transform 0.15s; }
        .li-container { padding: 4px 0; background: #f8fafc; border-top: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; }
        .li-table { width: 100%; border-collapse: collapse; }
        .li-item-row td { padding: 3px 4px; font-size: 10px; color: #475569; }
        .li-label { padding-left: 20px !important; width: 28%; white-space: nowrap; }
        .li-cell { text-align: center; width: 18%; }
        .li-check-wrap { display: flex; align-items: center; justify-content: center; gap: 2px; }
        .li-check { width: 13px; height: 13px; cursor: pointer; accent-color: #3b82f6; flex-shrink: 0; }
        .li-amount { width: 52px; border: 1px solid #e5e7eb; font-size: 10px; text-align: right; padding: 2px 4px; border-radius: 3px; background: white; }
        .li-amount:focus { outline: 1px solid #3b82f6; border-color: #3b82f6; }
        .li-totals-row td { padding: 4px; font-size: 10px; border-top: 1px solid #cbd5e1; color: #1e293b; }
        .li-total { font-weight: 700; }

        /* Account flow grid in Cash Flow table */
        .acct-flow-grid {
            display: grid;
            grid-template-columns: auto auto;
            gap: 1px 10px;
            justify-content: start;
        }
        .acct-flow-section-label {
            font-size: 10px;
            font-weight: 600;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 2px;
        }
        .acct-portfolio-note {
            font-weight: 400;
            text-transform: none;
            letter-spacing: 0;
            color: #94a3b8;
        }
        .acct-label { color: #64748b; font-size: 11px; white-space: nowrap; }
        .acct-val { font-weight: 600; font-size: 11px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
        .acct-flow-total {
            margin-top: 4px;
            padding-top: 4px;
            border-top: 1px solid #e2e8f0;
            font-weight: 700;
            font-size: 12px;
        }

        /* Retirement page styles */
        .portfolio-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
        @media (max-width: 900px) { .portfolio-summary { grid-template-columns: repeat(2, 1fr); } }
        .portfolio-card { background: white; border-radius: 12px; padding: 16px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
        .portfolio-card.total { background: var(--primary); color: white; }
        .portfolio-card .label { font-size: 12px; text-transform: uppercase; opacity: 0.8; }
        .portfolio-card .amount { font-size: 24px; font-weight: 700; margin-top: 4px; }
        .portfolio-card.total .label { color: rgba(255,255,255,0.9); }

        #retirement-chart { width: 100%; height: 300px; }


        /* Phase Summary Cards */
        .phase-summary-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 12px;
            margin-bottom: 16px;
        }
        @media (max-width: 768px) {
            .phase-summary-grid { grid-template-columns: repeat(2, 1fr); }
        }
        @media (max-width: 480px) {
            .phase-summary-grid { grid-template-columns: 1fr; }
        }
        .phase-card {
            background: white;
            border-radius: 8px;
            padding: 14px;
            border: 1px solid var(--gray-200);
            border-left: 4px solid #334155;
        }
        .phase-card[data-phase="early"] { border-left-color: #334155; }
        .phase-card[data-phase="elem"]  { border-left-color: #475569; }
        .phase-card[data-phase="mid"]   { border-left-color: #64748b; }
        .phase-card[data-phase="retire"]{ border-left-color: #94a3b8; }
        .phase-card-header {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            color: var(--gray-600);
            margin-bottom: 2px;
        }
        .phase-card-years {
            font-size: 10px;
            color: var(--gray-500);
            margin-bottom: 10px;
        }
        .phase-card-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 2px 0;
            font-size: 12px;
            color: var(--gray-600);
        }
        .phase-card-row span:last-child {
            font-weight: 600;
            color: var(--gray-800);
            font-variant-numeric: tabular-nums;
        }
        .phase-card-divider {
            border: none;
            border-top: 1px solid var(--gray-200);
            margin: 6px 0;
        }
        .phase-card-total {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 4px 0;
            font-size: 13px;
            font-weight: 700;
            color: var(--gray-800);
        }
        .phase-card-income {
            font-size: 11px;
            color: var(--gray-500);
            margin-top: 8px;
            padding-top: 8px;
            border-top: 1px solid var(--gray-100);
        }
        .phase-card-income .income-value {
            font-size: 13px;
            font-weight: 600;
            color: #1e40af;
        }
        .phase-card-income .income-label {
            font-size: 10px;
            color: var(--gray-500);
        }
        .surplus-badge {
            margin-top: 10px;
            padding: 6px 10px;
            border-radius: 6px;
            text-align: center;
            font-size: 14px;
            font-weight: 700;
        }
        .surplus-badge.positive {
            background: #dcfce7;
            color: #166534;
        }
        .surplus-badge.negative {
            background: #fee2e2;
            color: #991b1b;
        }

        /* Customize Panel */
        .customize-panel {
            display: none;
            margin-top: 16px;
            padding-top: 16px;
            border-top: 1px solid var(--gray-200);
        }
        .customize-panel.open {
            display: block;
        }
        .customize-toggle-btn {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 14px;
            border: 1px solid var(--gray-300);
            border-radius: 6px;
            background: white;
            color: var(--gray-600);
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.15s;
        }
        .customize-toggle-btn:hover {
            background: var(--gray-50);
            border-color: var(--gray-400);
        }
        .customize-toggle-btn.active {
            background: #1e293b;
            color: white;
            border-color: #1e293b;
        }

        /* Scenario Editor */
        .scenario-btn-wrap {
            display: flex;
            align-items: center;
            gap: 4px;
        }
        .scenario-btn-wrap .scenario-preset {
            flex: 1;
        }
        .scenario-edit-btn {
            width: 24px;
            height: 24px;
            padding: 0;
            border: 1px solid var(--gray-300);
            background: white;
            border-radius: 4px;
            cursor: pointer;
            font-size: 11px;
            line-height: 1;
            color: var(--gray-600);
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .scenario-edit-btn:hover {
            background: var(--gray-100);
            border-color: var(--gray-400);
        }
        .scenario-custom-btn {
            padding: 6px 10px;
            font-size: 11px;
            border: 1px dashed var(--gray-400);
            background: white;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            width: 100%;
            color: var(--gray-600);
            font-weight: 500;
            margin-top: 4px;
        }
        .scenario-custom-btn:hover {
            background: #f0f9ff;
            border-color: #0369a1;
            color: #0369a1;
        }
        .scenario-editor {
            display: none;
            margin-top: 8px;
            padding: 10px;
            background: white;
            border-radius: 6px;
            border: 2px solid var(--primary);
        }
        .scenario-editor.open {
            display: block;
        }
        .scenario-editor-title {
            font-size: 11px;
            font-weight: 600;
            color: var(--primary);
            margin-bottom: 8px;
        }
        .scenario-editor label {
            font-size: 11px;
            color: var(--gray-600);
            display: block;
            margin-bottom: 2px;
        }
        .scenario-editor input[type="text"],
        .scenario-editor input[type="number"] {
            width: 100%;
            padding: 4px 8px;
            border: 1px solid var(--gray-300);
            border-radius: 4px;
            font-size: 11px;
            margin-bottom: 6px;
        }
        .scenario-editor-section {
            margin-bottom: 8px;
            font-size: 11px;
            font-weight: 600;
            color: var(--gray-600);
        }
        .scenario-editor-radio-row {
            display: flex;
            gap: 12px;
            margin-bottom: 6px;
            font-size: 11px;
        }
        .scenario-editor-radio-row label {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            cursor: pointer;
        }
        .scenario-editor-fields {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 4px 8px;
            margin-bottom: 6px;
        }
        .school-toggle-row {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 4px 0;
            font-size: 11px;
        }
        .school-toggle-row input[type="checkbox"] {
            margin: 0;
        }
        .school-toggle-row .school-label {
            flex: 1;
            color: var(--gray-600);
        }
        .school-toggle-row input[type="number"] {
            width: 60px;
            padding: 2px 4px;
            border: 1px solid var(--gray-300);
            border-radius: 3px;
            font-size: 11px;
            text-align: right;
            margin-bottom: 0;
        }
        .scenario-editor-actions {
            display: flex;
            gap: 4px;
            margin-top: 8px;
        }
        .scenario-editor-actions button {
            padding: 4px 10px;
            font-size: 11px;
            border: 1px solid var(--gray-300);
            border-radius: 4px;
            cursor: pointer;
            font-weight: 500;
        }
        .scenario-editor-actions .btn-save {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }
        .scenario-editor-actions .btn-save:hover {
            opacity: 0.9;
        }
        .scenario-editor-actions .btn-save-new {
            background: white;
            color: var(--primary);
            border-color: var(--primary);
        }
        .scenario-editor-actions .btn-cancel {
            background: white;
            color: var(--gray-600);
        }
        .scenario-editor-actions .btn-delete {
            background: white;
            color: var(--danger);
            border-color: var(--danger);
            margin-left: auto;
        }
        .scenario-editor-note {
            font-size: 9px;
            color: var(--gray-500);
            margin-top: 4px;
            font-style: italic;
        }

        /* Simplified Cash Flow Table */
        .cashflow-trajectory {
            margin-top: 10px;
            padding: 10px 12px;
            background: linear-gradient(135deg, #eff6ff, #f0fdf4);
            border-radius: 6px;
            font-size: 12px;
            color: #1e40af;
            font-weight: 500;
        }

        /* ---- Planning Layout (shared sidebar for Retirement + Tax Strategy) ---- */
        #planning-layout { display: none; }
        #planning-layout.active { display: flex; gap: 16px; }
        #planning-sidebar {
            width: 300px;
            flex-shrink: 0;
            max-height: calc(100vh - 120px);
            overflow-y: auto;
            position: sticky;
            top: 20px;
            align-self: flex-start;
        }
        #planning-content { flex: 1; min-width: 0; }
        #planning-content .page { display: none; }
        #planning-content .page.active { display: block; }
        @media (max-width: 1000px) {
            #planning-layout.active { flex-direction: column; }
            #planning-sidebar { width: 100%; max-height: none; position: static; }
        }

        /* ---- Tax Strategy Tab ---- */
        .tax-kpi-row {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 12px;
            margin-bottom: 12px;
        }
        @media (max-width: 900px) { .tax-kpi-row { grid-template-columns: repeat(2, 1fr); } }
        .tax-kpi {
            background: white;
            border-radius: 10px;
            padding: 14px 16px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            text-align: center;
        }
        .tax-kpi-label { font-size: 11px; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.5px; }
        .tax-kpi-value { font-size: 22px; font-weight: 700; margin: 4px 0; color: var(--gray-800); }
        .tax-kpi-note { font-size: 11px; color: var(--gray-600); }

        .tax-table-card { padding: 0; overflow: hidden; }
        .tax-table-scroll { overflow-x: auto; max-height: 70vh; overflow-y: auto; }
        .tax-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 12px;
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
        }
        .tax-table thead { position: sticky; top: 0; z-index: 2; }
        .tax-thead-groups { position: sticky; top: 0; z-index: 3; }
        .tax-thead-cols { position: sticky; top: 28px; z-index: 3; }
        .tax-table th {
            padding: 6px 8px;
            background: #1e293b;
            color: white;
            font-size: 11px;
            font-weight: 600;
            text-align: right;
            border-bottom: 2px solid #0f172a;
        }
        .tax-table th:first-child, .tax-table th:nth-child(2), .tax-table th:nth-child(3) { text-align: center; }
        .tax-th-editable { background: #334155 !important; }
        .tax-th-sticky { position: sticky; left: 0; z-index: 4; }
        /* Group header row */
        .tax-group-header {
            background: #0f172a !important;
            text-align: center !important;
            font-size: 10px;
            font-weight: 600;
            letter-spacing: 0.5px;
            border-right: 2px solid #334155;
            border-left: 2px solid #334155;
            cursor: pointer;
            user-select: none;
            padding: 4px 8px;
        }
        .tax-group-header:hover { background: #1e3a5f !important; }
        .tax-group-income { color: #93c5fd; }
        .tax-group-shelters { color: #86efac; }
        .tax-group-taxes { color: #fca5a5; }
        .tax-group-cashflow { color: #c4b5fd; }
        .tax-group-accounts { color: #fcd34d; }
        .tax-group-drawdown { color: #fdba74; }
        /* Collapsed group placeholder */
        .tax-group-collapsed {
            background: #0f172a !important;
            width: 24px;
            min-width: 24px;
            max-width: 24px;
            padding: 4px 2px !important;
            cursor: pointer;
            user-select: none;
            text-align: center !important;
            border-right: 2px solid #334155;
            border-left: 2px solid #334155;
        }
        .tax-group-collapsed:hover { background: #1e3a5f !important; }
        .tax-group-collapsed span {
            writing-mode: vertical-rl;
            text-orientation: mixed;
            font-size: 9px;
            letter-spacing: 0.5px;
            white-space: nowrap;
            color: #94a3b8;
        }
        .tax-collapsed-cell {
            width: 24px;
            min-width: 24px;
            max-width: 24px;
            padding: 0 !important;
            background: #f8fafc;
            border-right: 1px solid var(--gray-200);
            border-left: 1px solid var(--gray-200);
        }
        .tax-table td {
            padding: 6px 8px;
            text-align: right;
            border-bottom: 1px solid var(--gray-100);
        }
        .tax-table td:first-child, .tax-table td:nth-child(2), .tax-table td:nth-child(3) { text-align: center; }
        .tax-col-year {
            font-weight: 600;
            color: var(--gray-600);
            position: sticky;
            left: 0;
            background: white;
            z-index: 1;
        }
        .tax-col-phase { font-size: 10px; color: var(--gray-500); text-transform: uppercase; }
        .tax-col-gross { font-weight: 600; }
        .tax-col-tax { color: #991b1b; }
        .tax-col-takehome { font-weight: 600; color: var(--primary); }
        .tax-col-surplus { font-weight: 500; color: var(--success); }
        .tax-col-negative { color: var(--danger) !important; }

        /* Editable cells */
        .tax-editable {
            background: #fefce8;
            cursor: pointer;
            transition: background 0.15s;
        }
        .tax-editable:hover { background: #fef08a; }

        /* Override indicator */
        .tax-row-override .tax-editable {
            border-left: 3px solid var(--primary);
        }

        /* Row states */
        .tax-row-retired { background: #eff6ff; }
        .tax-row-retired .tax-col-year { background: #eff6ff; }
        .tax-row-deficit { background: #fef2f2; }
        .tax-row-deficit .tax-col-year { background: #fef2f2; }

        /* Rate badge */
        .tax-rate-badge {
            display: inline-block;
            padding: 1px 5px;
            border-radius: 3px;
            font-size: 10px;
            font-weight: 600;
            margin-right: 4px;
        }
        /* Deduction badge */
        .tax-ded-badge {
            display: inline-block;
            padding: 1px 4px;
            border-radius: 3px;
            font-size: 9px;
            font-weight: 600;
            background: #dcfce7;
            color: #166534;
            margin-right: 2px;
        }

        /* Cell input */
        .tax-cell-input {
            width: 80px;
            padding: 2px 4px;
            border: 2px solid var(--primary);
            border-radius: 4px;
            font-size: 12px;
            font-family: inherit;
            text-align: right;
            outline: none;
        }

        /* Insights grid */
        .tax-insights-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
        }
        @media (max-width: 900px) { .tax-insights-grid { grid-template-columns: 1fr; } }
        .tax-insight {
            display: flex;
            gap: 12px;
            padding: 12px;
            background: var(--gray-50);
            border-radius: 8px;
        }
        .tax-insight-icon {
            width: 36px;
            height: 36px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            flex-shrink: 0;
        }
        .tax-insight-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
        .tax-insight-text { font-size: 12px; color: var(--gray-600); line-height: 1.5; }

        /* Column group toggle pills */
        .tax-group-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
        .tax-group-pill {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
            border: 1px solid var(--gray-300);
            background: white;
            color: var(--gray-600);
            cursor: pointer;
            transition: all 0.15s;
            user-select: none;
        }
        .tax-group-pill:hover { border-color: var(--primary); color: var(--primary); }
        .tax-group-pill.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        /* Account column colors */
        .tax-col-acct { font-weight: 500; font-variant-numeric: tabular-nums; }
        .tax-col-acct-cash { color: #16a34a; }
        .tax-col-acct-brok { color: #7c3aed; }
        .tax-col-acct-401k { color: #2563eb; }
        .tax-col-acct-roth { color: #d97706; }
        .tax-col-portfolio { font-weight: 600; color: var(--gray-700); }
        .tax-col-alloc { font-size: 10px; white-space: nowrap; text-align: center; min-width: 40px; }
        .tax-col-home-eq { color: #059669; }
        .tax-col-networth { color: var(--gray-800); }

        /* Bear market rows */
        .bear-crash-row { background: #fef2f2 !important; }
        .bear-crash-row td { color: #991b1b !important; }
        .bear-recovery-row { background: #f0fdf4 !important; }

        /* Clickable phase cells */
        .tax-phase-clickable { cursor: pointer; text-decoration: underline dotted var(--gray-400); text-underline-offset: 2px; }
        .tax-phase-clickable:hover { background: #f0f9ff; }

        /* Phase income popover */
        .phase-income-popover {
            position: fixed;
            z-index: 1000;
            background: white;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.15);
            padding: 12px 16px;
            min-width: 270px;
            border: 1px solid var(--gray-200);
        }
        .phase-pop-step:hover { background: var(--gray-100) !important; }

        /* Drawdown columns */
        .tax-col-dd { color: var(--gray-500); font-size: 11px; }
        .tax-col-roth-conv { background: #fef3c7 !important; color: #92400e; font-weight: 500; }
