@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@500;600;700&display=swap');

:root {
  color-scheme: light;
  --color-canvas: #edf1fb;
  --color-surface: #ffffff;
  --color-surface-soft: #f7f8fd;
  --color-field: #f3f5fb;
  --color-ink: #151620;
  --color-muted: #747987;
  --color-subtle: #a2a6b3;
  --color-line: #e7e9f0;
  --color-primary: #2979ed;
  --color-primary-dark: #1b5cc0;
  --color-purple: #7658df;
  --color-purple-soft: #d4ccff;
  --color-lavender: #bfcaff;
  --color-yellow: #fff28a;
  --color-mint: #c9efe4;
  --color-pink: #f3b9e6;
  --color-green: #2b9365;
  --color-danger: #c93f61;
  --shadow-card: 0 10px 28px rgba(67, 78, 118, .10);
  --shadow-float: 0 18px 42px rgba(55, 65, 102, .16);
  --font-display: "Playfair Display", "Baskerville", "Iowan Old Style", Georgia, serif;
  --font-body: "DM Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 20px;
  --text-xl: 31px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--color-canvas); }
body { color: var(--color-ink); font-family: var(--font-body); font-size: var(--text-md); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.trap-field { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--color-purple-soft); outline-offset: 3px; }
a { color: var(--color-primary); }

.app-shell { width: 100%; max-width: 480px; min-height: 100dvh; margin: 0 auto; overflow: hidden; background: var(--color-canvas); box-shadow: 0 0 0 1px rgba(52, 62, 95, .08), var(--shadow-float); }
.app-shell.is-printing { max-width: 1100px; background: #fff; box-shadow: none; }
.topbar { position: sticky; top: 0; z-index: 8; min-height: 68px; padding: max(var(--space-4), env(safe-area-inset-top)) var(--space-5) var(--space-3); background: rgba(255, 255, 255, .84); border-bottom: 1px solid rgba(231, 233, 240, .82); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); display: flex; align-items: end; justify-content: space-between; gap: var(--space-4); }
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm); background: linear-gradient(135deg, #d9d3ff, #ffe2f1); box-shadow: 0 5px 14px rgba(118, 88, 223, .16); }
.brand-mark .icon { width: 26px; height: 26px; }
.brand-copy { display: grid; gap: var(--space-1); }
.brand-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -.035em; }
.brand-user { color: var(--color-muted); font-size: var(--text-xs); }
.topbar-link { padding: var(--space-2) 0; color: var(--color-primary); font-size: var(--text-sm); text-decoration: none; }
.topbar-action { width: 40px; height: 40px; display: grid; place-items: center; color: var(--color-primary); background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-pill); box-shadow: 0 6px 16px rgba(67, 78, 118, .08); transition: transform .18s ease, background .18s ease, color .18s ease; }
.topbar-action:hover { color: var(--color-primary-dark); background: #eef2ff; transform: translateY(-1px); }
.topbar-action:active { transform: scale(.96); }
.topbar-action .icon { width: 19px; height: 19px; }
.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; }

.page { width: min(calc(100% - var(--space-6)), 430px); margin: 0 auto; padding: var(--space-6) 0 calc(120px + env(safe-area-inset-bottom)); }
.page.narrow { width: min(calc(100% - var(--space-6)), 430px); }
.home-intro { display: flex; align-items: end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); }
.eyebrow { margin: 0 0 var(--space-1); color: var(--color-muted); font-size: var(--text-xs); font-weight: 750; letter-spacing: .11em; }
.home-intro h1 { margin: 0; font-family: var(--font-display); font-size: 33px; font-weight: 600; line-height: 1.03; letter-spacing: -.045em; }
.intro-copy { margin: var(--space-2) 0 0; color: var(--color-muted); font-size: var(--text-sm); }
.icon-button { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border: 0; border-radius: var(--radius-pill); background: var(--color-surface); color: var(--color-primary); box-shadow: var(--shadow-card); }
.icon-button .icon { width: 20px; height: 20px; }

.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-7); }
.metric-card { min-height: 132px; padding: var(--space-4); border: 0; border-radius: var(--radius-lg); color: var(--color-ink); text-align: left; display: flex; flex-direction: column; align-items: flex-start; box-shadow: var(--shadow-card); transition: transform .18s ease, box-shadow .18s ease; }
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-float); }
.metric-card:active { transform: scale(.985); }
.metric-icon { width: 30px; height: 30px; margin-bottom: var(--space-3); display: grid; place-items: center; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .58); }
.metric-icon .icon { width: 18px; height: 18px; }
.metric-card-label { font-size: var(--text-sm); font-weight: 650; }
.metric-card strong { margin-top: var(--space-1); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: -.025em; }
.metric-card-note { margin-top: auto; color: rgba(21, 22, 32, .56); font-size: var(--text-xs); }
.metric-lavender { background: var(--color-lavender); }
.metric-yellow { background: var(--color-yellow); }
.metric-mint { background: var(--color-mint); }
.metric-pink { background: var(--color-pink); }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: var(--space-4); margin: 0 0 var(--space-3); }
.section-heading h2 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -.025em; }
.section-caption { color: var(--color-muted); font-size: var(--text-sm); }

.entry-card, .auth-card, .export-card { background: var(--color-surface); border: 1px solid rgba(231, 233, 240, .9); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); }
.entry-card { padding: var(--space-4); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4) var(--space-3); }
.field.full { grid-column: 1 / -1; }
.field label, .filter-field label { display: block; margin: 0 0 var(--space-2) var(--space-1); color: var(--color-muted); font-size: var(--text-xs); }
.input, .search-box { width: 100%; min-height: 48px; padding: 0 var(--space-3); color: var(--color-ink); background: var(--color-field); border: 1px solid transparent; border-radius: var(--radius-md); transition: border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.input::placeholder, .search-box::placeholder { color: var(--color-subtle); }
.input:hover, .search-box:hover { background: #edf0f8; }
.input:focus, .search-box:focus { background: var(--color-surface); border-color: #aeb8ff; box-shadow: 0 0 0 4px rgba(118, 88, 223, .10); outline: none; }
input[type="date"] { color-scheme: light; }
.readonly { color: var(--color-muted); background: var(--color-surface-soft); border-style: dashed; }
.button { width: 100%; min-height: 52px; padding: 0 var(--space-4); color: var(--color-surface); background: linear-gradient(135deg, var(--color-purple), #9a6cf1); border: 0; border-radius: var(--radius-md); font-weight: 750; box-shadow: 0 8px 16px rgba(118, 88, 223, .18); transition: transform .18s ease, box-shadow .18s ease; }
.button:hover { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(118, 88, 223, .24); }
.button:active { transform: scale(.985); }
.button.secondary { color: var(--color-primary-dark); background: #e9e5ff; box-shadow: none; }
.cancel-edit { margin-top: var(--space-2); color: var(--color-muted); background: var(--color-field); box-shadow: none; }
.cancel-edit:hover { color: var(--color-ink); background: #edf0f8; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.entry-card .button { margin-top: var(--space-4); }
.error { min-height: var(--space-3); margin: var(--space-2) 0 0; color: var(--color-danger); font-size: var(--text-xs); }

.summary-strip { margin-top: var(--space-3); padding: var(--space-4); border: 1px solid rgba(231, 233, 240, .9); border-radius: var(--radius-lg); background: var(--color-surface); box-shadow: var(--shadow-card); display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.summary-label { color: var(--color-muted); font-size: var(--text-sm); }
.currency-symbol { font-family: var(--font-body); font-size: .82em; font-weight: 700; letter-spacing: 0; vertical-align: .04em; }
.summary-value { margin-top: var(--space-1); color: var(--color-ink); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: -.025em; }
.summary-link { color: var(--color-primary); font-size: var(--text-sm); line-height: 1.25; text-align: right; text-decoration: none; }

.bottom-nav { position: fixed; inset: auto 0 0; z-index: 10; width: min(100%, 480px); height: calc(76px + env(safe-area-inset-bottom)); margin: 0 auto; padding-bottom: env(safe-area-inset-bottom); background: rgba(255, 255, 255, .88); border-top: 1px solid rgba(231, 233, 240, .9); box-shadow: 0 -12px 30px rgba(67, 78, 118, .08); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.nav-inner { width: min(100%, 430px); height: 76px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; }
.nav-divider { display: none; }
.nav-button { display: grid; place-items: center; align-content: center; gap: var(--space-1); border: 0; background: transparent; color: var(--color-subtle); font-size: var(--text-xs); font-weight: 700; }
.nav-button:hover, .nav-button.active { color: var(--color-primary); }
.nav-icon { width: 34px; height: 30px; display: grid; place-items: center; border-radius: var(--radius-sm); }
.nav-icon .icon { width: 20px; height: 20px; }
.nav-button.active .nav-icon { background: #e5ebff; }

.screen-title-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); margin: 0 0 var(--space-5); }
.screen-title { margin: 0; font-family: var(--font-display); font-size: 32px; font-weight: 600; line-height: 1; letter-spacing: -.035em; }
.back-link { display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-2) 0; color: var(--color-primary); font-size: var(--text-sm); text-decoration: none; }
.back-link .icon { width: 19px; height: 19px; }
.back-icon { width: 36px; height: 36px; justify-content: center; border-radius: var(--radius-pill); background: var(--color-surface); border: 1px solid var(--color-line); box-shadow: 0 6px 16px rgba(67, 78, 118, .08); }
.back-icon:hover { background: #eef2ff; border-color: #cbd5ff; box-shadow: 0 8px 18px rgba(67, 78, 118, .12); }
.clear-link { padding: var(--space-2) 0; color: var(--color-danger); border: 0; background: transparent; font-size: var(--text-sm); }
.clear-link:disabled { opacity: .35; cursor: not-allowed; }
.search-box-wrap { position: relative; margin-bottom: var(--space-3); }
.search-box { min-height: 46px; padding-left: 40px; }
.search-icon { position: absolute; left: 14px; top: 13px; color: var(--color-muted); }
.search-icon .icon { width: 19px; height: 19px; }
.history-filters, .export-range { display: grid; grid-template-columns: 1fr 1fr auto; gap: var(--space-2); align-items: end; margin-bottom: var(--space-4); }
.filter-field .input { min-height: 44px; padding: 0 var(--space-3); }
.filter-clear { min-height: 44px; padding: 0 var(--space-3); color: var(--color-muted); background: transparent; border: 1px solid var(--color-line); border-radius: var(--radius-md); font-size: var(--text-xs); white-space: nowrap; }
.filter-clear:hover:not(:disabled) { color: var(--color-primary); background: #eef2ff; border-color: #aeb8ff; }
.filter-clear:disabled { opacity: .4; cursor: not-allowed; }
.metrics { display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: var(--space-2); padding: var(--space-4); margin-bottom: var(--space-5); background: var(--color-surface); border: 1px solid rgba(231, 233, 240, .9); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.metric { display: grid; gap: var(--space-1); }
.metric:last-child { justify-items: end; }
.metric-label { color: var(--color-muted); font-size: var(--text-xs); }
.metric-value { color: var(--color-ink); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: -.025em; }
.metric:last-child .metric-value { color: var(--color-primary-dark); }
.empty-state { padding: var(--space-7) 0; color: var(--color-muted); font-size: var(--text-sm); text-align: center; }
.history-list { display: grid; gap: var(--space-3); }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); padding: var(--space-4); background: var(--color-surface); border: 1px solid rgba(231, 233, 240, .9); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.history-main { min-width: 0; }
.history-id { font-weight: 750; overflow-wrap: anywhere; }
.history-meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); margin-top: var(--space-2); color: var(--color-muted); font-size: var(--text-xs); }
.history-amount { color: var(--color-primary-dark); font-weight: 800; text-align: right; }
.history-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: var(--space-2); }
.tiny-button { padding: var(--space-2) var(--space-3); color: var(--color-muted); background: var(--color-field); border: 1px solid var(--color-line); border-radius: var(--radius-sm); font-size: var(--text-xs); }
.tiny-button:hover { color: var(--color-danger); background: #fff3f5; border-color: #f2bdc9; }
.tiny-button.edit { color: var(--color-primary); background: #eef2ff; border-color: #dce3ff; }
.tiny-button.edit:hover { color: var(--color-primary-dark); background: #e4ebff; border-color: #cbd5ff; }

.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-5) var(--space-4); background: radial-gradient(circle at 50% 5%, #d8ddff, transparent 34%), var(--color-canvas); }
.auth-card { width: min(100%, 360px); padding: var(--space-6); }
.logo-mark { width: 60px; height: 60px; display: grid; place-items: center; margin-bottom: var(--space-5); border-radius: var(--radius-lg); background: linear-gradient(135deg, var(--color-purple), #9b6ef1 60%, #f2a276); box-shadow: 0 12px 24px rgba(118, 88, 223, .22); }
.logo-mark .icon { width: 36px; height: 36px; }
.auth-card h1 { margin: 0 0 var(--space-1); font-family: var(--font-display); font-size: 29px; font-weight: 600; letter-spacing: -.035em; }
.auth-subtitle { margin: 0 0 var(--space-5); color: var(--color-muted); font-size: var(--text-sm); }
.auth-card .field { margin-top: var(--space-4); }
.auth-card .button { margin-top: var(--space-5); }
.auth-card .demo-button { margin-top: var(--space-3); }
.demo-note { margin-top: var(--space-2); text-align: center; }
.auth-footer { margin: var(--space-5) 0 0; text-align: center; font-size: var(--text-sm); }
.auth-note { margin: var(--space-3) 0 0; color: var(--color-muted); font-size: var(--text-xs); line-height: 1.5; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: end center; padding: 0; background: rgba(31, 38, 61, .24); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.export-card { width: min(100%, 480px); padding: var(--space-3) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom)); border-radius: var(--radius-xl) var(--radius-xl) 0 0; background: rgba(255, 255, 255, .98); box-shadow: 0 -18px 55px rgba(67, 78, 118, .18); }
.export-card::before { content: ""; display: block; width: 38px; height: 4px; margin: 0 auto var(--space-4); border-radius: var(--radius-pill); background: #d4d8e2; }
.export-card h2 { margin: 0 0 var(--space-2); font-family: var(--font-display); font-size: 24px; font-weight: 600; letter-spacing: -.03em; }
.export-card p { margin: 0 0 var(--space-4); color: var(--color-muted); font-size: var(--text-sm); }
.export-filter-note { margin-bottom: var(--space-4) !important; }
.export-range { grid-template-columns: 1fr 1fr; margin-bottom: var(--space-2); }
.export-summary { padding: var(--space-3); color: var(--color-primary-dark) !important; background: #eef2ff; border: 1px solid #dce3ff; border-radius: var(--radius-md); }
.export-card .button + .button { margin-top: var(--space-2); }
.modal-cancel { display: block; width: max-content; margin: var(--space-4) auto 0; color: var(--color-primary); font-size: var(--text-sm); }
.icon { display: block; width: 24px; height: 24px; }

.toast-region { position: fixed; right: var(--space-4); bottom: calc(92px + env(safe-area-inset-bottom)); left: var(--space-4); z-index: 40; display: grid; justify-items: center; gap: var(--space-2); pointer-events: none; }
.toast { padding: var(--space-3) var(--space-4); color: var(--color-surface); background: #292d3b; border-radius: var(--radius-pill); box-shadow: var(--shadow-card); font-size: var(--text-sm); animation: toast-in .18s ease-out; }
.toast.success { background: #23855c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.print-report { width: min(100%, 1100px); min-height: 100vh; margin: 0 auto; padding: 18px 12px; color: #111; background: #fff; font-family: Arial, Helvetica, sans-serif; box-sizing: border-box; }
.print-report-header h1 { margin: 0; font-size: 20px; line-height: 1.1; font-weight: 700; }
.print-report-header p { margin: 3px 0 12px; color: #536173; font-size: 11px; }
.export-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-family: Arial, Helvetica, sans-serif; font-size: 10px; }
.export-table th, .export-table td { padding: 6px 7px; border: 1px solid #c9c9c9; text-align: center; vertical-align: middle; white-space: nowrap; }
.export-table thead { display: table-header-group; }
.export-table thead th { color: #fff; background: #5d2cb4; border-color: #fff; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.export-table tbody tr { break-inside: avoid; page-break-inside: avoid; }
.export-table tbody tr:nth-child(even) { background: #f1ecfa; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.export-table tbody tr:nth-child(odd) { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.export-table th:nth-child(1), .export-table td:nth-child(1) { width: 7%; }
.export-table th:nth-child(2), .export-table td:nth-child(2), .export-table th:nth-child(3), .export-table td:nth-child(3) { width: 15%; }
.export-table th:nth-child(4), .export-table td:nth-child(4), .export-table th:nth-child(5), .export-table td:nth-child(5) { width: 13%; }
.export-table th:nth-child(6), .export-table td:nth-child(6), .export-table th:nth-child(7), .export-table td:nth-child(7) { width: 14%; }
.export-table th:nth-child(8), .export-table td:nth-child(8) { width: 15%; text-align: right; }
.export-table .export-total { background: #f1ecfa; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.export-table .export-total th:first-child { text-align: center; }
.export-table .export-total th:not(:first-child) { color: #111; background: #f1ecfa; border-color: #c9c9c9; }

@media (max-width: 560px) {
  body { background: var(--color-canvas); }
  .app-shell { box-shadow: none; }
  .topbar { padding-right: var(--space-4); padding-left: var(--space-4); }
  .page, .page.narrow { width: min(calc(100% - var(--space-5)), 430px); padding-top: var(--space-5); }
  .field-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .history-filters, .export-range { grid-template-columns: 1fr 1fr; }
  .filter-clear { grid-column: 1 / -1; width: 100%; }
}

@media (max-width: 360px) {
  .history-filters, .export-range { grid-template-columns: 1fr; }
  .filter-clear { grid-column: auto; }
  .summary-strip { display: grid; }
  .summary-link { text-align: left; }
}

@media print {
  @page { size: landscape; margin: .35in; }
  body { background: white; color: #111; }
  .app-shell { width: 100%; max-width: none; min-height: auto; background: white; box-shadow: none; }
  .print-report { width: 100%; min-height: auto; padding: 0; }
  .topbar, .bottom-nav, .home-intro, .section-heading, .screen-title-row, .search-box-wrap, .history-filters, .clear-link, .history-actions, .toast-region { display: none !important; }
  .page { width: 100%; padding: 0; }
  .metrics, .history-item { box-shadow: none; }
  .metrics, .history-item { border-color: #ccc; }
  .metric-label, .history-meta { color: #555; }
  .history-item { background: white; }
}
