:root {
  color-scheme: light dark;
  --bg: oklch(1 0 0);
  --surface: oklch(0.975 0.003 28.3);
  --surface-strong: oklch(0.945 0.006 28.3);
  --ink: oklch(0.22 0.015 28.3);
  --muted: oklch(0.47 0.018 28.3);
  --primary: oklch(0.489 0.19 28.3);
  --primary-hover: oklch(0.445 0.18 28.3);
  --accent: oklch(0.55 0.115 220);
  --success: oklch(0.48 0.13 155);
  --warning: oklch(0.64 0.14 78);
  --warning-ink: oklch(0.39 0.105 78);
  --error: oklch(0.47 0.19 28);
  --line: oklch(0.87 0.008 28.3);
  --focus: oklch(0.6 0.13 220);
  --radius-sm: 10px;
  --radius-md: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --max: 1180px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.09 0 0);
    --surface: oklch(0.145 0.006 28.3);
    --surface-strong: oklch(0.19 0.008 28.3);
    --ink: oklch(0.94 0.006 28.3);
    --muted: oklch(0.7 0.012 28.3);
    --primary: oklch(0.5 0.19 28.3);
    --primary-hover: oklch(0.44 0.18 28.3);
    --accent: oklch(0.76 0.1 220);
    --success: oklch(0.72 0.12 155);
    --warning: oklch(0.8 0.12 78);
    --warning-ink: oklch(0.87 0.09 78);
    --error: oklch(0.7 0.16 28);
    --line: oklch(0.3 0.012 28.3);
    --focus: oklch(0.76 0.1 220);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

a {
  color: var(--accent);
}

.skip-link {
  position: fixed;
  inset-block-start: var(--space-3);
  inset-inline-start: var(--space-3);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  background: var(--ink);
  color: var(--bg);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding:
    max(var(--space-3), env(safe-area-inset-top))
    max(var(--space-4), env(safe-area-inset-right))
    var(--space-3)
    max(var(--space-4), env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklch, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 750;
  text-decoration: none;
}

.brand img,
.mark img {
  display: block;
  border-radius: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.privacy-state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 650;
}

.privacy-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
}

main {
  width: min(100%, var(--max));
  min-height: calc(100vh - 144px);
  margin-inline: auto;
  padding:
    var(--space-6)
    max(var(--space-4), env(safe-area-inset-right))
    var(--space-7)
    max(var(--space-4), env(safe-area-inset-left));
}

.start-layout {
  display: grid;
  gap: var(--space-7);
  align-items: center;
  min-height: calc(100vh - 190px);
}

.start-copy {
  max-width: 68ch;
}

.mark {
  margin-block-end: var(--space-5);
}

h1,
h2,
p {
  margin-block-start: 0;
}

h1,
h2 {
  text-wrap: balance;
}

h1 {
  max-width: 18ch;
  margin-block-end: var(--space-4);
  font-size: 2.35rem;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

h2 {
  margin-block-end: var(--space-1);
  font-size: 1.25rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.lead {
  max-width: 62ch;
  margin-block-end: var(--space-6);
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.65;
  text-wrap: pretty;
}

.privacy-evidence {
  display: grid;
  gap: 0;
  border-block: 1px solid var(--line);
}

.privacy-evidence > div {
  display: grid;
  gap: var(--space-1);
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.privacy-evidence > div:last-child {
  border-bottom: 0;
}

.privacy-evidence strong {
  font-size: 0.95rem;
}

.privacy-evidence span,
.retention-note,
.analysis-meta,
.file-name,
.section-heading p,
details p {
  color: var(--muted);
}

.import-panel {
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

#pdf-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.drop-zone {
  display: flex;
  min-height: 280px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border: 2px dashed color-mix(in oklch, var(--primary) 60%, var(--line));
  border-radius: var(--radius-md);
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  transition:
    border-color 180ms ease-out,
    background-color 180ms ease-out;
}

.drop-zone.is-dragging {
  border-color: var(--primary);
  background: color-mix(in oklch, var(--primary) 7%, var(--bg));
}

.drop-zone > span:not(.button):not(.drop-icon) {
  color: var(--muted);
  font-size: 0.9rem;
}

.drop-icon {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border-radius: 12px;
  background: color-mix(in oklch, var(--primary) 12%, var(--bg));
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 800;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 11px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 160ms ease-out,
    border-color 160ms ease-out;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-primary {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: white;
}

.button-primary:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.button-secondary {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

.button-secondary:hover {
  border-color: var(--muted);
  background: var(--surface);
}

#sample-button {
  width: 100%;
  margin-block-start: var(--space-3);
}

.retention-note {
  margin: var(--space-4) 0;
  font-size: 0.85rem;
}

details {
  border-top: 1px solid var(--line);
  padding-block-start: var(--space-3);
}

summary {
  min-height: 44px;
  cursor: pointer;
  font-weight: 700;
}

.state-view {
  display: grid;
  min-height: calc(100vh - 220px);
  place-items: center;
  align-content: center;
  text-align: center;
}

.state-view > * {
  max-width: 560px;
}

.spinner {
  width: 46px;
  height: 46px;
  margin-block-end: var(--space-5);
  border: 4px solid var(--surface-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.state-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-block-end: var(--space-4);
  place-items: center;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 800;
}

.error-icon {
  background: color-mix(in oklch, var(--error) 12%, var(--bg));
  color: var(--error);
}

.state-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: center;
  margin-block-start: var(--space-5);
}

.dashboard {
  display: grid;
  gap: var(--space-6);
}

.analysis-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
}

.analysis-heading h1 {
  max-width: none;
  margin-block-end: var(--space-2);
  font-size: 1.85rem;
}

.file-name {
  max-width: 72ch;
  margin-block-end: var(--space-1);
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.quality-badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.quality-verified {
  background: color-mix(in oklch, var(--success) 12%, var(--bg));
  color: var(--success);
}

.quality-review {
  background: color-mix(in oklch, var(--warning) 13%, var(--bg));
  color: var(--warning-ink);
}

.quality-incomplete {
  background: color-mix(in oklch, var(--error) 12%, var(--bg));
  color: var(--error);
}

.memory-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  background: color-mix(in oklch, var(--accent) 8%, var(--bg));
}

.memory-notice > div {
  display: grid;
  gap: var(--space-1);
}

.memory-notice span {
  color: var(--muted);
  font-size: 0.88rem;
}

.warning-list {
  padding: var(--space-4);
  border: 1px solid color-mix(in oklch, var(--warning) 45%, var(--line));
  border-radius: var(--radius-sm);
  background: color-mix(in oklch, var(--warning) 7%, var(--bg));
}

.warning-list ul {
  margin: var(--space-2) 0 0;
  padding-inline-start: 22px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.metrics > div {
  min-width: 0;
  padding: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.metrics > div:nth-child(odd) {
  border-inline-end: 1px solid var(--line);
}

.metrics > div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.metrics dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.metrics dd {
  margin: var(--space-2) 0 0;
  overflow: hidden;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.positive {
  color: var(--success);
}

.analysis-grid {
  display: grid;
  gap: var(--space-6);
}

.analysis-section,
.transactions-section {
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-block-end: var(--space-4);
}

.section-heading p {
  margin: 0;
  font-size: 0.9rem;
}

.category-chart {
  display: grid;
  gap: var(--space-4);
}

.category-row {
  display: grid;
  gap: 7px;
}

.category-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.92rem;
}

.category-label span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.category-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.category-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--category-color);
}

.daily-chart {
  min-height: 240px;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--line);
}

.daily-chart svg {
  display: block;
  width: 100%;
  height: 240px;
}

.large-spends {
  border-block: 1px solid var(--line);
}

.large-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.large-row:last-child {
  border-bottom: 0;
}

.large-row > div {
  min-width: 0;
}

.large-row strong,
.large-row span {
  display: block;
}

.large-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.large-row span {
  color: var(--muted);
  font-size: 0.85rem;
}

.large-amount {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.transaction-controls {
  display: grid;
  gap: var(--space-3);
  margin-block-end: var(--space-4);
}

.transaction-controls label,
dialog label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

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

input::placeholder {
  color: color-mix(in oklch, var(--muted) 90%, var(--ink));
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: middle;
}

th {
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td {
  font-size: 0.9rem;
}

td.numeric,
th.numeric {
  text-align: end;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.payee-cell {
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direction-credit {
  color: var(--success);
  font-weight: 700;
}

.category-select {
  min-width: 175px;
}

.no-results {
  padding: var(--space-6);
  color: var(--muted);
  text-align: center;
}

.empty-copy {
  color: var(--muted);
}

dialog {
  width: min(calc(100% - 32px), 480px);
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--ink);
}

dialog::backdrop {
  background: rgb(0 0 0 / 55%);
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: var(--space-3);
  margin-block-start: var(--space-5);
}

footer {
  display: flex;
  width: min(100%, var(--max));
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  margin-inline: auto;
  padding:
    var(--space-5)
    max(var(--space-4), env(safe-area-inset-right))
    max(var(--space-5), env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--bg);
  color: var(--ink);
  text-align: center;
}

.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;
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 760px) {
  main {
    padding-block-start: var(--space-7);
  }

  .start-layout {
    grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  }

  h1 {
    font-size: 3.3rem;
  }

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

  .metrics > div,
  .metrics > div:nth-child(odd) {
    border-inline-end: 1px solid var(--line);
    border-bottom: 0;
  }

  .metrics > div:last-child {
    border-inline-end: 0;
  }

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

  .transaction-controls {
    grid-template-columns: minmax(240px, 1.4fr) minmax(190px, 0.8fr) minmax(150px, 0.6fr);
  }
}

@media (max-width: 759px) {
  .start-layout {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .start-copy {
    display: contents;
  }

  .mark {
    order: 1;
  }

  .start-copy h1 {
    order: 2;
  }

  .lead {
    order: 3;
  }

  .import-panel {
    order: 4;
  }

  .privacy-evidence {
    order: 5;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 64px;
  }

  .privacy-state {
    display: none;
  }

  .analysis-heading,
  .memory-notice {
    align-items: stretch;
    flex-direction: column;
  }

  .analysis-heading {
    display: flex;
  }

  .quality-badge {
    align-self: flex-start;
  }

  .memory-notice .button {
    width: 100%;
  }

  .metrics dd {
    font-size: 1.05rem;
  }

  .large-row {
    align-items: flex-start;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    display: block;
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody tr {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
  }

  tbody tr:last-child {
    border-bottom: 0;
  }

  td,
  td.numeric {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 8px 0;
    border: 0;
    text-align: end;
    white-space: normal;
  }

  td::before {
    flex: 0 0 34%;
    color: var(--muted);
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 700;
    text-align: start;
  }

  .payee-cell {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .category-select {
    min-width: 0;
    max-width: 62%;
  }
}

@media (max-width: 420px) {
  .topbar {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .topbar-actions {
    max-width: 100%;
    margin-inline-start: auto;
  }

  .topbar .button {
    min-height: 42px;
    padding: 8px 12px;
    white-space: normal;
  }

  h1 {
    font-size: 2rem;
    overflow-wrap: anywhere;
  }

  .analysis-heading h1 {
    font-size: 1.5rem;
  }

  .import-panel,
  .drop-zone {
    padding: var(--space-4);
  }

  .drop-zone {
    min-height: 240px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .metrics > div,
  .metrics > div:nth-child(odd),
  .metrics > div:nth-last-child(-n + 2) {
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
  }

  .metrics > div:last-child {
    border-bottom: 0;
  }

  td,
  td.numeric {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-1);
    text-align: start;
  }

  td::before {
    flex-basis: auto;
  }

  .category-select {
    width: 100%;
    max-width: 100%;
  }

  .daily-chart svg {
    min-width: 100% !important;
  }
}

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

@media (forced-colors: active) {
  .privacy-dot,
  .category-fill {
    forced-color-adjust: none;
  }

  .button,
  .quality-badge {
    border: 1px solid currentColor;
  }
}
