:root {
    --navy: #0A192F;
    --navy-light: #112240;
    --gold: #D4AF37;
    --slate: #64748B;
    --white: #FFFFFF;
    --bg-gray: #F1F5F9;
    --text-main: #1E293B;
    --text-muted: #64748B;
    --border: #CBD5E1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-gray);
    color: var(--text-main);
    line-height: 1.5;
    padding: 10px;
}

.calculator-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* --- HEADER & CURRENCY TOGGLE --- */
.calc-header {
    background: var(--navy);
    color: white;
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.calc-header h2 span { color: var(--gold); }

.header-controls { display: flex; gap: 10px; align-items: center; }

.currency-select {
    padding: 0.5rem;
    border-radius: 6px;
    border: none;
    background: var(--navy-light);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    font-size: 0.85rem;
}

.btn-primary { background: var(--gold); color: var(--navy); }

/* --- GRID SYSTEM --- */
.calc-grid {
    display: grid;
    grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
    .calc-grid { grid-template-columns: 300px 1fr 1.2fr; }
}

.panel {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

@media (min-width: 1024px) {
    .panel { border-bottom: none; border-right: 1px solid var(--border); padding: 1.5rem; }
}

/* --- TYPOGRAPHY & HERO --- */
.hero-number {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 800;
    color: var(--navy);
    text-align: center;
    margin: 0.5rem 0 1.5rem;
    letter-spacing: -1px;
}

.summary-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.stat-box { background: #F8FAFC; padding: 0.8rem; border-radius: 8px; border: 1px solid var(--border); text-align: center; }
.stat-label { display: block; font-size: 0.65rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; }
.stat-value { display: block; font-size: 0.95rem; font-weight: 700; color: var(--navy); margin-top: 4px; }
.gold-border { grid-column: span 2; border: 2px solid var(--gold); background: #FFFDF5; }

/* --- COMPACT INPUTS --- */
.input-group { margin-bottom: 0.85rem; }
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
label { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; display: block; }
input[type="number"], select { width: 100%; padding: 0.5rem 0.6rem; border-radius: 6px; border: 1px solid var(--border); font-size: 0.9rem; }
input[type="range"] { width: 100%; accent-color: var(--gold); margin-top: 5px; }
.highlight-group { background: #F1F5F9; padding: 0.85rem; border-radius: 8px; border: 1px dashed var(--gold); margin-top: 1rem; }
details summary { font-size: 0.85rem; font-weight: bold; color: var(--navy); cursor: pointer; margin: 0.5rem 0; }

/* --- PIE CHART & COMPARISON --- */
.comparison-box { margin-top: 1.5rem; padding: 0.85rem; background: var(--navy-light); color: var(--white); border-radius: 8px; font-size: 0.85rem; text-align: center; }
.pie-container { margin-top: 1.5rem; text-align: center; }
.pie-container h4 { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 10px; }
#pie-chart { width: 100%; height: 160px; display: block; }
.pie-legend { display: flex; justify-content: center; gap: 15px; font-size: 0.75rem; margin-top: 10px; font-weight: 600; }
.leg-prin::before { content: '■'; color: var(--navy); margin-right: 4px; }
.leg-int::before { content: '■'; color: var(--gold); margin-right: 4px; }
.leg-tax::before { content: '■'; color: var(--slate); margin-right: 4px; }

/* --- OVERLAP FIX: CHART & TABLE PANEL --- */
.chart-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem; /* Forces space between chart and table */
}

.canvas-container { 
    width: 100%; 
    height: 200px; 
    background: #FAFAFA; 
    border-radius: 8px; 
    position: relative;
    overflow: hidden; /* Prevents canvas spilling out */
}

/* Force canvas to respect its parent container fully */
canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.table-container { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 0.75rem; min-width: 300px; }
th { background: var(--navy); color: white; padding: 8px; text-align: right; }

/* Narrowed Month Column */
th:first-child, td:first-child { 
    width: 40px; 
    text-align: center; 
    font-weight: 700; 
    padding: 8px 4px;
}

td { padding: 8px; border-bottom: 1px solid #EDF2F7; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 400px) {
    .hide-mobile { display: none; }
    .input-row { grid-template-columns: 1fr; } 
}

/* --- PRINT --- */
@media print {
    body { background: white; padding: 0; }
    .header-controls, input[type="range"], .input-panel { display: none; }
    .calc-grid { display: block; }
    .calculator-wrapper { box-shadow: none; border: 1px solid #EEE; }
}