/* Tax page (js/tax.js). Builds on the app tokens in style.css (light + dark). */

:root {
    --tr-src-tx: var(--accent-primary);
    --tr-src-profile: #0d9488;
    --tr-src-default: #b45309;
    --tr-src-override: #7c3aed;
    --tr-seg-it: #3b82f6;
    --tr-seg-se: #8b5cf6;
    --tr-seg-ot: #64748b;
    --tr-seg-st: #0d9488;
    --tr-seg-kept: color-mix(in srgb, var(--accent-success) 28%, var(--bg-tertiary));
    --tr-gutter: #1e3a5f;
}
[data-theme="dark"] {
    --tr-src-profile: #2dd4bf;
    --tr-src-default: #fbbf24;
    --tr-src-override: #a78bfa;
    --tr-seg-it: #60a5fa;
    --tr-seg-se: #a78bfa;
    --tr-seg-ot: #94a3b8;
    --tr-seg-st: #2dd4bf;
    --tr-gutter: #93c5fd;
}

.tr-page { max-width: 1280px; display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.tr-page * { min-width: 0; }
.tr-muted { color: var(--text-muted); }
.tr-loading { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
.tr-error p { margin-bottom: 0.75rem; }
.tr-disclaimer { font-size: 0.8rem; color: var(--text-muted); max-width: 78ch; }
:where(.tr-page) button:focus-visible, :where(.tr-page) input:focus-visible,
:where(.tr-page) select:focus-visible, :where(.tr-page) summary:focus-visible {
    outline: 2px solid var(--accent-primary); outline-offset: 2px;
}

/* Top bar: year switch + export */
.tr-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.tr-years { display: inline-flex; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-secondary); }
.tr-years button {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0; text-align: left;
    padding: 0.4rem 0.9rem; border: 0; border-right: 1px solid var(--border-color);
    background: transparent; color: var(--text-secondary); cursor: pointer; font: inherit;
}
.tr-years button:last-child { border-right: 0; }
.tr-years button strong { font-size: 1rem; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tr-years button span { font-size: 0.72rem; line-height: 1.3; }
.tr-years button.on { background: var(--text-primary); }
.tr-years button.on strong, .tr-years button.on span { color: var(--bg-secondary); }
.tr-bar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.tr-proj { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); }
.tr-proj select { width: auto; padding: 0.3rem 0.5rem; font-size: 0.8rem; }
.tr-status { font-size: 0.78rem; color: var(--text-muted); min-width: 7.5em; }

/* Hero: the bottom line as a sentence + where the income goes */
.tr-hero { transition: opacity 0.2s; }
.tr-hero.busy { opacity: 0.6; }
.tr-hero-top { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.tr-hero-scope { font-size: 0.85rem; color: var(--text-secondary); }
.tr-headline { font-size: clamp(1.6rem, 3.4vw, 2.4rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 0.15rem 0 0.25rem; }
.tr-headline strong { font-weight: 750; font-variant-numeric: tabular-nums; }
.tr-headline .bad { color: var(--accent-danger); }
.tr-headline .good { color: var(--accent-success); }
.tr-hero-sub { color: var(--text-secondary); font-size: 0.9rem; }
.tr-basis { display: inline-flex; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; }
.tr-basis button { border: 0; background: var(--bg-secondary); color: var(--text-secondary); padding: 0.35rem 0.75rem; font-size: 0.8rem; cursor: pointer; }
.tr-basis button + button { border-left: 1px solid var(--border-color); }
.tr-basis button.on { background: var(--text-primary); color: var(--bg-secondary); }
.tr-flow { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 1.1rem 0 0.5rem; gap: 2px; background: var(--bg-tertiary); }
.tr-flow span { flex-basis: 0; min-width: 3px; }
.seg-it { background: var(--tr-seg-it); }
.seg-se { background: var(--tr-seg-se); }
.seg-ot { background: var(--tr-seg-ot); }
.seg-st { background: var(--tr-seg-st); }
.seg-kept { background: var(--tr-seg-kept); }
.tr-flow-key { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem; font-size: 0.8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tr-flow-key i { display: inline-block; width: 0.65rem; height: 0.65rem; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }
.tr-figs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.75rem 1.25rem; margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border-color); }
.tr-figs dt { font-size: 0.75rem; color: var(--text-secondary); }
.tr-figs dd { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tr-figs dd small { display: block; font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }
.tr-deadline.late dd { color: var(--accent-danger); }

/* Hints */
.tr-hints { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
.tr-hints li {
    display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
    font-size: 0.85rem; color: var(--text-secondary); padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm); background: var(--bg-secondary); border: 1px solid var(--border-color);
}
.tr-hints li.act { border-left: 3px solid var(--tr-src-default); color: var(--text-primary); }
.tr-hints .plan-link { white-space: nowrap; font-size: 0.85rem; }

/* Layout */
.tr-grid { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 1rem; align-items: start; }
.tr-main { display: flex; flex-direction: column; gap: 1rem; }
.tr-main > #tr-view { display: flex; flex-direction: column; gap: 1rem; }
.tr-side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: calc(var(--topbar-height) + 1rem); max-height: calc(100vh - var(--topbar-height) - 2rem); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.tr-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border-color); overflow-x: auto; }
.tr-tabs button { border: 0; background: none; padding: 0.55rem 0.9rem; font: inherit; font-size: 0.9rem; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tr-tabs button.on { color: var(--text-primary); border-bottom-color: var(--accent-primary); font-weight: 600; }
.tr-sec-head { margin-bottom: 0.85rem; }
.tr-sec-head h3 { font-size: 1.02rem; font-weight: 600; }
.tr-sec-head p { color: var(--text-secondary); font-size: 0.85rem; max-width: 72ch; }
.tr-sec-row { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.tr-foot { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.75rem; }

/* Form lines: IRS-style line-number gutter */
.tr-lines { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tr-lines th { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); text-align: left; padding: 0 0.5rem 0.35rem; }
.tr-lines td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border-color); vertical-align: top; }
.tr-lines tr:last-child td { border-bottom: 0; }
.tr-lines td.ln { width: 3.2rem; padding-left: 0; }
.tr-lines td.ln span {
    display: inline-flex; align-items: center; justify-content: center; min-width: 2.4rem; height: 1.45rem; padding: 0 0.3rem;
    border: 1px solid color-mix(in srgb, var(--tr-gutter) 45%, transparent); border-radius: 3px;
    color: var(--tr-gutter); font-weight: 650; font-size: 0.78rem; font-variant-numeric: tabular-nums;
}
.tr-lines td.ln span:empty { border: 0; }
.tr-lines td.lbl small { display: block; color: var(--text-muted); font-size: 0.76rem; }
.tr-lines td.amt, .tr-lines th.amt { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; width: 9rem; }
.tr-lines td.amt.muted { color: var(--text-muted); }
.tr-lines tr.tot td { font-weight: 650; }
.tr-lines tr.tot td.amt { border-top: 1px solid var(--text-secondary); }
.tr-lines tr.hi td.amt { color: var(--text-primary); font-size: 1rem; }
.tr-lines tr.info td { border-bottom: 0; padding-top: 0.15rem; }
.tr-row-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: center; margin-top: 0.15rem; }
.tr-row-meta:empty { display: none; }
.tr-drill, .tr-ref, .tr-reset {
    background: none; border: 0; padding: 0; font: inherit; font-size: 0.76rem; cursor: pointer;
    color: var(--accent-primary); text-decoration: underline; text-underline-offset: 2px;
}
.tr-ref { color: var(--text-secondary); }
.tr-reset { color: var(--tr-src-override); }
.tr-amt-edit { display: inline-flex; align-items: center; }
.tr-amt-edit::before { content: '$'; color: var(--text-muted); margin-right: 0.2rem; }
.tr-amt-input {
    width: 7.5rem; text-align: right; font: inherit; font-variant-numeric: tabular-nums;
    padding: 0.2rem 0.4rem; border: 1px solid var(--border-color); border-radius: 4px;
    background: var(--bg-primary); color: var(--text-primary);
}
.tr-amt-input:hover { border-color: var(--text-muted); }
.tr-counted { display: block; font-size: 0.72rem; color: var(--text-muted); }

/* Source chips */
.tr-src { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; color: var(--text-secondary); white-space: nowrap; }
.tr-src i { width: 0.55rem; height: 0.55rem; border-radius: 50%; display: inline-block; flex: none; }
.tr-src.src-tx i { background: var(--tr-src-tx); }
.tr-src.src-profile i { background: var(--tr-src-profile); }
.tr-src.src-default i { border: 1.5px dashed var(--tr-src-default); background: transparent; }
.tr-src.src-default { color: var(--tr-src-default); }
.tr-src.src-override i { background: var(--tr-src-override); border-radius: 2px; }
.tr-src.src-override { color: var(--tr-src-override); }
.tr-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-top: 0.5rem; }

/* Forms view */
.tr-forms { display: flex; flex-direction: column; gap: 0.6rem; }
.tr-form { padding: 0; }
.tr-form > summary {
    list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 0.85rem 1.1rem;
}
.tr-form > summary::-webkit-details-marker { display: none; }
.tr-form > summary::before { content: '▸'; color: var(--text-muted); margin-right: 0.15rem; transition: transform 0.15s; }
.tr-form[open] > summary::before { transform: rotate(90deg); }
.tr-form-title { flex: 1; display: flex; flex-wrap: wrap; gap: 0 0.6rem; align-items: baseline; }
.tr-form-title strong { font-size: 0.98rem; }
.tr-form-title span { font-size: 0.82rem; color: var(--text-secondary); }
.tr-form-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.tr-form .tr-lines { margin: 0 1.1rem 0.9rem; width: calc(100% - 2.2rem); }

/* Inputs panel */
.tr-inputs .tr-sec-head { margin-bottom: 0.5rem; }
.tr-group { border-top: 1px solid var(--border-color); }
.tr-group > summary { list-style: none; cursor: pointer; padding: 0.65rem 0; font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.tr-group > summary::-webkit-details-marker { display: none; }
.tr-group > summary::after { content: '+'; margin-left: auto; color: var(--text-muted); font-weight: 400; }
.tr-group[open] > summary::after { content: '−'; }
.tr-count { font-size: 0.72rem; font-weight: 500; color: var(--tr-src-override); }
.tr-fields { display: flex; flex-direction: column; gap: 0.7rem; padding-bottom: 0.85rem; }
.tr-field { display: grid; grid-template-columns: 1fr; gap: 0.2rem; border-radius: 6px; transition: background 0.4s; }
.tr-field.flash { background: color-mix(in srgb, var(--tr-src-default) 16%, transparent); }
.tr-field > label { font-size: 0.82rem; color: var(--text-secondary); }
.tr-field.is-bool { grid-template-columns: auto 1fr; align-items: center; column-gap: 0.55rem; }
.tr-field.is-bool > label { grid-column: 2; grid-row: 1; cursor: pointer; }
.tr-field.is-bool > input { grid-column: 1; grid-row: 1; width: 1rem; height: 1rem; accent-color: var(--accent-primary); }
.tr-field.is-bool > .tr-field-meta, .tr-field.is-bool > .tr-detail { grid-column: 2; }
.tr-field select.input, .tr-field .input { padding: 0.45rem 0.6rem; font-size: 0.9rem; }
.tr-money { position: relative; display: block; }
.tr-money::before { content: '$'; position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.9rem; pointer-events: none; }
.tr-money.plain::before { content: none; }
.tr-money .input { padding-left: 1.35rem; font-variant-numeric: tabular-nums; width: 100%; }
.tr-money.plain .input { padding-left: 0.6rem; }
.tr-field-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; align-items: center; }
.tr-ytd { font-size: 0.72rem; color: var(--text-muted); }
.tr-detail { font-size: 0.74rem; color: var(--text-muted); line-height: 1.4; }
.tr-wi-pair { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; }
.tr-wi-pair select { width: auto; }
.tr-wi-out { border-top: 1px solid var(--border-color); padding-top: 0.75rem; }
.tr-wi-total { font-size: 1rem; }
.tr-wi-total strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.tr-wi-total.good strong { color: var(--accent-success); }
.tr-wi-total.bad strong { color: var(--accent-danger); }
.tr-wi-break { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.35rem 1rem; margin-top: 0.5rem; }
.tr-wi-break dt { font-size: 0.72rem; color: var(--text-secondary); }
.tr-wi-break dd { font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Dependents, payers, estimated payments, mapping */
.tr-deps, .tr-payers { list-style: none; display: flex; flex-direction: column; }
.tr-deps li { display: grid; grid-template-columns: 1fr auto auto; gap: 0.75rem; align-items: center; padding: 0.6rem 0; border-top: 1px solid var(--border-color); }
.tr-deps li small, .tr-payers small { display: block; font-size: 0.76rem; color: var(--text-muted); }
.tr-pill { font-size: 0.74rem; padding: 0.15rem 0.55rem; border-radius: 999px; border: 1px solid var(--border-color); white-space: nowrap; }
.tr-pill.ok { color: var(--accent-success); border-color: color-mix(in srgb, var(--accent-success) 45%, transparent); }
.tr-pill.mid { color: var(--tr-src-profile); border-color: color-mix(in srgb, var(--tr-src-profile) 45%, transparent); }
.tr-pill.no { color: var(--text-muted); }
.tr-depform { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 1rem; margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px dashed var(--border-color); }
.tr-depform label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--text-secondary); }
.tr-depform label.chk, .tr-payers label.chk { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text-primary); }
.tr-depform-actions { grid-column: 1 / -1; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.tr-payers li { padding: 0.5rem 0; border-top: 1px solid var(--border-color); font-size: 0.86rem; }
.tr-payers label.chk { align-items: flex-start; cursor: pointer; }
.tr-payers input { margin-top: 0.3rem; accent-color: var(--accent-primary); }
.tr-es { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tr-es th { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); text-align: left; padding: 0 0.5rem 0.35rem 0; }
.tr-es td { padding: 0.45rem 0.5rem 0.45rem 0; border-top: 1px solid var(--border-color); font-variant-numeric: tabular-nums; }
.tr-es td small { display: block; color: var(--text-muted); font-size: 0.74rem; }
.tr-es .amt { text-align: right; }
.tr-es tr.past td { color: var(--text-muted); }
.tr-es tr.next td:first-child { font-weight: 650; }
.tr-map-wrap, .tr-drill-wrap { overflow-x: auto; }
.tr-map { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tr-map th { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); text-align: left; padding: 0 0.5rem 0.35rem; }
.tr-map td { padding: 0.5rem; border-top: 1px solid var(--border-color); vertical-align: middle; }
.tr-map td small { display: block; color: var(--text-muted); font-size: 0.74rem; }
.tr-map .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-map select { min-width: 14rem; padding: 0.35rem 0.5rem; font-size: 0.85rem; }

/* Drill-down modal */
.tr-drill-head { margin-bottom: 0.75rem; font-size: 0.88rem; }
.tr-drill-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.tr-drill-table th { font-size: 0.74rem; color: var(--text-muted); font-weight: 500; text-align: left; padding: 0 0.4rem 0.35rem; }
.tr-drill-table td { padding: 0.45rem 0.4rem; border-top: 1px solid var(--border-color); vertical-align: middle; }
.tr-drill-table td small { display: block; color: var(--text-muted); font-size: 0.74rem; }
.tr-drill-table .amt { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tr-drill-table select { padding: 0.3rem 0.4rem; font-size: 0.8rem; max-width: 12rem; }
.tr-bup { width: 4.5rem; padding: 0.3rem 0.4rem; font-size: 0.8rem; }

@media (max-width: 1180px) {
    .tr-figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
    .tr-grid { grid-template-columns: minmax(0, 1fr); }
    .tr-side { position: static; max-height: none; overflow: visible; order: -1; }
}
@media (max-width: 640px) {
    .tr-bar { flex-direction: column; align-items: stretch; }
    .tr-years { display: grid; grid-template-columns: 1fr 1fr; }
    .tr-bar-right { justify-content: flex-start; }
    .tr-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tr-lines td.amt, .tr-lines th.amt { width: auto; }
    .tr-lines td.ln { width: 2.6rem; }
    .tr-lines td.ln span { min-width: 2rem; font-size: 0.72rem; }
    .tr-amt-input { width: 5.6rem; }
    .tr-form .tr-lines { margin: 0 0.6rem 0.75rem; width: calc(100% - 1.2rem); }
    .tr-form > summary { padding: 0.75rem; }
    .tr-depform { grid-template-columns: minmax(0, 1fr); }
    .tr-deps li { grid-template-columns: 1fr auto; }
    .tr-deps li .plan-link { grid-column: 2; }
    .tr-hints li { flex-direction: column; gap: 0.25rem; }
    .tr-map select { min-width: 10rem; }
}
@media (prefers-reduced-motion: reduce) {
    .tr-page * { transition: none !important; scroll-behavior: auto !important; }
}
@media print {
    .tr-side, .tr-bar-right, .tr-tabs, .tr-hints { display: none; }
    .tr-grid { grid-template-columns: 1fr; }
}
.tr-hints li.more { background: none; border: 0; padding: 0.1rem 0.85rem; }
@media (max-width: 480px) {
    .tr-page .card { padding: 1rem 0.85rem; }
    .tr-lines { font-size: 0.82rem; }
    .tr-lines td { padding: 0.4rem 0.3rem; }
    .tr-lines td.amt { font-size: 0.8rem; }
    .tr-lines tr.hi td.amt { font-size: 0.86rem; }
    .tr-lines td.lbl small { font-size: 0.72rem; }
    .tr-lines td.ln { width: 2.3rem; }
    .tr-lines td.ln span { min-width: 1.8rem; height: 1.3rem; font-size: 0.68rem; padding: 0 0.15rem; }
    .tr-headline { font-size: 1.55rem; }
}

/* Year statuses, no-data banner, filed return */
.tr-years button.st-filed span::before { content: '✓ '; color: var(--accent-success); }
.tr-years button.on.st-filed span::before { color: inherit; }
.tr-years button.st-past_due:not(.on) span { color: var(--tr-src-default); }
.tr-nodata { border-left: 3px solid var(--tr-src-default); }
.tr-nodata h3 { font-size: 1.02rem; margin-bottom: 0.25rem; }
.tr-nodata p { color: var(--text-secondary); font-size: 0.88rem; max-width: 70ch; margin-bottom: 0.75rem; }
.tr-nodata-actions, .tr-filed-btns { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.tr-filed.done { border-left: 3px solid var(--accent-success); }
.tr-hero-scope .tr-pill { margin-left: 0.35rem; font-size: 0.7rem; vertical-align: 1px; }
@media (max-width: 640px) {
    .tr-years { grid-template-columns: 1fr 1fr; }
    .tr-years button:nth-child(2) { border-right: 0; }
    .tr-years button:nth-child(-n+2) { border-bottom: 1px solid var(--border-color); }
}
/* #page-content is an overflow container while the window scrolls, so sticky can't engage there;
   the side column flows with the page instead of clipping. */
.tr-side { position: static; max-height: none; overflow: visible; }
