/* Lowertown Lights. Dusk blue ground; amber is reserved for light that is on, and its strength
   follows the level. Brick marks anything off-schedule. */
:root {
  --ground: #162036;
  --raised: #1d2944;
  --line: #2c3a5a;
  --ink: #ece7dc;
  --muted: #98a3ba;
  --amber: #f5b841;
  --amber-ink: #241a04;
  --brick: #e0705a;
  --day: #2a3b60;
  --night: #121a2c;
  --radius-s: 8px;
  --radius-l: 16px;
  --font: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #eef1f6;
    --raised: #ffffff;
    --line: #d5dbe6;
    --ink: #172033;
    --muted: #5b667c;
    --amber: #e9a315;
    --amber-ink: #241a04;
    --brick: #b8442e;
    --day: #dfe7f3;
    --night: #c3cddd;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 400 16px/1.45 var(--font); font-variant-numeric: tabular-nums;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* Header + tabs */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px; max-width: 980px; margin: 0 auto; }
.top h1 { font-size: 19px; white-space: nowrap; }
.status { border: 1px solid var(--line); background: var(--raised); border-radius: 999px;
  padding: 5px 12px 5px 10px; font-size: 14px; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="connected"] i { background: #6fcf8e; }
.status[data-state="error"] i, .status[data-state="reconnecting"] i { background: var(--brick); }

.tabs { position: fixed; inset: auto 0 0 0; z-index: 5; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--ground) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: 14px;
  font-weight: 500; padding: 10px 4px; border-radius: var(--radius-s); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--raised); }
@media (min-width: 760px) {
  body { padding-bottom: 40px; }
  .tabs { position: static; max-width: 980px; margin: 0 auto 8px; justify-content: flex-start; gap: 4px;
    background: none; backdrop-filter: none; border: 0; padding: 0 16px; }
  .tabs a { flex: none; padding: 8px 14px; }
}

main { max-width: 980px; margin: 0 auto; padding: 4px 16px 24px; outline: none; scroll-padding-bottom: 90px; }
html { scroll-padding-bottom: 90px; }
section + section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 17px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.banner { border: 1px solid var(--line); border-radius: var(--radius-l); padding: 12px 14px; margin-bottom: 16px;
  font-size: 14px; color: var(--muted); background: var(--raised); }
.banner b { color: var(--ink); font-weight: 600; }

/* The day chart: the one bold thing */
.day { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 14px 0 10px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 14px 10px; gap: 8px; }
.day-head h2 { font-size: 17px; }
.day-head .next { color: var(--muted); font-size: 14px; text-align: right; }
.day-head .next b { color: var(--ink); font-weight: 600; }
.chart { position: relative; padding: 0 14px; }
.sky { position: relative; height: 20px; border-radius: 6px; margin-left: var(--label-w);
  background: linear-gradient(90deg, var(--night) var(--rise0), var(--day) var(--rise1), var(--day) var(--set0), var(--night) var(--set1)); }
.sky span { position: absolute; top: 2px; font-size: 11px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }
.lanes { margin-top: 6px; }
.lane { display: grid; grid-template-columns: var(--label-w) 1fr; align-items: center; min-height: 26px; }
.lane .name { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; }
.lane .name.off-sched { color: var(--brick); }
.lane-area { font-size: 11px; color: var(--muted); opacity: .8; padding: 6px 0 1px; }
.lane-area:first-child { padding-top: 0; }
.track { position: relative; height: 14px; border-radius: 3px; background: color-mix(in srgb, var(--line) 45%, transparent); overflow: hidden; }
.track i { position: absolute; top: 0; bottom: 0; background: var(--amber); }
.track i.unknown { background: repeating-linear-gradient(135deg, transparent 0 4px, color-mix(in srgb, var(--muted) 30%, transparent) 4px 6px); }
.axis { position: relative; height: 18px; margin-left: var(--label-w); }
.axis span { position: absolute; font-size: 11px; color: var(--muted); transform: translateX(-50%); }
.nowline { position: absolute; top: -4px; bottom: 0; width: 2px; background: var(--ink); border-radius: 1px; pointer-events: none; }
.nowline::before { content: ""; position: absolute; top: -3px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.ticks { position: absolute; inset: 0 0 0 var(--label-w); pointer-events: none; }
.ticks b { position: absolute; top: 0; bottom: 0; width: 1px; background: color-mix(in srgb, var(--ink) 14%, transparent); }
:root { --label-w: 108px; }
@media (min-width: 760px) { :root { --label-w: 150px; } }

/* Device controls */
.areas { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.area h3 { font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 6px 2px; }
.dev { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px;
  border-radius: var(--radius-s); background: var(--raised); border: 1px solid var(--line); }
.dev + .dev { margin-top: 6px; }
.bulb { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--ground);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.bulb[data-on="true"] { border-color: transparent; color: var(--amber-ink);
  background: color-mix(in srgb, var(--amber) calc(35% + var(--lvl) * 0.65%), var(--ground)); }
.bulb:disabled { cursor: default; opacity: .55; }
.dev .label { min-width: 0; }
.dev .label b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .label small { color: var(--muted); font-size: 13px; }
.dev .label small.warn { color: var(--brick); }
.dev input[type="range"] { width: 110px; accent-color: var(--amber); }
.shield { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }

.scenes { display: flex; flex-wrap: wrap; gap: 8px; }
.scene-btn { border: 1px solid var(--line); background: var(--raised); border-radius: 999px; padding: 9px 16px; font-weight: 500; }
.scene-btn:active { background: var(--amber); color: var(--amber-ink); }
.ghost { border: 1px dashed var(--line); background: none; color: var(--muted); }

/* Lists (schedule, scenes, devices, log) */
.list { border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--raised); overflow: hidden; }
.row { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--line); }
.row .time { font-weight: 600; font-size: 15px; }
.row .time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.row .what { min-width: 0; }
.row .what b { font-weight: 500; display: block; }
.row .what small { color: var(--muted); font-size: 13px; display: block; }
.row .what small.warn { color: var(--brick); }
.row.disabled .time, .row.disabled .what b { color: var(--muted); }
.row.past .time { color: var(--muted); }
.row-btn { all: unset; grid-column: 1 / 3; display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; cursor: pointer; border-radius: 6px; min-width: 0; }
.row-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.chip { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--amber) 22%, transparent); color: var(--ink); }
.chip.check { background: none; border: 1px solid color-mix(in srgb, var(--brick) 60%, transparent); color: var(--brick); }
.chip.zero { background: color-mix(in srgb, var(--line) 70%, transparent); }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
.switch input:checked + span { background: var(--amber); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--amber-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }

.btn { border: 1px solid var(--line); background: var(--raised); border-radius: var(--radius-s); padding: 9px 14px; font-weight: 500; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.btn.danger { color: var(--brick); }
.btn:disabled { opacity: .5; cursor: default; }

/* Sheet (editor dialog) */
dialog { border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--ground); color: var(--ink);
  padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); }
dialog::backdrop { background: rgb(5 9 18 / .6); }
.sheet { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.sheet header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet header h2 { font-size: 17px; }
.sheet .body { padding: 14px 16px; overflow: auto; display: grid; gap: 16px; }
.sheet footer { display: flex; gap: 8px; justify-content: space-between; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet footer .right { display: flex; gap: 8px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--muted); }
.field input[type="text"], .field input[type="time"], .field input[type="number"], .field select, .field textarea {
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 10px; width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--raised); padding: 8px 12px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); font-weight: 600; }
.days { display: flex; gap: 5px; }
.days button { flex: 1; min-width: 0; max-width: 52px; height: 40px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--raised); font-size: 14px; }
.days button[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 600; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input[type="number"] { width: 90px; }
.levels { border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.lvl-area { padding: 8px 10px 2px; font-size: 13px; color: var(--muted); }
.lvl-area:not(:first-child) { border-top: 1px solid var(--line); }
.lvl { display: grid; grid-template-columns: 24px 1fr 104px 40px; gap: 8px; align-items: center; padding: 8px 10px; }
.lvl select { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; }
.lvl input[type="range"] { width: 100%; accent-color: var(--amber); }
.lvl output { text-align: right; font-size: 14px; color: var(--muted); }
.lvl small { color: var(--muted); }
.note { font-size: 14px; color: var(--muted); }
.note.warn { color: var(--brick); }

.log .row { grid-template-columns: 76px 1fr; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.bad { background: var(--brick); color: #fff; }

.login { max-width: 340px; margin: 12vh auto; display: grid; gap: 12px; }
.login input { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 11px 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
