:root {
    color-scheme: light;
    --bg: #f4f7f5;
    --surface: #ffffff;
    --ink: #18212f;
    --muted: #64706d;
    --line: #d8e0dc;
    --brand: #147d6f;
    --brand-dark: #0f5f55;
    --navy: #263a59;
    --blue: #2563a8;
    --red: #b9383e;
    --amber: #a76212;
    --green-soft: #e5f4ee;
    --blue-soft: #e7f0fb;
    --red-soft: #fbe8e8;
    --amber-soft: #fff1d8;
    --shadow: 0 10px 28px rgba(24, 33, 47, 0.08);
    --scope: #2365a8;
    --scope-strong: #174f87;
    --scope-soft: #eaf3ff;
    --scope-line: #b9d7f5;
}

body[data-scope="sage"] {
    --scope: #7454a3;
    --scope-strong: #56377f;
    --scope-soft: #f1ebfb;
    --scope-line: #d9c8f0;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea { font: inherit; }

button {
    min-height: 44px;
    border: 0;
    border-radius: 7px;
    background: var(--brand);
    color: white;
    font-weight: 750;
    padding: 0 16px;
    cursor: pointer;
}

button:active { transform: translateY(1px); }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(37, 99, 168, 0.24);
    outline-offset: 2px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: white;
    color: var(--ink);
    padding: 10px 12px;
}

textarea { resize: vertical; }

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.hidden { display: none !important; }
.stack { display: grid; gap: 14px; }
.wide { grid-column: 1 / -1; }
.muted { color: var(--muted); font-size: 12px; }
.positive { color: var(--brand-dark); }
.negative { color: var(--red); }

.login-screen,
.install-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
}

.login-panel,
.install-panel {
    width: min(440px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 26px;
}

.login-panel h1,
.install-panel h1,
.topbar h1 {
    margin: 0;
    letter-spacing: 0;
    line-height: 1.08;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--brand-dark);
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0;
}

.shell {
    min-height: 100vh;
    max-width: 960px;
    margin: 0 auto;
    padding: 18px 18px 96px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.screen-helper,
.form-helper {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.ghost,
.icon-btn,
.text-btn,
.icon-action {
    background: transparent;
    color: var(--navy);
    border: 1px solid var(--line);
}

.icon-btn {
    min-width: 44px;
    padding: 0 10px;
}

.text-btn,
.icon-action {
    min-height: 34px;
    padding: 0 9px;
    font-size: 12px;
}

.icon-action { border: 0; }
.danger-text { color: var(--red); }

.small-btn {
    min-height: 36px;
    padding: 0 11px;
    font-size: 12px;
}

.scope-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 14px 0 10px;
}

.scope-tabs button,
.bottom-nav button {
    background: white;
    border: 1px solid var(--line);
    color: var(--muted);
}

.scope-tabs button {
    min-height: 62px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 9px 8px;
}

.scope-tabs span {
    display: block;
    font-size: 14px;
    font-weight: 850;
    line-height: 1.1;
}

.scope-tabs small {
    display: block;
    color: inherit;
    font-size: 10px;
    font-weight: 650;
    line-height: 1.2;
    opacity: 0.78;
}

.scope-tabs button[data-scope="personal"].active {
    background: #2365a8;
    border-color: #2365a8;
}

.scope-tabs button[data-scope="sage"].active {
    background: #7454a3;
    border-color: #7454a3;
}

.scope-tabs button.active,
.bottom-nav button.active {
    background: var(--navy);
    border-color: var(--navy);
    color: white;
}

.month-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 8px;
    margin-bottom: 15px;
}

.month-row > * { min-width: 0; }

.focus-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 16px;
    padding: 15px 16px;
    border: 1px solid var(--scope-line);
    border-radius: 8px;
    background: var(--scope-soft);
}

.focus-strip > div { display: grid; gap: 3px; }
.focus-strip .eyebrow { color: var(--scope-strong); margin: 0; }
.focus-strip strong { font-size: 15px; }
.focus-action { background: var(--scope); white-space: nowrap; }

.metrics,
.review-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.review-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.metrics article,
.review-grid article,
.account-item {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 13px;
}

.metric-card {
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--metric-color, var(--scope));
}

.metric-income { --metric-color: #27805e; background: #f0faf5; }
.metric-expense { --metric-color: #bf4c55; background: #fff6f6; }
.metric-net { --metric-color: var(--scope); background: var(--scope-soft); }
.metric-support { --metric-color: #b77a20; background: #fff9ef; }

.metrics article,
.review-grid article {
    min-height: 92px;
    display: grid;
    align-content: space-between;
}

.metrics span,
.review-grid span,
.account-item span,
.review-hero span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.metrics strong,
.review-grid strong {
    font-size: 22px;
    line-height: 1.05;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.notice-line {
    margin: 0 0 18px;
    border-left: 4px solid var(--amber);
    background: var(--amber-soft);
    color: #74420a;
    padding: 11px 13px;
    font-weight: 700;
}

.section-block {
    border-top: 1px solid var(--line);
    padding: 18px 0 6px;
    margin-top: 10px;
}

.section-block > .section-head {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.section-head,
.form-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.section-head h2,
.form-heading h2 {
    margin: 0;
    font-size: 17px;
    letter-spacing: 0;
}

.account-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}

.account-item {
    min-height: 104px;
    display: grid;
    align-content: space-between;
}

.account-item strong {
    margin: 5px 0;
    font-size: 20px;
    line-height: 1.05;
    overflow-wrap: anywhere;
}

.account-item small { color: var(--muted); }

.list { display: grid; }
.empty { color: var(--muted); padding: 10px 0; }

.summary-row,
.record-row,
.ledger-row,
.check-row {
    border-top: 1px solid var(--line);
    padding: 12px 0;
}

.summary-row:first-child,
.record-row:first-child,
.ledger-row:first-child,
.check-row:first-child { border-top: 0; }

.summary-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
}

.summary-row div { display: grid; gap: 2px; }
.summary-row span { color: var(--muted); font-size: 12px; }
.summary-row b { white-space: nowrap; }

.record-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
}

.record-row:hover { background: #fafcfc; }
.record-row { padding-left: 10px; padding-right: 8px; border-radius: 7px; }

.record-main,
.record-side { min-width: 0; }
.record-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.record-sub {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.record-side {
    display: grid;
    justify-items: end;
    gap: 4px;
}

.record-actions,
.button-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
}

.amount { white-space: nowrap; }
.kind-income { color: var(--brand-dark); }
.kind-expense { color: var(--red); }
.kind-transfer { color: var(--blue); }
.kind-repayment { color: var(--amber); }

.status {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}

.status-actual { color: #0b5e4f; background: var(--green-soft); }
.status-estimate,
.status-planned { color: #7d4c0a; background: var(--amber-soft); }
.status-unknown { color: #8f282e; background: var(--red-soft); }

.form-surface {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 7px 20px rgba(24, 33, 47, 0.05);
    padding: 18px;
}

.form-surface {
    border-top: 4px solid var(--scope);
    padding: 20px;
}

.form-heading { align-items: flex-start; }

.form-grid {
    gap: 16px;
}

.entry-basics {
    margin-top: 23px;
    padding-top: 15px;
    border-top: 1px solid var(--scope-line);
}

.entry-details {
    margin-top: 18px;
    padding: 12px 0 0;
    border-top: 1px solid var(--line);
}

.entry-details summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    color: var(--scope-strong);
    cursor: pointer;
    font-size: 13px;
    font-weight: 850;
}

.entry-details summary span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    text-align: right;
}

.entry-details[open] summary { margin-bottom: 2px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.required-field::after {
    content: "Required for actual cash";
    color: var(--brand-dark);
    font-size: 10px;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 46px;
    color: var(--ink);
}

.check-label input {
    width: 20px;
    min-height: 20px;
    margin: 0;
}

.wide-button {
    width: 100%;
    margin-top: 16px;
}

.form-error {
    min-height: 20px;
    margin: 8px 0 0;
    color: var(--red);
    font-weight: 700;
}

.review-hero {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
    border-left: 5px solid var(--brand);
    background: var(--green-soft);
    padding: 16px;
}

.review-hero strong {
    color: var(--brand-dark);
    font-size: 30px;
    letter-spacing: 0;
}

.ledger-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
}

.ledger-row > div { display: grid; gap: 2px; }
.ledger-row > div:last-child { justify-items: end; }
.ledger-row span,
.ledger-row small { color: var(--muted); font-size: 12px; }

.two-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.editor-details {
    border-top: 1px solid var(--line);
    margin-top: 14px;
    padding-top: 12px;
}

.editor-details summary {
    color: var(--navy);
    cursor: pointer;
    font-weight: 800;
}

.compact-section { margin-top: 14px; }

.check-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px auto;
    align-items: center;
    gap: 10px;
}

.check-row > div { display: grid; gap: 2px; }
.check-row span { color: var(--muted); font-size: 12px; }
.check-amount { min-width: 0; }

.compact-form {
    display: grid;
    grid-template-columns: minmax(180px, 1.3fr) 0.8fr auto 54px auto;
    gap: 8px;
    margin: 12px 0;
}

.small-check {
    min-width: 84px;
    font-size: 12px;
}

.swatch {
    width: 22px;
    height: 22px;
    border: 1px solid rgba(24, 33, 47, 0.18);
    border-radius: 4px;
}

.active-secondary {
    color: white;
    background: var(--blue);
    border-color: var(--blue);
}

.notice {
    padding: 10px 12px;
    border-radius: 7px;
    margin: 12px 0;
}

.notice.good { background: var(--green-soft); color: var(--brand-dark); }
.notice.bad { background: var(--red-soft); color: var(--red); }

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 10;
    transform: translateX(-50%);
    width: min(960px, 100%);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: rgba(244, 247, 245, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.bottom-nav button[data-screen="add"] {
    color: var(--scope-strong);
    border-color: var(--scope-line);
    background: var(--scope-soft);
}

.bottom-nav button[data-screen="add"].active {
    background: var(--scope);
    border-color: var(--scope);
    color: white;
}

.bottom-nav button {
    min-height: 50px;
    padding: 0 4px;
    font-size: 12px;
}

@media (max-width: 720px) {
    .shell { padding: 14px 12px 94px; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .review-grid,
    .account-grid,
    .two-columns { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .wide { grid-column: auto; }
    .compact-form { grid-template-columns: 1fr 1fr; }
    .compact-form input:first-child { grid-column: 1 / -1; }
    .check-row { grid-template-columns: minmax(0, 1fr) 108px; }
    .check-row button { grid-column: 1 / -1; }
    .topbar h1 { font-size: 24px; }
    .focus-strip { align-items: stretch; flex-direction: column; }
    .focus-action { width: 100%; }
}

@media (max-width: 440px) {
    .metrics { gap: 7px; }
    .metrics article { min-height: 86px; padding: 11px; }
    .metrics strong { font-size: 19px; }
    .record-row { grid-template-columns: 1fr; }
    .record-side {
        grid-template-columns: 1fr auto;
        align-items: center;
        justify-items: start;
    }
    .record-actions { justify-self: end; }
    .review-hero {
        display: grid;
        gap: 5px;
    }
    .ledger-row { grid-template-columns: 1fr; }
    .ledger-row > div:last-child {
        grid-template-columns: 1fr auto auto;
        align-items: center;
        justify-items: start;
    }
    .compact-form { grid-template-columns: 1fr; }
    .compact-form input:first-child { grid-column: auto; }
    .bottom-nav button { font-size: 11px; }
}
