/* Centsibly component styles. Colors, type and radii come from tokens.css. */

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

html, body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--text-base);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* FocusOnNavigate moves focus to each page title for screen readers; no ring needed there. */
h1:focus { outline: none; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Screen scaffolding ---------- */

.screen {
    min-height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.screen__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: calc(24px + env(safe-area-inset-top)) 20px calc(116px + env(safe-area-inset-bottom));
}

.screen--plain .screen__body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.screen--form .screen__body { padding-top: calc(20px + env(safe-area-inset-top)); gap: 18px; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: var(--tap);
}

.topbar__titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.topbar__title { font-size: var(--text-title); font-weight: 700; letter-spacing: -0.03em; }
.topbar__title--sm { font-size: var(--text-lg); font-weight: 700; letter-spacing: 0; }
.topbar__sub { font-size: var(--text-sm); color: var(--muted); }

.wordmark { font-size: 20px; font-weight: 800; letter-spacing: -0.03em; }
.wordmark span { color: var(--accent); }
.wordmark--lg { font-size: 34px; }

.section-title { font-size: var(--text-md); font-weight: 700; color: var(--muted); padding: 0 4px; }
.section-title--ink { color: var(--ink); font-size: 15px; padding: 0; }
.section { display: flex; flex-direction: column; gap: 8px; }
.section__head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.section__link { font-size: var(--text-md); font-weight: 600; text-decoration: none; }

/* ---------- Buttons ---------- */

.pill-btn {
    height: 40px;
    padding: 0 14px;
    border-radius: var(--pill);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    white-space: nowrap;
}
.pill-btn:hover { color: var(--ink); border-color: var(--faint); }
.pill-btn--quiet { color: var(--muted); }

.icon-btn {
    width: var(--tap);
    height: var(--tap);
    flex: none;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    text-decoration: none;
}
.icon-btn:hover { color: var(--ink); border-color: var(--faint); }
.icon-btn--accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.icon-btn--accent:hover { color: var(--on-accent); background: var(--accent-strong); }
.icon-btn--danger { color: var(--danger); }
.icon-btn--danger:hover { color: var(--danger); }

.month-switch {
    height: 40px;
    border-radius: var(--pill);
    border: 1px solid var(--line);
    background: var(--surface);
    display: inline-flex;
    align-items: center;
    font-size: var(--text-md);
    font-weight: 600;
}
.month-switch a, .month-switch span.month-switch__arrow {
    width: 36px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ink);
}
.month-switch span.month-switch__arrow { color: var(--line); }
.month-switch__label { padding: 0 2px; white-space: nowrap; }

.btn-primary {
    height: 58px;
    width: 100%;
    border: 0;
    border-radius: var(--pill);
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--text-lg);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: background 120ms ease, opacity 120ms ease;
}
.btn-primary:hover { background: var(--accent-strong); color: var(--on-accent); }
.btn-primary:disabled { background: var(--faint); opacity: 0.7; }
.btn-primary--compact { height: 48px; font-size: var(--text-base); }

.btn-text {
    background: none; border: 0; padding: 10px 4px;
    color: var(--accent); font-weight: 600; font-size: var(--text-md);
    min-height: var(--tap);
}
.btn-text--danger { color: var(--danger); }
.btn-text--muted { color: var(--muted); }

/* ---------- Cards, tiles, lists ---------- */

.card { background: var(--surface); border-radius: var(--radius-lg); padding: 16px; }
.card--xl { border-radius: var(--radius-xl); padding: 20px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile {
    background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
    display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink);
}
.tile:hover { color: var(--ink); }
.tile__label { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); color: var(--muted); min-width: 0; }
.tile__label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile__value--lg { font-size: 20px; }

.dot { width: 8px; height: 8px; flex: none; border-radius: 3px; background: var(--c, var(--faint)); }

.list { background: var(--surface); border-radius: var(--radius-lg); padding: 4px 14px; }
.row {
    display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 0;
    border-bottom: 1px solid var(--line-soft); color: var(--ink); text-decoration: none;
    background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left;
}
.row:last-child { border-bottom: 0; }
a.row:hover, button.row:hover { color: var(--ink); }
.row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row__title { font-size: var(--text-base); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub { font-size: var(--text-xs); color: var(--muted); }
.row__amount { font-size: var(--text-base); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row__amount--muted { color: var(--muted); }
.row--setting { min-height: 56px; justify-content: space-between; }
.row--setting .row__value { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

.cat-icon {
    width: 38px; height: 38px; flex: none; border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--c, #5F646B) 13%, white);
    color: color-mix(in srgb, var(--c, #5F646B) 85%, black);
    display: inline-flex; align-items: center; justify-content: center;
}
.cat-icon--lg { width: 44px; height: 44px; }

.date-tile {
    width: 44px; height: 44px; flex: none; border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--c, #5F646B) 13%, white);
    color: color-mix(in srgb, var(--c, #5F646B) 85%, black);
    display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.date-tile b { font-size: 15px; }
.date-tile small { font-size: 9px; font-weight: 600; text-transform: uppercase; }

.check-dot {
    width: 28px; height: 28px; flex: none; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent);
    display: inline-flex; align-items: center; justify-content: center;
}

.avatar {
    width: 40px; height: 40px; flex: none; border-radius: 50%;
    background: #E3D9C6; color: #4A3F2B;
    font-size: var(--text-md); font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}
.avatar--me { background: var(--accent); color: var(--on-accent); }
.avatar--sm { width: 22px; height: 22px; font-size: 10px; }

/* ---------- Donut & ring ---------- */

.donut { position: relative; height: 236px; display: flex; align-items: center; justify-content: center; }
.donut svg { transform: rotate(-90deg); }
.donut__center {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    font-variant-numeric: tabular-nums;
}
.donut__label { font-size: var(--text-sm); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.donut__value { font-size: var(--text-hero); font-weight: 700; letter-spacing: -0.04em; }
.donut__value small { font-size: 20px; color: var(--muted); }

.badge {
    font-size: var(--text-sm); font-weight: 600; padding: 4px 10px; border-radius: var(--pill);
    background: var(--accent); color: var(--on-accent); text-decoration: none; white-space: nowrap;
}
.badge:hover { color: var(--on-accent); }
.badge--warn { background: var(--warn); }
.badge--quiet { background: var(--surface-2); color: var(--muted); }
.badge--quiet:hover { color: var(--ink); }

.ring-card { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring__center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring__pct { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; }
.ring__sub { font-size: var(--text-xs); color: var(--muted); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__label { font-size: var(--text-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat__value { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat__value--sm { font-size: 15px; font-weight: 600; letter-spacing: 0; }

/* ---------- Banners & empty states ---------- */

.banner { display: flex; gap: 12px; align-items: flex-start; border-radius: 18px; padding: 14px 16px; background: var(--warn-soft); color: var(--warn-ink); }
.banner__icon {
    width: 32px; height: 32px; flex: none; border-radius: 10px; background: var(--surface); color: var(--warn);
    display: inline-flex; align-items: center; justify-content: center;
}
.banner__title { font-size: var(--text-md); font-weight: 700; }
.banner__text { font-size: var(--text-sm); line-height: 1.5; }
.banner--info { background: var(--accent-soft); color: var(--accent-strong); }
.banner--info .banner__icon { color: var(--accent); }

.empty {
    background: var(--surface); border-radius: var(--radius-lg); padding: 28px 20px;
    display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
}
.empty__title { font-weight: 700; font-size: 15px; }
.empty__text { font-size: var(--text-md); color: var(--muted); line-height: 1.5; max-width: 280px; }

.error-text { color: var(--danger); font-size: var(--text-md); line-height: 1.4; }
.hint { font-size: var(--text-xs); color: var(--muted); padding: 0 4px; line-height: 1.5; }

/* ---------- Floating nav ---------- */

.nav {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(24px + env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 4px;
    background: var(--surface);
    border: 1px solid var(--track);
    border-radius: var(--pill);
    padding: 6px;
    box-shadow: var(--shadow-float);
    z-index: 10;
}
.nav__item {
    width: 52px; height: 48px; border-radius: var(--pill);
    color: var(--nav-idle);
    display: inline-flex; align-items: center; justify-content: center;
}
.nav__item:hover { color: var(--ink); }
.nav__item.active { background: var(--surface-2); color: var(--ink); }
.nav__add {
    height: 48px; padding: 0 18px 0 14px; border-radius: var(--pill);
    background: var(--accent); color: var(--on-accent);
    font-size: var(--text-base); font-weight: 700; text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
}
.nav__add:hover { background: var(--accent-strong); color: var(--on-accent); }

/* ---------- Add expense ---------- */

.amount { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.amount__label { font-size: var(--text-sm); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.amount__value {
    display: flex; align-items: baseline; gap: 6px;
    font-variant-numeric: tabular-nums; font-size: var(--text-amount); font-weight: 700; letter-spacing: -0.05em; line-height: 1;
}
.amount__value small { font-size: 40px; font-weight: 600; color: var(--muted); letter-spacing: -0.03em; }
.amount__value small span { color: var(--faint); }
.amount__value--empty { color: var(--faint); }
.amount__value--long { font-size: 54px; }

.line-input {
    border: 0; border-bottom: 1px solid #DADBD5; background: transparent;
    font-size: var(--text-lg); padding: 10px 0; outline: none; width: 100%;
}
.line-input:focus { border-bottom-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    height: 40px; padding: 0 14px; border-radius: var(--pill);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font-size: var(--text-md); font-weight: 600;
    display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
}
.chip:hover { color: var(--ink); }
.chip[aria-pressed="true"] {
    border-color: var(--c, var(--accent));
    background: color-mix(in srgb, var(--c, var(--accent)) 13%, white);
    color: color-mix(in srgb, var(--c, var(--accent)) 70%, black);
}
.chip--dashed { border-style: dashed; border-color: #C8C9C4; background: transparent; color: var(--muted); }

.toggles { display: flex; gap: 8px; }
.toggle-btn {
    flex: 1; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
    font-size: var(--text-md); font-weight: 600; color: var(--ink);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 10px;
}
.toggle-btn--quiet { color: var(--muted); }
.toggle-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }

.date-pill { position: relative; }
.date-pill input {
    position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0;
}

.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; font-variant-numeric: tabular-nums; }
.key {
    height: 54px; border: 0; border-radius: var(--radius); background: var(--surface);
    font-size: 22px; font-weight: 500;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 80ms ease;
}
.key:active { background: var(--surface-2); }

.spacer { flex: 1; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: var(--text-sm); font-weight: 600; color: var(--muted); padding: 0 4px; }
.input {
    height: 52px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
    padding: 0 16px; font-size: var(--text-lg); width: 100%; outline: none;
}
.input:focus { border-color: var(--accent); }
.input--code { letter-spacing: 0.4em; font-size: 24px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
select.input { appearance: none; background-image: none; }

.switch { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- Segmented control ---------- */

.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--pill); padding: 3px; }
.seg button {
    height: 34px; padding: 0 12px; border: 0; border-radius: var(--pill);
    background: transparent; color: var(--muted); font-size: var(--text-sm); font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

/* ---------- Insights ---------- */

.bars { display: grid; gap: 10px; align-items: end; height: 170px; font-variant-numeric: tabular-nums; }
.bar { display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; height: 100%; }
.bar__value { font-size: 10px; color: var(--muted); }
.bar__fill { width: 100%; min-height: 3px; background: #D3E6E1; border-radius: 8px 8px 4px 4px; }
.bar--current .bar__value { color: var(--ink); font-weight: 700; }
.bar--current .bar__fill { background: var(--accent); }
.bar-labels {
    display: grid; gap: 10px; font-size: var(--text-xs); color: var(--muted); text-align: center;
    border-top: 1px solid var(--line-soft); padding-top: 8px;
}
.bar-labels .current { color: var(--ink); font-weight: 700; }

.change { font-size: var(--text-sm); font-weight: 700; padding: 4px 8px; border-radius: var(--pill); white-space: nowrap; }
.change--up { color: var(--up-ink); background: var(--up-soft); }
.change--down { color: var(--down-ink); background: var(--down-soft); }
.change--flat { color: var(--muted); background: var(--surface-2); }

/* ---------- Household ---------- */

.split-bar { display: flex; gap: 3px; height: 14px; }
.split-bar div { border-radius: 2px; }
.split-bar div:first-child { border-top-left-radius: 7px; border-bottom-left-radius: 7px; }
.split-bar div:last-child { border-top-right-radius: 7px; border-bottom-right-radius: 7px; }

.balance {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--accent-soft); color: var(--accent-strong); border-radius: var(--radius); padding: 12px 14px;
}

.invite {
    height: 56px; border-radius: 18px; border: 1.5px dashed #C8C9C4; background: transparent;
    font-size: var(--text-base); font-weight: 600; color: var(--ink);
    display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
}

/* ---------- Category editor ---------- */

.icon-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.icon-grid button {
    aspect-ratio: 1; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
    display: inline-flex; align-items: center; justify-content: center; color: var(--ink); padding: 0;
}
.icon-grid button[aria-pressed="true"] { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 13%, white); color: color-mix(in srgb, var(--c, var(--accent)) 85%, black); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
    width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface);
    background: var(--c); box-shadow: 0 0 0 1px var(--line); padding: 0;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- Loading ---------- */

.loading { min-height: 60dvh; display: flex; align-items: center; justify-content: center; }
.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--track); border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: var(--surface); border-radius: var(--radius-lg); min-height: 60px; opacity: 0.6; }

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

/* ---------- Sign-in ---------- */

.welcome { display: flex; flex-direction: column; gap: 28px; padding-top: 12dvh; }
.welcome__hero { display: flex; flex-direction: column; gap: 10px; }
.welcome__tag { font-size: var(--text-lg); color: var(--muted); line-height: 1.5; }
