/* Fit Checklist - mobile-first */
:root {
  --bg: #fff7ed;
  --card: #ffffff;
  --ink: #1c1917;
  --muted: #6b6560;
  --line: #e7e0da;
  --primary: #c2410c;
  --primary-ink: #ffffff;
  --primary-soft: #ffedd5;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 4px 14px rgba(60, 30, 10, .06);
  --radius: 16px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181210;
    --card: #241c18;
    --ink: #faf5f0;
    --muted: #b3aaa2;
    --line: #3b312a;
    --primary: #fb923c;
    --primary-ink: #1c0f05;
    --primary-soft: #3a2415;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #facc15;
    --warn-soft: #3a2f0d;
    --bad: #f87171;
    --bad-soft: #3d1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', 'Noto Sans Thai', sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
body.no-nav { padding-bottom: 24px; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .7em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.hidden { display: none !important; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary); color: var(--primary-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: inherit; }
.topbar .who { font-size: .85rem; opacity: .95; }
.container { max-width: 640px; margin: 0 auto; padding: 16px; }
.container.wide { max-width: 900px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; font-size: .95rem; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .75rem; font-weight: 600;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav svg { width: 24px; height: 24px; }
svg.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }

.subnav { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 12px; margin: 0 -4px; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  flex: none; padding: 8px 14px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); color: var(--ink); font-size: .95rem; font-weight: 600;
}
.subnav a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* Cards & lists */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
details.card > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '+'; font-size: 1.4rem; color: var(--primary); line-height: 1; }
details.card[open] > summary::after { content: '\2212'; }
details.card[open] > summary { margin-bottom: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  background: var(--primary-soft); color: var(--primary);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.grey { background: var(--line); color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; color: var(--primary); }
.stat span { font-size: .78rem; color: var(--muted); }

.progress { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s ease; }
.progress-label { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
.progress-label b { color: var(--ink); }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inline { display: inline; margin: 0; }

label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: 3px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; font-size: 16px;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-weight: 600; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--bad-soft); color: var(--bad); }

/* Checklist */
.tasks { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 72px; padding: 12px 16px; border-radius: 16px;
  background: var(--card); border: 2px solid var(--line); color: var(--ink); font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.task:active { transform: scale(.985); }
.task .box {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--muted);
  display: flex; align-items: center; justify-content: center; color: transparent; transition: all .15s;
}
.task .box svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.task .body { flex: 1; min-width: 0; }
.task .name { display: block; font-size: 1.15rem; font-weight: 700; }
.task .target { display: block; color: var(--muted); font-size: 1rem; }
.task.done { background: var(--ok-soft); border-color: var(--ok); }
.task.done .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.done .name { text-decoration: line-through; text-decoration-thickness: 2px; opacity: .8; }
.task.readonly { cursor: default; }
.task.readonly:active { transform: none; }
.task.locked { opacity: .6; }
.day-banner { display: none; padding: 12px; border-radius: 12px; background: var(--ok-soft); color: var(--ok); font-weight: 700; text-align: center; margin-top: 12px; }
.day-complete .day-banner { display: block; }
.rest-day { text-align: center; padding: 18px 8px; color: var(--muted); }

/* Day grid */
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.day {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 58px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  color: var(--ink); font-weight: 700; line-height: 1.15;
}
.day small { font-size: .7rem; font-weight: 600; opacity: .85; }
.day.done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.day.partial { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.day.missed { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.day.future { color: var(--muted); }
.day.rest { border-style: dashed; color: var(--muted); background: transparent; }
.day.is-today { box-shadow: 0 0 0 3px var(--primary); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .8rem; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 4px; vertical-align: -1px; border: 2px solid; }
.legend .l-done { background: var(--ok-soft); border-color: var(--ok); }
.legend .l-partial { background: var(--warn-soft); border-color: var(--warn); }
.legend .l-missed { background: var(--bad-soft); border-color: var(--bad); }
.legend .l-rest { border-style: dashed; border-color: var(--muted); }

.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.daynav h1 { margin: 0; text-align: center; font-size: 1.3rem; }
.daynav a, .daynav span.ph { min-width: 46px; min-height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.daynav span.ph { visibility: hidden; }

/* Admin day picker */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 8px 0; }
.pick {
  min-height: 44px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer;
}
.pick[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.quick .btn { min-height: 36px; padding: 4px 12px; font-size: .85rem; }
.range { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .9rem; }
.range input { width: 70px; min-height: 36px; padding: 4px 8px; }
.sel-count { font-size: .9rem; color: var(--muted); }

.userpick { display: grid; gap: 4px; }

/* Table-ish for admin dashboard */
.pcard { display: block; color: inherit; }
.pcard .title { font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: #1c1917; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 50; font-weight: 600;
  max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.logo { width: 72px; height: 72px; border-radius: 20px; display: block; margin: 0 auto 12px; }

@media (min-width: 760px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .bottom-nav { max-width: 640px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--line); }
}
@media print { .bottom-nav, .topbar { display: none; } }
