/* CME Retirement Planner - Dashboard Stylesheet */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #60a5fa;
    --success: #16a34a;
    --warning: #eab308;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', Consolas, monospace;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--gray-100);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header.compact {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.header.compact h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.tagline {
    font-size: 0.75rem;
    opacity: 0.85;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tier-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
}

.tier-badge:hover {
    opacity: 0.9;
}

.tier-badge:active {
    transform: scale(0.98);
}

.tier-badge.free {
    background: var(--gray-200);
    color: var(--gray-700);
}

.tier-badge.pro {
    background: var(--warning);
    color: var(--gray-900);
    cursor: default;
}

.license-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.license-btn:hover {
    background: rgba(255,255,255,0.3);
}

.header-link {
    color: white;
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.header-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Dashboard Layout */
.dashboard {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 280px;
    gap: 16px;
    flex: 1;
    padding: 16px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Sidebars */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Main Results */
.main-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    min-height: 0;
    min-width: 0;
}

/* Panels */
.panel {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.panel-header {
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.panel-header.clickable {
    cursor: pointer;
}

.panel-header.clickable:hover {
    background: var(--gray-100);
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
}

.collapse-icon {
    font-size: 0.7rem;
    color: var(--gray-500);
}

.panel-body {
    padding: 12px;
}

/* Inputs */
.input-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.input-group label {
    font-size: 0.7rem;
    color: var(--gray-600);
    font-weight: 500;
}

.input-group input,
.input-group select {
    padding: 6px 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 100%;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Allocation Sliders */
.allocation-sliders.compact .allocation-item {
    margin-bottom: 6px;
}

.allocation-item label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--gray-700);
    margin-bottom: 2px;
}

.allocation-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: var(--gray-200);
    border-radius: 3px;
}

.allocation-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.allocation-total {
    text-align: right;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    padding-top: 6px;
    border-top: 1px solid var(--gray-200);
}

.allocation-total.error {
    color: var(--danger);
    font-weight: 700;
}

.allocation-total.error::after {
    content: ' - must equal 100%';
    font-weight: 400;
    font-size: 0.85em;
}

/* Simulation Controls */
.simulation-controls {
    display: flex;
    gap: 8px;
}

.sim-select {
    padding: 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    background: white;
}

.flex-1 { flex: 1; }

/* Buttons */
.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.primary-btn:hover {
    background: var(--primary-dark);
}

.primary-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.small-btn {
    padding: 4px 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    background: white;
    cursor: pointer;
}

.small-btn:hover {
    background: var(--gray-50);
}

.small-btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.small-btn.primary:disabled {
    background: var(--gray-300);
    border-color: var(--gray-300);
}

.full-width { width: 100%; }

/* Results Header */
.results-header {
    display: flex;
    gap: 16px;
    align-items: center;
    background: white;
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--gray-200);
}

/* Success Gauge */
.gauge-container {
    width: 120px;
    text-align: center;
}

.gauge-svg {
    width: 120px;
    height: 60px;
}

.gauge-bg {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 8;
    stroke-linecap: round;
}

.gauge-fill {
    fill: none;
    stroke: var(--success);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 126;
    stroke-dashoffset: 126;
    transition: stroke-dashoffset 0.5s;
}

.gauge-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: -10px;
}

.gauge-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.methodology-link {
    font-size: 0.65rem;
    color: var(--gray-400);
    margin-top: 8px;
    display: none;
    white-space: nowrap;
}

.methodology-link.visible {
    display: block;
}

.methodology-link a {
    color: var(--primary);
    text-decoration: none;
}

.methodology-link a:hover {
    text-decoration: underline;
}

/* Percentile Row (boxes + export actions) */
.percentile-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

/* Percentile Boxes */
.percentile-boxes {
    display: flex;
    gap: 8px;
    flex: 1;
}

.percentile-box {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-md);
    text-align: center;
}

.percentile-box.bad { background: #fef2f2; border: 1px solid #fecaca; }
.percentile-box.neutral { background: #f3f4f6; border: 1px solid #d1d5db; }
.percentile-box.good { background: #f0fdf4; border: 1px solid #bbf7d0; }

.percentile-label {
    font-size: 0.7rem;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.percentile-value {
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Charts */
.charts-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-row {
    display: flex;
    gap: 12px;
}

.chart-container {
    background: white;
    padding: 12px;
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--gray-200);
    flex: 1;
    min-width: 0;
}

.chart-container.wide {
    flex: 2;
}

.chart-container.narrow {
    flex: 1;
    max-width: 220px;
}

.chart-container h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.chart-header-with-select {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.chart-header-with-select h3 {
    margin-bottom: 0;
}

.chart-select {
    font-size: 0.7rem;
    padding: 2px 4px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
}

.chart-select.hidden {
    display: none;
}

.chart-container canvas {
    width: 100% !important;
    height: 180px !important;
}

.chart-container.narrow canvas {
    height: 160px !important;
}

/* Chart Empty State */
.chart-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--gray-400);
    font-size: 0.8rem;
    text-align: center;
    z-index: 5;
}

.chart-empty-state.hidden {
    display: none;
}

.chart-empty-icon {
    font-size: 1.5rem;
    opacity: 0.5;
}

.chart-container {
    position: relative;
}

/* Tooltips */
.tooltip-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-500);
    font-size: 0.65rem;
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
}

.tooltip-trigger:hover {
    background: var(--primary-light);
    color: white;
}

.tooltip-content {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    min-width: 200px;
    color: white;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    white-space: nowrap;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    margin-bottom: 6px;
    max-width: 300px;
    white-space: normal;
    text-align: left;
}

.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--gray-800);
}

.tooltip-wrapper {
    position: relative;
    display: inline-block;
}

.tooltip-wrapper:hover .tooltip-content {
    opacity: 1;
    visibility: visible;
}

/* Loading */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    border-radius: var(--radius-lg);
    z-index: 10;
}

.loading-overlay.hidden { display: none; }

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner.small { width: 20px; height: 20px; border-width: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    color: var(--gray-600);
    font-size: 0.8rem;
}

.loading-inline.hidden { display: none; }

/* CME */
.cme-source-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.cme-source-row label {
    font-weight: 500;
    white-space: nowrap;
}

.cme-source-select {
    flex: 1;
    min-width: 100px;
    padding: 4px 6px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    background: white;
}

.cme-source-select:focus {
    outline: none;
    border-color: var(--primary);
}

.compare-btn {
    padding: 4px 8px !important;
    font-size: 0.7rem !important;
    white-space: nowrap;
}

/* Inline Comparison Section */
.compare-section {
    margin-top: 12px;
    padding: 12px;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.compare-section.hidden { display: none; }

.compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.compare-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-700);
}

.compare-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    max-height: 180px;
    overflow-y: auto;
}

.compare-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
}

.compare-checkbox:hover {
    border-color: var(--primary);
}

.compare-checkbox input {
    margin-top: 2px;
}

.checkbox-label strong {
    display: block;
    color: var(--gray-800);
}

.checkbox-label small {
    color: var(--gray-500);
    font-size: 0.65rem;
}

.compare-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    font-size: 0.8rem;
    color: var(--gray-600);
}

.compare-loading.hidden { display: none; }

.compare-results {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-200);
}

.compare-results.hidden { display: none; }

.compare-chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.compare-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compare-bar-label {
    width: 90px;
    font-size: 0.7rem;
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compare-bar-container {
    flex: 1;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    height: 20px;
    overflow: hidden;
}

.compare-bar {
    height: 100%;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    transition: width 0.3s ease;
    min-width: 45px;
}

.compare-bar-value {
    font-size: 0.7rem;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}

.compare-sensitivity {
    margin-top: 12px;
    padding: 10px;
    background: white;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

.sensitivity-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}

.sensitivity-label {
    color: var(--gray-600);
}

.sensitivity-value {
    font-weight: 600;
}

.sensitivity-note {
    margin-top: 6px;
    font-size: 0.7rem;
    color: var(--gray-500);
    line-height: 1.4;
}

.cme-table.compact {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.cme-table.compact th,
.cme-table.compact td {
    padding: 4px;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}

.cme-table.compact th {
    font-weight: 500;
    color: var(--gray-600);
    font-size: 0.7rem;
}

.cme-input {
    width: 55px;
    padding: 2px 4px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-align: right;
}

.cme-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Correlation Matrix */
.corr-details, .constraints-details {
    margin: 8px 0;
}

.corr-details summary, .constraints-details summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--gray-600);
    padding: 4px 0;
}

.correlation-matrix {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    margin-top: 4px;
}

.corr-cell {
    padding: 3px;
    text-align: center;
    font-size: 0.65rem;
    font-family: var(--font-mono);
}

.corr-header {
    font-weight: 600;
    background: var(--gray-50);
    font-family: var(--font-sans);
}

.corr-value { background: var(--gray-50); }
.corr-editable { background: transparent !important; padding: 1px; }
.corr-mirror { opacity: 0.7; }

.corr-input {
    width: 100%;
    height: 24px;
    padding: 2px;
    border: 2px solid var(--primary-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    text-align: center;
    background: white;
}

.corr-input:focus {
    outline: none;
    border-color: var(--primary);
}

.cme-buttons {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.cme-message {
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.cme-message.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.cme-message.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.cme-message.hidden { display: none; }

/* Optimizer */
.constraint-grid.compact { font-size: 0.75rem; }

.constraint-row {
    display: grid;
    grid-template-columns: 1fr 45px 45px;
    gap: 4px;
    align-items: center;
    padding: 2px 0;
}

.constraint-row.header {
    font-weight: 500;
    color: var(--gray-600);
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 4px;
}

.constraint-row input {
    padding: 2px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    text-align: center;
}

.optimizer-results {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--gray-200);
}

.optimizer-results.hidden { display: none; }

/* Inline optimization progress */
.optimizer-progress {
    margin-top: 12px;
    padding: 12px;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.optimizer-progress.hidden { display: none; }

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-title {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--primary);
}

.btn-cancel-inline {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-cancel-inline:hover {
    color: var(--gray-600);
}

.optimizer-progress .progress-bar {
    height: 6px;
    margin-bottom: 8px;
}

.progress-status {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.progress-phases-inline {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.phase-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-300);
    transition: background 0.3s, transform 0.3s;
}

.phase-dot.running {
    background: var(--primary);
    animation: pulse 1.5s infinite;
}

.phase-dot.done {
    background: var(--success);
}

.allocation-bar {
    display: flex;
    height: 20px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 4px;
}

.allocation-bar > div {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: white;
    font-weight: 500;
}

.allocation-details {
    font-size: 0.7rem;
    color: var(--gray-600);
}

.expected-metrics {
    display: flex;
    gap: 16px;
    margin: 8px 0;
}

.metric { flex: 1; text-align: center; }
.metric-label { font-size: 0.7rem; color: var(--gray-500); }
.metric-value { font-size: 1rem; font-weight: 600; font-family: var(--font-mono); }

.hint {
    font-size: 0.7rem;
    color: var(--gray-500);
    margin: 4px 0;
}

/* Allocation Period Tabs */
.alloc-period-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.alloc-period-tabs {
    display: flex;
    gap: 4px;
}

.alloc-period-tab {
    padding: 4px 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.7rem;
    cursor: pointer;
}

.alloc-period-tab:hover {
    background: var(--gray-50);
}

.alloc-period-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.alloc-period-content {
    display: none;
}

.alloc-period-content.active {
    display: block;
}

.alloc-period-years {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--gray-100);
}

.remove-alloc-period-btn {
    margin-left: auto;
    padding: 2px 6px;
    border: none;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
}

.remove-alloc-period-btn.hidden {
    display: none;
}

/* Glide Path / Multi-Period Optimizer */
.glide-path-section {
    margin: 12px 0;
}

.glide-path-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.period-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 8px;
}

.period-tab {
    padding: 4px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.period-tab:hover {
    background: var(--gray-50);
}

.period-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.period-content {
    display: none;
    padding: 8px;
    background: var(--gray-50);
    border-radius: var(--radius-md);
}

.period-content.active {
    display: block;
}

.period-years {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.75rem;
}

.period-years label {
    font-weight: 500;
    color: var(--gray-600);
}

.year-input {
    width: 45px;
    padding: 3px 4px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    text-align: center;
}

.year-input:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
}

.remove-period-btn {
    margin-left: auto;
    padding: 2px 8px;
    border: none;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
}

.remove-period-btn.hidden {
    display: none;
}

/* Optimal allocations display for multiple periods */
.period-allocation {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-100);
}

.period-allocation:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.period-allocation-header {
    font-size: 0.7rem;
    color: var(--gray-600);
    margin-bottom: 4px;
    font-weight: 500;
}

/* Install Banner */
.install-banner {
    position: fixed;
    bottom: -100px;
    left: 16px;
    right: 16px;
    background: var(--gray-800);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: bottom 0.3s;
    z-index: 1000;
}

.install-banner.show { bottom: 16px; }
.install-banner p { flex: 1; font-size: 0.85rem; }

.install-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.dismiss-btn {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1.2rem;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 1100px) {
    .dashboard {
        grid-template-columns: 1fr 1fr;
    }
    .right-sidebar {
        grid-column: span 2;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }
    .charts-area {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    .dashboard {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    .right-sidebar {
        grid-column: auto;
        display: flex;
        flex-direction: column;
    }

    .results-header {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }

    .gauge-container {
        width: 100px;
    }

    .gauge-svg {
        width: 100px;
        height: 50px;
    }

    .gauge-value {
        font-size: 1.3rem;
    }

    .percentile-boxes {
        width: 100%;
        flex-wrap: wrap;
    }

    .percentile-box {
        flex: 1 1 45%;
        min-width: 80px;
    }

    .input-grid {
        grid-template-columns: 1fr 1fr;
    }

    .panel-body {
        padding: 10px;
    }

    .chart-container canvas {
        height: 200px !important;
    }

    .chart-container.narrow canvas {
        height: 180px !important;
    }

    /* Scrollable tabs */
    .period-tabs,
    .alloc-period-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .period-tab,
    .alloc-period-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Full width buttons */
    .primary-btn {
        width: 100%;
        padding: 12px;
    }

    .small-btn {
        padding: 8px 12px;
    }

    /* Modal adjustments */
    .modal-overlay .modal-content {
        padding: 20px;
        margin: 16px;
    }
}

@media (max-width: 480px) {
    .dashboard {
        padding: 8px;
    }

    .input-grid {
        grid-template-columns: 1fr;
    }

    .simulation-controls {
        flex-direction: column;
    }

    .percentile-boxes {
        flex-direction: column;
    }

    .percentile-box {
        flex: 1 1 100%;
    }

    .chart-container canvas {
        height: 180px !important;
    }

    .header.compact {
        padding: 6px 12px;
    }

    .header.compact h1 {
        font-size: 0.95rem;
    }

    .tagline {
        display: none;
    }

    .progress-time {
        flex-direction: column;
        gap: 4px;
        text-align: center;
    }
}

/* Touch-friendly targets */
@media (hover: none) and (pointer: coarse) {
    .primary-btn,
    .small-btn,
    .period-tab,
    .alloc-period-tab,
    .chart-tab {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    input,
    select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .allocation-slider {
        height: 8px;
    }

    .allocation-slider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .constraint-row input {
        min-height: 36px;
    }
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.modal-content h3 {
    margin-bottom: 16px;
    color: var(--gray-800);
}

.modal-content p {
    margin-bottom: 12px;
    color: var(--gray-600);
}

.modal-content .pricing {
    background: var(--gray-50);
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--gray-700);
}

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.license-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.license-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Optimization Progress Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    backdrop-filter: blur(2px);
}

.modal-overlay .modal-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-overlay .modal-content h3 {
    margin-bottom: 20px;
    font-size: 1.2rem;
    color: var(--gray-800);
}

.progress-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    width: 0%;
    transition: width 0.5s ease-out;
    border-radius: 4px;
}

.progress-text {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.progress-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-bottom: 20px;
    padding: 0 8px;
}

.progress-phases {
    text-align: left;
    border-top: 1px solid var(--gray-200);
    padding-top: 16px;
    margin-bottom: 20px;
}

.phase {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    color: var(--gray-400);
    font-size: 0.85rem;
    transition: color 0.3s;
}

.phase.running {
    color: var(--primary);
    font-weight: 500;
}

.phase.done {
    color: var(--success);
}

.phase-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-400);
}

.phase.running .phase-icon {
    background: var(--primary);
    color: white;
    animation: pulse 1.5s infinite;
}

.phase.done .phase-icon {
    background: var(--success);
    color: white;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.btn-cancel {
    padding: 10px 24px;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:hover {
    background: var(--gray-200);
    color: var(--gray-800);
}

/* Error and Success Toasts */
.error-toast,
.success-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.error-toast {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.success-toast {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.error-toast.visible,
.success-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.error-toast button,
.success-toast button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.6;
    padding: 0 4px;
}

.error-toast button:hover,
.success-toast button:hover {
    opacity: 1;
}

/* Legal Footer */
.legal-footer {
    background: var(--gray-800);
    color: var(--gray-400);
    padding: 12px 20px;
    text-align: center;
    font-size: 11px;
    line-height: 1.6;
}

.legal-footer .disclaimer {
    max-width: 800px;
    margin: 0 auto;
}

.legal-footer a {
    color: var(--gray-300);
    text-decoration: none;
}

.legal-footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Upgrade Modal Enhancements */
.upgrade-modal {
    max-width: 420px;
}

.pro-features-box {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 16px;
    margin: 16px 0;
    text-align: left;
}

.pro-header {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 12px;
}

.pro-subtext {
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--gray-500);
}

.pro-features-list {
    list-style: none;
    padding: 0;
    margin: 0 0 12px 0;
}

.pro-features-list li {
    padding: 4px 0 4px 24px;
    position: relative;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.pro-features-list li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: bold;
}

.pro-anchor {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-style: italic;
    margin: 0;
    padding-top: 8px;
    border-top: 1px solid var(--gray-200);
}

/* Two-Tier Upgrade Popup */
.upgrade-popup {
    max-width: 620px;
    padding: 24px;
    position: relative;
}

.upgrade-popup h3 {
    text-align: center;
    margin-bottom: 8px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--gray-600);
}

.upgrade-context {
    text-align: center;
    color: var(--gray-600);
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
}

.tier-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 20px 0;
}

.tier-card {
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.tier-card:hover {
    border-color: var(--gray-300);
}

.tier-card.selected {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.03);
}

.tier-radio {
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-300);
    border-radius: 50%;
    position: absolute;
    top: 16px;
    right: 16px;
    transition: all 0.15s ease;
}

.tier-card.selected .tier-radio {
    border-color: var(--primary);
    background: var(--primary);
    box-shadow: inset 0 0 0 3px white;
}

.tier-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--gray-800);
    margin-bottom: 8px;
}

.tier-price {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.tier-period {
    font-size: 1rem;
    font-weight: 400;
    color: var(--gray-500);
}

.tier-billing {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 12px;
}

.tier-desc {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.tier-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tier-features li {
    font-size: 0.85rem;
    color: var(--gray-700);
    padding: 4px 0 4px 20px;
    position: relative;
}

.tier-features li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: bold;
}

.tier-features .coming-soon {
    font-size: 0.75rem;
    color: var(--gray-400);
    font-style: italic;
}

.price-anchor {
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-500);
    font-style: italic;
    margin: 0 0 16px 0;
}

.license-link {
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-top: 12px;
}

.license-link a {
    color: var(--primary);
}

/* Tier badge clickable */
.tier-badge {
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.tier-badge.free:hover {
    background: var(--gray-300);
}

.tier-badge .badge-arrow {
    font-size: 0.7em;
    margin-left: 2px;
    opacity: 0.7;
}

/* PRO Status Popup */
.pro-status-popup {
    max-width: 400px;
    text-align: center;
}

.pro-status-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.pro-status-badge {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1rem;
}

.pro-status-active {
    background: var(--success);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.pro-benefits-list {
    list-style: none;
    padding: 0;
    margin: 16px 0;
    text-align: left;
}

.pro-benefits-list li {
    padding: 8px 0;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 10px;
}

.benefit-check {
    color: var(--success);
    font-weight: bold;
    font-size: 1.1rem;
}

.tier-badge.pro .badge-arrow,
.tier-badge.advisor .badge-arrow {
    display: none;
}

.tier-badge.advisor {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: white;
}

/* Mobile: stack tier cards */
@media (max-width: 600px) {
    .tier-cards {
        grid-template-columns: 1fr;
    }

    .upgrade-popup {
        max-width: 95vw;
        padding: 16px;
    }
}

/* Collapsible Income Details */
.income-details {
    margin-top: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--gray-50);
}

.income-details summary {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 500;
    user-select: none;
    list-style: none;
}

.income-details summary::-webkit-details-marker {
    display: none;
}

.income-details summary::before {
    content: "▶ ";
    font-size: 0.7em;
    margin-right: 4px;
}

.income-details[open] summary::before {
    content: "▼ ";
}

.income-details[open] {
    background: white;
}

.income-details .input-grid {
    padding: 8px 12px;
    grid-template-columns: 1fr 1fr;
}

.income-details .input-grid:first-of-type {
    padding-top: 4px;
}

.income-details .input-grid:last-of-type {
    padding-bottom: 12px;
}

.input-group.single {
    margin-top: 8px;
}

/* Export PDF Actions */
.export-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.icon-btn {
    padding: 4px 8px;
    min-width: auto;
}

/* PDF Settings Modal */
.pdf-settings-modal {
    max-width: 420px;
}

.pdf-setting-group {
    margin-bottom: 16px;
}

.pdf-setting-group > label {
    display: block;
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: var(--gray-700);
}

.pdf-setting-group .optional {
    font-weight: 400;
    color: var(--gray-400);
    font-size: 0.8rem;
}

.pdf-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.pdf-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.branding-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.radio-option input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.logo-upload-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.logo-hint {
    font-size: 0.75rem;
    color: var(--gray-400);
    font-weight: 400;
}

.logo-upload-area {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-preview {
    width: 100px;
    height: 60px;
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    background: var(--gray-50);
    transition: border-color 0.15s;
}

.logo-preview:hover {
    border-color: var(--primary);
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.upload-placeholder {
    font-size: 0.7rem;
    color: var(--gray-400);
    text-align: center;
    padding: 4px;
}

/* ================================================================
 * Tax-Aware Mode Styles
 * ================================================================ */

.tax-aware-toggle {
    margin: 8px 0;
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-200);
}

.tax-aware-toggle .toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
}

.tax-aware-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.tax-aware-toggle .badge-pro {
    background: var(--primary);
    color: white;
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
}

.account-total-row {
    text-align: right;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 8px;
}

.account-total-row span {
    color: var(--primary);
}

.three-col {
    grid-template-columns: 1fr 1fr 1fr;
}

.tax-summary-boxes {
    margin-top: 0;
}

/* Withdrawal Table */
.withdrawal-details {
    margin: 8px 0;
}

.withdrawal-details summary {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    padding: 8px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}

.withdrawal-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 8px;
}

.withdrawal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.7rem;
}

.withdrawal-table th {
    position: sticky;
    top: 0;
    background: var(--gray-100);
    padding: 4px 6px;
    text-align: right;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-300);
}

.withdrawal-table th:first-child {
    text-align: center;
}

.withdrawal-table td {
    padding: 3px 6px;
    text-align: right;
    border-bottom: 1px solid var(--gray-100);
}

.withdrawal-table td:first-child {
    text-align: center;
    font-weight: 500;
}

.withdrawal-table tr:nth-child(even) {
    background: var(--gray-50);
}

.withdrawal-table tr:hover {
    background: #eff6ff;
}

/* ================================================================
 * Cookie Consent Banner
 * ================================================================ */

.cookie-consent-banner {
    position: fixed;
    bottom: -100px;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--gray-200);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    transition: bottom 0.3s ease-out;
    padding: 16px 20px;
}

.cookie-consent-banner.show {
    bottom: 0;
}

.cookie-consent-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.cookie-consent-text {
    flex: 1;
    font-size: 0.9rem;
    color: var(--gray-700);
    margin: 0;
}

.cookie-consent-text a {
    color: var(--primary);
    text-decoration: underline;
}

.cookie-consent-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.cookie-btn {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.cookie-btn-accept {
    background: var(--primary);
    color: white;
}

.cookie-btn-accept:hover {
    background: var(--primary-dark);
}

.cookie-btn-decline {
    background: var(--gray-200);
    color: var(--gray-700);
}

.cookie-btn-decline:hover {
    background: var(--gray-300);
}

@media (max-width: 768px) {
    .cookie-consent-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .cookie-consent-buttons {
        width: 100%;
        justify-content: center;
    }

    .cookie-btn {
        flex: 1;
        min-width: 100px;
    }
}
