:root {
  color-scheme: light;
  --bg: #f7f6f3; --surface: #ffffff; --surface-2: #f1efea; --border: #e2e0da;
  --text: #1b1b1a; --text-2: #52514e; --muted: #6f6e69;
  --primary: #2a78d6; --primary-ink: #ffffff; --primary-soft: #e6f0fb;
  --danger: #c43c3b; --danger-soft: #fbeaea;
  --ok: #18794e; --ok-soft: #e5f4ec; --warn: #8a5a00; --warn-soft: #fdf3dc;
  --series-1: #2a78d6; --grid: #e7e5df;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9b9a93;
    --primary: #3987e5; --primary-ink: #ffffff; --primary-soft: #1c2c40;
    --danger: #e66767; --danger-soft: #3a1f1f;
    --ok: #4cc38a; --ok-soft: #173023; --warn: #e3b341; --warn-soft: #33290f;
    --series-1: #3987e5; --grid: #2c2c29;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9b9a93;
  --primary: #3987e5; --primary-ink: #ffffff; --primary-soft: #1c2c40;
  --danger: #e66767; --danger-soft: #3a1f1f;
  --ok: #4cc38a; --ok-soft: #173023; --warn: #e3b341; --warn-soft: #33290f;
  --series-1: #3987e5; --grid: #2c2c29; --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
.card h2:first-child, .card h2.nomargin { margin-top: 0; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
.nomargin { margin: 0; }
.wrap { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.right { text-align: right; white-space: nowrap; }

/* nav */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a { padding: 6px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; }
.topnav a.on, .topnav a:hover { background: var(--primary-soft); color: var(--primary); }
.logout { margin-left: auto; display: none; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: .75rem;
  color: var(--muted); text-decoration: none; }
.tabbar a.on { color: var(--primary); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tabbar svg circle { fill: currentColor; stroke: none; }
@media (min-width: 820px) {
  .topnav, .logout { display: flex; }
  .tabbar, .mobile-only { display: none !important; }
  .wrap { padding-bottom: 48px; }
}

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow { max-width: 420px; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .between { justify-content: space-between; }
.wrap-row { flex-wrap: wrap; } .align-end { align-items: flex-end; } .grow { flex: 1; min-width: 160px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.inline { display: inline; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--text-2); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); flex: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
label .row input { flex: 1; min-width: 0; } label .row { gap: 6px; }
.w-sm { max-width: 130px; }
fieldset { border: 1px dashed var(--border); border-radius: 10px; padding: 12px; margin: 0; }
legend { padding: 0 6px; color: var(--text-2); font-size: .9rem; font-weight: 500; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.btn { flex-direction: row; color: var(--text); font-weight: 600; font-size: 1rem; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2); vertical-align: middle; margin-left: 4px; }
.tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.ok { background: var(--ok-soft); color: var(--ok); }

/* login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login .card { text-align: left; }

/* ongoing */
.ongoing { border-color: var(--warn); background: var(--warn-soft); display: flex; flex-direction: column; gap: 10px; }
.ongoing input { max-width: 140px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.item.sel { padding: 0 0 0 12px; align-items: stretch; }
.item.sel > input { align-self: center; }
.item-body { flex: 1; display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px 12px 4px;
  color: var(--text); text-decoration: none; min-width: 0; }
.item-body > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.item.sel:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.item-d { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.item-d form { margin-top: 10px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.card > summary + * , details.card > form { margin-top: 14px; }
.filters summary { font-weight: 600; }
.toolbar { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }
.toolbar.sticky { position: sticky; top: 0; z-index: 10; background: var(--bg); }
@media (min-width: 820px) { .toolbar.sticky { top: 49px; } }
.pager { justify-content: center; margin-top: 14px; }
.danger-zone { border-top: 1px solid var(--border); padding-top: 12px; }

/* entry detail */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: .75rem; color: var(--muted); } .facts dd { margin: 0; font-weight: 600; }
.notes { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.thumbs img, .thumbs .pend { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.pend { position: relative; } .pend span { position: absolute; inset: auto 0 0 0; font-size: .7rem; text-align: center;
  background: rgba(0,0,0,.6); color: #fff; border-radius: 0 0 8px 8px; }
.pend button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: var(--danger); color: #fff; font-weight: 700; cursor: pointer; line-height: 1; padding: 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 10px 0 14px; }
.ph { position: relative; display: block; border-radius: 10px; overflow: hidden; border: 2px solid transparent; background: var(--surface-2); }
.ph:has(input:checked) { border-color: var(--primary); }
.ph img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.ph input { position: absolute; top: 8px; left: 8px; }
.ph-actions { display: block; font-size: .8rem; padding: 6px 8px; font-weight: 400; }

/* summary */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.chip { padding: 6px 12px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); text-decoration: none;
  font-size: .9rem; border: 1px solid var(--border); font: inherit; font-size: .9rem; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; }
.tl { font-size: .8rem; color: var(--text-2); } .tv { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ts { font-size: .8rem; color: var(--muted); }
.charts { display: grid; grid-template-columns: 1fr; gap: 0 14px; margin-top: 14px; }
@media (min-width: 820px) { .charts { grid-template-columns: 1fr 1fr; } }
.chart { margin: 0 0 14px; } figcaption { font-weight: 600; margin-bottom: 8px; }
.chart-box { position: relative; height: 220px; } .chart-box.tall { height: 260px; }
.table-scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tfoot th { border-bottom: 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 16px; } }
.modal-card h3 { margin-top: 0; }
fieldset { min-width: 0; }
.photos-field .row { flex-wrap: wrap; }
@media (max-width: 480px) { .tbl { font-size: .88rem; } .tbl th, .tbl td { padding: 8px 4px; } }
.tbl td:first-child { min-width: 110px; }
