/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --bg: #f3f4f1;
    --surface: #ffffff;
    --ink: #16211b;
    --ink-2: #5b6862;
    --ink-3: #8a958f;
    --line: #dfe4df;
    --accent: #1f6f50;
    --accent-ink: #ffffff;
    --accent-soft: #e2f0e8;
    --bar: #1a7a52;
    --danger: #b3261e;
    --danger-ink: #ffffff;
    --danger-soft: #fbe9e7;
    --shadow: 0 1px 2px rgba(22, 33, 27, 0.06);
    --radius: 12px;
    --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #121715;
        --surface: #1a211d;
        --ink: #edf1ee;
        --ink-2: #a2aea8;
        --ink-3: #6f7b75;
        --line: #2a332e;
        --accent: #4fb389;
        --accent-ink: #0d1a14;
        --accent-soft: #1d3129;
        --bar: #3fa07a;
        --danger: #f28b82;
        --danger-ink: #2b0d0b;
        --danger-soft: #3a1f1c;
        --shadow: none;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121715;
    --surface: #1a211d;
    --ink: #edf1ee;
    --ink-2: #a2aea8;
    --ink-3: #6f7b75;
    --line: #2a332e;
    --accent: #4fb389;
    --accent-ink: #0d1a14;
    --accent-soft: #1d3129;
    --bar: #3fa07a;
    --danger: #f28b82;
    --danger-ink: #2b0d0b;
    --danger-soft: #3a1f1c;
    --shadow: none;
}

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

html {
    font-family: var(--font);
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, p, dl { margin: 0; }
h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; }

/* ---------- Shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 34rem; margin: 0 auto; padding: 0 16px; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.brand {
    font-weight: 800;
    font-size: 1.125rem;
    letter-spacing: -0.01em;
    color: var(--ink);
}
.brand:hover { text-decoration: none; }

.nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 0 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-3);
}
.nav-link:hover { text-decoration: none; color: var(--ink-2); }
.nav-link.active { color: var(--accent); font-weight: 700; }
.nav-link svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.content {
    flex: 1;
    padding-top: 12px;
    padding-bottom: calc(var(--nav-height) + 24px + env(safe-area-inset-bottom));
}

@media (min-width: 720px) {
    .nav {
        position: static;
        border: 0;
        background: transparent;
        padding: 0;
        gap: 4px;
    }
    .nav-link {
        flex: none;
        flex-direction: row;
        gap: 8px;
        padding: 8px 14px;
        border-radius: 999px;
        font-size: 0.9375rem;
    }
    .nav-link.active { background: var(--accent-soft); }
    .nav-link svg { width: 18px; height: 18px; }
    .content { padding-top: 24px; padding-bottom: 48px; }
}

/* ---------- Common blocks ---------- */
.page-title { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 1rem; }
.block { margin-top: 2rem; }
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}
.section-head h2 { margin: 0; }
.section-head a { font-size: 0.875rem; font-weight: 600; }

.message {
    margin-top: 0.75rem;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.9375rem;
}
.flash { background: var(--accent-soft); color: var(--ink); }
.error { background: var(--danger-soft); color: var(--ink); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 20px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { text-decoration: none; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover:not(:disabled) { border-color: var(--ink-3); }
.danger { background: transparent; border-color: transparent; color: var(--danger); }
.danger:hover:not(:disabled) { background: var(--danger-soft); }
.danger-fill { background: var(--danger); color: var(--danger-ink); }
.icon-btn {
    width: 40px; height: 40px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 1rem; }

/* Segmented control */
.seg {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    max-width: 100%;
}
.seg button {
    border: 0;
    background: transparent;
    padding: 7px 14px;
    border-radius: 999px;
    font-weight: 500;
    color: var(--ink-2);
    white-space: nowrap;
}
.seg button[aria-pressed="true"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
}

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.875rem; font-weight: 500; color: var(--ink-2); }
.field input {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 44px;
    width: 100%;
}
.field input::placeholder { color: var(--ink-3); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.entry-form > .field, .entry-form > .fields { margin-top: 14px; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.choice { border: 0; padding: 0; margin: 0 0 0.5rem; display: flex; flex-direction: column; gap: 8px; }
.choice label { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.choice input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.file-name { font-size: 0.9375rem; color: var(--ink-2); word-break: break-all; }

/* ---------- Tips page ---------- */
.entry-title { font-size: 1rem; font-weight: 600; color: var(--ink-2); }

.amount-field {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 4px;
    border-bottom: 2px solid var(--line);
    transition: border-color 120ms ease;
}
.amount-field:focus-within { border-color: var(--accent); }
.currency {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    font-weight: 600;
    color: var(--ink-3);
    line-height: 1;
}
.amount-input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-size: clamp(3rem, 14vw, 4.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--ink);
    background: transparent;
    border: 0;
    padding: 4px 0 8px;
    outline: none;
}
.amount-input::placeholder { color: var(--ink-3); opacity: 0.6; }

.recent { margin-top: 2.5rem; }

/* Entry rows (shared with Reports) */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 12px 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: none;
    text-align: left;
    color: var(--ink);
    border-radius: 0;
}
.entry-row:hover { text-decoration: none; background: color-mix(in srgb, var(--surface) 60%, transparent); }
.entry-row.is-editing { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
.entry-main { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.entry-date { font-weight: 600; }
.entry-meta {
    display: flex;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--ink-2);
    min-width: 0;
}
.entry-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-amount { font-weight: 700; font-size: 1.0625rem; flex-shrink: 0; }

/* ---------- Reports ---------- */
.period { display: flex; flex-direction: column; gap: 14px; }
.period-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.period-title { font-size: 1.25rem; font-weight: 700; text-align: center; flex: 1; }

.summary { margin-top: 1.5rem; }
.hero {
    font-size: clamp(2.75rem, 12vw, 4rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.05;
}
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    margin-top: 1rem;
}
.stats div { display: flex; flex-direction: column-reverse; gap: 2px; }
.stats dt { font-size: 0.8125rem; color: var(--ink-2); }
.stats dd { margin: 0; font-size: 1.125rem; font-weight: 700; }
.summary .small { margin-top: 0.75rem; }

/* Weekday bars (single series) */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
    display: grid;
    grid-template-columns: 2.75rem 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 24px;
}
.bar-label { font-size: 0.875rem; color: var(--ink-2); }
.bar-track { display: block; height: 12px; }
.bar-fill {
    display: block;
    height: 100%;
    min-width: 4px;
    background: var(--bar);
    border-radius: 0 4px 4px 0;
}
.bar-value { font-size: 0.875rem; font-weight: 600; min-width: 4.5rem; text-align: right; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: 10px 0; border-bottom: 1px solid var(--line); text-align: left; }
.table thead th { font-weight: 500; color: var(--ink-2); font-size: 0.8125rem; }
.table tbody th { font-weight: 500; }
.table .num { text-align: right; }
.table tr.muted td, .table tr.muted th { color: var(--ink-3); }

/* ---------- Loading & errors ---------- */
.loading { display: grid; place-items: center; min-height: 60dvh; }
.loading-progress {
    position: relative;
    display: block;
    width: 6rem;
    height: 6rem;
}
.loading-progress circle {
    fill: none;
    stroke: var(--line);
    stroke-width: 0.5rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 700;
    inset: calc(30dvh + 2.4rem) 0 auto 0;
}
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui {
    color-scheme: light only;
    background: #fff3cd;
    color: #3b2f0a;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
#blazor-error-ui .reload { margin-left: 0.5rem; color: inherit; text-decoration: underline; }

.blazor-error-boundary {
    background: var(--danger-soft);
    color: var(--ink);
    padding: 1rem;
    border-radius: var(--radius);
}
.blazor-error-boundary::after { content: "An error has occurred."; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

/* FocusOnNavigate focuses the page heading; no ring needed there */
h1:focus { outline: none; }
