:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1c2620;
  --muted: #6b7770;
  --line: #e3e6e1;
  --green: #2f6d4f;
  --green-ink: #ffffff;
  --amber: #b7791f;
  --blue: #2b5d8a;
  --red: #b3402f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 16px rgba(20,40,30,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tap: 48px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12160f; --card: #1b211a; --ink: #e8ece6; --muted: #9aa79f;
    --line: #2a322a; --green: #4f9e73; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 16px rgba(0,0,0,.35);
  }
}
/* explicit dark, chosen via the toggle regardless of OS setting */
:root[data-theme="dark"] {
  --bg: #12160f; --card: #1b211a; --ink: #e8ece6; --muted: #9aa79f;
  --line: #2a322a; --green: #4f9e73; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(var(--safe-b));
}
body.has-nav { padding-bottom: calc(72px + var(--safe-b)); }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 19px; letter-spacing: -.01em; flex: 1; }
.back { font-size: 30px; line-height: 1; width: 40px; margin: -6px 0 -6px -8px; color: var(--green); }
.theme-toggle { flex: none; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.theme-toggle svg { width: 20px; height: 20px; }
.datenav input[type=date] {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 8px 10px; min-height: 40px;
}
.wrap { padding: 16px; max-width: 640px; margin: 0 auto; }

/* ---- stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 16px 12px;
  box-shadow: var(--shadow); text-align: center; position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; }
.s-onsite::before { background: var(--green); }
.s-in::before { background: var(--blue); }
.s-out::before { background: var(--amber); }
.stat-num { font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.stat-label { font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cap { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }

/* ---- sections ---- */
.sec { display: flex; align-items: center; gap: 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; }
.sec span { background: var(--line); color: var(--ink); border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 2px 2px; }

/* ---- row cards ---- */
.rowlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rowcard {
  display: flex; align-items: stretch; gap: 10px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.rowcard-main { flex: 1; padding: 12px 14px; min-width: 0; }
.rowcard-name { font-weight: 700; font-size: 16px; }
.rowcard-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.rowcard-dates { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.rowcard-act { display: flex; }
.rowcard-act button {
  border: 0; height: 100%; min-height: var(--tap); padding: 0 16px; font-weight: 700; font-size: 14px; cursor: pointer;
}
.btn-in { background: var(--blue); color: #fff; }
.btn-out { background: var(--amber); color: #fff; }

/* ---- search / chips ---- */
.searchbar input {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 14px; min-height: var(--tap);
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; -ms-overflow-style: none; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.chip.on { background: var(--green); color: var(--green-ink); border-color: var(--green); }

/* ---- form ---- */
.bform { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 13px 14px; min-height: var(--tap);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* stepper */
.stepper-ctl { display: flex; align-items: center; border: 1px solid var(--line); background: var(--card); border-radius: 12px; overflow: hidden; }
.stepper-ctl button { width: 52px; min-height: var(--tap); border: 0; background: transparent; font-size: 24px; font-weight: 600; color: var(--green); cursor: pointer; }
.stepper-ctl button:active { background: var(--line); }
.stepper-ctl input { flex: 1; text-align: center; border: 0; min-height: var(--tap); padding: 0; background: transparent; font-weight: 700; font-size: 18px; }
.stepper-ctl input:focus { outline: none; }

/* pick chips (site type / payment) */
.picks { display: flex; flex-wrap: wrap; gap: 8px; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick span {
  display: inline-block; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 10px 15px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: var(--tap);
  display: inline-flex; align-items: center;
}
.pick input:checked + span { background: var(--green); color: var(--green-ink); border-color: var(--green); }
.pick input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 30%, transparent); }

.depart { margin: -6px 0 0; font-size: 13px; color: var(--green); font-weight: 600; }

.pricebox { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; background: color-mix(in srgb, var(--green) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--green) 25%, var(--line)); border-radius: 14px; padding: 14px 16px; }
.pricebox-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.pricebox-amount { font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--green); margin-left: auto; }
.pricebox-calc { flex-basis: 100%; font-size: 12.5px; color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.archive-link { font-size: 14px; font-weight: 600; color: var(--muted); }
.btn-danger[disabled] { opacity: .45; }
.editflags { display: flex; gap: 8px; }
.tag { border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.tag.in { background: color-mix(in srgb, var(--blue) 16%, transparent); color: var(--blue); }
.tag.out { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }

.status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.tag.on { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.btn-line { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 12px; min-height: 44px; padding: 0 18px; font-weight: 700; cursor: pointer; }

.danger { margin-top: 18px; }
.btn-danger { width: 100%; background: transparent; color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 40%, var(--line)); border-radius: 12px; min-height: var(--tap); font-weight: 700; cursor: pointer; }

/* ---- sticky action bar ---- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.actionbar .btn-primary { max-width: 640px; margin: 0 auto; display: block; }
body:has(.actionbar) .wrap { padding-bottom: 96px; }
.btn-primary {
  width: 100%; background: var(--green); color: var(--green-ink); border: 0;
  border-radius: 14px; min-height: 54px; font-weight: 800; font-size: 17px; cursor: pointer;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--green) 30%, transparent);
}
.btn-primary:active { transform: translateY(1px); }

/* ---- FAB ---- */
.fab {
  position: fixed; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; background: var(--green); color: #fff;
  font-size: 34px; font-weight: 300; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--green) 40%, transparent);
}

/* ---- bottom tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 0 8px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar a.on { color: var(--green); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.add svg { stroke-width: 2.4; }

/* ---- QR / book online ---- */
.qr-wrap { display: flex; flex-direction: column; align-items: center; }
.qr-card { background: #fff; color: #111; border-radius: 22px; box-shadow: var(--shadow); padding: 28px 24px; text-align: center; width: 100%; max-width: 380px; }
.qr-title { font-size: 22px; margin: 0 0 4px; color: #111; }
.qr-sub { color: #555; margin: 0 0 20px; font-size: 14px; }
.qr-img { width: 100%; max-width: 320px; height: auto; display: block; margin: 0 auto; }
.qr-url { display: inline-block; margin-top: 18px; font-size: 14px; font-weight: 600; color: var(--green); word-break: break-all; }
.qr-hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 18px; max-width: 380px; }

/* ---- login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 34px 26px; text-align: center; }
.login-toggle { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; }
.login-logo { font-size: 42px; }
.login-card h1 { font-size: 22px; margin: 10px 0 2px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.login-card input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 14px; min-height: var(--tap); margin-bottom: 14px; text-align: center; }
.login-err { color: var(--red); font-size: 14px; margin: -4px 0 12px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 560px) { .stat-num { font-size: 38px; } }
