:root {
  --ink: #1d2327;
  --muted: #5d6b72;
  --paper: #f6f5f1;
  --card: #ffffff;
  --line: #d9ddd9;
  --accent: #1f4e5f;
  --accent-ink: #ffffff;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --ok: #2f6b3a;
  --radius: 10px;
  --tap: 44px;
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Elements given display rules below must still disappear when hidden. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.topbar {
  background: var(--accent);
  color: var(--accent-ink);
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }

.banner {
  background: var(--warn-bg);
  color: var(--warn-ink);
  padding: 8px 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.banner a { color: inherit; font-weight: 600; }

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 12px 16px 24px;
}
main:focus { outline: none; }

h2 { font-size: 1.3rem; margin: 8px 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 8px; }

nav.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
nav.tabs a {
  text-align: center;
  padding: 14px 4px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  min-height: var(--tap);
}
nav.tabs a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin: 12px 0;
}

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="date"], input[type="month"], input[type="search"], input:not([type]), select, textarea {
  width: 100%;
  font: inherit;
  padding: 10px;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }

button, .button {
  font: inherit;
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.big, .button.big { min-height: 52px; font-weight: 600; }
button.toggle.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 8px 0; }
.row > input, .row > select { flex: 1 1 10rem; width: auto; }
.grow { flex: 1 1 auto; }

.capture-buttons > button { flex: 1 1 0; }

.check { display: flex; gap: 10px; align-items: center; margin: 10px 0; min-height: var(--tap); }
.check input { width: 22px; height: 22px; }

.actions { margin: 16px 0; display: flex; gap: 8px; flex-wrap: wrap; }
.actions .primary.big { flex: 1 1 100%; }
.actions.stack { flex-direction: column; }

.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }

.warning {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
}
.warning-card { border-color: #e6c26a; }

.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.thumb { margin: 0; width: calc(50% - 5px); background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.thumb img { width: 100%; height: 160px; object-fit: contain; background: #eee; display: block; }
.thumb figcaption { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; }
.thumb figcaption button { min-height: 36px; padding: 4px 8px; font-size: 0.85rem; }
.thumb .missing { height: 160px; display: grid; place-items: center; color: var(--muted); }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.segmented a { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); background: #fff; }
.segmented a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.entry-list, .period-list { list-style: none; padding: 0; margin: 8px 0; }
.entry-list li, .period-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 6px 0;
  padding: 8px 10px;
}
.entry-list li input { width: 22px; height: 22px; flex: none; }
.entry-list a, .period-list a { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: var(--tap); justify-content: center; }
.entry-list .empty { color: var(--muted); justify-content: center; }

.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: #eceeec; color: var(--muted); width: fit-content; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.ok { background: #e1efe3; color: var(--ok); }

table { border-collapse: collapse; width: 100%; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
table.totals tr.grand td { font-weight: 700; }

.pick-list { max-height: 50vh; overflow: auto; margin-top: 8px; }
.pick { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  max-width: calc(100% - 32px);
  z-index: 30;
}

.dialog { border: none; border-radius: var(--radius); padding: 16px; width: min(32rem, calc(100% - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

.crop-overlay {
  position: fixed;
  inset: 0;
  background: #111;
  z-index: 40;
  display: grid;
  grid-template-rows: 1fr auto auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.crop-canvas { width: 100%; height: 100%; touch-action: none; display: block; }
.crop-toolbar, .crop-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px; align-items: center; color: #fff; }
.crop-actions { justify-content: space-between; }
.crop-straighten { display: flex; gap: 8px; align-items: center; flex: 1 1 14rem; }
.crop-straighten input { flex: 1; }
.crop-angle { min-width: 5ch; font-variant-numeric: tabular-nums; }
