/* Cabin Camera: modern, mobile-first, no external assets. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --ink: #17201b;
  --ink-2: #5d6862;
  --line: #e3e0d8;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe7;
  --on: #1f8a50;
  --on-soft: #e3f4ea;
  --off: #b26a00;
  --off-soft: #fbefd9;
  --warn-ink: #8a5200; /* warning text: 5.6:1 on --off-soft (--off is too light for text) */
  --bad: #c62828;
  --bad-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 8px 24px rgba(20, 30, 25, .06);
  --radius: 20px;
  --radius-sm: 14px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a201d;
    --surface-2: #232a26;
    --ink: #edf1ee;
    --ink-2: #9aa59f;
    --line: #2c3530;
    --accent: #7fcf9f;
    --accent-ink: #0d1a13;
    --accent-soft: #1d3326;
    --on: #6fd398;
    --on-soft: #17301f;
    --off: #f3b558;
    --off-soft: #36280f;
    --warn-ink: #f3b558;
    --bad: #ff8a80;
    --bad-soft: #3a1715;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--ink-2); }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) max(20px, calc((100% - 560px) / 2 + 16px)) 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand svg { color: var(--accent); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.menu {
  margin: 0; inset: auto max(16px, calc((100% - 560px) / 2 + 16px)) auto auto; top: 60px; position: fixed;
  min-width: 220px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.menu-who { padding: 8px 10px; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.menu a { display: block; padding: 10px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.menu a:hover { background: var(--surface-2); }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(120px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }

/* ---------- Dock: the main button, pinned to the bottom ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px max(16px, calc((100% - 560px) / 2 + 16px)) max(14px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}

/* ---------- Status card ---------- */
.status {
  display: flex; gap: 16px; align-items: flex-start;
  padding: 22px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transition: background .3s var(--ease), border-color .3s var(--ease);
}
.status-icon {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--ink-2);
}
.status-icon svg { width: 28px; height: 28px; display: none; }
.status[data-state="on"] { background: var(--on-soft); border-color: color-mix(in srgb, var(--on) 30%, transparent); }
.status[data-state="on"] .status-icon { background: var(--on); color: #fff; }
.status[data-state="on"] .i-on { display: block; }
.status[data-state="off"] { background: var(--off-soft); border-color: color-mix(in srgb, var(--off) 30%, transparent); }
.status[data-state="off"] .status-icon { background: var(--off); color: #fff; }
.status[data-state="off"] .i-off { display: block; }
.status[data-state="bad"] { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.status[data-state="bad"] .status-icon { background: var(--bad); color: #fff; }
.status[data-state="bad"] .i-bad { display: block; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.status:not([data-state="loading"]) .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-text { min-width: 0; display: grid; gap: 4px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.status[data-state="on"] .eyebrow { color: var(--on); }
.status[data-state="off"] .eyebrow { color: var(--off); }
.status[data-state="bad"] .eyebrow { color: var(--bad); }
.status h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; font-weight: 750; }
.sub { font-size: 16px; }
.pill {
  justify-self: start; margin-top: 6px; padding: 6px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 70%, transparent); font-weight: 650; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.meta { margin-top: 4px; color: var(--ink-2); font-size: 13px; }
.meta:empty, .sub:empty { display: none; }

.alert {
  padding: 14px 16px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); font-weight: 650;
}
.queued {
  display: grid; gap: 4px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 15px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.queued[hidden] { display: none; }
.queued p { margin: 0; }
.queued .btn { min-height: 40px; justify-self: start; padding: 6px 0; }
.queued.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink-2); font-size: 14px; }

/* ---------- Buttons & rows ---------- */
.actions { display: grid; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 12px 20px; border-radius: 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 650;
  transition: transform .12s var(--ease), filter .2s, background .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--bad); color: var(--accent-ink); border-color: transparent; } /* white on light red fails contrast in dark mode */
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.xl { min-height: 64px; font-size: 18px; border-radius: 18px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.busy { cursor: progress; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px;
  background: none; border: 0; border-top: 1px solid var(--line); text-align: left; cursor: pointer;
}
.row:first-child { border-top: 0; }
.row[hidden] { display: none; }
.row:hover { background: var(--surface-2); }
.row:active { background: var(--line); }
.row:disabled { opacity: .5; cursor: progress; }
.row-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.row-icon svg { width: 20px; height: 20px; }
.row-icon.on { background: var(--on-soft); color: var(--on); }
.row-icon.off { background: var(--off-soft); color: var(--off); }
.row-icon.bad { background: var(--bad-soft); color: var(--bad); }
.row-text { flex: 1; display: grid; min-width: 0; }
.row-text strong { font-weight: 650; }
.row-text small { color: var(--ink-2); font-size: 14px; }
.row.danger strong { color: var(--bad); }
.chev { color: var(--ink-2); font-size: 22px; line-height: 1; }

/* ---------- Card / timeline ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 15px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-2); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 20px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after, .timeline li.muted::before, .timeline li.muted::after { display: none; }
.timeline li.muted { padding-left: 0; }
.timeline li.on::before { background: var(--on); }
.timeline li.off::before { background: var(--off); }
.timeline li.fail::before { background: var(--bad); }
.timeline time { display: block; color: var(--ink-2); font-size: 13px; }
.timeline .err { color: var(--bad); font-weight: 600; }

/* ---------- Sheet (dialog) ---------- */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; padding: 0; border: 0;
  margin: auto auto 0; border-radius: 24px 24px 0 0;
  background: var(--surface); color: var(--ink); box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
  overflow: hidden;
  transition: transform .32s var(--ease), opacity .2s, overlay .32s allow-discrete, display .32s allow-discrete;
  transform: translateY(0);
}
dialog.sheet:not([open]) { transform: translateY(100%); opacity: 0; }
@starting-style { dialog.sheet[open] { transform: translateY(100%); opacity: 0; } }
dialog.sheet::backdrop { background: rgba(10, 14, 12, .45); backdrop-filter: blur(2px); }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 24px; }
  dialog.sheet:not([open]) { transform: translateY(24px) scale(.98); }
  @starting-style { dialog.sheet[open] { transform: translateY(24px) scale(.98); opacity: 0; } }
}
dialog.sheet form { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 8px; }
.sheet-head h2 { font-size: 20px; letter-spacing: -.01em; }
.grabber { position: absolute; top: 8px; left: 50%; translate: -50% 0; width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
@media (min-width: 640px) { .grabber { display: none; } }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.sheet-body { padding: 8px 20px 16px; overflow-y: auto; display: grid; gap: 22px; overscroll-behavior: contain; }
.sheet-foot { padding: 14px 20px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: grid; gap: 12px; background: var(--surface); }
.sheet-foot.stack { border-top: 0; }
dialog.compact { max-width: 420px; }
dialog.compact .sheet-body { padding-top: 26px; gap: 8px; }
dialog.compact h2 { font-size: 20px; }
.dlg-body { color: var(--ink-2); }

.field { display: grid; gap: 12px; }
.field h3 { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 14px; margin-top: -4px; }

/* Segmented control (radio inputs) */
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { text-align: center; padding: 10px; border-radius: 11px; font-weight: 650; cursor: pointer; color: var(--ink-2); transition: background .2s, color .2s; }
.segmented input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 600; }
.chip:hover { background: var(--surface-2); }

/* Date/time picker */
.picker { display: grid; gap: 12px; }
.picker[hidden] { display: none; }
.days {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  margin: 0 -20px; padding: 2px 20px 6px; scroll-padding: 0 20px;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: none; scroll-snap-align: start; width: 64px; padding: 10px 0 9px; border-radius: 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); display: grid; gap: 1px; justify-items: center;
  transition: background .15s, border-color .15s, color .15s;
}
.day .dow { font-size: 12px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; }
.day .dnum { font-size: 22px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.day .mon { font-size: 12px; color: var(--ink-2); }
.day[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.day[aria-selected="true"] .dow, .day[aria-selected="true"] .mon { color: inherit; opacity: .85; }
/* Hour grid 1-12, quarter-hour minutes, then a big AM/PM toggle under them (issues #17, #18) */
.hours { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.hour {
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 18px; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
}
.hour[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg-btn {
  min-height: 44px; border: 0; border-radius: 11px; background: transparent; color: var(--ink-2);
  font-weight: 700; font-size: 17px; cursor: pointer; font-variant-numeric: tabular-nums; transition: background .2s, color .2s;
}
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.ampm .seg-btn { min-height: 54px; font-size: 20px; letter-spacing: .04em; }
.ampm .seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.readout { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 15px; }
.readout strong { font-size: 17px; }
.readout.warn { background: var(--off-soft); color: var(--warn-ink); }
.readout.bad { background: var(--bad-soft); color: var(--bad); }
.hint.warn { color: var(--warn-ink); font-weight: 650; }
.picked { font-weight: 650; }
.picked small { color: var(--ink-2); font-weight: 500; }

.form-error { color: var(--bad); font-weight: 650; }
.summary { font-size: 15px; color: var(--ink); }
.summary:empty { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); /* above the dock */ translate: -50% 20px;
  max-width: min(92vw, 480px); padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s, translate .25s var(--ease); z-index: 20;
}
.toast.show { opacity: 1; translate: -50% 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
