:root {
  --bg: #f4f5f7; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-text: #fff; --ok: #15803d; --warn: #b45309; --bad: #b91c1c; --chip: #eef2ff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #181b22; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f3a; --accent: #3b82f6; --chip: #1e2537;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .row (flex) must not override the hidden attribute */
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 600; }
nav a.on { color: var(--accent); background: var(--chip); }
main { max-width: 1180px; margin: 0 auto; padding: 16px; padding-bottom: 64px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px; }
button:disabled { opacity: .55; cursor: default; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--chip); }
.badge.online, .badge.taken { color: var(--ok); } .badge.offline, .badge.pending { color: var(--warn); } .badge.lost, .badge.missed, .badge.never { color: var(--bad); }
.cap-card { text-decoration: none; color: inherit; display: block; }
.cap-card:hover { border-color: var(--accent); }
.big { font-size: 28px; font-weight: 800; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.kpi .big.ok { color: var(--ok); } .kpi .big.warn { color: var(--warn); } .kpi .big.bad { color: var(--bad); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { margin: 0; font-weight: 600; font-size: 12px; }
.days input { display: none; }
.days span { display: inline-block; width: 34px; text-align: center; padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.days input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.step { display: grid; grid-template-columns: 1fr 110px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.battery { display: inline-flex; align-items: center; gap: 6px; }
.battery i { display: inline-block; width: 26px; height: 12px; border: 2px solid currentColor; border-radius: 3px; position: relative; }
.battery i b { position: absolute; left: 1px; top: 1px; bottom: 1px; background: currentColor; border-radius: 1px; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }
.chart { width: 100%; height: 160px; }
.chart rect { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }
.steps-help { font-size: 13px; color: var(--muted); }
ol.setup li { margin-bottom: 8px; }
@media (max-width: 520px) { .brand span { font-size: 14px; } main { padding: 12px; } .step { grid-template-columns: 1fr 90px 36px; } }
.card.compact { padding: 12px 14px; }
.card.compact h2 { font-size: 15px; margin: 4px 0 6px; }
.opts { display: grid; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.opt { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; margin: 0; padding: 7px 10px; font-weight: 500; font-size: 14px; border-top: 1px solid var(--line); cursor: pointer; }
.opt:first-child { border-top: 0; }
.opt.off { opacity: .6; }
.opt input[type=checkbox] { width: 18px; height: 18px; margin: 0; }
.opt .after { color: var(--muted); font-size: 13px; white-space: nowrap; }
input.inl { padding: 4px 6px; font-size: 13px; display: inline-block; width: auto; }
.opt:has(input[type=checkbox]:not(:checked)) .after { opacity: .45; }
@media (max-width: 520px) { .opt { gap: 6px; padding: 7px 8px; font-size: 13.5px; } .opt .after { font-size: 12.5px; } .opt input.inl { padding: 3px 4px; } }

/* pairing code */
.pair { text-align: center; }
.paircode { font: 800 40px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 4px; margin: 6px 0; user-select: all; }
.paircode.dead { color: var(--muted); text-decoration: line-through; }
details summary { cursor: pointer; color: var(--accent); margin: 8px 0; }

/* desktop: two columns from 960 px; phones and narrow windows keep one */
.cols { display: grid; gap: 14px; align-items: start; }
.cols > .card, .cols > form.card, .cols > .kpis { margin-bottom: 0; }
.cols.tight { gap: 0 18px; }
#tab.cols { margin-bottom: 14px; }
@media (min-width: 960px) {
  .cols { grid-template-columns: 1fr 1fr; }
  .cols.side { grid-template-columns: minmax(300px, 380px) 1fr; }
  .cols > .wide { grid-column: 1 / -1; }
  .sticky { position: sticky; top: 76px; }
  .paircode { font-size: 52px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
.cols.tight > div { min-width: 0; }
@media (max-width: 959px) { .cols.tight { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .opt.wrap { grid-template-columns: 22px 1fr; } .opt.wrap .after { grid-column: 2; } }

/* sign in */
.card.login { max-width: 440px; margin: 30px auto; }
.big-btn { width: 100%; padding: 12px 14px; font-size: 16px; }
/* in-page "are you sure?" (ask() in app.js) */
.ask-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
.ask { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
.ask p { margin: 0 0 16px; }
button.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; }
.waitcap { text-align: center; }
.waitcap .row { justify-content: center !important; }
.spin { width: 34px; height: 34px; margin: 0 auto 12px; border: 3px solid var(--line); border-top-color: var(--accent, #2b7); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }
.done-tick { font-size: 34px; line-height: 1; margin: 0 0 8px; color: var(--ok); }

/* the public demo (demo.js): a bar under the header with the visitor's virtual cap, and the start page */
#demobar { position: sticky; top: 49px; z-index: 4; background: var(--card); border-bottom: 2px solid #8b5cf6; box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.db-strip { display: flex; align-items: center; gap: 10px; padding: 6px 16px; font-size: 13px; max-width: 1180px; margin: 0 auto; }
.db-tag { background: #8b5cf6; color: #fff; font-weight: 800; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; }
.db-say { flex: 1; color: var(--muted); }
.db-body { display: flex; gap: 14px; align-items: center; padding: 4px 16px 10px; max-width: 1180px; margin: 0 auto; }
.db-main { flex: 1; min-width: 0; }
.db-status { font-size: 14px; margin: 0 0 6px; } .db-late { color: var(--bad); }
.db-btns { display: flex; flex-wrap: wrap; gap: 6px; } .db-btns button { padding: 7px 11px; font-size: 14px; }
.db-log { margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  #demobar { top: 0; position: relative; }
  .db-body { flex-direction: column; align-items: stretch; } .db-bottlebtn { margin: 0 auto; }
  .db-btns button { flex: 1 1 45%; }
}
.demo-start { max-width: 560px; margin: 24px auto; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.demo-start .lead { font-size: 16px; }
.demo-start .demo-points { text-align: left; display: inline-block; margin: 0 0 12px; padding-left: 20px; }
.demo-start .demo-points li { margin: 4px 0; }
/* While the "tap the cap" overlay is up, the demo's cap stays above it and its Tap button pulses: it is the only way to
   tap a virtual cap. (.ask-back is z-index 30.) */
body.demo #demobar { z-index: 31; }
body.demo:has(#waitcap) #demobar .db-tapbtn, body.demo:has(.wiz-step[data-step="done"]) #demobar .db-tapbtn { border-color: var(--accent); animation: db-pulse 1.4s ease-in-out infinite; }
/* The bar's cap is the bottle itself (welcome.css draws it). While a tap is wanted (the overlay, or the guide's last step)
   a finger presses its cap with a click ring, like the bottle in the overlay; clicking the bottle taps the cap. */
.db-bottlebtn { padding: 0; border: 0; background: none; border-radius: 12px; flex: none; cursor: pointer; }
#demobar .ill.bottle.db-bottle { width: 72px; height: 78px; }   /* not the guide's large size */
.db-bottlebtn:focus-visible { outline: 2px solid var(--accent); }
.db-bottle .finger, .db-bottle .tapring { display: none; }
body.demo:has(#waitcap) .db-bottle .finger, body.demo:has(.wiz-step[data-step="done"]) .db-bottle .finger,
body.demo:has(#waitcap) .db-bottle .tapring, body.demo:has(.wiz-step[data-step="done"]) .db-bottle .tapring { display: inline; }
body.demo:has(#waitcap) .db-capgrp, body.demo:has(.wiz-step[data-step="done"]) .db-capgrp { animation: cap-press 2s infinite; }
.wc-bottle { display: flex; justify-content: center; margin: 0 0 6px; }
@media (prefers-reduced-motion: reduce) { body.demo:has(#waitcap) #demobar .db-tapbtn, body.demo:has(.wiz-step[data-step="done"]) #demobar .db-tapbtn { animation: none; outline: 3px solid var(--accent); } }
  .db-tapbtn::after { animation: none !important; } }
@media (max-width: 640px) { body.demo:has(#waitcap) #demobar { position: sticky; top: 0; } }

/* demo, before the cap is paired: the bar shows the account's pairing code, big, and the page is the cap's setup page */
.db-pair { flex: 1; text-align: center; padding: 2px 0 4px; }
.db-pair-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.db-code { font: 800 46px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 6px; color: var(--text); user-select: all; }
.db-pair-sub { font-size: 13px; color: var(--muted); }
#demobar.unpaired .db-code { animation: db-glow 2s ease-in-out infinite; }
@keyframes db-glow { 0%, 100% { text-shadow: none; } 50% { text-shadow: 0 0 18px rgba(139, 92, 246, .8); } }
@media (min-width: 960px) { .db-code { font-size: 56px; } }
@media (max-width: 640px) { .db-code { font-size: 36px; letter-spacing: 4px; } }
.demo-pair { max-width: 460px; margin: 6px auto 24px; }
.dp-intro { font-size: 15px; margin: 0 0 12px; }
.dp-portal { background: #fff; color: #1f2937; border-radius: 14px; padding: 18px 18px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.dp-portal label { color: #1f2937; font-size: 14px; margin-top: 14px; }
.dp-portal input, .dp-portal select { background: #fff; color: #1f2937; border-color: #d1d5db; }
.dp-portal input:disabled, .dp-portal select:disabled { background: #f3f4f6; color: #6b7280; }
.dp-portal small { color: #6b7280; display: block; margin-top: 4px; font-size: 12px; }
.dp-head { font-size: 20px; font-weight: 800; }
.dp-msg { background: #fef3c7; color: #92400e; padding: 10px; border-radius: 8px; margin-top: 10px; font-size: 14px; } .dp-msg.ok { background: #dcfce7; color: #166534; }
.dp-code { font: 800 28px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; letter-spacing: 4px; text-transform: uppercase; text-align: center; border: 2px solid #8b5cf6 !important; }
.dp-point { color: #6d28d9; font-weight: 700; font-size: 14px; margin: 2px 0 6px; }
.dp-arrow { display: inline-block; font-size: 22px; line-height: 1; vertical-align: -2px; animation: dp-bounce 1.1s ease-in-out infinite; }
@keyframes dp-bounce { 0%, 100% { transform: translateY(2px); } 50% { transform: translateY(-6px); } }
.dp-connect { width: 100%; margin-top: 16px; padding: 12px; font-size: 16px; }
.dp-forme { text-align: center; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.dp-forme .link { font-size: 15px; }
@media (prefers-reduced-motion: reduce) { .dp-arrow, #demobar.unpaired .db-code { animation: none; } }

/* the demo bar: what the last tap said, kept up for 8 s */
.db-tapres { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; padding: 6px 12px; border-radius: 99px; font-size: 14px; animation: dm-in .2s ease-out; }
.db-tapres i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.db-tapres.green { background: rgba(34, 197, 94, .15); color: var(--ok); } .db-tapres.green i { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.db-tapres.red { background: rgba(239, 68, 68, .15); color: var(--bad); } .db-tapres.red i { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
@keyframes dm-in { from { opacity: 0; transform: translateY(-4px); } }

/* Short screens (a phone on its side, a small laptop window): the demo bar and the guide's buttons scroll with the page
   instead of sticking, so the page itself keeps room. The guide's progress line sits under the demo bar, not behind it. */
body.demo .wiz-top { position: static; }
@media (max-height: 640px) { #demobar { position: relative; top: auto; } .wiz .wiz-foot { position: static; } }
