* {
    box-sizing: border-box;
}

:root {
    --bg: #0b1220;
    --panel: #0f172a;
    --panel-2: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --primary: #2563eb;
    --accent: #059669;
    --border: #1f2937;
    --danger: #ef4444;
    /* Desktop grid column ratios (≥900px). Tweak these to adjust Inputs vs Summary width */
    --grid-left: 1.8fr;
    /* left column (Inputs) */
    --grid-right: 1.2fr;
    /* right column (Summary) */
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji;
    background: var(--bg);
    color: var(--text);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 12px 0 20px;
}

.app-header h1 {
    margin: 0 0 6px;
}

.sub {
    color: var(--muted);
    margin: 0;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 900px) {
    .grid {
        /* Two columns using CSS vars for easy tuning */
        grid-template-columns: var(--grid-left) var(--grid-right);
        align-items: start;
    }

    .grid.two {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    /* Items marked span-2 should span both columns */
    .grid>.span-2 {
        grid-column: 1 / -1;
    }

    /* Fallback: if the markup didn't include span-2, make the last card full width (Yearly breakdown) */
    .grid>.card:last-of-type {
        grid-column: 1 / -1;
    }
}

.card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.card-header h2 {
    margin: 0;
    font-size: 18px;
}

.card-body {
    padding: 14px 16px 18px;
}

.field {
    display: grid;
    gap: 6px;
    margin: 8px 0 10px;
}

.field label {
    font-size: 12px;
    color: var(--muted);
}

.label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    position: relative;
    /* anchor help popovers */
}

.field input[type="checkbox"] {
    vertical-align: middle;
}

.input-affix {
    display: flex;
    align-items: center;
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.input-affix.invalid {
    border-color: var(--danger);
}

.input-affix input {
    flex: 1;
    min-width: 0;
    /* allow shrinking so suffix affix stays visible */
    padding: 10px 12px;
    background: transparent;
    border: 0;
    color: var(--text);
    outline: none;
    font-size: 14px;
}

/* Hide number input spinners but keep numeric keyboard */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    appearance: textfield;
    /* Standard */
    -webkit-appearance: textfield;
    /* WebKit (Chrome/Safari) */
    -moz-appearance: textfield;
    /* Firefox */
}

.affix {
    padding: 8px 10px;
    color: var(--muted);
    border-right: 1px solid var(--border);
}

.affix+input {
    padding-left: 8px;
}

input+.affix {
    border-right: 0;
    border-left: 1px solid var(--border);
}

button {
    background: var(--primary);
    color: white;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

button.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.pill {
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
}

.summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 18px;
}

.summary-item {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}

.summary .label {
    color: var(--muted);
    font-size: 12px;
}

.summary .value {
    font-weight: 600;
    margin-top: 6px;
    font-size: 18px;
}

.summary .value.emphasize {
    color: #f3f4f6;
    font-size: 22px;
}

.chart-wrap {
    height: 300px;
}

/* Spacer card to preserve layout when chart is removed */
.card.spacer {
    min-height: 360px;
}

.table-wrap {
    overflow: auto;
}

.table-wrap .table-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
}

.table-wrap th,
.table-wrap td {
    text-align: right;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table-wrap td:last-child .icon-btn {
    margin-left: 8px;
}

.table-wrap th:first-child,
.table-wrap td:first-child,
.table-wrap th:nth-child(2),
.table-wrap td:nth-child(2) {
    text-align: left;
}

/* small icon button for help */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
}

.icon-btn:hover {
    color: var(--text);
    border-color: var(--primary);
}

/* small help popover for label "?" */
.help-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    max-width: 280px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
    z-index: 5;
}

.error-popover {
    margin-top: 6px;
    background: rgba(239, 68, 68, 0.12);
    color: var(--text);
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
}

/* modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(640px, calc(100% - 32px));
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.modal-body {
    padding: 14px;
}

.note {
    color: var(--muted);
    font-size: 12px;
    margin-top: 8px;
}

.badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    font-size: 10px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
}

/* utility spacing */
.mt-24 {
    margin-top: 24px;
}

.error {
    color: var(--danger);
}

.app-footer {
    color: var(--muted);
    text-align: center;
    margin: 16px 0 8px;
}

/* Debug panel */
.debug-panel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 260px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    z-index: 60;
}