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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3345;
    --text: #e4e6ef;
    --text-dim: #8b8fa3;
    --green: #34d399;
    --green-dim: #065f46;
    --red: #f87171;
    --red-dim: #7f1d1d;
    --blue: #60a5fa;
    --cyan: #22d3ee;
    --yellow: #fbbf24;
    --purple: #a78bfa;
    --radius: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

/* --- Header --- */
header {
    text-align: center;
    padding: 2rem 0 1rem;
}
header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--green), var(--cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.subtitle {
    color: var(--text-dim);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* --- Cards --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.card h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--cyan);
}
.card h3 {
    font-size: 0.95rem;
    color: var(--text-dim);
    margin: 1.25rem 0 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Forms --- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}
.form-group select,
.input-with-prefix input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}
.form-group select:focus,
.input-with-prefix input:focus {
    border-color: var(--cyan);
}
.input-with-prefix {
    position: relative;
}
.input-with-prefix .prefix {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 1rem;
    pointer-events: none;
}
.input-with-prefix input {
    padding-left: 1.5rem;
}
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    padding-top: 0.5rem;
}
.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--cyan);
}

.btn-primary {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, var(--green), var(--cyan));
    color: #000;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
    font-family: var(--font);
}
.btn-primary:hover { opacity: 0.9; }

/* --- Summary --- */
.summary-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.summary-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0;
}
.summary-item .label { flex: 1; color: var(--text-dim); font-size: 0.9rem; }
.summary-item .value { font-family: var(--mono); font-size: 1.05rem; font-weight: 600; }
.summary-item .per { font-size: 0.8rem; color: var(--text-dim); }
.summary-item.gross .value { color: var(--green); }
.summary-item.super .value { color: var(--text-dim); font-weight: 400; }

/* --- Deductions --- */
.deductions-list {
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
}
.deduction-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.9rem;
}
.deduction-amount {
    font-family: var(--mono);
    color: var(--red);
}
.deduction-amount.credit {
    color: var(--green);
}
.total-line {
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}
.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-weight: 600;
}
.total-amount.deduction { color: var(--red); font-family: var(--mono); }
.total-amount { font-family: var(--mono); }

.net-pay {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--green-dim);
    border: 1px solid var(--green);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    font-weight: 700;
    font-size: 1.1rem;
}
.net-pay span:last-child {
    font-family: var(--mono);
    color: var(--green);
    font-size: 1.2rem;
}

/* --- Period Table --- */
.table-scroll { overflow-x: auto; }
.period-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}
.period-table th {
    text-align: right;
    padding: 0.4rem 0.6rem;
    color: var(--text-dim);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.period-table th:first-child { text-align: left; }
.period-table td {
    text-align: right;
    padding: 0.4rem 0.6rem;
    font-family: var(--mono);
    font-size: 0.82rem;
}
.period-table td:first-child {
    text-align: left;
    font-family: var(--font);
    color: var(--text-dim);
}
.row-gross td:not(:first-child) { color: var(--green); }
.row-tax td:not(:first-child) { color: var(--red); }
.row-help td:not(:first-child) { color: var(--red); }
.row-net td:not(:first-child) { color: var(--green); font-weight: 600; }
.row-super td:not(:first-child) { color: var(--text-dim); }

/* --- Tax Spending --- */
.tax-intro { font-size: 0.9rem; margin-bottom: 1rem; }
.spending-list { display: flex; flex-direction: column; gap: 0.6rem; }
.spending-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.25rem 1rem;
    align-items: center;
}
.spending-item .s-name {
    font-size: 0.88rem;
    font-weight: 500;
}
.spending-item .s-amount {
    text-align: right;
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap;
}
.spending-bar-track {
    grid-column: 1 / -1;
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}
.spending-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--cyan), var(--blue));
    transition: width 0.5s ease;
}
.spending-desc {
    grid-column: 1 / -1;
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.4;
}
.source-note {
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    font-style: italic;
}

/* --- Budget --- */
.budget-controls {
    display: flex;
    gap: 1.5rem;
    align-items: end;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.budget-controls .form-group { flex: 1; min-width: 150px; }
.budget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.budget-net {
    font-family: var(--mono);
    font-weight: 700;
    color: var(--green);
    font-size: 1.1rem;
}

.budget-list { display: flex; flex-direction: column; gap: 0.5rem; }
.budget-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0 0.75rem;
    align-items: center;
}
.budget-item .b-name { font-size: 0.88rem; }
.budget-item .b-amount {
    font-family: var(--mono);
    font-size: 0.85rem;
    text-align: right;
}
.budget-item .b-pct {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: right;
    min-width: 42px;
}
.budget-bar-track {
    grid-column: 1 / -1;
    height: 5px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}
.budget-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}
.budget-item.rent .b-name { color: var(--purple); }
.budget-item.rent .budget-bar-fill { background: var(--purple); }
.budget-item.savings .b-name { color: var(--cyan); font-weight: 600; }
.budget-item.savings .budget-bar-fill { background: var(--cyan); }
.budget-item:not(.rent):not(.savings) .budget-bar-fill { background: var(--blue); }

.budget-surplus {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
}
.budget-surplus.positive {
    background: var(--green-dim);
    border: 1px solid var(--green);
    color: var(--green);
}
.budget-surplus.negative {
    background: var(--red-dim);
    border: 1px solid var(--red);
    color: var(--red);
}

.affordability-check {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.88rem;
    line-height: 1.5;
}
.affordability-check.good { background: rgba(52,211,153,0.1); color: var(--green); }
.affordability-check.warn { background: rgba(251,191,36,0.1); color: var(--yellow); }
.affordability-check.bad { background: rgba(248,113,113,0.1); color: var(--red); }

/* --- Footer --- */
footer {
    text-align: center;
    padding: 2rem 0 1rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}
footer a { color: var(--cyan); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* --- Utility --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    header h1 { font-size: 1.5rem; }
    .card { padding: 1rem; }
    .net-pay { flex-direction: column; text-align: center; gap: 0.25rem; }
    .period-table { font-size: 0.75rem; }
    .period-table td, .period-table th { padding: 0.3rem 0.35rem; }
    .budget-controls { flex-direction: column; gap: 0.75rem; }
    .spending-item { grid-template-columns: 1fr; }
    .spending-item .s-amount { text-align: left; }
}
