/* Design system in the style of shadcn/ui (PROJECT.md §5.14): tokens, components, layout.
   Mobile first; breakpoints 768 px and 1024 px. No webfonts, no external requests. */

:root {
  color-scheme: light dark;
  --background: #ffffff;
  --foreground: #09090b;
  --card: #ffffff;
  --muted: #f4f4f5;
  --muted-foreground: #52525b;
  --border: #e4e4e7;
  --input: #d4d4d8;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --secondary: #f4f4f5;
  --secondary-foreground: #18181b;
  --destructive: #b91c1c;
  --destructive-foreground: #fafafa;
  --success: #166534;
  --success-bg: #dcfce7;
  --info-bg: #e0f2fe;
  --info: #075985;
  --error-bg: #fee2e2;
  --ring: #2563eb;
  --radius: 0.5rem;
  --touch: 2.75rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #09090b;
    --foreground: #fafafa;
    --card: #111113;
    --muted: #27272a;
    --muted-foreground: #a1a1aa;
    --border: #27272a;
    --input: #3f3f46;
    --primary: #fafafa;
    --primary-foreground: #18181b;
    --secondary: #27272a;
    --secondary-foreground: #fafafa;
    --destructive: #f87171;
    --destructive-foreground: #09090b;
    --success: #86efac;
    --success-bg: #052e16;
    --info-bg: #082f49;
    --info: #7dd3fc;
    --error-bg: #450a0a;
    --ring: #60a5fa;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 1rem; font-weight: 700; }
h2 { font-size: 1.125rem; line-height: 1.3; margin: 0 0 0.75rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
a { color: inherit; }
strong { font-weight: 600; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted-foreground); font-size: 0.875rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon { flex: none; vertical-align: -0.2em; }

/* ---- layout --------------------------------------------------------------------------- */

.page { max-width: 64rem; margin: 0 auto; padding: 1rem; }
.page > :last-child { margin-bottom: 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  max-width: 64rem; margin: 0 auto; padding: 0.5rem 1rem;
}
.brand { font-weight: 700; text-decoration: none; margin-right: auto; }
.year-form { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.year-form select { width: auto; min-width: 5.5rem; }

.nav-menu { position: relative; }
.nav-menu > summary { list-style: none; }
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu nav {
  position: absolute; right: 0; top: calc(100% + 0.25rem); z-index: 20;
  display: flex; flex-direction: column; gap: 0.125rem; min-width: 12rem;
  padding: 0.5rem; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
}
.nav-menu nav a, .nav-menu nav .button {
  display: flex; align-items: center; gap: 0.5rem; justify-content: flex-start;
  width: 100%; min-height: var(--touch); padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) - 2px); text-decoration: none;
}
.nav-menu nav a:hover { background: var(--muted); }
.nav-menu nav a[aria-current="page"] { background: var(--muted); font-weight: 600; }
.nav-menu nav form { margin: 0; }

@media (min-width: 768px) {
  .page { padding: 1.5rem; }
  .topbar-inner { padding: 0.5rem 1.5rem; flex-wrap: nowrap; }
  .nav-menu { order: 3; min-width: 0; }
  .js .nav-menu > summary { display: none; }
  .nav-menu nav {
    position: static; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; min-width: 0;
    padding: 0; border: 0; box-shadow: none; background: transparent;
  }
  .nav-menu nav a, .nav-menu nav .button { width: auto; min-height: 2.25rem; }
}

.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---- components ----------------------------------------------------------------------- */

.card {
  background: var(--card); color: var(--foreground);
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px);
  padding: 1rem; margin-bottom: 1rem;
}
.card > :last-child { margin-bottom: 0; }
.card-notice { border-color: var(--info); }
@media (min-width: 768px) { .card { padding: 1.25rem; } }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--touch); padding: 0.5rem 1rem;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: 1rem; font-weight: 500; line-height: 1.25;
  text-decoration: none; cursor: pointer;
  background: var(--primary); color: var(--primary-foreground);
}
.button:hover { opacity: 0.9; }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.button-primary { background: var(--primary); color: var(--primary-foreground); }
.button-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.button-outline { background: transparent; color: var(--foreground); border-color: var(--input); }
.button-outline:hover, .button-ghost:hover { background: var(--muted); opacity: 1; }
.button-ghost { background: transparent; color: var(--foreground); }
.button-destructive { background: var(--destructive); color: var(--destructive-foreground); }
@media (min-width: 768px) { .button { min-height: 2.25rem; font-size: 0.875rem; } }

label { display: block; font-weight: 500; margin: 1rem 0 0.25rem; }
input[type="text"], input[type="password"], input[type="search"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  display: block; width: 100%; min-height: var(--touch); padding: 0.5rem 0.75rem;
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius);
  font: inherit; font-size: 1rem; /* >= 16 px: no zoom on iOS */
}
textarea { min-height: 5rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] {
  width: 1.25rem; height: 1.25rem; margin: 0 0.5rem 0 0; vertical-align: -0.2em;
  accent-color: var(--primary);
}
.year-form select { display: inline-block; }
form > .button { margin-top: 1.25rem; }
.field-error { color: var(--destructive); font-size: 0.875rem; margin: 0.25rem 0 0; }

.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.0625rem 0.5rem; border-radius: 999px; border: 1px solid var(--border);
  font-size: 0.75rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--primary); color: var(--primary-foreground);
}
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge-outline { background: transparent; color: var(--foreground); }
.badge-destructive { background: var(--destructive); color: var(--destructive-foreground); border-color: transparent; }

.alert {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.75rem 1rem; margin: 0 0 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--info-bg); color: var(--info);
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--destructive); }
.alert-info { background: var(--info-bg); color: var(--info); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: 0.5rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th.num, .table td.num { text-align: right; }
.table thead th { color: var(--muted-foreground); font-size: 0.8125rem; font-weight: 500; }
.table tbody th { font-weight: 500; }
.table tbody tr:last-child > * { border-bottom: 0; }

.tabs { display: flex; gap: 0.25rem; padding: 0.25rem; overflow-x: auto; background: var(--muted); border-radius: var(--radius); }
.tabs a {
  flex: none; display: inline-flex; align-items: center; gap: 0.375rem;
  min-height: 2.25rem; padding: 0.25rem 0.75rem; border-radius: calc(var(--radius) - 2px);
  color: var(--muted-foreground); text-decoration: none; font-weight: 500; font-size: 0.875rem;
}
.tabs a[aria-current="page"] { background: var(--background); color: var(--foreground); box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); }

.separator { height: 1px; margin: 1rem 0; border: 0; background: var(--border); }

dialog {
  width: min(32rem, calc(100% - 2rem)); max-height: calc(100% - 2rem); padding: 1.25rem;
  background: var(--card); color: var(--foreground);
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }

.progress { display: block; width: 100%; height: 0.625rem; margin: 0.5rem 0 0.75rem; border: 0; border-radius: 999px; overflow: hidden; background: var(--muted); appearance: none; }
.progress::-webkit-progress-bar { background: var(--muted); }
.progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
.progress::-moz-progress-bar { background: var(--primary); }
.progress-text { font-size: 1.0625rem; margin-bottom: 0; }

.todo-list, .plain-list { list-style: none; margin: 0; padding: 0; }
.todo-list li { display: flex; align-items: flex-start; gap: 0.625rem; padding: 0.625rem 0; border-bottom: 1px solid var(--border); }
.todo-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.plain-list li { padding: 0.375rem 0; }

.balances { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; margin: 0 0 0.75rem; }
.balances dt { color: var(--muted-foreground); }
.balances dd { margin: 0; font-weight: 600; }

/* ---- entry list (month view): cards below 768 px, grid rows from 768 px ------------------ */

.badge-warning { background: var(--error-bg); color: var(--destructive); border-color: transparent; }
.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-review { background: var(--info-bg); color: var(--info); border-color: transparent; }
.tabs { margin-bottom: 1rem; }
.summary p { margin-bottom: 0.5rem; }

.entries { list-style: none; margin: 0 0 1rem; padding: 0; }
.entries-head { display: none; }
.entry {
  display: grid; gap: 0.5rem; padding: 0.875rem; margin-bottom: 0.75rem;
  background: var(--card); border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px);
  scroll-margin-top: 4.5rem;
}
.entry:target { border-color: var(--ring); }
.entry > * { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.entry-id, .entry-what, .entry-amount, .entry-status { display: flex; flex-direction: column; gap: 0.125rem; }
.entry-id { flex-direction: row; justify-content: space-between; align-items: baseline; }
.entry-amount { align-items: flex-end; }
.entry-badges, .entry-status { flex-wrap: wrap; }
.entry-badges { display: flex; gap: 0.25rem; margin-top: 0.25rem; }
.entry-status .badge { align-self: flex-start; }
.booking-no { font-weight: 600; font-variant-numeric: tabular-nums; }
.receipt-file { font-weight: 500; }
.entry-comment, .entry-details { grid-column: 1 / -1; }
.entry-details summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--muted-foreground); }
.entry-details h3 { font-size: 0.9375rem; margin: 1rem 0 0.5rem; }
.source-fields { display: grid; grid-template-columns: minmax(7rem, 1fr) 2fr; gap: 0.125rem 0.75rem; margin: 0; font-size: 0.875rem; }
.source-fields dt { color: var(--muted-foreground); }
.source-fields dd { margin: 0; overflow-wrap: anywhere; }

@media (min-width: 768px) {
  .entries-head, .entry {
    grid-template-columns: 9rem 1fr 9rem 13rem; align-items: start; gap: 0.5rem 1rem;
  }
  .entries-head {
    display: grid; padding: 0 0.875rem 0.375rem; color: var(--muted-foreground);
    font-size: 0.8125rem; font-weight: 500;
  }
  .entry { padding: 0.75rem 0.875rem; margin-bottom: 0.5rem; }
  .entry-id { flex-direction: column; }
}

/* ---- PDF view -------------------------------------------------------------------------- */

.pdf-frame { display: none; width: 100%; height: 80vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--muted); }
.pdf-open { margin-bottom: 1rem; }
@media (min-width: 768px) {
  .pdf-frame { display: block; }
  .pdf-open { display: none; }
}
.file-link { font-weight: 500; text-underline-offset: 2px; }

/* ---- entry actions, forms, picker ------------------------------------------------------- */

.entry-message { grid-column: 1 / -1; margin: 0; }
.entry-actions-wrap { grid-column: 1 / -1; }
.entry-actions summary, .entry-details summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--muted-foreground); }
.entry-actions form { margin: 0 0 1.25rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.entry-actions h3 { font-size: 0.9375rem; margin: 0 0 0.25rem; }
.field-row { display: grid; grid-template-columns: 2fr 1fr; gap: 0.75rem; }
.field-row:has(> :nth-child(3)) { grid-template-columns: 2fr 1fr 1fr; }
label.check { display: flex; align-items: flex-start; gap: 0.25rem; font-weight: 400; margin: 0.625rem 0 0; min-height: var(--touch); align-items: center; }
.action-pair { display: grid; gap: 0 1rem; }
@media (min-width: 768px) { .action-pair { grid-template-columns: 1fr 1fr; } }
.picker-list { border: 0; margin: 0.5rem 0; padding: 0; max-height: 14rem; overflow-y: auto; }
.picker-list label[hidden] { display: none; }
.new-collective { margin: 0.5rem 0; }
.new-collective summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; }
.upload-progress { width: 100%; margin-top: 0.5rem; }
.js #picker-dialog form { margin-bottom: 0; }

.field { margin-bottom: 0.25rem; }
.field-help { margin: 0.25rem 0 0; }
.self-receipt-form h2 { margin-top: 1.5rem; }
.self-receipt-form h2:first-of-type { margin-top: 1rem; }
[aria-invalid="true"] { border-color: var(--destructive); }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc h2 { margin-bottom: 0.25rem; overflow-wrap: anywhere; }
.doc-actions summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--muted-foreground); }
.doc-actions form { margin: 0 0 1.25rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.file-actions { font-size: 0.875rem; }

/* ---- review, open, search --------------------------------------------------------------- */

.search-form { display: flex; gap: 0.5rem; margin: 0 0 0.5rem; }
.search-form input { flex: 1; min-width: 0; }
.search-form .button { flex: none; }
.nav-menu nav .search-form .button { width: auto; }
@media (min-width: 768px) {
  .search-form { margin: 0 0.5rem 0 0; }
  .search-form input { width: 7.5rem; }
  .nav-menu nav .search-form .button { display: none; } /* Enter submits the single-field form */
}
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.review-list { margin-bottom: 1.5rem; }
.review-card {
  display: grid; gap: 0.75rem; padding: 0.875rem; margin-bottom: 0.75rem; scroll-margin-top: 4.5rem;
  background: var(--card); border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px);
}
.review-card > * { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.review-entry, .review-proposal { display: flex; flex-direction: column; gap: 0.125rem; }
.review-proposal .badge { align-self: flex-start; }
.review-pick { display: flex; align-items: center; min-height: var(--touch); }
.proposal-forms form, .proposal-actions form { margin: 0 0 1rem; }
.proposal-more { margin: 0.25rem 0; }
.proposal-more summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--muted-foreground); }
.proposal-actions { grid-column: 1 / -1; padding-top: 0.5rem; }
.proposal-actions h3 { font-size: 0.9375rem; margin: 0 0 0.5rem; }
.pdf-panel { display: none; }
@media (min-width: 768px) {
  .review-card { grid-template-columns: 2rem 1fr 1fr; gap: 0.5rem 1rem; align-items: start; }
  .review-actions, .review-card > .entry-message { grid-column: 2 / -1; }
}
@media (min-width: 1024px) {
  .review-layout.with-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
  .review-layout.with-panel .pdf-panel { display: flex; flex-direction: column; gap: 0.5rem; position: sticky; top: 4.5rem; height: calc(100vh - 6rem); }
  .review-layout.with-panel .pdf-panel iframe { flex: 1; width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--muted); }
  .review-layout.with-panel .review-card { grid-template-columns: 2rem 1fr; }
  .review-layout.with-panel .review-proposal, .review-layout.with-panel .review-actions { grid-column: 2; }
}

[hidden] { display: none !important; }

/* Import previews keep long CSV fields readable on narrow screens. */
.import-entry { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.import-report { overflow-wrap: anywhere; }
