/*
 * Mis Finanzas - single hand-written stylesheet (no framework, no build step).
 * Mobile-first: base rules target a phone; the 900px breakpoint moves the
 * bottom tab bar into a top navigation for wide screens.
 */

/* ---------- Design tokens ---------- */
:root {
    color-scheme: light dark;

    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --text: #15171c;
    --text-muted: #5b6270;
    --border: #e1e4e9;
    --accent: #4b45d6;
    --accent-strong: #3a34b8;
    --accent-soft: #ebeafd;
    --on-accent: #ffffff;
    --income: #0b7d55;
    --income-soft: #e3f4ec;
    --expense: #c7392f;
    --expense-soft: #fbe9e7;
    --warning-bg: #fff6e0;
    --warning-text: #7a5300;
    --focus: #4b45d6;

    /* Category colours: every category stores a slot (1-12) and is drawn with
       --cat-N (.cat-swatch-N here, read by app.js for the chart), so it keeps
       its colour across months and follows the theme. --cat-other is the
       neutral "Others" slice. */
    --cat-1: #4b45d6;
    --cat-2: #e8705f;
    --cat-3: #1c9a6c;
    --cat-4: #e0a526;
    --cat-5: #3a8fd6;
    --cat-6: #a35fc9;
    --cat-7: #d4568c;
    --cat-8: #13999f;
    --cat-9: #b06a32;
    --cat-10: #6e9a1f;
    --cat-11: #c23b3b;
    --cat-12: #3d5a80;
    --cat-other: #a3a9b4;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --radius-sm: 10px;
    --radius: 16px;
    --radius-pill: 999px;
    --shadow: 0 1px 2px rgba(16, 18, 23, 0.04), 0 4px 16px rgba(16, 18, 23, 0.06);
    --tap: 44px;
    --tabbar-height: 64px;
    --topbar-height: 56px;
    --page-max: 960px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101217;
        --surface: #1a1d24;
        --surface-2: #242832;
        --text: #eceef2;
        --text-muted: #a1a8b5;
        --border: #2c313b;
        --accent: #8f8aff;
        --accent-strong: #aaa6ff;
        --accent-soft: #272653;
        --on-accent: #12121f;
        --income: #43d39b;
        --income-soft: #133227;
        --expense: #ff8577;
        --expense-soft: #3a1d1b;
        --warning-bg: #3a2e10;
        --warning-text: #f5d17a;
        --focus: #aaa6ff;

        --cat-1: #8f8aff;
        --cat-2: #ff8f7d;
        --cat-3: #43d39b;
        --cat-4: #f2c14e;
        --cat-5: #5eb2f5;
        --cat-6: #c58af0;
        --cat-7: #f57fb0;
        --cat-8: #4fd3d8;
        --cat-9: #e3a06a;
        --cat-10: #b6d96b;
        --cat-11: #ff6f6f;
        --cat-12: #93aedb;
        --cat-other: #6b7383;

        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-4));
}

h1, h2, h3, p {
    margin: 0;
}

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

img,
svg {
    display: block;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

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

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.skip-link:focus {
    top: calc(env(safe-area-inset-top) + var(--space-2));
}

.muted {
    color: var(--text-muted);
}

.amount {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.amount-income {
    color: var(--income);
}

.amount-expense {
    color: var(--expense);
}

.currency {
    font-size: 0.7em;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: calc(var(--topbar-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(var(--space-4), env(safe-area-inset-right)) 0 max(var(--space-4), env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--tap);
    color: var(--text);
    font-weight: 700;
    font-size: 1.05rem;
    text-decoration: none;
    /* Pushes the language switch and the account controls to the right edge. */
    margin-right: auto;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
}

.logout-form {
    margin: 0;
}

/* Account controls (admin, settings, sign out). Mobile first: square icon buttons whose text
   stays in the accessibility tree; from 720px up the text shows instead of the icon. */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

/* Two classes: must win over .button, which is declared further down. */
.button.topbar-action {
    width: var(--tap);
    padding: 0;
}

.topbar-icon {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

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

/* A phone has no room for the app name next to the language switch and three buttons:
   the logo stays (the link keeps its name for screen readers). */
@media (max-width: 479px) {
    .topbar:has(.topbar-actions) {
        gap: var(--space-2);
    }

    .topbar:has(.topbar-actions) .brand-name {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
}

@media (min-width: 720px) {
    .topbar-actions {
        gap: var(--space-2);
    }

    .button.topbar-action {
        width: auto;
        padding: 0 var(--space-5);
    }

    .topbar-icon {
        display: none;
    }

    .topbar-label {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
    }
}

.remember-me {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--tap);
    font-size: 0.95rem;
}

.locale-switch {
    display: inline-flex;
    padding: 3px;
    background: var(--surface-2);
    border-radius: var(--radius-pill);
}

.locale-switch a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap);
    min-height: 38px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.locale-switch a.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: end;
    min-height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border);
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-height);
    padding: var(--space-1) 2px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.tab-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.tab.is-active {
    color: var(--accent);
}

.tab-primary-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-top: -22px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
    border: 4px solid var(--bg);
}

.tab-primary.is-active .tab-primary-badge {
    background: var(--accent-strong);
}

/* ---------- Page layout ---------- */
.page {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: var(--space-4) max(var(--space-4), env(safe-area-inset-right)) var(--space-4) max(var(--space-4), env(safe-area-inset-left));
}

.page-narrow {
    max-width: 560px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
}

/* ---------- Buttons ---------- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--tap);
    padding: 0 var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.button-primary {
    background: var(--accent);
    color: var(--on-accent);
}

.button-primary:hover {
    background: var(--accent-strong);
}

.button-secondary {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

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

.button-ghost:hover {
    background: var(--surface-2);
}

/* Secondary action next to a primary one: a visible outline, unlike the faint ghost border. */
.button-outline {
    background: var(--surface);
    color: var(--text);
    border-color: color-mix(in srgb, var(--text) 28%, transparent);
}

.button-outline:hover {
    background: var(--surface-2);
    border-color: color-mix(in srgb, var(--text) 45%, transparent);
}

.button-danger-ghost {
    background: transparent;
    color: var(--expense);
    border-color: transparent;
}

.button-danger-ghost:hover {
    background: var(--expense-soft);
}

.button-small {
    padding: 0 var(--space-3);
    font-size: 0.9rem;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    border-radius: 50%;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

.icon-button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
}

/* ---------- Notices ---------- */
.notice {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.notice-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.notice-error {
    background: var(--expense-soft);
    color: var(--expense);
}

/* ---------- Dashboard ---------- */
.period-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.period-picker {
    flex: 1;
    text-align: center;
}

.period-picker summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    list-style: none;
    cursor: pointer;
}

.period-picker summary::-webkit-details-marker {
    display: none;
}

.period-picker summary::after {
    content: "";
    width: 8px;
    height: 8px;
    margin-left: var(--space-2);
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: translateY(-2px) rotate(45deg);
}

.period-picker[open] summary::after {
    transform: translateY(2px) rotate(-135deg);
}

.period-label {
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: capitalize;
}

.period-form {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding: var(--space-4);
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.period-form label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.inline-field {
    display: flex;
    gap: var(--space-2);
}

.inline-field .input,
.inline-field input[type="month"] {
    flex: 1;
    min-width: 0;
}

.chips {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    /* Enlarge the hit area to 44px without changing the visual size. */
    position: relative;
}

.chip::after {
    content: "";
    position: absolute;
    inset: -4px 0;
}

.chip.is-active {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

.summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.stat {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-4);
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.stat-balance {
    grid-column: 1 / -1;
    background: var(--accent);
    border-color: transparent;
    color: var(--on-accent);
}

.stat-balance .stat-label,
.stat-balance .currency {
    color: color-mix(in srgb, var(--on-accent) 75%, transparent);
}

.stat-balance .stat-value {
    font-size: 2.1rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-4);
    text-align: center;
}

.empty-state h2 {
    font-size: 1.1rem;
}

.empty-state p {
    color: var(--text-muted);
    max-width: 36ch;
}

.breakdown {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
}

.breakdown-body {
    display: grid;
    gap: var(--space-4);
}

.chart-wrap {
    position: relative;
    width: min(260px, 100%);
    margin: 0 auto;
}

.legend {
    display: grid;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.legend li {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 36px;
    border-bottom: 1px solid var(--border);
}

.legend li:last-child {
    border-bottom: 0;
}

.breakdown-all summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.legend-plain {
    margin-top: var(--space-2);
}

.swatch {
    flex: none;
    width: 12px;
    height: 12px;
    border-radius: 4px;
    background: var(--cat-other);
}

/* A category's own colour, by slot: legend swatches, the Categories page and its picker. */
.cat-swatch-1 { background: var(--cat-1); }
.cat-swatch-2 { background: var(--cat-2); }
.cat-swatch-3 { background: var(--cat-3); }
.cat-swatch-4 { background: var(--cat-4); }
.cat-swatch-5 { background: var(--cat-5); }
.cat-swatch-6 { background: var(--cat-6); }
.cat-swatch-7 { background: var(--cat-7); }
.cat-swatch-8 { background: var(--cat-8); }
.cat-swatch-9 { background: var(--cat-9); }
.cat-swatch-10 { background: var(--cat-10); }
.cat-swatch-11 { background: var(--cat-11); }
.cat-swatch-12 { background: var(--cat-12); }
.cat-swatch-other { background: var(--cat-other); }

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

.legend-value {
    font-weight: 600;
}

/* ---------- Ledger ---------- */
.ledger {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ledger-date {
    padding: var(--space-3) var(--space-1) 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ledger-date:first-child {
    padding-top: 0;
}

.ledger-item {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "main amount"
        "actions actions";
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-left: 4px solid var(--expense);
}

.ledger-item.is-income {
    border-left-color: var(--income);
}

.ledger-main {
    grid-area: main;
    min-width: 0;
}

.ledger-concept {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ledger-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.pill {
    display: inline-block;
    max-width: 100%;
    padding: 1px var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.78rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ledger-amount {
    grid-area: amount;
    align-self: center;
    font-size: 1.1rem;
    font-weight: 700;
}

.ledger-actions {
    grid-area: actions;
    display: flex;
    justify-content: flex-end;
    gap: var(--space-1);
    margin: 0 calc(-1 * var(--space-2)) calc(-1 * var(--space-1));
}

.ledger-actions form {
    margin: 0;
}

/* ---------- Forms ---------- */
.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-4);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

/* The new-category field, hidden by app.js until "+ New category" is chosen. */
.field[hidden] {
    display: none;
}

.field-row {
    display: flex;
    gap: var(--space-3);
}

.field-grow {
    flex: 1;
}

.field-currency {
    width: 96px;
}

.field-label {
    padding: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.input,
input[type="month"] {
    width: 100%;
    min-height: 48px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    /* 16px+ keeps iOS Safari from zooming into focused inputs. */
    font: inherit;
    font-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
}

.input:focus,
input[type="month"]:focus {
    border-color: var(--accent);
    outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 0;
}

.input-amount {
    font-size: 1.25rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

#currency {
    text-transform: uppercase;
}

.has-error .input {
    border-color: var(--expense);
}

.has-error .field-label {
    color: var(--expense);
}

.fieldError {
    color: var(--expense);
    font-size: 0.85rem;
    font-weight: 500;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1);
    padding: var(--space-1);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

.segment {
    position: relative;
    display: flex;
}

.segment input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

.segment span {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    border-radius: 8px;
    font-weight: 600;
    color: var(--text-muted);
}

.segment input:checked + span {
    background: var(--surface);
    box-shadow: var(--shadow);
}

.segment-expense input:checked + span {
    color: var(--expense);
}

.segment-income input:checked + span {
    color: var(--income);
}

.segment input:focus-visible + span {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.form-actions .button {
    width: 100%;
}

/* Upload */
.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-6) var(--space-4);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    text-align: center;
    cursor: pointer;
}

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

.dropzone:has(+ .file-input:focus-visible) {
    border-color: var(--accent);
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.dropzone-icon {
    width: 48px;
    height: 48px;
    padding: 10px;
    border-radius: 50%;
    background: var(--accent);
    fill: var(--on-accent);
}

.dropzone-title {
    font-weight: 700;
}

.dropzone-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.dropzone-file {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    word-break: break-all;
}

/* Error page */
.error-state h1 {
    font-size: 1.4rem;
}

.error-icon {
    width: 56px;
    height: 56px;
    fill: var(--expense);
}

/* ---------- Wide screens ---------- */
@media (min-width: 600px) {
    .summary {
        grid-template-columns: repeat(3, 1fr);
    }

    .stat-balance {
        grid-column: auto;
    }

    .stat-balance .stat-value {
        font-size: 1.6rem;
    }

    .breakdown-body {
        grid-template-columns: 260px 1fr;
        align-items: center;
    }

    .form-actions {
        flex-direction: row-reverse;
        justify-content: flex-start;
    }

    .form-actions .button {
        width: auto;
    }

    /* Single-action forms (sign-in, registration, reset) keep a full-width button. */
    .form-actions-block .button {
        width: 100%;
    }

    .ledger-item {
        grid-template-columns: 1fr auto auto;
        grid-template-areas: "main amount actions";
        align-items: center;
    }

    .ledger-actions {
        margin: 0;
    }
}

@media (min-width: 900px) {
    body {
        padding-bottom: var(--space-6);
    }

    .tabbar {
        position: sticky;
        top: calc(var(--topbar-height) + env(safe-area-inset-top));
        bottom: auto;
        display: flex;
        justify-content: center;
        gap: var(--space-1);
        min-height: 0;
        padding: var(--space-2) var(--space-4);
        background: var(--surface);
        border-top: 0;
        border-bottom: 1px solid var(--border);
        z-index: 15;
    }

    .tab {
        flex-direction: row;
        gap: var(--space-2);
        min-height: var(--tap);
        padding: 0 var(--space-4);
        border-radius: var(--radius-pill);
        font-size: 0.92rem;
    }

    .tab:hover {
        background: var(--surface-2);
        color: var(--text);
    }

    .tab.is-active {
        background: var(--accent-soft);
        color: var(--accent-strong);
    }

    .tab-icon {
        width: 20px;
        height: 20px;
    }

    .tab-primary-badge {
        width: auto;
        height: auto;
        margin: 0;
        border: 0;
        background: none;
        color: inherit;
        box-shadow: none;
    }

    .tab-primary {
        order: 5;
        background: var(--accent);
        color: var(--on-accent);
    }

    .tab-primary:hover,
    .tab-primary.is-active {
        background: var(--accent-strong);
        color: var(--on-accent);
    }

    .page {
        padding-top: var(--space-6);
        gap: var(--space-5);
    }
}

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

/* ---------- Loading state (receipt upload) ---------- */
.form-loadable {
    position: relative;
}

.spinner {
    display: inline-block;
    flex: none;
    width: 18px;
    height: 18px;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-inline {
    display: none;
}

.button.is-loading .spinner-inline {
    display: inline-block;
}

.button:disabled {
    opacity: 0.75;
    cursor: progress;
}

.spinner-large {
    width: 44px;
    height: 44px;
    border-width: 4px;
    color: var(--accent);
}

.loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-5);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    text-align: center;
}

.loading-overlay[hidden] {
    display: none;
}

.loading-message {
    max-width: 32ch;
    color: var(--text);
    font-weight: 600;
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}

@media (prefers-reduced-motion: reduce) {
    /* Overrides the global animation reset: a slow pulse instead of spinning. */
    .spinner {
        animation: pulse 1.6s ease-in-out infinite !important;
        border-color: currentColor;
    }
}

/* With JS the upload form submits as soon as a photo is chosen, so the
   explicit submit button is redundant; without JS it stays visible. */
.js [data-loading-button] {
    display: none;
}

/* ---------- Ledger range filter and summary ---------- */
.range-bar {
    align-items: center;
}

.range-label {
    flex: 1;
    text-transform: none;
}

.period-bar .period-picker {
    align-self: center;
    text-align: center;
    text-transform: capitalize;
}

.range-picker summary {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}

.range-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    align-items: end;
    margin-top: var(--space-2);
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.range-form .button {
    grid-column: 1 / -1;
}

.ledger-summary {
    display: grid;
    gap: var(--space-2);
}

.summary-row {
    display: grid;
    grid-template-columns: auto repeat(3, 1fr);
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
}

.summary-currency {
    font-weight: 700;
    color: var(--text-muted);
}

.summary-item {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.summary-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.summary-item .amount {
    font-weight: 700;
}

@media (min-width: 600px) {
    .range-form {
        grid-template-columns: 1fr 1fr auto;
    }

    .range-form .button {
        grid-column: auto;
    }
}

/* ---------- Insights and budgets ---------- */
.insights-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: 0 var(--space-4);
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
}

.insights-link svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.insight-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.insight-list {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding-left: var(--space-5);
}

.insight-rows {
    display: grid;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.insight-row {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

.insight-row:last-child {
    border-bottom: 0;
}

.insight-row-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 36px;
}

.insight-name {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    min-width: 0;
    font-weight: 600;
}

.insight-amount {
    font-weight: 700;
}

.insight-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.budget-progress-list {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.budget-progress {
    --state-color: var(--income);
    --state-bg: var(--income-soft);
}

.budget-progress.is-warning {
    --state-color: var(--warning-text);
    --state-bg: var(--warning-bg);
}

.budget-progress.is-over {
    --state-color: var(--expense);
    --state-bg: var(--expense-soft);
}

.budget-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.budget-name {
    font-weight: 600;
}

/* Text label next to the color, so the state never relies on color alone. */
.budget-state {
    padding: 1px var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--state-bg);
    color: var(--state-color);
    font-size: 0.78rem;
    font-weight: 700;
}

.progress {
    height: 10px;
    overflow: hidden;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
}

.progress-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--state-color);
}

.budget-figures {
    margin-top: var(--space-1);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.budget-list {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.budget-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
}

.budget-main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.budget-edit {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.budget-edit .input {
    flex: 1;
    min-width: 0;
}

.budget-item > form:last-child {
    grid-row: 1;
    grid-column: 2;
}

/* ---------- Categories page ---------- */
.category-list {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.category-item {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
}

.category-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.category-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.category-swatch {
    flex: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    border: 0;
}

.color-choice {
    position: relative;
    display: inline-flex;
}

/* The radio stays in the accessibility tree and keyboard order; the swatch is what is seen. */
.color-choice input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.color-choice-swatch {
    display: block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
}

.color-choice input:checked + .color-choice-swatch {
    box-shadow: 0 0 0 2px var(--text);
}

.color-choice input:focus-visible + .color-choice-swatch {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.category-meta {
    font-size: 0.85rem;
}

.category-actions summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.category-action {
    display: grid;
    gap: var(--space-1);
    margin: var(--space-3) 0 0;
}

.page-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
    font-size: 0.95rem;
}

.page-links a {
    font-weight: 600;
}

/* ---------- Public demo banner ---------- */
.demo-banner {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1) var(--space-3);
    padding: calc(var(--space-2) + env(safe-area-inset-top)) var(--space-4) var(--space-2);
    background: var(--warning-bg);
    color: var(--warning-text);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.demo-banner a {
    color: inherit;
}

/* The banner already pads for the notch, so the sticky top bar below it does not. */
.demo-banner + .topbar {
    padding-top: 0;
    min-height: var(--topbar-height);
}

/* ---------- Insights tone selector ---------- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.tone-switch form {
    display: inline-flex;
    gap: 2px;
    margin: 0;
    padding: 3px;
    background: var(--surface-2);
    border-radius: var(--radius-pill);
}

.tone-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    filter: grayscale(0.6);
    opacity: 0.7;
}

.tone-button[aria-pressed="true"] {
    background: var(--surface);
    box-shadow: var(--shadow);
    filter: none;
    opacity: 1;
}

.insights-summary {
    display: flex;
    flex-direction: column;
}

.insights-summary .insights-link {
    border-radius: var(--radius);
}

.insights-summary-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0 var(--space-4) var(--space-4);
}

.insight-summary-line {
    flex: 1 1 200px;
    color: var(--text-muted);
}

/* ---------- Admin panel ---------- */
.admin-tabs {
    margin-bottom: var(--space-3);
}

.admin-list {
    display: grid;
    gap: var(--space-2);
    margin: 0 0 var(--space-4);
    padding: 0;
    list-style: none;
}

.admin-item {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
}

.admin-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.admin-email {
    overflow-wrap: anywhere;
}

.admin-meta {
    margin: 0;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

/* The freshly issued link: wraps inside the card instead of running off a phone screen. */
.issued-link {
    display: block;
    padding: var(--space-3);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-all;
    white-space: pre-wrap;
    resize: none;
}

.issued-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-2) 0;
}

/* Copying needs app.js: without it the field can still be selected by hand. */
html:not(.js) [data-copy-target] {
    display: none;
}

/* ---------- Public landing page (anonymous visitors to /) ---------- */
/* No tab bar here, so the body keeps no room for it. */
body.landing {
    padding-bottom: env(safe-area-inset-bottom);
}

@media (prefers-reduced-motion: no-preference) {
    html:has(body.landing) {
        scroll-behavior: smooth;
    }
}

.login-about {
    text-align: center;
    font-size: 0.95rem;
}

/* The landing page is wider than the app pages: the hero needs room for two columns.
   Spacing stays on the 8px scale (the 48px and 64px steps only exist here). */
body.landing {
    --landing-max: 1080px;
    --landing-gap: 48px;
    --landing-gap-lg: 64px;
    /* Phone bezel around the screenshots: dark in both themes, lifted a little on a dark page. */
    --landing-frame: #16181d;
    --landing-shot-shadow: 0 2px 4px rgba(16, 18, 23, 0.06), 0 24px 48px -16px rgba(16, 18, 23, 0.3);
}

@media (prefers-color-scheme: dark) {
    body.landing {
        --landing-frame: #2c313b;
        --landing-shot-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -16px rgba(0, 0, 0, 0.6);
    }
}

.landing-page {
    max-width: var(--landing-max);
    gap: var(--landing-gap);
    padding-top: var(--space-5);
}

/* Anchored sections clear the sticky top bar. */
.landing-page > section {
    scroll-margin-top: calc(var(--topbar-height) + env(safe-area-inset-top) + var(--space-4));
}

/* ----- Hero: copy and CTAs, then one phone screenshot ----- */
.landing-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: var(--space-6);
}

.landing-hero-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
}

.landing-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin: 0;
    font-size: clamp(2.25rem, 7vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.badge-beta {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.landing-tagline {
    max-width: 60ch;
    color: var(--text-muted);
    font-size: 1.125rem;
    line-height: 1.6;
}

.landing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.landing-actions .button,
.landing-contact-button {
    min-height: 48px;
    padding: 0 var(--space-5);
    font-size: 1rem;
}

.landing-beta-note {
    max-width: 60ch;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Below 900px the hero is a single column: the screenshot would push the benefits out of the
   first screen and repeat the tour's first step (same image, so hiding it costs no download). */
.landing-hero-shot {
    display: none;
    position: relative;
    isolation: isolate;
    justify-self: center;
    width: min(100%, 300px);
    margin: 0;
}

/* A soft accent glow behind the phone. */
.landing-hero-shot::before {
    content: "";
    position: absolute;
    inset: 8% -16%;
    z-index: -1;
    border-radius: 50%;
    background: radial-gradient(closest-side, var(--accent-soft), transparent);
}

.landing-hero-shot img,
.tour-shot img {
    width: 100%;
    height: auto;
    border: 6px solid var(--landing-frame);
    border-radius: 32px;
    background: var(--landing-frame);
    box-shadow: var(--landing-shot-shadow);
}

/* Phones: the CTAs fill the width, the primary one first. */
@media (max-width: 479px) {
    .landing-actions {
        flex-direction: column;
        align-self: stretch;
    }

    .landing-actions .button {
        width: 100%;
    }
}

@media (min-width: 900px) {
    .landing-page {
        gap: var(--landing-gap-lg);
        padding-top: var(--landing-gap);
    }

    .landing-hero {
        grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
        gap: var(--landing-gap);
    }

    .landing-hero-shot {
        display: block;
    }

    .landing-hero-shot img {
        border-width: 8px;
        border-radius: 40px;
    }
}

/* ----- Benefits: four compact cards ----- */
.benefit-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

/* On a phone each card is a row: icon on the left, title and line on the right. */
.benefit {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    column-gap: var(--space-4);
    row-gap: var(--space-1);
    align-content: start;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.benefit-icon {
    grid-row: span 2;
    width: 40px;
    height: 40px;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    fill: none;
    stroke: var(--accent-strong);
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.benefit-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.benefit-text {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

@media (min-width: 600px) {
    .benefit-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .benefit {
        grid-template-columns: minmax(0, 1fr);
        row-gap: var(--space-2);
        padding: var(--space-5);
    }

    .benefit-icon {
        grid-row: auto;
        margin-bottom: var(--space-2);
    }
}

@media (min-width: 900px) {
    .benefit-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ----- Tour: screenshot and text side by side, alternating ----- */
.landing-section-title {
    margin: 0;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.landing-tour {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.landing-tour > .landing-section-title {
    text-align: center;
}

.tour-steps {
    display: flex;
    flex-direction: column;
    gap: var(--landing-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tour-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
    scroll-margin-top: calc(var(--topbar-height) + env(safe-area-inset-top) + var(--space-4));
}

.tour-shot {
    width: min(100%, 220px);
    margin: 0;
}

.tour-shot-install {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    aspect-ratio: 390 / 560;
    border: 1px solid var(--border);
    border-radius: 32px;
    background: linear-gradient(160deg, var(--accent-soft), var(--surface-2));
}

.tour-shot-install img {
    width: 96px;
    height: 96px;
    border: 0;
    border-radius: 24px;
    background: none;
    box-shadow: var(--shadow);
}

.tour-shot-name {
    font-weight: 700;
}

.tour-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    max-width: 60ch;
    text-align: center;
}

.tour-count {
    display: inline-flex;
    gap: var(--space-1);
    color: var(--accent-strong);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tour-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
}

.tour-text {
    color: var(--text-muted);
}

@media (min-width: 720px) {
    .tour-steps {
        gap: var(--landing-gap-lg);
    }

    .tour-step {
        flex-direction: row;
        justify-content: center;
        gap: var(--landing-gap-lg);
    }

    .tour-step:nth-child(even) {
        flex-direction: row-reverse;
    }

    .tour-shot {
        flex: 0 0 auto;
        width: 240px;
    }

    .tour-body {
        flex: 0 1 28rem;
        align-items: flex-start;
        text-align: left;
    }

    .tour-title {
        font-size: 1.5rem;
    }

    .tour-text {
        font-size: 1.0625rem;
    }
}

/* ----- Closing CTA ----- */
.landing-contact {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: var(--landing-gap) var(--space-5);
    background: linear-gradient(160deg, var(--accent-soft), var(--surface) 70%);
    text-align: center;
}

.landing-contact-text {
    max-width: 60ch;
    color: var(--text-muted);
    font-size: 1.0625rem;
}

.landing-contact-button {
    margin-top: var(--space-2);
}

.button-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* ----- Footer ----- */
.landing-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    max-width: var(--landing-max);
    margin: var(--landing-gap) auto 0;
    padding: var(--space-5) max(var(--space-4), env(safe-area-inset-right)) var(--space-6) max(var(--space-4), env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

.landing-footer p {
    max-width: 60ch;
}

.landing-footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    font-weight: 600;
}

/* Same trade-off as the app's top bar: on a phone the logo stays, the name goes. */
@media (max-width: 479px) {
    .landing .topbar {
        gap: var(--space-2);
    }

    .landing .topbar .brand-name {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
}

.button.landing-topbar-signin {
    white-space: nowrap;
}

/* ---------- Settings: "How do I get my key?" guide ---------- */
.key-guide {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
}

.key-guide summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: var(--tap);
    padding: 0 var(--space-3);
    color: var(--accent);
    font-weight: 600;
    list-style: none;
    cursor: pointer;
}

.key-guide summary::-webkit-details-marker {
    display: none;
}

.key-guide summary::after {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
}

.key-guide[open] summary::after {
    transform: translateY(2px) rotate(-135deg);
}

.key-guide-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: 0 var(--space-3) var(--space-4);
}

.key-guide-body p {
    margin: 0;
}

.key-guide-heading {
    margin: var(--space-2) 0 0;
    font-size: 0.95rem;
    font-weight: 700;
}

.key-guide-steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding-left: var(--space-5);
}

.key-guide-steps a {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.key-guide-note {
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--warning-bg);
    color: var(--warning-text);
    font-size: 0.9rem;
}

/* ---------- Privacy notice and the links to it ---------- */
.privacy-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-4);
}

.privacy-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding-left: var(--space-5);
}

.privacy-list code {
    font-size: 0.9em;
    overflow-wrap: anywhere;
}

.privacy-back,
.settings-privacy {
    text-align: center;
    font-size: 0.95rem;
}

.privacy-back a,
.settings-privacy a {
    font-weight: 600;
}

.register-privacy {
    font-size: 0.9rem;
}

.login-about {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2);
}
