:root {
    --ink: #18212f;
    --muted: #6f7885;
    --line: #e7e9ed;
    --canvas: #f5f6f8;
    --surface: #ffffff;
    --navy: #10243c;
    --navy-soft: #1c3553;
    --gold: #b38a4a;
    --gold-soft: #f4ecdf;
    --green: #1e8b63;
    --red: #c44848;
    --shadow: 0 16px 45px rgba(23, 31, 42, .07);
    --radius: 18px;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }
.sidebar {
    position: sticky; top: 0; height: 100vh; padding: 26px 18px 20px;
    display: flex; flex-direction: column; background: var(--navy); color: white;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; color: white; text-decoration: none; }
.sidebar-logo { display: block; flex: 0 0 auto; width: 66px; height: 62px; object-fit: contain; }
.brand-name { font-size: 17px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark {
    width: 39px; height: 39px; border: 1px solid rgba(255,255,255,.5); border-radius: 50%;
    display: grid; place-items: center; font-size: 23px; color: #e5c58d;
}
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-size: 19px; font-weight: 600; letter-spacing: .02em; }
.brand small { margin-top: 4px; color: rgba(255,255,255,.55); font-size: 10px; letter-spacing: .24em; text-transform: uppercase; }
.main-nav { display: grid; gap: 6px; }
.nav-item {
    display: flex; align-items: center; gap: 13px; min-height: 48px; padding: 0 14px; border-radius: 12px;
    color: rgba(255,255,255,.67); text-decoration: none; font-size: 14px; font-weight: 600;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: white; }
.nav-item.active { background: rgba(255,255,255,.11); color: white; }
.nav-icon { width: 21px; font-size: 21px; font-weight: 400; text-align: center; color: #d4b273; }
.sidebar-footer {
    margin-top: auto; padding: 17px 8px 2px; border-top: 1px solid rgba(255,255,255,.12);
    display: grid; grid-template-columns: 34px minmax(0,1fr) 25px; align-items: center; gap: 10px;
}
.user-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #d7b67c; color: var(--navy); font-weight: 800; }
.user-copy { min-width: 0; }
.user-copy strong, .user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { font-size: 12px; }
.user-copy small { margin-top: 3px; font-size: 9px; color: rgba(255,255,255,.5); }
.logout { color: rgba(255,255,255,.55); text-decoration: none; font-size: 18px; }
.logout:hover { color: white; }

.main-content { min-width: 0; }
.topbar {
    min-height: 112px; padding: 27px clamp(24px, 4vw, 56px) 22px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 24px; background: rgba(255,255,255,.86);
    backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 10;
}
.eyebrow, .panel-kicker { margin: 0 0 5px; color: var(--gold); font-size: 10px; line-height: 1; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: 29px; font-weight: 650; letter-spacing: -.02em; }
.topbar-title { display: flex; align-items: center; gap: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.sync-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.sync-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(30,139,99,.1); }
.button {
    min-height: 42px; padding: 0 17px; border: 1px solid transparent; border-radius: 10px; display: inline-flex;
    align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 750;
    transition: transform .15s ease, background .15s ease, border .15s ease, opacity .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.primary { background: var(--navy); color: white; box-shadow: 0 8px 20px rgba(16,36,60,.16); }
.button.primary:hover { background: var(--navy-soft); }
.button.secondary { background: white; border-color: var(--line); }
.button.secondary:hover { background: var(--canvas); }
.button.danger-text { color: var(--red); background: transparent; padding-left: 0; padding-right: 0; }

.content-section { padding: 37px clamp(24px, 4vw, 56px) 0; max-width: 1540px; margin-inline: auto; }
.section-heading, .panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.section-heading { margin-bottom: 21px; }
.section-heading h2, .panel-heading h2 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; }
.metric-card {
    min-height: 143px; padding: 22px 23px 20px; border: 1px solid var(--line); border-radius: 15px;
    display: flex; flex-direction: column; background: var(--surface); box-shadow: 0 8px 28px rgba(25,34,46,.035);
}
.metric-card.featured { border-color: #dbc69e; background: linear-gradient(140deg, #fff 25%, #faf6ef); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-value { margin-top: 17px; font-size: clamp(25px, 2.1vw, 34px); line-height: 1; font-weight: 650; letter-spacing: -.03em; }
.metric-change { margin-top: auto; color: var(--green); font-size: 11px; font-weight: 700; }
.metric-change.negative { color: var(--red); }
.metric-change.neutral { color: #949ba4; font-weight: 550; }
.skeleton { color: transparent; border-radius: 5px; background: linear-gradient(90deg,#f0f1f3,#f7f7f8,#f0f1f3); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.chart-panel { margin-top: 18px; padding: 26px 28px 20px; }
.chart-heading { align-items: center; }
.panel-heading h3 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.period-tabs { display: flex; padding: 4px; border-radius: 11px; background: var(--canvas); }
.period-tab { min-height: 34px; padding: 0 13px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; }
.period-tab.active { color: var(--navy); background: white; box-shadow: 0 2px 8px rgba(24,33,47,.1); }
.chart-wrap { position: relative; height: 340px; margin-top: 10px; }
.revenue-chart { width: 100%; height: 100%; overflow: visible; }
.chart-grid { stroke: #edf0f2; stroke-width: 1; }
.chart-axis-label { fill: #929aa4; font-size: 10px; }
.chart-bar { fill: var(--navy); transition: opacity .15s ease; }
.chart-bar:hover { opacity: .78; }
.chart-bar.current { fill: var(--gold); }
.chart-label { fill: #78818d; font-size: 10px; text-anchor: middle; }
.chart-value-label { fill: var(--ink); font-size: 9px; font-weight: 650; text-anchor: middle; paint-order: stroke; stroke: white; stroke-width: 3px; stroke-linejoin: round; }
.chart-value-label.dense { font-size: 8px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; z-index: 1; }
.chart-tooltip { position: absolute; z-index: 2; pointer-events: none; min-width: 108px; padding: 9px 11px; border-radius: 8px; color: white; background: var(--navy); box-shadow: 0 7px 20px rgba(0,0,0,.16); font-size: 11px; line-height: 1.45; transform: translate(-50%,-115%); }
.chart-tooltip strong { display: block; font-size: 13px; }
.payment-summary { padding-top: 15px; border-top: 1px solid var(--line); display: flex; gap: 28px; color: var(--muted); font-size: 11px; }
.payment-summary span { display: flex; align-items: center; gap: 8px; }
.payment-summary strong { color: var(--ink); font-size: 12px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--navy); }
.legend-dot.check { background: var(--gold); }

.journal-section { padding-bottom: 56px; }
.journal-panel { overflow: hidden; }
.journal-heading { padding: 25px 28px 19px; align-items: center; }
.journal-tools { display: flex; align-items: flex-end; justify-content: flex-end; gap: 14px; }
.date-filter { display: flex; align-items: flex-end; gap: 8px; }
.date-filter label { display: grid; gap: 4px; }
.date-filter label span { color: var(--muted); font-size: 9px; font-weight: 650; }
.date-filter input {
    width: 132px; height: 34px; padding: 0 8px; border: 1px solid #dfe3e7; border-radius: 5px;
    outline: none; color: var(--ink); background: white; font-size: 11px;
}
.date-filter input:focus { border-color: #b89a64; box-shadow: 0 0 0 3px rgba(179,138,74,.12); }
.date-filter button { height: 34px; padding: 0 11px; border-radius: 6px; cursor: pointer; font-size: 10px; font-weight: 700; }
.date-filter-apply { border: 1px solid var(--navy); color: white; background: var(--navy); }
.date-filter-reset { border: 1px solid var(--line); color: var(--muted); background: white; }
.record-count { padding: 7px 11px; border-radius: 999px; color: var(--muted); background: var(--canvas); font-size: 11px; font-weight: 700; }
.table-scroll { overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 1030px; }
.col-date { width: 168px; }
.col-weekday { width: 82px; }
.col-money { width: 145px; }
.col-total { width: 125px; }
.col-comment { width: auto; }
th { padding: 12px 17px; color: #8b939d; background: #fafbfb; text-align: left; font-size: 9px; letter-spacing: .09em; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 17px; border-top: 1px solid #eef0f2; color: #394351; font-size: 12px; vertical-align: middle; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #fbfaf7; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
td.total-cell { color: var(--ink); font-size: 14px; font-weight: 700; }
.date-cell { color: var(--ink); font-size: 13px; font-weight: 400; white-space: nowrap; }
.weekday-cell { color: var(--ink); font-size: 13px; font-weight: 400; text-transform: lowercase; }
.inline-money-wrap { position: relative; display: inline-flex; align-items: center; width: 100%; max-width: 124px; }
.inline-money-prefix { position: absolute; left: 9px; z-index: 1; color: #8b939d; pointer-events: none; }
.inline-field {
    width: 100%; min-height: 35px; padding: 7px 9px; border: 1px solid #dfe3e7; border-radius: 5px;
    outline: none; color: var(--ink); background: white; transition: border-color .15s, background .15s, box-shadow .15s;
}
.inline-money { padding-left: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.inline-note-cell { min-width: 0; }
.inline-comment { display: block; min-width: 0; }
.inline-comment + .inline-comment { margin-top: 3px; }
.inline-field:hover { border-color: #cbd1d8; background: white; }
.inline-field:focus { border-color: #b89a64; background: white; box-shadow: 0 0 0 3px rgba(179,138,74,.12); }
.inline-field:disabled { opacity: .55; cursor: wait; }
.inline-field::-webkit-inner-spin-button { appearance: none; margin: 0; }
tbody tr.inline-saving { background: #faf8f3; }
tbody tr.inline-saved { animation: row-saved .8s ease; }
@keyframes row-saved { 0%, 45% { background: #edf8f2; } 100% { background: transparent; } }
.loading-row, .empty-row { height: 120px; text-align: center; color: var(--muted); }
.table-footer { min-height: 58px; padding: 0 20px 0 28px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.pagination-actions { display: flex; align-items: center; gap: 7px; }
.page-numbers { display: flex; align-items: center; gap: 3px; }
.page-number {
    min-width: 30px; height: 30px; padding: 0 7px; border: 1px solid transparent; border-radius: 7px;
    color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 650;
}
.page-number:hover { border-color: var(--line); background: white; }
.page-number.active { border-color: var(--navy); color: white; background: var(--navy); }
.page-ellipsis { width: 18px; text-align: center; color: #9aa1a9; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: white; cursor: pointer; }
.icon-button:disabled { opacity: .35; cursor: default; }

.entry-dialog { width: min(585px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 20px; color: var(--ink); box-shadow: 0 28px 90px rgba(9,20,32,.26); }
.entry-dialog::backdrop { background: rgba(8,18,31,.58); backdrop-filter: blur(3px); }
.entry-dialog form { padding: 28px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.dialog-heading h2 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--canvas); cursor: pointer; color: var(--muted); font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.form-grid .full { grid-column: 1 / -1; }
.field { position: relative; display: grid; gap: 7px; }
.field > span:first-child { color: #596370; font-size: 11px; font-weight: 750; }
.field input, .field textarea {
    width: 100%; border: 1px solid #dfe3e7; border-radius: 10px; outline: 0; background: white; color: var(--ink); transition: border .15s, box-shadow .15s;
}
.field input { height: 44px; padding: 0 12px; }
.field textarea { padding: 11px 12px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: #a88b58; box-shadow: 0 0 0 3px rgba(179,138,74,.13); }
.money-field input { padding-left: 29px; }
.input-prefix { position: absolute; top: 35px; left: 12px; color: #9aa1a9; font-size: 13px; }
.calculated-total { padding: 14px 16px; border-radius: 11px; display: flex; justify-content: space-between; align-items: center; background: #f7f3eb; color: #6b5a3f; font-size: 12px; }
.calculated-total strong { color: var(--ink); font-size: 21px; font-weight: 650; }
.additional-fields { border-top: 1px solid var(--line); padding-top: 12px; }
.additional-fields summary { color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 700; }
.form-grid.nested { margin-top: 16px; }
.form-error { margin: 15px 0 0; padding: 10px 12px; border-radius: 8px; color: #a33535; background: #fff0f0; font-size: 11px; }
.dialog-actions { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; gap: 9px; }
.dialog-spacer { flex: 1; }
.toast { position: fixed; right: 26px; bottom: 26px; z-index: 50; max-width: 360px; padding: 13px 17px; border-radius: 10px; color: white; background: var(--navy); box-shadow: 0 12px 35px rgba(0,0,0,.2); font-size: 12px; }
.toast.error { background: #9f3737; }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 50% 12%, #253e5b, var(--navy) 46%, #09182a); }
.login-card { width: min(430px, 100%); padding: 45px 44px 38px; border-radius: 22px; background: white; text-align: center; box-shadow: 0 35px 100px rgba(0,0,0,.3); }
.login-logo { display: block; width: 170px; height: 140px; margin: -16px auto 2px; object-fit: contain; }
.login-card h1 { margin: 0 0 28px; font-size: 29px; font-weight: 650; letter-spacing: -.02em; }
.login-copy { margin: 0 auto 28px; max-width: 330px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.google-sign-in { display: flex; justify-content: center; min-height: 44px; }
.login-error { display: none; margin-top: 16px; padding: 10px; border-radius: 8px; color: #a03535; background: #fff0f0; font-size: 11px; }
.login-error.visible { display: block; }
.login-note { margin: 25px 0 0; padding-top: 20px; border-top: 1px solid var(--line); color: #9a9fa7; font-size: 9px; line-height: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
    .app-shell { grid-template-columns: 78px minmax(0,1fr); }
    .sidebar { padding-inline: 11px; }
    .brand { justify-content: center; padding-inline: 0; }
    .sidebar-logo { width: 58px; height: 70px; }
    .brand-name { display: none; }
    .nav-item span:last-child, .user-copy, .logout { display: none; }
    .nav-item { justify-content: center; padding: 0; }
    .sidebar-footer { display: flex; justify-content: center; padding-inline: 0; }
    .metrics-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .journal-heading { align-items: flex-start; flex-direction: column; }
    .journal-tools { width: 100%; justify-content: space-between; }
}

@media (max-width: 720px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; z-index: 20; inset: auto 0 0; width: auto; height: 62px; padding: 7px 18px; flex-direction: row; align-items: center; }
    .brand, .sidebar-footer { display: none; }
    .main-nav { width: 100%; display: flex; justify-content: space-around; }
    .nav-item { min-width: 120px; min-height: 48px; }
    .nav-item span:last-child { display: block; }
    .topbar { position: static; min-height: 92px; padding: 20px; }
    .topbar h1 { font-size: 27px; }
    .sync-status { display: none; }
    .button.primary { padding-inline: 13px; }
    .content-section { padding: 25px 16px 0; }
    .metrics-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .metric-card { min-height: 125px; padding: 17px; }
    .metric-value { font-size: 23px; }
    .chart-panel { padding: 20px 14px 16px; }
    .chart-heading { align-items: flex-start; flex-direction: column; }
    .period-tabs { width: 100%; overflow: auto; }
    .period-tab { flex: 1 0 auto; padding-inline: 10px; }
    .chart-wrap { height: 285px; }
    .payment-summary { padding-inline: 8px; gap: 16px; }
    .journal-heading { padding-inline: 18px; }
    .journal-tools { align-items: flex-start; flex-direction: column; }
    .date-filter { width: 100%; flex-wrap: wrap; }
    .record-count { align-self: flex-start; }
    .journal-section { padding-bottom: 92px; }
    .entry-dialog form { padding: 22px 18px; }
    .form-grid { gap: 14px 10px; }
}

@media (max-width: 450px) {
    .topbar-actions .button span { display: none; }
    .metrics-grid { grid-template-columns: 1fr; }
    .metric-card { min-height: 112px; }
    .metric-value { margin-top: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: auto; }
    .login-card { padding: 38px 22px 30px; }
    .table-footer { padding-inline: 12px; }
    .page-number { min-width: 27px; padding-inline: 5px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
