:root {
    color-scheme: dark;
    --bg: #090c11;
    --surface: #11161e;
    --surface-raised: #171e28;
    --surface-soft: #0e131a;
    --line: #283240;
    --line-bright: #3b4858;
    --text: #f4f7fb;
    --muted: #94a0af;
    --accent: #7dd3a7;
    --accent-strong: #55b98a;
    --accent-ink: #07140e;
    --danger: #ff7a87;
    --danger-soft: rgba(255, 122, 135, .12);
    --radius: 16px;
    --shadow: 0 24px 70px rgba(0, 0, 0, .34);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 15% -10%, rgba(125, 211, 167, .09), transparent 32rem),
        var(--bg);
    font-size: 15px;
    line-height: 1.55;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }

.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.wide-shell { width: min(1600px, calc(100% - 40px)); margin-inline: auto; }
.page-shell { padding-block: 64px 90px; }
.narrow-page { max-width: 800px; }

.site-header {
    position: sticky;
    z-index: 50;
    top: 0;
    border-bottom: 1px solid rgba(59, 72, 88, .65);
    background: rgba(9, 12, 17, .88);
    backdrop-filter: blur(18px);
}

.header-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.wordmark { font-size: 17px; font-weight: 800; letter-spacing: -.03em; text-decoration: none; }
.wordmark span, .login-card h1 span { color: var(--accent); }
.site-header nav { display: flex; align-items: center; gap: 6px; }
.site-header nav > a, .nav-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 7px 11px;
    border: 0;
    border-radius: 9px;
    color: var(--muted);
    background: transparent;
    text-decoration: none;
    cursor: pointer;
}
.site-header nav > a:hover, .nav-button:hover { color: var(--text); background: var(--surface-raised); }
.site-header nav form { margin: 0; }

.flash {
    margin-top: 22px;
    padding: 12px 16px;
    border: 1px solid rgba(125, 211, 167, .35);
    border-radius: 10px;
    color: #baf0d2;
    background: rgba(125, 211, 167, .09);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2.2rem, 5vw, 4.7rem); line-height: .98; letter-spacing: -.055em; }
h2 { margin-bottom: 5px; font-size: 1.3rem; letter-spacing: -.025em; }
h3 { margin-bottom: 4px; }
p { color: var(--muted); }
.eyebrow { margin-bottom: 14px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.page-heading { margin-bottom: 42px; }
.page-heading p:last-child { max-width: 620px; margin-bottom: 0; font-size: 1.04rem; }
.page-heading.centered { text-align: center; }
.page-heading.centered p:last-child { margin-inline: auto; }
.heading-row, .tracker-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; }

.panel {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(145deg, rgba(23, 30, 40, .82), rgba(14, 19, 26, .94));
    box-shadow: 0 1px 0 rgba(255, 255, 255, .025) inset;
}
.section-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 24px; }
.section-heading.spread { justify-content: space-between; }
.section-heading p { margin: 0; font-size: .9rem; }
.section-index {
    display: grid;
    flex: 0 0 35px;
    height: 35px;
    place-items: center;
    border: 1px solid var(--line-bright);
    border-radius: 50%;
    color: var(--accent);
    font-size: .74rem;
    font-weight: 800;
}
.count-badge { min-width: 36px; padding: 5px 10px; border-radius: 99px; color: var(--accent); background: rgba(125, 211, 167, .1); text-align: center; }

.form-stack { display: grid; gap: 18px; }
.form-grid { display: grid; gap: 18px; }
.form-grid-three { grid-template-columns: 2fr .7fr 1fr; align-items: end; }
label { display: grid; gap: 7px; color: #c5ced8; }
label > span { font-size: .78rem; font-weight: 700; letter-spacing: .035em; }
label small { color: var(--muted); font-weight: 500; }
input, select, textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    outline: none;
    color: var(--text);
    background: var(--surface-soft);
    padding: 10px 12px;
    transition: border-color .16s ease, box-shadow .16s ease;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(125, 211, 167, .11); }
input::placeholder, textarea::placeholder { color: #657181; }

.button {
    display: inline-flex;
    width: fit-content;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-weight: 760;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: var(--accent-ink); background: var(--accent); }
.button.primary:hover { background: #9be0bb; }
.button.secondary { border-color: var(--line-bright); color: var(--text); background: var(--surface-raised); }
.button.secondary:hover { border-color: #59687a; }
.button.danger { border-color: rgba(255, 122, 135, .28); color: var(--danger); background: var(--danger-soft); }
.button.small { min-height: 36px; padding: 6px 11px; font-size: .83rem; }
.button.full { width: 100%; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }

.error-box { padding: 12px 14px; border: 1px solid rgba(255, 122, 135, .35); border-radius: 10px; color: #ffc0c7; background: var(--danger-soft); }
.error-summary { margin-bottom: 24px; }
.error-summary ul { margin: 7px 0 0; padding-left: 20px; }

.login-page { display: grid; place-items: center; }
.login-shell { width: min(430px, calc(100% - 34px)); padding-block: 50px; }
.login-card {
    padding: 42px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(17, 22, 30, .92);
    box-shadow: var(--shadow);
}
.brand-mark { display: grid; width: 52px; height: 52px; margin-bottom: 30px; place-items: center; border-radius: 14px; color: var(--accent-ink); background: var(--accent); font-weight: 900; letter-spacing: -.04em; }
.login-card h1 { margin-bottom: 32px; font-size: clamp(2.1rem, 10vw, 3rem); line-height: 1; }
.login-divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.login-divider::before, .login-divider::after { height: 1px; flex: 1; background: var(--line); content: ''; }
.form-status { min-height: 1.4em; margin: 10px 0 0; font-size: .84rem; }
.form-status.is-error { color: var(--danger); }

.menu-page { min-height: calc(100vh - 68px); display: grid; align-content: center; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.menu-card {
    position: relative;
    min-height: 240px;
    padding: 25px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.menu-card:hover { transform: translateY(-4px); border-color: var(--line-bright); background: var(--surface-raised); }
.menu-card.accent { border-color: rgba(125, 211, 167, .34); background: linear-gradient(155deg, rgba(125, 211, 167, .13), var(--surface) 60%); }
.menu-number { display: block; margin-bottom: 67px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
.menu-card strong { display: block; margin-bottom: 7px; font-size: 1.35rem; }
.menu-card small { color: var(--muted); }
.menu-arrow { position: absolute; right: 23px; bottom: 20px; color: var(--accent); font-size: 1.5rem; }
.placeholder-panel { padding-block: 70px; text-align: center; }
.placeholder-panel h1 { max-width: 600px; margin-inline: auto; font-size: clamp(2.2rem, 6vw, 4rem); }
.placeholder-panel .button { margin-inline: auto; }
.profile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 22px; }
.security-panel { margin-top: 22px; }
.section-heading-copy { display: flex; align-items: flex-start; gap: 14px; }
.security-stack { display: grid; gap: 16px; }
.security-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: rgba(9, 12, 17, .42); }
.security-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px; }
.security-card-heading .eyebrow { margin-bottom: 6px; }
.security-card-heading h3, .security-card-heading p { margin-bottom: 0; }
.security-card-heading p:last-child { margin-top: 5px; font-size: .86rem; }
.security-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 20px; border-top: 1px solid var(--line); }
.security-row small { display: block; margin-top: 3px; color: var(--muted); }
.security-empty { padding: 18px 20px; border-top: 1px solid var(--line); color: var(--muted); }
.recovery-count { margin: 0; padding: 12px 20px; border-top: 1px solid var(--line); font-size: .8rem; }
.app-pin-panel { margin-top: 22px; }
.pin-status { flex: 0 0 auto; padding: 6px 11px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: var(--surface-soft); font-size: .74rem; font-weight: 800; }
.pin-status.is-active { border-color: rgba(125, 211, 167, .34); color: var(--accent); background: rgba(125, 211, 167, .09); }
.pin-settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pin-settings-grid > .security-card { padding: 22px; }
.pin-settings-grid h3 { margin-bottom: 7px; }
.pin-explanation { display: flex; flex-direction: column; justify-content: space-between; gap: 28px; }
.pin-explanation p:last-child { margin-bottom: 0; }
.pin-remove-form { padding-top: 20px; border-top: 1px solid var(--line); }
.security-note { padding: 13px 14px; border: 1px solid rgba(125, 211, 167, .2); border-radius: 10px; background: rgba(125, 211, 167, .06); font-size: .84rem; }
.pin-input { font-variant-numeric: tabular-nums; letter-spacing: .34em; }
.pin-input::placeholder { letter-spacing: .34em; }
.pin-challenge-page { display: grid; min-height: calc(100vh - 68px); max-width: 560px; align-content: center; }
.pin-challenge-panel { padding: 42px; box-shadow: var(--shadow); }
.pin-lock-mark { width: fit-content; margin: 0 auto 28px; padding: 10px 14px 10px 19px; border: 1px solid rgba(125, 211, 167, .3); border-radius: 10px; color: var(--accent); background: rgba(125, 211, 167, .08); font-size: .8rem; font-weight: 900; letter-spacing: .45em; }
.pin-challenge-form { width: min(330px, 100%); margin-inline: auto; }
.pin-challenge-form .button { width: 100%; }
.pin-input-large { min-height: 58px; padding-left: 1.05em; font-size: 1.35rem; text-align: center; }

.budget-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); gap: 22px; align-items: start; }
.create-block { margin-bottom: 22px; border: 1px solid var(--line); border-radius: 12px; background: rgba(9, 12, 17, .42); }
.create-block > summary { padding: 15px 18px; color: var(--accent); font-weight: 760; cursor: pointer; }
.create-block[open] > summary { border-bottom: 1px solid var(--line); }
.create-block form { padding: 18px; }
.tracker-list { display: grid; gap: 10px; }
.tracker-card { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: rgba(9, 12, 17, .44); }
.tracker-summary { display: flex; align-items: center; gap: 14px; min-width: 0; }
.tracker-summary h3, .tracker-summary p { overflow: hidden; margin: 0; text-overflow: ellipsis; white-space: nowrap; }
.tracker-summary p { font-size: .85rem; }
.year-stamp { display: grid; flex: 0 0 54px; height: 54px; place-items: center; border-radius: 11px; color: var(--accent); background: rgba(125, 211, 167, .09); font-size: .78rem; font-weight: 800; }
.row-actions { display: flex; align-items: center; gap: 7px; }
.row-actions form { margin: 0; }
.inline-details > summary { list-style: none; }
.inline-details > summary::-webkit-details-marker { display: none; }
.floating-form { position: absolute; z-index: 10; top: calc(100% - 8px); right: 10px; width: min(310px, calc(100vw - 60px)); padding: 18px; border: 1px solid var(--line-bright); border-radius: 12px; background: #151b24; box-shadow: var(--shadow); }
.empty-state, .mini-empty { padding: 24px; border: 1px dashed var(--line); border-radius: 11px; color: var(--muted); text-align: center; }
.category-panel { position: sticky; top: 92px; }
.category-create { display: grid; grid-template-columns: 1fr .72fr auto; gap: 8px; align-items: end; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.category-group { padding-top: 23px; }
.category-group h3 { display: flex; justify-content: space-between; color: #d6dde5; font-size: .85rem; text-transform: uppercase; letter-spacing: .09em; }
.category-group h3 span { color: var(--muted); }
.category-list { display: grid; gap: 7px; }
.category-row { display: flex; align-items: center; gap: 8px; }
.category-name-form { display: flex; flex: 1; align-items: center; gap: 5px; }
.category-name-form input { min-height: 37px; padding: 6px 9px; }
.text-button { border: 0; color: var(--accent); background: transparent; font-size: .75rem; cursor: pointer; }
.category-actions { display: flex; gap: 3px; }
.category-actions form { margin: 0; }
.icon-button { display: grid; width: 29px; height: 29px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface-soft); cursor: pointer; }
.icon-button:disabled { opacity: .28; cursor: default; }
.danger-text { color: var(--danger); }
.mini-empty { padding: 12px; font-size: .82rem; }

.tracker-page { padding-top: 42px; }
.tracker-heading { margin-bottom: 26px; }
.tracker-heading h1 { margin-bottom: 0; font-size: clamp(2rem, 4vw, 3.4rem); }
.back-link { display: inline-block; margin-bottom: 19px; color: var(--muted); font-size: .83rem; text-decoration: none; }
.tracker-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; }
.view-switcher { display: flex; flex-wrap: wrap; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.view-switcher a { padding: 7px 11px; border-radius: 8px; color: var(--muted); font-size: .82rem; text-decoration: none; }
.view-switcher a.active { color: var(--accent-ink); background: var(--accent); font-weight: 800; }
.item-modal { width: min(1080px, calc(100% - 32px)); max-height: 90vh; padding: 0; overflow: visible; border: 0; border-radius: 18px; color: var(--text); background: transparent; }
.item-modal::backdrop { background: rgba(2, 4, 7, .78); backdrop-filter: blur(8px); }
.modal-surface { max-height: 90vh; overflow: auto; border: 1px solid var(--line-bright); border-radius: 18px; background: #111720; box-shadow: var(--shadow); }
.modal-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); background: rgba(17, 23, 32, .96); backdrop-filter: blur(15px); }
.modal-header .eyebrow { margin-bottom: 5px; }
.modal-header h2 { margin: 0; }
.modal-close { display: grid; flex: 0 0 40px; width: 40px; height: 40px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--surface-soft); font-size: 1.45rem; line-height: 1; cursor: pointer; }
.modal-close:hover { border-color: var(--line-bright); color: var(--text); }
.item-modal .error-summary { margin: 22px 22px 0; }
.item-form { grid-template-columns: repeat(4, minmax(140px, 1fr)); padding: 22px; }
.modal-delete-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, .7fr) auto; align-items: end; gap: 16px; margin: 0 22px 22px; padding: 18px; border: 1px solid rgba(255, 122, 135, .3); border-radius: 12px; background: var(--danger-soft); }
.delete-copy p { margin: 4px 0 0; font-size: .85rem; }
.span-two { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }
.custom-frequency { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.forecast-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table-scroll { max-height: 70vh; overflow: auto; border-radius: inherit; }
.forecast-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8rem; }
.forecast-table th, .forecast-table td { min-width: 112px; padding: 12px 13px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.forecast-table thead th { position: sticky; z-index: 4; top: 0; background: #171e28; }
.forecast-table th:first-child, .forecast-table td:first-child { width: 260px; min-width: 260px; text-align: left; }
.forecast-table .sticky-cell { position: sticky; z-index: 3; left: 0; background: #111720; }
.forecast-table thead .sticky-cell { z-index: 6; background: #171e28; }
.forecast-table tfoot .sticky-cell { z-index: 5; }
.forecast-table thead small { display: block; color: var(--muted); font-size: .66rem; font-weight: 500; }
.type-row th, .type-row td { color: var(--accent); background: #18231f; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; }
.type-row .sticky-cell { background: #18231f; }
.group-row th, .group-row td { color: #cad4de; background: #151b24; font-size: .75rem; }
.group-row .sticky-cell { padding-left: 22px; background: #151b24; }
.item-cell { padding-left: 28px !important; }
.item-title { display: flex; justify-content: space-between; gap: 12px; }
.item-title a { color: var(--accent); font-size: .72rem; }
.item-cell > small { display: block; color: var(--muted); }
.item-note { color: #d5b778 !important; }
.total-cell { color: var(--text); font-weight: 800; background: rgba(255, 255, 255, .018); }
.forecast-table tfoot th { position: sticky; z-index: 4; bottom: 0; background: #19212b; }
.forecast-table tfoot tr:nth-last-child(2) th { bottom: 43px; }
.forecast-table tfoot tr:nth-last-child(3) th { bottom: 86px; }
.forecast-table .net-row th { color: var(--accent); background: #1a2a24; }
.muted-cell { color: var(--muted); }

.compact-modal { width: min(560px, calc(100% - 32px)); }
.security-modal { width: min(920px, calc(100% - 32px)); }
.authenticator-grid { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(300px, 1fr); gap: 24px; padding: 24px; }
.qr-panel { display: grid; align-content: center; justify-items: center; padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); text-align: center; }
.qr-panel canvas { width: 200px; height: 200px; padding: 8px; border-radius: 10px; background: white; }
.qr-panel p { margin: 14px 0 0; font-size: .84rem; }
.security-form { align-content: start; }
.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
.copy-field .button { flex: 0 0 auto; }
.modal-form { padding: 22px; }
.compact-heading { margin: 0; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.recovery-panel { text-align: center; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.recovery-grid code { padding: 13px; border: 1px solid var(--line); border-radius: 9px; color: var(--accent); background: var(--surface-soft); font-size: 1rem; letter-spacing: .12em; }
.recovery-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }

.tracker-page { width: 100%; height: calc(100dvh - 68px); min-height: 520px; margin: 0; padding: 15px; overflow: hidden; display: flex; flex-direction: column; }
.tracker-page .tracker-heading { flex: 0 0 auto; }
.tracker-page .forecast-panel { display: flex; min-height: 0; flex: 1 1 auto; overflow: hidden; }
.tracker-page .table-scroll { width: 100%; max-height: none; flex: 1 1 auto; }
.tracker-page .forecast-table { height: 100%; }
.tracker-page .forecast-table tfoot tr { height: 43px; }

@media (max-width: 980px) {
    .menu-grid, .profile-grid, .pin-settings-grid { grid-template-columns: 1fr; }
    .menu-card { min-height: 175px; }
    .menu-number { margin-bottom: 30px; }
    .budget-layout { grid-template-columns: 1fr; }
    .category-panel { position: static; }
    .item-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .shell, .wide-shell { width: min(100% - 24px, 1180px); }
    .page-shell { padding-block: 38px 65px; }
    .header-inner { min-height: 62px; }
    .site-header nav > a { display: none; }
    .wordmark { font-size: 15px; }
    .login-card { padding: 28px 22px; }
    .heading-row, .tracker-heading { align-items: flex-start; flex-direction: column; }
    .page-heading { margin-bottom: 28px; }
    .panel { padding: 19px; }
    .pin-challenge-page { min-height: calc(100vh - 62px); }
    .pin-challenge-panel { padding: 30px 20px; }
    .form-grid-three, .category-create, .item-form { grid-template-columns: 1fr; }
    .span-two, .span-full { grid-column: auto; }
    .custom-frequency { grid-template-columns: 1fr; }
    .tracker-card { align-items: flex-start; flex-direction: column; }
    .row-actions { width: 100%; flex-wrap: wrap; }
    .floating-form { right: auto; left: 0; }
    .category-row { align-items: flex-start; flex-direction: column; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
    .category-name-form { width: 100%; }
    .tracker-heading { margin-bottom: 20px; }
    .tracker-tools { width: 100%; justify-content: stretch; }
    .view-switcher { width: 100%; }
    .view-switcher a { flex: 1; text-align: center; }
    .tracker-tools > .button { width: 100%; }
    .item-modal { width: calc(100% - 20px); }
    .item-form { padding: 18px; }
    .modal-delete-form { grid-template-columns: 1fr; margin: 0 18px 18px; }
    .modal-delete-form .button { width: 100%; }
    .security-card-heading, .security-row { align-items: flex-start; flex-direction: column; }
    .security-card-heading .button { width: 100%; }
    .authenticator-grid, .recovery-grid { grid-template-columns: 1fr; }
    .authenticator-grid { padding: 18px; }
    .tracker-page { width: 100%; height: calc(100dvh - 62px); min-height: 480px; padding: 15px; }
    .forecast-table th:first-child, .forecast-table td:first-child { width: 210px; min-width: 210px; }
}
