:root {
    color-scheme: light;
    --ink: #182338;
    --muted: #536176;
    --line: #dce3ec;
    --background: #f4f7fb;
    --surface: #fff;
    --navy: #18253e;
    --blue: #214db5;
    --blue-dark: #173c95;
    --red: #a62431;
    --radius: 14px;
    font-family: "Segoe UI", system-ui, sans-serif;
    line-height: 1.5;
    color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); min-height: 100vh; }
a { color: var(--blue-dark); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #3b79f0; outline-offset: 3px; }
p, h1, h2, h3 { margin: 0; }
h1 { font-size: clamp(2rem, 4vw, 2.75rem); line-height: 1.1; letter-spacing: -.045em; }
h2 { font-size: 1.25rem; letter-spacing: -.02em; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
small { font-size: .875rem; }

.signed-in { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--navy);
    color: #fff;
    padding: 2rem 1.25rem 1.5rem;
    min-width: 0;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 2.65rem;
    height: 2.65rem;
    flex: 0 0 auto;
    border-radius: 11px;
    background: #dbe7ff;
    color: #123d93;
    font-weight: 750;
    font-size: .9rem;
    letter-spacing: -.025em;
}
.brand strong, .brand div > span, .account-name strong, .account-name > span { display: block; }
.brand div > span, .account-name > span { font-size: .875rem; }
.sidebar .brand div > span, .sidebar .account-name > span { color: #c2cee1; }
.side-nav { display: grid; gap: .35rem; margin-top: 3rem; }
.side-nav a {
    color: #e1e9f7;
    text-decoration: none;
    font-weight: 600;
    padding: .7rem .8rem;
    border-radius: 9px;
}
.side-nav a:hover, .side-nav a[aria-current="page"] { background: #2c4165; color: #fff; }
.account { margin-top: auto; padding: 1rem 0 0; border-top: 1px solid #435374; }
.account-name { overflow-wrap: anywhere; margin-bottom: .65rem; }
.skip-link { position: fixed; left: .7rem; top: .7rem; z-index: 2; transform: translateY(-200%); }
.skip-link:focus { transform: none; background: #fff; padding: .5rem; }

.workspace { width: min(100%, 1280px); min-width: 0; padding: clamp(1.4rem, 4.4vw, 4.5rem); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 1.2rem; margin-bottom: 1.8rem; }
.page-heading p { margin-top: .45rem; }
.period { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; margin-bottom: 1.25rem; }
.period label { margin-right: .25rem; }
.period input { width: auto; }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.metric, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.metric { min-height: 8rem; padding: 1.12rem 1.25rem; }
.metric-total { background: #e9f0ff; border-color: #d3e0fc; }
.metric span, .metric small { color: var(--muted); }
.metric span { display: block; font-size: .875rem; font-weight: 650; }
.metric strong {
    display: block;
    font-size: clamp(1.35rem, 3vw, 2.35rem);
    line-height: 1.2;
    letter-spacing: -.05em;
    font-variant-numeric: tabular-nums;
    margin-top: .45rem;
    overflow-wrap: anywhere;
}
.metric strong.metric-category { font-size: 1.24rem; letter-spacing: -.025em; }
.panel-heading { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.empty { text-align: center; padding: 3.2rem 1.25rem; }
.empty p { color: var(--muted); margin-top: .35rem; }
.table-scroll { overflow-x: auto; border-radius: 0 0 var(--radius) var(--radius); }
table { width: 100%; min-width: 525px; border-collapse: collapse; text-align: left; }
th, td { padding: .9rem 1.25rem; vertical-align: top; }
th { color: var(--muted); background: #f8faff; font-size: .875rem; font-weight: 650; }
td { border-top: 1px solid var(--line); }
.date, .money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.money, .row-action { text-align: right; }
td.money { font-weight: 700; }
.expense-title, .supplier { display: block; overflow-wrap: anywhere; }
.supplier { color: var(--muted); margin-top: .2rem; }
details { margin-top: .4rem; }
details summary { cursor: pointer; color: var(--blue-dark); font-size: .9rem; }
.expense-notes { color: var(--muted); margin-top: .3rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.category { display: inline-block; border-radius: 8px; padding: .2rem .5rem; background: #edf1f7; color: #384962; font-size: .875rem; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.65rem;
    padding: .48rem .9rem;
    border: 1px solid transparent;
    border-radius: 9px;
    font-weight: 650;
    font-size: .95rem;
    text-decoration: none;
    cursor: pointer;
    text-align: center;
}
.primary { color: #fff; background: var(--blue); }
.primary:hover { background: var(--blue-dark); }
.secondary { color: var(--ink); background: #fff; border-color: #c6d0de; }
.secondary:hover { background: #f0f4fa; }
.sign-out { background: #2c4165; color: #fff; }
.sign-out:hover { background: #3c5581; }
.danger { background: #9e2430; color: #fff; }
.danger:hover { background: #7e1923; }
.text-danger { background: transparent; color: var(--red); }
.text-danger:hover { background: #fff1f3; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; }
.field { display: grid; gap: .35rem; min-width: 0; }
.full { grid-column: 1 / -1; }
label { font-size: .9rem; font-weight: 650; }
label .muted { font-weight: 400; }
input, select, textarea {
    width: 100%;
    min-width: 0;
    min-height: 2.65rem;
    border: 1px solid #abb8cb;
    border-radius: 8px;
    padding: .52rem .7rem;
    background: #fff;
    color: var(--ink);
}
select {
    appearance: none;
    padding-right: 2rem;
    background:
        linear-gradient(45deg, transparent 50%, #4a5b75 50%) right 1.02rem center / 6px 6px no-repeat,
        linear-gradient(135deg, #4a5b75 50%, transparent 50%) right .67rem center / 6px 6px no-repeat,
        #fff;
}
textarea { resize: vertical; }
.form-panel { padding: clamp(1rem, 3vw, 1.5rem); max-width: 48rem; }
.form-panel > p + .form-actions { margin-top: 1rem; }
.form-actions, .partner-actions, .copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.push-right { margin-left: auto; }
.notice, .error { border-radius: 9px; padding: .7rem .9rem; }
.notice { color: #164633; background: #e6f5ed; margin-bottom: 1rem; }
.error { color: #881d2a; background: #fff0f1; }

.invite-panel { border-color: #b9cafa; background: #f3f6ff; margin-bottom: 1rem; }
.invite-panel p { margin: .45rem 0 1rem; }
.copy-row { margin-top: .35rem; }
.copy-row input { flex: 1 1 16rem; }
#copy-status { display: block; color: var(--muted); }
.partner-list { margin-top: 1.5rem; max-width: 48rem; }
.partner-empty { padding: 1rem 1.25rem; }
.partner-row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; padding: .85rem 1.25rem; }
.partner-row + .partner-row { border-top: 1px solid var(--line); }
.partner-info { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }
.partner-info strong, .partner-info span { display: block; }
.partner-info span { color: var(--muted); font-size: .9rem; }

.signed-out { background: radial-gradient(ellipse at 20% 20%, #dbe6fc 0%, var(--background) 60%); }
.entry { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.entry-card {
    width: min(100%, 29rem);
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #fff;
    padding: clamp(1.4rem, 6vw, 2.5rem);
    box-shadow: 0 16px 42px rgb(25 47 84 / .08);
}
.entry-card .brand { margin-bottom: 2rem; }
.entry-card .brand div > span { color: var(--muted); }
.entry-card h1 { font-size: 2rem; }
.entry-card h1 + p { margin-top: .55rem; }
.entry-card form, .entry-card .error { margin-top: 1.2rem; }
.entry-card .back-link, .entry-card > a.button { display: inline-block; margin-top: 1rem; }

@media (max-width: 960px) {
    .signed-in { grid-template-columns: 188px minmax(0, 1fr); }
    .workspace { padding: 2rem; }
    .sidebar { padding-inline: .9rem; }
    .metric { padding: .95rem; }
    th, td { padding-inline: .85rem; }
}
@media (max-width: 780px) {
    .signed-in { display: block; }
    .sidebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .8rem; padding: .9rem 1rem; }
    .side-nav { display: flex; flex-wrap: wrap; grid-column: 1 / -1; grid-row: 2; margin: 0; }
    .side-nav a { display: flex; align-items: center; min-height: 44px; padding: .45rem .65rem; }
    .account { display: flex; align-items: center; gap: .55rem; border: 0; margin: 0; padding: 0; }
    .account-name { text-align: right; margin: 0; }
    .account-name strong { display: none; }
    .workspace { padding: 1.35rem 1rem; }
    .page-heading { margin-bottom: 1.3rem; }
    .summary { gap: .55rem; }
    .metric { min-height: 7rem; padding: .8rem .65rem; }
    .metric strong.metric-category { font-size: 1rem; }
    .metric span, .metric small { font-size: .83rem; }
}
@media (max-width: 570px) {
    .button, input, textarea, select { min-height: 44px; }
    .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .metric { min-height: 5.8rem; padding: .85rem 1rem; }
    .metric-total { grid-column: 1 / -1; padding: 1rem 1.1rem; }
    .metric-total strong { font-size: 2.25rem; }
    .metric strong.metric-category { line-height: 1.35; }
    .period { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
    .period label { grid-column: 1 / -1; }
    .period input { width: 100%; }
    .field-grid { grid-template-columns: minmax(0, 1fr); }
    .form-actions > button.primary { width: 100%; }
    .form-actions .push-right { margin-left: 0; }
    .table-scroll { overflow: visible; }
    table, tbody { display: block; min-width: 0; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: .35rem .75rem;
        align-items: start;
        padding: .9rem 1rem;
    }
    tbody tr + tr { border-top: 1px solid var(--line); }
    td { padding: 0; border: 0; }
    td.date { grid-column: 1; grid-row: 2; color: var(--muted); font-size: .875rem; }
    td.description { grid-column: 1; grid-row: 1; }
    td.expense-category { grid-column: 1; grid-row: 3; }
    td.money { grid-column: 2; grid-row: 1; }
    td.row-action { grid-column: 2; grid-row: 2; }
    td.row-action a, details summary { min-height: 44px; padding-block: .6rem; }
    td.row-action a { display: inline-flex; align-items: center; padding-inline: .4rem; }
    .panel-heading { padding-inline: 1rem; }
}
@media (max-width: 340px) {
    .account-name { display: none; }
}
