/*
 * Copyright (c) 2026 Tax Doc Scanner. All rights reserved.
 */

/*
 * Tax Doc Scanner — one stylesheet, no framework, no web fonts.
 *
 * The look is "ledger": warm paper, hairline rules, a serif for headings and a tabular monospace for
 * anything numeric. CPAs read tables of numbers all day; the type stack is chosen so figures line up
 * in columns and a 3 never reads as an 8.
 */

:root {
    --paper: #fbfaf7;
    --surface: #ffffff;
    --surface-2: #f4f2ec;
    --ink: #14202e;
    --ink-soft: #3d4a5a;
    --muted: #6b7787;
    --line: #e2ded3;
    --line-strong: #cdc7b8;

    --accent: #0f766e;
    --accent-strong: #0b5952;
    --accent-wash: #e6f2f0;
    --gold: #a86b1a;
    --gold-wash: #fdf4e5;
    --danger: #b42318;
    --danger-wash: #fdeceb;
    --ok: #1a7f5a;

    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 2px rgba(20, 32, 46, .06), 0 8px 24px -12px rgba(20, 32, 46, .18);
    --shadow-lg: 0 2px 4px rgba(20, 32, 46, .05), 0 24px 48px -20px rgba(20, 32, 46, .28);

    --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #10161e;
        --surface: #161e28;
        --surface-2: #1c2632;
        --ink: #e8eaed;
        --ink-soft: #b9c1cb;
        --muted: #8b96a5;
        --line: #2a3644;
        --line-strong: #3a4858;

        --accent: #4db6a9;
        --accent-strong: #6fcabd;
        --accent-wash: #11302d;
        --gold: #d9a441;
        --gold-wash: #2e2413;
        --danger: #f2695c;
        --danger-wash: #2f1614;
        --ok: #4cc38a;

        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
        --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 24px 48px -20px rgba(0, 0, 0, .7);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Faint ledger rules behind the page — the "accounting paper" cue, kept subtle enough to read over. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: linear-gradient(var(--line) 1px, transparent 1px);
    background-size: 100% 32px;
    opacity: .35;
    mask-image: linear-gradient(to bottom, transparent, #000 40%, #000 60%, transparent);
}

.container {
    position: relative;
    z-index: 1;
    width: min(1120px, 100% - 2.5rem);
    margin-inline: auto;
}

h1, h2, h3 {
    font-family: var(--serif);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -.01em;
    margin: 0 0 .5rem;
}

h1 { font-size: clamp(2rem, 1.4rem + 2.6vw, 3.25rem); }
h2 { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 2rem); }
h3 { font-size: 1.15rem; }

p { margin: 0 0 1rem; }

a {
    color: var(--accent);
    text-underline-offset: 3px;
}

a:hover { color: var(--accent-strong); }

code, pre, .num {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

/* ── Navbar ─────────────────────────────────────────────────────── */

.nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: 2.5rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-family: var(--serif);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    margin-right: auto;
}

.nav-brand:hover { color: var(--ink); }
.nav-brand svg { display: block; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: .95rem;
    font-weight: 500;
}

.nav-links a:hover { color: var(--accent); }

.nav-credits {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .7rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--surface);
    font-size: .85rem;
    color: var(--ink-soft);
}

.nav-credits strong {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.nav-logout {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: .95rem;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
}

.nav-logout:hover { color: var(--danger); }

/* ── Buttons ────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}

.btn:hover { background: var(--accent-strong); color: #fff; }
.btn:active { transform: translateY(1px); }

.btn:disabled, .btn[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink);
}

.btn-secondary:hover {
    background: var(--surface-2);
    border-color: var(--muted);
    color: var(--ink);
}

.btn-ghost {
    background: none;
    border-color: transparent;
    color: var(--accent);
    padding-inline: .5rem;
}

.btn-ghost:hover { background: var(--accent-wash); color: var(--accent-strong); }

.btn-lg { padding: .9rem 1.6rem; font-size: 1.02rem; }
.btn-block { width: 100%; }

@media (prefers-color-scheme: dark) {
    .btn { color: #08211e; }
    .btn:hover { color: #08211e; }
}

/* ── Cards & panels ─────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.card-head h2, .card-head h3 { margin: 0; }

/* Long-form prose (terms/privacy): give section headings room to breathe. */
.legal h2 { margin-top: 1.9rem; }
.legal h2:first-of-type { margin-top: .25rem; }
.legal p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

/* ── Alerts ─────────────────────────────────────────────────────── */

.alert {
    display: flex;
    gap: .65rem;
    padding: .85rem 1rem;
    border: 1px solid;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: .92rem;
}

.alert-ok {
    background: var(--accent-wash);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--accent-strong);
}

.alert-error {
    background: var(--danger-wash);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
    color: var(--danger);
}

.alert-warn {
    background: var(--gold-wash);
    border-color: color-mix(in srgb, var(--gold) 40%, transparent);
    color: var(--gold);
}

/* ── Forms ──────────────────────────────────────────────────────── */

.form-group { margin-bottom: 1.1rem; }

label {
    display: block;
    margin-bottom: .35rem;
    font-size: .875rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.form-control {
    display: block;
    width: 100%;
    padding: .65rem .8rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: .95rem;
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-wash);
}

.field-error {
    margin-top: .3rem;
    font-size: .82rem;
    color: var(--danger);
}

.form-hint {
    margin-top: .3rem;
    font-size: .82rem;
    color: var(--muted);
}

/* ── Auth pages ─────────────────────────────────────────────────── */

.auth {
    max-width: 26rem;
    margin: 3rem auto 4rem;
}

.auth-art {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.auth h1 {
    font-size: 1.9rem;
    text-align: center;
    margin-bottom: .35rem;
}

.auth-sub {
    text-align: center;
    color: var(--muted);
    margin-bottom: 2rem;
}

.auth-alt {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
    text-align: center;
    font-size: .9rem;
    color: var(--muted);
}

/* ── Landing page ───────────────────────────────────────────────── */

.lp-hero {
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    gap: 3.5rem;
    align-items: center;
    padding: 2rem 0 4.5rem;
}

@media (max-width: 860px) {
    .lp-hero { grid-template-columns: 1fr; gap: 2.5rem; padding-bottom: 3rem; }
}

.lp-badge {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem .8rem;
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: 999px;
    background: var(--accent-wash);
    color: var(--accent-strong);
    font-size: .8rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.lp-badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.lp-accent {
    display: block;
    color: var(--accent);
    font-style: italic;
}

.lp-lead {
    font-size: 1.15rem;
    color: var(--ink-soft);
    max-width: 34rem;
    margin-bottom: 1.75rem;
}

.lp-cta-row {
    display: flex;
    gap: .85rem;
    flex-wrap: wrap;
    align-items: center;
}

.lp-note {
    margin: 1.25rem 0 0;
    font-size: .85rem;
    color: var(--muted);
}

.lp-section {
    padding: 3.5rem 0;
    border-top: 1px solid var(--line);
}

.lp-section-head {
    max-width: 40rem;
    margin-bottom: 2.5rem;
}

.lp-grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 1.25rem;
}

.lp-feature .icon {
    display: inline-flex;
    padding: .6rem;
    border-radius: var(--radius);
    background: var(--accent-wash);
    color: var(--accent);
    margin-bottom: .85rem;
}

.lp-feature h3 { margin-bottom: .35rem; }

.lp-feature p {
    color: var(--muted);
    font-size: .93rem;
    margin: 0;
}

.lp-steps {
    counter-reset: step;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1.5rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.lp-steps li { counter-increment: step; }

.lp-steps li::before {
    content: counter(step);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--ink);
    color: var(--paper);
    font-family: var(--mono);
    font-size: .9rem;
    font-weight: 600;
    margin-bottom: .75rem;
}

.lp-steps h3 { margin-bottom: .3rem; }

.lp-steps p {
    color: var(--muted);
    font-size: .93rem;
    margin: 0;
}

.lp-cta-band {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
    padding: 2.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    margin-bottom: 3.5rem;
}

.lp-cta-band h2 { margin-bottom: .25rem; }
.lp-cta-band p { margin: 0; color: var(--muted); }

.footer {
    padding: 2rem 0 3rem;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: .85rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ── Page header (signed-in pages) ──────────────────────────────── */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.page-head p {
    color: var(--muted);
    margin: 0;
    max-width: 46rem;
}

/* ── Scan page ──────────────────────────────────────────────────── */

.scan-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 20rem;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 3rem;
}

@media (max-width: 900px) {
    .scan-grid { grid-template-columns: 1fr; }
}

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    padding: 2.5rem 1.5rem;
    border: 2px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.dropzone:hover, .dropzone.is-over {
    border-color: var(--accent);
    background: var(--accent-wash);
}

.dropzone strong { font-size: 1.02rem; }
.dropzone .muted { font-size: .875rem; }

.dz-actions {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: .35rem;
}

.file-list {
    list-style: none;
    padding: 0;
    margin: 1.25rem 0 0;
    display: grid;
    gap: .5rem;
}

.file-list:empty { display: none; }

.file-list li {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: .88rem;
}

.file-list .name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-list .size {
    font-family: var(--mono);
    font-size: .8rem;
    color: var(--muted);
}

.file-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--line);
    flex-shrink: 0;
}

/* Output-mode picker: two big radio cards. */
.mode-options {
    display: grid;
    gap: .75rem;
}

.mode-option {
    position: relative;
    display: block;
    padding: 1rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.mode-option:hover { border-color: var(--accent); }

.mode-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode-option:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-wash);
    box-shadow: 0 0 0 1px var(--accent);
}

.mode-option:has(input:focus-visible) {
    box-shadow: 0 0 0 3px var(--accent-wash);
}

.mode-option .mode-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
    font-size: .95rem;
    margin-bottom: .2rem;
    color: var(--ink);
}

.mode-option .mode-desc {
    font-size: .82rem;
    color: var(--muted);
    line-height: 1.45;
}

.tag-tbd {
    font-family: var(--sans);
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .1rem .4rem;
    border-radius: 4px;
    background: var(--gold-wash);
    color: var(--gold);
    border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
}

.result {
    margin-bottom: 3rem;
}

.result-body {
    max-height: 34rem;
    overflow: auto;
    padding: 1.1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: .82rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    tab-size: 2;
}

.result-actions {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
}

/* Busy state while Gemini is working. */
.is-busy { pointer-events: none; opacity: .6; }

.spinner {
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2s; }
    * { transition: none !important; }
}

/* ── Billing ────────────────────────────────────────────────────── */

.billing-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 22rem;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 3rem;
}

@media (max-width: 900px) {
    .billing-grid { grid-template-columns: 1fr; }
}

.balance {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .25rem;
}

.balance .figure {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 3rem;
    font-weight: 600;
    line-height: 1;
    color: var(--ink);
}

.balance .unit { color: var(--muted); font-size: .95rem; }

.pack {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    border-block: 1px solid var(--line);
    margin: 1.25rem 0;
}

.pack .price {
    font-family: var(--mono);
    font-size: 1.75rem;
    font-weight: 600;
}

.pack .per {
    font-size: .82rem;
    color: var(--muted);
}

.ledger {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.ledger th {
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 .75rem .5rem 0;
    border-bottom: 1px solid var(--line-strong);
}

.ledger td {
    padding: .6rem .75rem .6rem 0;
    border-bottom: 1px solid var(--line);
    vertical-align: baseline;
}

.ledger tr:last-child td { border-bottom: none; }

.ledger .num {
    text-align: right;
    padding-right: 0;
}

.ledger .source {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
}

#payment-element { margin-block: 1rem; }

/* ── Account page ───────────────────────────────────────────────── */

.account {
    max-width: 34rem;
    margin-bottom: 3rem;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 520px) {
    .field-row { grid-template-columns: 1fr; }
}

.readonly-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 0;
    border-bottom: 1px solid var(--line);
}

.readonly-row:last-of-type { border-bottom: none; }

.readonly-row .label {
    font-size: .875rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.readonly-row .value {
    font-family: var(--mono);
    font-size: .88rem;
    color: var(--muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Utilities ──────────────────────────────────────────────────
   These exist so no template needs a style="" attribute. The CSP sets
   style-src 'self' with no 'unsafe-inline', which blocks inline style
   attributes outright — a nonce can't rescue them, since nonces only apply
   to <style> elements. Reach for a class here rather than reintroducing one. */

.mt-sm { margin-top: 1rem; }
.mt-md { margin-top: 1.25rem; }
.mt-lg { margin-top: 1.5rem; }

.divider {
    border: none;
    border-top: 1px solid var(--line);
    margin: 1.5rem 0;
}

.hero-art {
    width: 100%;
    height: auto;
}

.inline-form { margin: 0; }
