/* =====================================================================
   Baan-Care styles. Design notes: docs/design.md
   Change colors/sizes in the tokens below; components only use tokens.
   ===================================================================== */
:root {
  /* surfaces & text */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eeece7;
  --surface-press: #f1efea;
  --text: #1c1b19;
  --muted: #63615c;
  --line: #e2dfd8;

  /* brand (blue, so it never gets confused with the status colors) */
  --primary: #2f5d8a;
  --on-primary: #ffffff;
  --primary-soft: #e4edf6;

  /* status: red = overdue/out, amber = soon/low, green = fine */
  --red: #c42f2f;
  --red-bg: #fbe8e6;
  --amber: #8a5a00;
  --amber-line: #e2a000;
  --amber-bg: #fcf0d6;
  --green: #22703f;
  --green-line: #2f9a5a;
  --green-bg: #e2f2e8;
  --grey: #b8b5ad;

  /* scale (4/8 rhythm) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --icon: 22px;
  --tap: 44px;
  --tabbar-h: 58px;

  /* motion */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --t-fast: 120ms;
  --t-med: 240ms;

  --shadow-card: 0 1px 2px rgb(28 27 25 / 6%), 0 0 0 1px rgb(28 27 25 / 3%);
  --scrim: rgb(20 20 18 / 45%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1d1d1c;
    --surface-2: #2a2a28;
    --surface-press: #262624;
    --text: #f2f1ec;
    --muted: #a9a79f;
    --line: #353430;

    --primary: #8db7e6;
    --on-primary: #0d1a28;
    --primary-soft: #1e2a38;

    --red: #ff8077;
    --red-bg: #3b1c1a;
    --amber: #f3bb45;
    --amber-line: #f3bb45;
    --amber-bg: #382c13;
    --green: #6fd09c;
    --green-line: #4fb97f;
    --green-bg: #15301f;
    --grey: #5d5b55;

    --shadow-card: 0 0 0 1px rgb(255 255 255 / 4%);
    --scrim: rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", "Leelawadee UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .35; }
svg { display: block; flex: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--space-4) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px);
}
@media (min-width: 700px) { .app { padding-inline: var(--space-5); } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: calc(env(safe-area-inset-top) + 14px) 0 var(--space-2);
  background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.25; }
.add-btn {
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
  transition: transform var(--t-fast) var(--ease-out), filter var(--t-fast);
}
.add-btn svg { width: var(--icon); height: var(--icon); }
.add-btn:active { transform: scale(.94); filter: brightness(.92); }
.add-btn[hidden] { display: none; }
.text-btn {
  margin-left: auto; min-height: var(--tap); padding: 0 var(--space-2);
  border: 0; background: none; color: var(--primary); font-weight: 600; font-size: 17px;
}
.text-btn[aria-pressed="true"] { font-weight: 700; }
.text-btn[hidden] { display: none; }

/* ---------- summary pills + room chips ---------- */
.summary { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-1) 0 var(--space-3); }
.pill { font-size: 14px; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.soon { background: var(--amber-bg); color: var(--amber); }

.chips {
  display: flex; gap: var(--space-2);
  overflow-x: auto;
  margin: 0 calc(var(--space-4) * -1) var(--space-2);
  padding: 2px var(--space-4) 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
  padding: 0 14px; font-size: 14px; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }

/* ---------- งานบ้าน: summary hero ---------- */
.hero {
  --tone: var(--primary);
  --tone-bg: var(--primary-soft);
  display: flex; align-items: center; gap: var(--space-4);
  margin: var(--space-1) 0 var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--tone) 18%, transparent), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow-card);
  animation: rise-in var(--t-med) var(--ease-out);
}
.hero.tone-overdue { --tone: var(--red); --tone-bg: var(--red-bg); }
.hero.tone-soon { --tone: var(--amber-line); --tone-bg: var(--amber-bg); }
.hero.tone-ok { --tone: var(--green-line); --tone-bg: var(--green-bg); }
.hero-text { flex: 1; min-width: 0; }
.hero-date { margin: 0; font-size: 13px; color: var(--muted); }
.hero-title { margin: 2px 0; font-size: 22px; line-height: 1.3; font-weight: 700; }
.hero.tone-overdue .hero-title { color: var(--red); }
.hero-sub { margin: 0; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--space-3); }
.hero-chip {
  font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  color: var(--lv-text); background: var(--surface-2);
}
.hero-chip.lv-overdue { background: var(--red-bg); }
.hero-chip.lv-soon { background: var(--amber-bg); }
.hero-chip.lv-ok { background: var(--green-bg); }

.hero-ring {
  --p: 0;
  flex: none; width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--tone) calc(var(--p) * 1%), var(--surface-2) 0);
  position: relative;
}
.hero-ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--surface); }
.hero-ring > * { position: relative; }
.hero-ring span { font-size: 22px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-ring small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 1px; }
.hero-ring.empty { background: var(--tone-bg); color: var(--tone); }
.hero-ring.empty::before { display: none; }
.hero-ring.empty svg { width: 34px; height: 34px; }
@keyframes rise-in { from { transform: translateY(8px); opacity: 0; } }

/* task icon tile + cycle bar */
.task-icon {
  flex: none; width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.task-icon svg { width: 22px; height: 22px; }
.lv-overdue .task-icon { background: var(--red-bg); color: var(--red); }
.lv-soon .task-icon { background: var(--amber-bg); color: var(--amber); }
.lv-ok .task-icon { background: var(--green-bg); color: var(--green); }
.lv-none .task-icon { background: var(--primary-soft); color: var(--primary); }

.cycle { display: block; height: 4px; margin-top: 6px; border-radius: 2px; background: var(--surface-2); overflow: hidden; max-width: 160px; }
.cycle > span {
  display: block; height: 100%; width: calc(var(--p) * 100%);
  border-radius: inherit; background: var(--lv);
  transform-origin: left; animation: grow var(--t-med) var(--ease-out);
}
@keyframes grow { from { transform: scaleX(0); } }

/* ---------- sections ---------- */
.group + .group { margin-top: var(--space-2); }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  margin: var(--space-4) 0 var(--space-2);
}
.section-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- cards ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.card {
  --lv: transparent;
  --lv-text: var(--muted);
  position: relative;
  display: flex; align-items: center;
  min-height: 64px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--lv);
}
.card-main {
  flex: 1; min-width: 0; align-self: stretch;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-2) var(--space-3) var(--space-4);
  border: 0; background: none; text-align: left;
  transition: background var(--t-fast);
}
.card-main:active { background: var(--surface-press); }
.info { flex: 1; min-width: 0; }
.name, .meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name { font-weight: 600; line-height: 1.35; }
.meta { font-size: 13px; color: var(--muted); line-height: 1.4; }
.state { flex: none; text-align: right; max-width: 50%; }
.state-main, .state-sub { display: block; }
.state-main { font-size: 14px; font-weight: 600; color: var(--lv-text); }
.state-sub { font-size: 12px; color: var(--muted); }

.lv-overdue, .st-out { --lv: var(--red); --lv-text: var(--red); }
.lv-soon, .st-low { --lv: var(--amber-line); --lv-text: var(--amber); }
.lv-ok, .st-ok { --lv: var(--green-line); --lv-text: var(--green); }
.lv-none { --lv: var(--grey); --lv-text: var(--text); }
.lv-never, .st-unknown { --lv: var(--grey); --lv-text: var(--muted); }

.chevron { flex: none; color: var(--grey); margin-left: calc(var(--space-1) * -1); }
.chevron svg { width: 18px; height: 18px; }
@media (hover: hover) { .card-main:hover { background: var(--surface-press); } }
.card-main.static { cursor: default; }
.card-main.static:active { background: none; }

/* colored status line inside rows (stock + shopping) */
.st-out .level-text { color: var(--red); }
.st-low .level-text { color: var(--amber); }

/* broken bulb: red line + icon, and the "แจ้งว่าเสีย" button */
.lv-broken { --lv: var(--red); --lv-text: var(--red); }
.lv-broken .task-icon { background: var(--red-bg); color: var(--red); }
.status-badge.lv-broken { background: var(--red-bg); }
.btn.report-broken { background: var(--red-bg); color: var(--red); }

/* bulb number tile (bulb placed on its room plan) */
.task-icon.num { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* room plan: the room seen from above, door side at the bottom */
.plan {
  position: relative;
  width: 100%; max-width: 360px; aspect-ratio: 3 / 2;
  margin: 0 auto var(--space-3);
  background: var(--surface);
  border: 2px solid var(--muted);
  border-radius: 4px;
  box-shadow: var(--shadow-card);
}
.plan-door {
  position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%);
  width: 64px; padding-top: 2px;
  border-top: 2px solid var(--surface); /* gap in the wall = the doorway */
  background: var(--surface);
  font-size: 11px; line-height: 1; text-align: center; color: var(--muted);
  pointer-events: none;
}
.plan-dot {
  position: absolute; transform: translate(-50%, -50%);
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--primary);
  background: var(--primary-soft); color: var(--primary);
  font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
button.plan-dot::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; } /* 44px tap area */
button.plan-dot:active { transform: translate(-50%, -50%) scale(.92); }
.plan-dot.broken { border-color: var(--red); background: var(--red-bg); color: var(--red); }
.plan-dot.faded { opacity: .4; pointer-events: none; }
.plan-dot.mark { background: var(--primary); color: var(--on-primary); pointer-events: none; }
.plan-dot.mark svg { width: 18px; height: 18px; }
.plan-dot[hidden] { display: none; }
.plan.pick {
  cursor: crosshair; margin-bottom: 0; touch-action: manipulation;
  /* faint 9 × 6 grid: a tap lands in the middle of its cell (PLAN_COLS / PLAN_ROWS in app.js) */
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: calc(100% / 9) calc(100% / 6);
}
.sheet-body > .plan { max-width: 280px; }

/* "ใส่ในรายการซื้อ" line in the bulb sheet */
.btn.cart-line { display: flex; align-items: center; justify-content: center; gap: var(--space-2); }
.btn.cart-line svg { width: 20px; height: 20px; }

/* stock rows */
.stock .card-main { padding-right: var(--space-1); }
.cart-btn { color: var(--muted); }
.cart-btn[aria-pressed="true"] { color: var(--primary); }
.row-btn {
  flex: none; min-width: 96px; margin-right: var(--space-3);
  padding: 0 12px; font-size: 15px; border-radius: 999px;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.btn.use-btn { background: var(--primary-soft); color: var(--primary); }

.qty-field {
  display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.qty-field input {
  border: 0; min-width: 0; flex: 1; padding-inline: 0;
  text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
.qty-field input:focus { outline: none; }
.qty-field:focus-within { outline: 2px solid var(--primary); outline-offset: -1px; }

/* shopping rows */
.check {
  flex: none; width: 26px; height: 26px;
  border: 2px solid var(--grey); border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.check svg { width: 16px; height: 16px; }
.bought .check { background: var(--green-line); border-color: var(--green-line); }
.bought .name { color: var(--muted); text-decoration: line-through; font-weight: 400; }
.shop { --lv: transparent !important; }
.delete-btn { color: var(--red); margin-right: var(--space-1); }
.edit-hint { background: var(--primary-soft); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; }

/* ---------- buttons, forms, panels ---------- */
.btn {
  min-height: var(--tap);
  border: 0; border-radius: 12px;
  padding: 10px 16px;
  background: var(--surface-2);
  font-weight: 600;
  transition: filter var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.btn:active { filter: brightness(.94); transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.ghost { background: none; color: var(--text); }
.btn.danger { background: none; color: var(--red); }
.btn.danger-solid { background: var(--red); color: #fff; }
.btn.big {
  width: 100%; min-height: 56px; margin-bottom: var(--space-3);
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-size: 18px; border-radius: var(--radius);
}
.btn.big svg { width: 24px; height: 24px; }
.btn.big.done:disabled { opacity: 1; background: var(--green-bg); color: var(--green); }
.danger-zone {
  display: flex; justify-content: space-between; gap: var(--space-2);
  margin-top: var(--space-5); padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}
.btn.block { display: block; width: 100%; margin-top: var(--space-4); }
.icon-btn {
  flex: none; width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: none; color: var(--muted);
  display: grid; place-items: center;
  transition: background var(--t-fast);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.link-btn { min-height: var(--tap); border: 0; background: none; color: var(--primary); font-weight: 600; padding: 0 var(--space-1); }

input, select, textarea {
  width: 100%; min-height: var(--tap);
  font-size: 16px; /* 16px stops iPhone from zooming in on focus */
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
::placeholder { color: var(--muted); opacity: .8; }

.row { display: flex; gap: var(--space-2); align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.split { justify-content: space-between; margin-top: var(--space-2); }
.row > input, .row > select { flex: 1; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field > span { font-size: 14px; font-weight: 600; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 var(--space-3); }
.field .hint { margin: 0; }

.inline-add { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.inline-add input { flex: 1; min-width: 0; }

.panel { background: var(--surface); border-radius: var(--radius); padding: var(--space-3); box-shadow: var(--shadow-card); }
.panel-title { font-weight: 600; }
.log-form { display: flex; flex-direction: column; margin-top: var(--space-3); }
.log-form .field:last-of-type { margin-bottom: 0; }
.log-form .btn.block { margin-top: var(--space-3); }
.disclosure { margin-bottom: var(--space-3); padding: 0 var(--space-3); }
.disclosure summary {
  min-height: var(--tap); display: flex; align-items: center; gap: var(--space-2);
  cursor: pointer; font-weight: 600; color: var(--primary); list-style: none;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::after { content: "›"; margin-left: auto; font-size: 22px; color: var(--muted); transition: transform var(--t-fast); }
.disclosure[open] summary::after { transform: rotate(90deg); }
.disclosure[open] { padding-bottom: var(--space-3); }

.plain-list { list-style: none; margin: 0 0 var(--space-3); padding: 2px var(--space-3); }
.plain-list li { display: flex; align-items: center; gap: var(--space-2); padding: 6px 0; min-height: 48px; }
.plain-list li + li { border-top: 1px solid var(--line); }
.plain-list .meta { white-space: normal; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--muted); padding: 56px var(--space-4); }
.empty svg { width: 40px; height: 40px; margin-bottom: var(--space-3); color: var(--grey); }
.empty p { margin: 0; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: var(--space-1) !important; }

/* ---------- bottom sheet (details / forms) ---------- */
.sheet {
  width: 100%; max-width: min(560px, 100%);
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0 0 env(safe-area-inset-bottom);
  border: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--bg); color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-in var(--t-med) var(--ease-out); }
.sheet::backdrop { background: var(--scrim); }
.sheet[open]::backdrop { animation: fade-in var(--t-med) ease-out; }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: var(--radius-lg); }
}
@keyframes sheet-in { from { transform: translateY(32px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: flex-start; gap: var(--space-2);
  padding: 22px var(--space-2) var(--space-2) var(--space-4);
  background: var(--bg);
}
/* grabber: purely visual cue that this is a sheet */
.sheet-head::before {
  content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 5px; border-radius: 3px; background: var(--line);
}
@media (min-width: 700px) { .sheet-head::before { display: none; } }
.sheet-head h2 { margin: 6px 0 0; font-size: 21px; line-height: 1.3; }
.sheet-head .meta { white-space: normal; margin: 2px 0 0; }
.sheet-body { padding: 0 var(--space-4) var(--space-5); }

.status-badge {
  display: inline-block; margin: var(--space-1) 0 var(--space-3);
  padding: 4px 12px; border-radius: 999px;
  font-weight: 700; font-size: 15px;
  color: var(--lv-text); background: var(--surface-2);
}
.status-badge.lv-overdue { background: var(--red-bg); }
.status-badge.lv-soon { background: var(--amber-bg); }
.status-badge.lv-ok { background: var(--green-bg); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); margin-bottom: var(--space-3); }
.stat { background: var(--surface); border-radius: 12px; padding: 10px; box-shadow: var(--shadow-card); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-weight: 600; font-size: 15px; }
.note { background: var(--surface); border-radius: 12px; padding: 10px 12px; margin: 0 0 var(--space-3); white-space: pre-wrap; box-shadow: var(--shadow-card); }

/* ---------- confirm dialog ---------- */
.confirm {
  width: calc(100% - 32px); max-width: 360px;
  padding: 0; border: 0; border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 25%);
}
.confirm[open] { animation: pop-in var(--t-med) var(--ease-out); }
.confirm::backdrop { background: var(--scrim); }
.confirm-body { padding: var(--space-5) var(--space-4) var(--space-4); text-align: center; }
.confirm-body h2 { margin: 0 0 var(--space-2); font-size: 19px; line-height: 1.35; }
.confirm-body p { margin: 0; color: var(--muted); font-size: 15px; }
.confirm-actions { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-5); }
.confirm-actions .btn { width: 100%; min-height: 48px; }
@keyframes pop-in { from { transform: scale(.94); opacity: 0; } }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 140px; height: var(--tabbar-h);
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 500;
  transition: color var(--t-fast);
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--primary); font-weight: 700; }
/* red count on the หลอดไฟ tab = bulbs reported broken */
.tab-icon { position: relative; display: block; }
.tab-badge {
  position: absolute; top: -5px; left: 15px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; border: 2px solid var(--surface);
  font-size: 11px; font-weight: 700; line-height: 14px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.tab-badge[hidden] { display: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px;
  padding: 6px 8px 6px 16px; min-height: 48px;
  border-radius: 14px;
  background: var(--text); color: var(--bg);
  font-size: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 22%);
  animation: toast-in var(--t-med) var(--ease-out);
}
.toast[hidden] { display: none; }
.toast button { min-height: 36px; border: 0; border-radius: 8px; background: none; color: inherit; font-weight: 700; padding: 0 10px; text-decoration: underline; }
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }

/* ---------- login (online mode) ---------- */
.signed-out .tabbar { display: none; }
.login { max-width: 360px; margin: 32px auto 0; text-align: center; }
.login h2 { margin: 0 0 4px; font-size: 22px; }
.login .field { margin: var(--space-4) 0 0; text-align: left; }
.login-icon {
  width: 64px; height: 64px; margin: 0 auto var(--space-3); border-radius: 18px;
  display: grid; place-items: center; background: var(--primary-soft); color: var(--primary);
}
.login-icon svg { width: 32px; height: 32px; }
.login-error { margin: var(--space-3) 0 0; color: var(--red); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::backdrop {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
