/* ========================================================================
   KhanHub design system
   Light, crisp surfaces with a navy sidebar. Palette taken from the logo:
   navy "Khan", blue-to-cyan "Hub".
   ===================================================================== */

:root {
  /* brand */
  --brand-700: #1544b8;
  --brand-600: #1e5fe0;
  --brand-500: #2b7bff;
  --brand-400: #5fa0ff;
  --brand-100: #e3edff;
  --brand-50:  #f2f7ff;
  --cyan-500:  #00b4f0;
  --brand-grad: linear-gradient(135deg, #1e5fe0, #00b4f0);

  /* neutrals */
  --ink-900: #0b1220;
  --ink-800: #16233c;
  --ink-700: #1e293b;
  --ink-600: #334155;
  --ink-500: #475569;
  --ink-400: #64748b;
  --ink-300: #94a3b8;
  --ink-200: #cbd5e1;

  --bg:       #f4f7fc;
  --surface:  #ffffff;
  --surface-2:#f8fafc;
  --line:     #e4eaf3;
  --line-2:   #eef2f8;

  /* status */
  --ok: var(--kh-online);  --ok-bg: #e7f8ef;
  --warn: #f79009; --warn-bg: #fef4e6;
  --bad: #f04438; --bad-bg: #feecea;

  /* chrome */
  --sidebar-w: 244px;
  --topbar-h: 64px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, .12), 0 4px 8px -4px rgba(16, 24, 40, .08);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --text: var(--ink-800);
  --text-muted: var(--ink-400);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:       #0d1420;
    --surface:  #141d2c;
    --surface-2:#1a2436;
    --line:     #253148;
    --line-2:   #1e2a3d;
    --text:     #e8eef7;
    --text-muted: #90a1b9;
    --ink-800: #e8eef7;
    --ink-700: #d3dce8;
    --ink-600: #b6c2d3;
    --ink-500: #97a5ba;
    --ink-200: #33415a;
    --brand-100:#1b2f52;
    --brand-50: #16233c;
    --ok-bg: #10281c; --warn-bg: #2a1f0d; --bad-bg: #2b1614;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 10px rgba(0,0,0,.45);
    --shadow-lg: 0 14px 30px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1420; --surface: #141d2c; --surface-2:#1a2436;
  --line: #253148; --line-2:#1e2a3d;
  --text: #e8eef7; --text-muted:#90a1b9;
  --ink-800:#e8eef7; --ink-700:#d3dce8; --ink-600:#b6c2d3; --ink-500:#97a5ba; --ink-200:#33415a;
  --brand-100:#1b2f52; --brand-50:#16233c;
  --ok-bg:#10281c; --warn-bg:#2a1f0d; --bad-bg:#2b1614;
  --shadow-sm:0 1px 2px rgba(0,0,0,.4); --shadow-md:0 4px 10px rgba(0,0,0,.45); --shadow-lg:0 14px 30px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; color: var(--text); }
a { color: var(--brand-600); }

/* ---------- primitives ---------- */

.btn {
  --btn-bg: var(--surface); --btn-fg: var(--ink-700); --btn-bd: var(--line);
  appearance: none; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 7px; white-space: nowrap; text-decoration: none;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--radius-sm);
  padding: 9px 14px; font-size: 14px; font-weight: 550;
  box-shadow: var(--shadow-sm);
  transition: filter .15s, transform .06s, background .15s, border-color .15s;
}
.btn:hover { filter: brightness(.98); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

.btn-primary { --btn-bg: var(--brand-600); --btn-fg: #fff; --btn-bd: transparent; }
.btn-primary:hover { --btn-bg: var(--brand-500); }
.btn-danger  { --btn-fg: var(--bad); --btn-bd: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn-danger:hover { --btn-bg: var(--bad-bg); }
.btn-ghost   { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; }
.btn-ghost:hover { --btn-bg: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--line);
}
.chip-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
.chip-bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip-brand{ background: var(--brand-100); color: var(--brand-600); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-2);
}
.card-head h2 { font-size: 15px; }
.card-sub { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 180px; }
.field > label, .field > span.lbl { font-size: 12.5px; font-weight: 550; color: var(--ink-500); }
.input, .field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14.5px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .field input:focus, .field select:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent);
}
.field input::placeholder { color: var(--ink-300); }
.field-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field.narrow { flex: 0 0 118px; }
.field.check { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 8px; padding-bottom: 10px; }
.field.check input { width: 17px; height: 17px; accent-color: var(--brand-600); }
.hint { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
code {
  background: var(--surface-2); border: 1px solid var(--line-2);
  padding: 1px 5px; border-radius: 5px; font-size: .88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.note { font-size: 13.5px; line-height: 1.6; margin: 10px 0 0; color: var(--text-muted); }
.note-ok  { color: var(--ok); }
.note-bad { color: var(--bad); }
.banner {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--brand-50); border: 1px solid var(--brand-100);
  font-size: 13.5px; line-height: 1.6; color: var(--ink-600);
}
.banner-warn { background: var(--warn-bg); border-color: transparent; }
.banner-bad  { background: var(--bad-bg);  border-color: transparent; }

.toggle {
  position: relative; flex: none; cursor: pointer;
  width: 46px; height: 27px; border-radius: 999px;
  background: var(--ink-200); border: 0; transition: background .2s;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s;
}
.toggle[aria-checked="true"] { background: var(--ok); }
.toggle[aria-checked="true"]::after { transform: translateX(19px); }
.toggle:disabled { opacity: .45; cursor: not-allowed; }
.toggle.busy { animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- loading feedback ----------
   Three levels, deliberately: a global bar for any request in flight, skeletons
   for a view that has no data yet, and a shimmer on a camera tile waiting for
   its first frame. Nothing here should ever flash for a fast local call. */

.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 120;
  overflow: hidden; pointer-events: none; opacity: 0; transition: opacity .18s;
}
.progress.on { opacity: 1; }
.progress i {
  display: block; height: 100%; width: 38%; border-radius: 0 3px 3px 0;
  background: var(--brand-grad); animation: slide 1.15s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(380%); }
}

.skel { background: var(--surface-2); border-radius: var(--radius-sm);
        position: relative; overflow: hidden; }
.skel::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--line), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

.skel-title { height: 30px; width: 210px; margin-bottom: 20px; }
.skel-stat  { height: 86px; border-radius: var(--radius); }
.skel-tile  { aspect-ratio: 16/9; }
.skel-row   { height: 64px; margin-bottom: 10px; }
.skel-text  { display: inline-block; height: 1em; width: 110px;
              vertical-align: middle; border-radius: 4px; }

/* A tile sits dark until its first frame, so its shimmer has to be dark too. */
.cam-skel {
  position: absolute; inset: 0; background: #0f1724; overflow: hidden;
}
.cam-skel::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.13), transparent);
  animation: shimmer 1.5s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skel::after, .cam-skel::after { animation: none; }
  .progress i { animation: none; width: 100%; }
}

/* ---------- app shell ---------- */

.app { min-height: 100vh; padding-left: var(--sidebar-w); }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  z-index: 30; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #101d33 0%, #0a1424 100%);
  color: #cdd8e8; padding: calc(18px + var(--safe-t)) 14px calc(14px + var(--safe-b));
  border-right: 1px solid rgba(255,255,255,.06);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.nav-close { display: none; color: #cdd8e8; margin-bottom: 18px; }
.nav-close:hover { background: rgba(255,255,255,.08); }

/* Tapping outside the menu closes it on small screens */
.nav-scrim {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(8, 13, 22, .55); backdrop-filter: blur(2px);
}
.brand img { width: 34px; height: 34px; border-radius: 9px; background: #fff; padding: 2px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -.02em; color: #fff; }
.brand-name em { font-style: normal; color: var(--brand-400); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: #a9b8cd; text-decoration: none; font-size: 14.5px; font-weight: 550;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 12px rgba(30,95,224,.35); }
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav-sep { margin: 14px 10px 8px; font-size: 11px; letter-spacing: .1em;
           text-transform: uppercase; color: #64748b; font-weight: 650; }

.sidebar-foot { margin-top: auto; }
.host-card {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07);
  font-size: 13px;
}
.host-card .who { font-weight: 600; color: #e6edf7; }
.host-card .where { color: #7e8ea6; font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h); padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .burger { display: none; }
.search { position: relative; flex: 1 1 320px; max-width: 460px; }
.search input { padding-left: 38px; border-radius: 999px; background: var(--surface); }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
              width: 17px; height: 17px; color: var(--ink-300); pointer-events: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--brand-grad); color: #fff; font-weight: 650; font-size: 14px;
}

.content { padding: 24px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between;
             gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 25px; }
.eyebrow { font-size: 11.5px; font-weight: 650; letter-spacing: .1em;
           text-transform: uppercase; color: var(--brand-600); margin-bottom: 5px; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }

/* ---------- stat strip ---------- */

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 20px; }
.stat { display: flex; align-items: center; gap: 13px; padding: 15px 17px; }
.stat-icon { width: 40px; height: 40px; border-radius: 11px; flex: none;
             display: grid; place-items: center; background: var(--brand-100); color: var(--brand-600); }
.stat-icon svg { width: 20px; height: 20px; }
.stat-val { font-size: 21px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; }
.stat-lbl { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }

/* ---------- camera grid ---------- */

.cam-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.cam-grid.list { grid-template-columns: 1fr; }

.cam {
  position: relative; overflow: hidden; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); transition: box-shadow .18s, transform .12s, border-color .18s;
}
.cam:hover { box-shadow: var(--shadow-md); border-color: var(--ink-200); }
.cam.dragging { opacity: .45; }
.cam.drop-before { border-left: 3px solid var(--brand-500); }
.cam.drop-after  { border-right: 3px solid var(--brand-500); }

.cam-media { position: relative; aspect-ratio: 16/9; background: #0a0f18; cursor: pointer; }
.cam-media img { width: 100%; height: 100%; object-fit: cover; display: block;
                 opacity: 0; transition: opacity .4s; }
.cam-media img.loaded { opacity: 1; }
.cam-media .placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 8px;
  color: #64748b; font-size: 12.5px; text-align: center; padding: 16px;
}
.cam-badges { position: absolute; top: 10px; left: 10px; right: 10px;
              display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cam-badges .chip { backdrop-filter: blur(6px); background: rgba(10,15,24,.6); border-color: transparent; color: #e8eef7; }
.cam-badges .chip-ok {
  background: color-mix(in srgb, var(--kh-online) 88%, transparent); color: #06301c;
  font-weight: 650;
}
.cam-badges .chip-bad { background: rgba(240,68,56,.9); color: #fff; }
.cam-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  opacity: 0; transition: opacity .18s; background: rgba(8,13,22,.35);
}
.cam-media:hover .cam-play { opacity: 1; }
.cam-play span {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255,255,255,.94); color: var(--brand-600); box-shadow: var(--shadow-lg);
}
.cam-play svg { width: 22px; height: 22px; margin-left: 2px; }

.cam-body { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.cam-info { min-width: 0; flex: 1; }
.cam-name { font-weight: 620; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-actions { display: flex; gap: 6px; flex: none; }
.grip { cursor: grab; color: var(--ink-300); padding: 4px; border-radius: 6px; flex: none; }
.grip:hover { background: var(--surface-2); color: var(--ink-500); }
.grip:active { cursor: grabbing; }
.grip svg { width: 16px; height: 16px; display: block; }

/* ---------- device cards ---------- */

.dev-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.dev.offline { opacity: .62; }
.dev-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dev-name { font-weight: 620; font-size: 15px; }
.dev-room { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.dp {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line-2);
}
.dp:first-of-type { margin-top: 8px; }
.dp-name { font-size: 14px; color: var(--ink-600); }
.dp-range { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 200px; }
.dp-range input { flex: 1; accent-color: var(--brand-600); }
.dp-val { font-size: 12.5px; color: var(--text-muted); min-width: 36px; text-align: right; }

/* ---------- empty states ---------- */

.empty { text-align: center; padding: 54px 24px; }
.empty-art {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 17px;
  display: grid; place-items: center; background: var(--brand-100); color: var(--brand-600);
}
.empty-art svg { width: 29px; height: 29px; }
.empty h3 { font-size: 17px; margin-bottom: 6px; }
.empty p { color: var(--text-muted); font-size: 14px; max-width: 420px; margin: 0 auto 18px; line-height: 1.6; }

/* ---------- tabs ---------- */

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2);
       border: 1px solid var(--line); border-radius: 999px; }
.seg button {
  appearance: none; cursor: pointer; border: 0; background: transparent;
  padding: 7px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 550;
  color: var(--text-muted); transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--brand-600); box-shadow: var(--shadow-sm); }

/* ---------- discovery result rows ---------- */

.rows { display: flex; flex-direction: column; }
.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0; border-top: 1px solid var(--line-2);
}
.row-item:first-child { border-top: 0; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; font-size: 14.5px; }
.row-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.row-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.found-group {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; background: var(--surface-2);
}
.found-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }

/* ---------- steps ---------- */

.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text-muted); }
.step + .step::before { content: ""; width: 22px; height: 1px; background: var(--line); }
.step b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
          background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.step.done b { background: var(--ok); border-color: transparent; color: #fff; }
.step.active { color: var(--text); font-weight: 600; }
.step.active b { background: var(--brand-600); border-color: transparent; color: #fff; }

/* ---------- viewer ---------- */

.viewer { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: #05080e; }
.viewer-bar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  color: #e8eef7; border-bottom: 1px solid rgba(255,255,255,.09);
}
.viewer-bar .vtitle { font-weight: 620; }
.viewer-bar .vmeta { font-size: 12.5px; color: #8fa1b8; }
.viewer-bar .btn { --btn-bg: rgba(255,255,255,.1); --btn-fg: #e8eef7; --btn-bd: rgba(255,255,255,.14); box-shadow: none; }
.viewer-bar .btn:hover { --btn-bg: rgba(255,255,255,.18); }
.viewer-actions { margin-left: auto; display: flex; gap: 8px; }
.viewer-body { flex: 1; min-height: 0; background: #000; position: relative; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.viewer-foot { padding: 12px 16px calc(16px + var(--safe-b)); }

.ptz { display: grid; gap: 7px; grid-template-columns: repeat(3, 56px); justify-content: center; }
.ptz button {
  height: 44px; cursor: pointer; font-size: 16px;
  background: rgba(255,255,255,.1); color: #e8eef7;
  border: 1px solid rgba(255,255,255,.14); border-radius: var(--radius-sm);
}
.ptz button:active { background: var(--brand-600); }
.ptz .wide { grid-column: span 3; font-size: 13.5px; }
.presets { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 12px; }
.presets button {
  cursor: pointer; padding: 7px 14px; font-size: 13px; border-radius: 999px;
  background: rgba(255,255,255,.1); color: #e8eef7; border: 1px solid rgba(255,255,255,.14);
}

/* ---------- modal ---------- */

.modal-scrim {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(8, 13, 22, .55); backdrop-filter: blur(3px); padding: 20px;
}
.modal {
  width: 100%; max-width: 440px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  border: 1px solid var(--line); overflow: hidden;
}
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 14px 20px;
              border-top: 1px solid var(--line-2); background: var(--surface-2); }

/* ---------- toast ---------- */

.toasts { position: fixed; z-index: 90; bottom: calc(22px + var(--safe-b)); left: 50%;
          transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px;
          align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 9px;
  max-width: min(92vw, 480px); padding: 11px 16px; border-radius: 11px;
  background: var(--ink-900); color: #fff; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: rise .18s ease-out;
}
.toast.err { background: var(--bad); }
.toast.ok  { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- login ---------- */

.login-wrap { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.login-hero {
  position: relative; display: flex; flex-direction: column; justify-content: center;
  align-items: center; text-align: center; padding: 48px;
  background:
    radial-gradient(1100px 620px at 18% 12%, rgba(0,180,240,.30), transparent 62%),
    radial-gradient(900px 520px at 82% 86%, rgba(30,95,224,.34), transparent 60%),
    linear-gradient(160deg, #0e1c33 0%, #0a1424 58%, #081120 100%);
  color: #fff; overflow: hidden;
}
.login-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 45%, #000 25%, transparent 78%);
}
.login-hero .hero-inner { position: relative; z-index: 1; max-width: 430px; }
.login-hero img { width: 132px; height: 132px; border-radius: 28px; background: #fff;
                  padding: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.42); margin-bottom: 26px; }
.login-hero h1 { font-size: 40px; letter-spacing: -.03em; color: #fff; margin-bottom: 12px; }
.login-hero h1 em { font-style: normal;
  background: linear-gradient(90deg, #5fa0ff, #00d4ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.login-hero .tag { font-size: 19px; font-weight: 600; color: #dbe6f5; margin-bottom: 14px; }
.login-hero .blurb { font-size: 14.5px; line-height: 1.75; color: #9db0c9; }
.hero-points { display: flex; flex-direction: column; gap: 11px; margin-top: 30px; text-align: left; }
.hero-point { display: flex; align-items: center; gap: 11px; font-size: 14px; color: #c7d5e8; }
.hero-point i {
  width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: rgba(95,160,255,.16); color: #7fb4ff;
}
.hero-point svg { width: 16px; height: 16px; }

.login-panel { display: grid; place-items: center; padding: 40px 28px; background: var(--surface); }
.login-card { width: 100%; max-width: 372px; }
.login-card .mark { display: none; }
.login-card h2 { font-size: 26px; margin-bottom: 7px; }
.login-card .sub { color: var(--text-muted); font-size: 14.5px; margin-bottom: 26px; line-height: 1.6; }
.login-card .field { margin-bottom: 15px; }
.login-card .btn-primary { padding: 12px; font-size: 15px; margin-top: 4px; }
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
                    width: 17px; height: 17px; color: var(--ink-300); pointer-events: none; }
.input-icon input { padding-left: 38px; }
.input-icon .peek {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer; padding: 7px; color: var(--ink-400);
  border-radius: 7px; line-height: 0;
}
.input-icon .peek:hover { background: var(--surface-2); color: var(--ink-600); }
.input-icon .peek svg { width: 17px; height: 17px; }
.login-row { display: flex; align-items: center; justify-content: space-between;
             gap: 10px; margin: 4px 0 18px; font-size: 13.5px; }
.login-row label { display: flex; align-items: center; gap: 8px; color: var(--ink-600); cursor: pointer; }
.login-row input { width: 16px; height: 16px; accent-color: var(--brand-600); }
.login-foot { margin-top: 24px; font-size: 12.5px; color: var(--text-muted); text-align: center; line-height: 1.7; }

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  /* Small screens get only the sign-in panel, per the brief. */
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-card .mark { display: block; width: 62px; height: 62px; margin: 0 auto 20px;
                      border-radius: 16px; background: #fff; box-shadow: var(--shadow-md); }
  .login-card { text-align: center; }
  .login-card .field { text-align: left; }
  .login-row { text-align: left; }
}

@media (max-width: 900px) {
  .app { padding-left: 0; }
  .sidebar {
    width: 272px; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .nav-close { display: inline-flex; }
  .topbar { padding: 0 14px; }
  .topbar .burger { display: inline-flex; }
  .content { padding: 16px 14px calc(24px + var(--safe-b)); }
  .page-head h1 { font-size: 21px; }
  .search { flex-basis: 140px; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 13px; }
  .stat-val { font-size: 18px; }
  .search { display: none; }
}

/* <details> used for the collapsible "add manually" panels */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
  content: "▾"; margin-left: auto; color: var(--ink-300); font-size: 13px;
  transition: transform .18s;
}
details[open] > summary::after { transform: rotate(180deg); }

/* Wider modal for the scan wizard */
.modal-lg { max-width: 660px; }
.modal-lg .modal-body { overflow-y: auto; }

/* Live video tiles: the <video-stream> component sits over the poster image */
.cam-media { overflow: hidden; }
.cam-media video-stream,
.cam-media .tile-video {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%; background: #0a0f18;
}
.cam-media video-stream video,
.cam-media .tile-video video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
/* go2rtc's component paints its own status overlay; keep it subtle in a tile */
.cam-media video-stream .info { font-size: 11px; opacity: .75; padding: 8px !important; }

/* Device icons: a light switch should look like a light, a camera like a camera */

.dev-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-100); color: var(--brand-600);
}
.dev-icon svg { width: 19px; height: 19px; }
.dev-icon-bulb { background: #fff4d6; color: color-mix(in srgb, var(--kh-lit) 65%, #6b4c00); }
.dev-icon-cam  { background: var(--brand-100); color: var(--brand-600); }
.dev-icon-plug { background: var(--surface-2); color: var(--ink-500); }
:root[data-theme="dark"] .dev-icon-bulb,
:root:not([data-theme="light"]) .dev-icon-bulb {
  background: #3a2f12; color: var(--kh-lit);
}


.dp-icon { width: 22px; height: 22px; flex: none; display: grid; place-items: center;
           color: var(--ink-300); }
.dp-icon svg { width: 16px; height: 16px; }
.dp-icon-bulb { color: color-mix(in srgb, var(--kh-lit) 70%, var(--ink-300)); }
.dp[data-on="1"] .dp-icon-bulb {
  color: var(--kh-lit);
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--kh-lit) 60%, transparent));
}

/* ==================== fixes for small screens ==================== */

/* Inline SVGs inside buttons had no intrinsic size, so the burger rendered as
   an invisible (but clickable) blob. Give every button icon a real size. */
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-icon svg { width: 20px; height: 20px; }

/* Brand in the top bar, for when the sidebar (and its logo) is off-canvas */
.topbrand { display: none; align-items: center; gap: 8px; text-decoration: none; min-width: 0; }
.topbrand img { width: 28px; height: 28px; border-radius: 8px; background: #fff; flex: none; }
.topbrand span { font-size: 16px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.topbrand em { font-style: normal; color: var(--brand-600); }

a.avatar { text-decoration: none; }
a.avatar:hover { filter: brightness(1.08); }

/* Profile */
.profile-head { display: flex; align-items: center; gap: 15px; }
.profile-avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--brand-grad); color: #fff; font-size: 21px; font-weight: 650;
}
.profile-name { font-size: 18px; font-weight: 650; }

@media (max-width: 900px) {
  .topbrand { display: flex; }
  /* The search box crowded the brand out on a phone. */
  .search { display: none; }
  .topbar { gap: 8px; }
}

@media (max-width: 620px) {
  /* Switch rows were overlapping: the label and the control both wanted the
     same space. Let the label wrap and keep the control hard against the right. */
  .dp {
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    padding: 13px 0;
  }
  /* A slider needs a whole row of its own at this width. */
  .dp-range { flex: 1 0 100%; max-width: none; }

  .dev .dev-head { padding: 0 13px 11px; }
  .dev .dp { padding-left: 13px; padding-right: 13px; }
  .dev-banner { height: 88px; }
  .dev-head { gap: 8px; }
  .dev-icon { width: 34px; height: 34px; }
  .dev-name { font-size: 14.5px; }

  /* Stop long device names forcing the card wider than the screen */
  .dev-titles { min-width: 0; }
  /* names wrap rather than truncate now that the row has room */

  .page-head { gap: 10px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .field-row > .btn { width: 100%; }
}

/* ---- grid blow-out guard -------------------------------------------------
   Grid and flex items default to min-width:auto, so a long device name or a
   status chip can force its track wider than the screen -- which is what
   pushed the toggles off the right edge on a phone. minmax(min(...)) lets the
   track shrink below its nominal minimum, and min-width:0 lets the contents
   actually compress instead of overflowing. */
.cam-grid { grid-template-columns: repeat(auto-fill, minmax(min(268px, 100%), 1fr)); }
.dev-grid { grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); }
.stats    { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.list     { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }

.cam, .dev, .card, .stat { min-width: 0; }
.dev-head, .dp, .dp-label, .item, .item-main, .row-item, .row-main { min-width: 0; }
.dev-head > *, .item > *, .row-item > * { min-width: 0; }

/* Nothing should scroll the page sideways -- but NOT with overflow-x:hidden,
   which turns html/body into a scroll container and silently breaks
   position:sticky for every descendant (it is what made the sidebar detach
   when the dashboard was scrolled). `clip` contains the overflow without
   creating a scroll container. */
html, body { max-width: 100%; overflow-x: clip; }

/* The scrim is inert unless the slide-over menu is actually open. */
.nav-scrim { display: none; }
@media (max-width: 900px) { .app.nav-open ~ .nav-scrim, .nav-scrim.on { display: block; } }

/* ==================== device cards: press the bulb ==================== */

.dev-head { display: flex; align-items: flex-start; gap: 13px; }
.dev-titles { flex: 1 1 auto; min-width: 0; }
/* Long names wrap now that the IP and the switch count are gone. */
.dev-name { font-weight: 620; font-size: 15px; line-height: 1.3;
            overflow-wrap: anywhere; white-space: normal; }
.dev-room { font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
            overflow-wrap: anywhere; white-space: normal; }
.dev-head > .chip { flex: none; margin-top: 2px; }

/* The master control: whole device on or off */
.dev-power {
  appearance: none; cursor: pointer; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-300);
  border: 1px solid var(--line);
  transition: background .18s, color .18s, box-shadow .18s, transform .08s;
}
.dev-power svg { width: 21px; height: 21px; }
.dev-power:hover:not(:disabled) { border-color: var(--ink-200); }
.dev-power:active:not(:disabled) { transform: scale(.94); }
.dev-power:disabled { opacity: .45; cursor: not-allowed; }
.dev-power.on {
  background: var(--kh-lit); border-color: var(--kh-lit); color: #5a4200;
  box-shadow: 0 0 0 4px rgba(240,180,41,.20), 0 2px 10px rgba(240,180,41,.45);
}
.dev-power-cam.on {
  background: var(--brand-500); border-color: var(--brand-600); color: #fff;
  box-shadow: 0 0 0 4px rgba(43,123,255,.18);
}

/* One bulb per gang, in place of a toggle */
.dp { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dp-name { font-size: 14.5px; color: var(--ink-600); overflow-wrap: anywhere; }
.bulb {
  appearance: none; cursor: pointer; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-300);
  border: 1px solid var(--line);
  transition: background .18s, color .18s, box-shadow .18s, transform .08s;
}
.bulb svg { width: 18px; height: 18px; }
.bulb:hover:not(:disabled) { border-color: var(--ink-200); color: var(--ink-500); }
.bulb:active:not(:disabled) { transform: scale(.92); }
.bulb:disabled { opacity: .4; cursor: not-allowed; }
.bulb:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.bulb.on {
  background: var(--kh-lit); border-color: var(--kh-lit); color: #5a4200;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--kh-lit) 20%, transparent),
              0 2px 12px color-mix(in srgb, var(--kh-lit) 45%, transparent);
}
.bulb-cam.on { background: var(--brand-500); border-color: var(--brand-600); color: #fff;
               box-shadow: 0 0 0 4px rgba(43,123,255,.16); }
.bulb.busy, .dev-power.busy { animation: pulse .9s ease-in-out infinite; }

:root[data-theme="dark"] .bulb.on, :root:not([data-theme="light"]) .bulb.on,
:root[data-theme="dark"] .dev-power.on, :root:not([data-theme="light"]) .dev-power.on {
  background: var(--kh-lit); border-color: var(--kh-lit); color: #3a2b00;
}

/* ==================== device card banner ==================== */

.dev { overflow: hidden; padding: 0; }
.dev-banner {
  position: relative; height: 104px; overflow: hidden;
  background: linear-gradient(135deg, #1f2a44, #101a2e);
}
.dev-banner-img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* A wash at the bottom so the icon and name stay readable over any photo */
.dev-banner::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(8,13,22,.10) 0%, rgba(8,13,22,.55) 100%);
}
.dev-banner-bulb, .dev-banner-plug {
  background: linear-gradient(135deg, #3a2f12 0%, #191d2c 70%);
}
.dev-banner-cam { background: linear-gradient(135deg, #16294a 0%, #101a2e 70%); }

/* Watermark shown when no photo has been set */
.dev-banner-ghost {
  position: absolute; right: 14px; bottom: 6px;
  color: rgba(255, 255, 255, .13); line-height: 0;
}
.dev-banner-ghost svg { width: 78px; height: 78px; }

/* The header now straddles the banner, like a profile picture */
.dev .dev-head { padding: 0 16px 12px; margin-top: -22px; position: relative; z-index: 1; }
.dev .dp { padding-left: 16px; padding-right: 16px; }
.dev > .note { padding: 0 16px 14px; }
.dev .dev-name { padding-top: 24px; }
.dev .dev-head > .chip { margin-top: 26px; }

.dev-power {
  box-shadow: 0 2px 10px rgba(8, 13, 22, .35);
  border-width: 2px; border-color: var(--surface);
  background: var(--surface-2);
}
.dev-power.on { border-color: var(--surface); }

.dev.offline .dev-banner-img { filter: grayscale(.8); }

/* ==================== setup rows on a narrow screen ==================== */
/* A row of four action buttons refuses to shrink, which squeezed the text
   column to almost nothing and wrapped an IP address one character per line.
   Below this width the row becomes two stacked blocks instead. */
@media (max-width: 720px) {
  .row-item, .item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .row-main, .item-main { width: 100%; }
  .row-actions, .item-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
  .row-actions .btn, .item-actions .btn { flex: 1 1 auto; justify-content: center; }
  /* Text may wrap normally now that it has the full width */
  .row-title, .row-meta, .item-name, .item-meta { overflow-wrap: break-word; word-break: normal; }
  .found-group { padding: 12px 13px; }
  .found-head { flex-wrap: wrap; }
}

/* ==================== modal sizing ==================== */
/* A dialog with one field per gang grew taller than the viewport, putting its
   title and Save button out of reach. Cap the height, scroll the body, and
   keep the header and footer pinned. */
.modal {
  display: flex; flex-direction: column;
  max-height: min(88vh, 860px);
}
.modal > .card-head { flex: none; }
.modal-body { flex: 1 1 auto; overflow-y: auto; }
.modal-foot { flex: none; }

/* .field carries flex:1 1 180px for side-by-side rows; inside a column-flex
   modal that made every field stretch, leaving big gaps between them. */
.modal-body .field { flex: 0 0 auto; }

/* A label wrapping a file input: the input must be reachable but invisible.
   display:none would stop the dialog opening in some browsers. */
.file-btn { cursor: pointer; position: relative; overflow: hidden; }
.file-input {
  position: absolute; width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
}
.file-btn.busy { opacity: .7; pointer-events: none; }

/* ---------- users ---------- */

.user-list { display: flex; flex-direction: column; gap: 10px; }

.user-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface);
}
.user-row.off { opacity: .6; }

.user-av {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  color: #fff; background: var(--brand-grad); letter-spacing: .3px;
}

.user-main { min-width: 0; flex: 1; }
.user-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-name { font-weight: 650; }
.user-at { color: var(--ink-300); font-size: 13px; }
.user-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.user-meta { font-size: 12.5px; color: var(--ink-300); margin-top: 2px; }
.user-perms { font-size: 12.5px; color: var(--ink-700); margin-top: 4px; }
.user-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* The picker: one scrolling column per device type, so a long camera list
   never pushes the Save button off the modal. */
.picker { border: 1px solid var(--line); border-radius: var(--radius-sm);
          background: var(--surface-2); padding: 8px 10px; }
.pick, .pick-all {
  display: flex; align-items: flex-start; gap: 9px; padding: 6px 2px;
  font-size: 13.5px; cursor: pointer;
}
.pick-all { border-bottom: 1px solid var(--line); margin-bottom: 4px; font-weight: 600; }
.pick input, .pick-all input {
  width: 16px; height: 16px; flex: none; margin-top: 1px; accent-color: var(--brand-600);
}
.pick-list { max-height: 190px; overflow-y: auto; }
.perm-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.perm-split .lbl { display: block; margin-bottom: 6px; }

@media (max-width: 720px) {
  .perm-split { grid-template-columns: 1fr; }
  .user-row { flex-wrap: wrap; }
  .user-main { flex: 1 1 100%; order: 2; }
  .user-actions { flex: 1 1 100%; order: 3; flex-wrap: wrap; }
  .user-actions .btn { flex: 1 1 auto; }
}

/* ---------- display designer ---------- */

.mono-sm { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
           font-size: 11.5px; word-break: break-all; }

.dzf-wrap { display: flex; gap: 16px; align-items: flex-start; }
.dzf-main { flex: 1; min-width: 0; }

.dzf-stage {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; display: grid; place-items: center;
}
/* Shaped like the tablet it is for, so what you arrange is what you get. */
.dzf-canvas {
  position: relative; width: 100%; max-height: 62vh;
  background: #0b1119; border-radius: 10px; overflow: hidden;
  touch-action: none;             /* we do the dragging ourselves */
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.dzf-canvas.snapping {
  background-image:
    linear-gradient(to right, rgba(255,255,255,.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: var(--snap) var(--snap);
}
.dzf-empty {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center;
  gap: 6px; text-align: center; color: #7d8ea6; padding: 24px; pointer-events: none;
}
.dzf-empty b { color: #cfdaea; font-size: 15px; }
.dzf-empty span { font-size: 12.5px; max-width: 340px; }

.dzf-tile {
  position: absolute; overflow: hidden; cursor: grab;
  border-radius: 9px; border: 1px solid rgba(255,255,255,.14);
  background: #16202e; color: #fff; box-sizing: border-box;
}
.dzf-tile.selected { border-color: var(--brand-500);
                     box-shadow: 0 0 0 2px var(--brand-500), 0 8px 22px rgba(0,0,0,.4); }
.dzf-tile.dragging { cursor: grabbing; opacity: .92; }
.dzf-live { position: absolute; inset: 0; pointer-events: none; display: flex; }
.dzf-live > * { flex: 1; min-width: 0; }

.dzf-badge {
  position: absolute; left: 5px; top: 5px; z-index: 3; pointer-events: none;
  font-size: 9.5px; font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,.55); color: #fff; padding: 1px 6px; border-radius: 999px;
  opacity: 0; transition: opacity .15s;
}
.dzf-tile.selected .dzf-badge, .dzf-tile.dragging .dzf-badge { opacity: 1; }

.dzf-h {
  position: absolute; width: 14px; height: 14px; z-index: 4; border-radius: 3px;
  background: var(--brand-500); border: 2px solid #fff; opacity: 0;
  transition: opacity .15s;
}
.dzf-tile.selected .dzf-h { opacity: 1; }
.dzf-h-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.dzf-h-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.dzf-h-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.dzf-h-se { right: -7px; bottom: -7px; cursor: nwse-resize; }

/* ---- the inspector ---- */

.dzf-inspector {
  width: 320px; flex: none; position: sticky; top: 74px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  max-height: calc(100vh - 100px); display: flex; flex-direction: column;
}
.dzf-wrap.collapsed .dzf-inspector { width: 46px; }
.dzf-wrap.collapsed .dzi-list, .dzf-wrap.collapsed .dzi-top b { display: none; }
.dzf-wrap.collapsed .dzi-collapse { transform: rotate(180deg); }

.dzi-top { display: flex; align-items: center; justify-content: space-between;
           padding: 10px 12px; border-bottom: 1px solid var(--line-2); flex: none; }
.dzi-list { overflow-y: auto; }
.dzi-sec { border-bottom: 1px solid var(--line-2); }
.dzi-head {
  width: 100%; display: flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 11px 12px; background: none; border: 0; color: inherit;
  font: inherit; font-weight: 600; font-size: 13px; text-align: left;
}
.dzi-head:hover { background: var(--surface-2); }
.dzi-title { flex: 1; }
.dzi-caret svg { width: 14px; height: 14px; transition: transform .18s; display: block; }
.dzi-head.open .dzi-caret svg { transform: rotate(90deg); }
.dzi-body { padding: 0 12px 14px; display: flex; flex-direction: column; gap: 10px; }
/* .field carries flex-grow for use in rows; in this column it would stretch
   every input to fill the panel. Same trap the modal hit. */
.dzi-body .field, .dzi-body .pick, .dzi-body .picker { flex: 0 0 auto; }
.dzi-grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dzi-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.dzi-body .picker { background: var(--surface-2); }
.dzi-body .pick-list { max-height: 160px; }

/* ---- previews inside designer tiles ---- */

.dzc-cam { position: relative; background: #05080e; }
.dzc-cam img { position: absolute; inset: 0; width: 100%; height: 100%;
               object-fit: contain; }
.dzc-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px;
  font-size: 10px; font-weight: 600; color: #fff; line-height: 1.2; z-index: 2;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dzc-slides::before, .dzc-slides::after {
  content: ''; position: absolute; top: 4px; bottom: 4px; width: 3px; z-index: 2;
  background: rgba(255,255,255,.4); border-radius: 2px;
}
.dzc-slides::before { right: 4px; }
.dzc-slides::after  { right: 9px; opacity: .5; }

.dzc-quad { position: relative; display: grid; gap: 2px; padding: 2px;
            grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
            background: #05080e; }
.dzc-quad .dzc-cam { border-radius: 5px; overflow: hidden; }
.dzc-quad > .dzc-cap { grid-column: 1 / -1; }

.dzc-photos { display: grid; place-items: center; align-content: center; gap: 5px;
              background: #1d2433; }
.dzc-photos svg { width: 24px; height: 24px; opacity: .7; }

.dzc-clock { display: flex; flex-direction: column; align-items: center;
             justify-content: center; gap: 2px; padding: 6px; text-align: center;
             background: #4b3fb0; }
.dzc-clock.analogwrap { padding: 8px; color: #fff; }
.dzc-analog { width: 100%; height: 100%; max-height: 100%; }
.dzc-analog .cf-h, .dzc-analog .cf-m { transform-origin: 50px 50px; }
.dzc-time { font-size: clamp(14px, 2vw, 26px); font-weight: 300; line-height: 1;
            font-variant-numeric: tabular-nums; }
.dzc-date { font-size: 9.5px; opacity: .85; }

.dzc-wx { display: flex; align-items: center; justify-content: center; gap: 8px;
          padding: 8px; background: #4b3fb0; }
.dzc-wxicon svg { width: 26px; height: 26px; }
.dzc-temp { font-size: 18px; font-weight: 350; line-height: 1.1; }
.dzc-dim { font-size: 10px; opacity: .85; }

.dzc-sw { display: flex; flex-direction: column; gap: 5px; padding: 8px;
          justify-content: center; overflow: hidden; background: #0f6b52; }
.dzc-swhead { display: flex; align-items: center; gap: 6px; }
.dzc-bulb { width: 20px; height: 20px; flex: none; border-radius: 50%;
            display: grid; place-items: center; background: rgba(255,255,255,.18); }
.dzc-bulb svg { width: 12px; height: 12px; }
.dzc-bulb.on { background: var(--kh-lit); color: #4a3200; }
.dzc-swname { font-size: 10.5px; font-weight: 650; line-height: 1.2;
              overflow: hidden; display: -webkit-box;
              -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dzc-gangs { display: flex; flex-wrap: wrap; gap: 3px; }
.dzc-gang { font-size: 9px; padding: 1px 5px; border-radius: 999px;
            background: rgba(255,255,255,.16); white-space: nowrap; }
.dzc-gang.on { background: var(--kh-lit); color: #4a3200; font-weight: 600; }
.dzc-missing { display: grid; place-items: center; padding: 6px; font-size: 10px;
               text-align: center; background: var(--bad); }

.dz-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.dz-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-700); font-size: 12.5px; text-align: left;
}
.dz-chip svg { width: 14px; height: 14px; flex: none; }
.dz-chip:hover:not(:disabled) { border-color: var(--brand-500); color: var(--brand-600); }
.dz-chip.used { opacity: .4; cursor: default; text-decoration: line-through; }

@media (max-width: 1000px) {
  .dzf-wrap { flex-direction: column; }
  .dzf-inspector { width: 100%; position: static; max-height: none; }
  .dzf-wrap.collapsed .dzf-inspector { width: 100%; }
  .dzf-wrap.collapsed .dzi-list { display: block; }
  .dzf-canvas { max-height: none; }
}

/* ---------- dashboard now-strip ---------- */

.nowbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 16px 20px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.nb-time { font-size: 34px; font-weight: 300; line-height: 1;
           font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.nb-date { font-size: 12.5px; color: var(--ink-300); margin-top: 5px; }
.nb-sep { width: 1px; align-self: stretch; background: var(--line); }
.nb-wx { display: flex; align-items: center; gap: 13px; min-width: 0; }
.nb-wx svg { width: 42px; height: 42px; color: #f0a93a; flex: none; }
.nb-temp { font-size: 25px; font-weight: 350; line-height: 1.1; }
.nb-desc { font-size: 12.5px; color: var(--ink-700); }
.nb-place { font-size: 11px; color: var(--ink-300); }
.nb-days { display: flex; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.nb-day { text-align: center; font-size: 11.5px; color: var(--ink-300);
          display: flex; flex-direction: column; gap: 3px; align-items: center; }
.nb-day svg { width: 19px; height: 19px; color: var(--ink-700); }
.nb-day b { color: var(--ink-900, var(--ink-700)); font-weight: 600;
            font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .nowbar { gap: 14px; padding: 14px; }
  .nb-sep { display: none; }
  .nb-days { margin-left: 0; width: 100%; justify-content: space-between;
             border-top: 1px solid var(--line-2); padding-top: 12px; }
  .nb-time { font-size: 28px; }
}

.dz-tile.dz-clock, .dz-tile.dz-weather { background: #6b4fd8; }
.dz-chip-w { border-style: dashed; }
.dz-chip-w:hover { border-color: #6b4fd8; color: #6b4fd8; }

/* The canvas is framed to the shape of the tablet being designed for, so a
   portrait layout is not laid out on a landscape rectangle and vice versa. */
.dz-stage { margin: 0 auto 18px; }
.dz-stage.dz-landscape { max-width: 100%; }
.dz-stage.dz-portrait { max-width: min(460px, 100%); }
.dz-stage .dz-grid { margin-bottom: 0; }
.dz-head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .dz-stage.dz-portrait { max-width: 100%; }
  .dz-head-actions { width: 100%; }
}

.dz-tile.dz-slideshow { background: #0e7fa8; }


/* ---------- live previews inside the designer ---------- */

.dzc-cam { position: relative; background: #0a0f18; }
.dzc-cam img { position: absolute; inset: 0; width: 100%; height: 100%;
               object-fit: cover; }
.dzc-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 8px 6px;
  font-size: 10.5px; font-weight: 600; color: #fff; line-height: 1.2;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* A slideshow wears a stack edge, so it reads as several cameras at a glance. */
.dzc-slides::before, .dzc-slides::after {
  content: ''; position: absolute; top: 4px; bottom: 4px; width: 3px;
  background: rgba(255,255,255,.35); border-radius: 2px;
}
.dzc-slides::before { right: 4px; }
.dzc-slides::after  { right: 9px; opacity: .5; }

.dzc-clock { display: flex; flex-direction: column; align-items: center;
             justify-content: center; gap: 2px; padding: 6px; text-align: center; }
.dzc-time { font-size: clamp(16px, 2.4vw, 30px); font-weight: 300; line-height: 1;
            font-variant-numeric: tabular-nums; }
.dzc-date { font-size: 10px; opacity: .8; }

.dzc-wx { display: flex; align-items: center; justify-content: center; gap: 9px;
          padding: 8px; }
.dzc-wxicon svg { width: 30px; height: 30px; }
.dzc-temp { font-size: 20px; font-weight: 350; line-height: 1.1; }
.dzc-dim { font-size: 10.5px; opacity: .82; }

.dzc-sw { display: flex; flex-direction: column; gap: 6px; padding: 9px;
          justify-content: center; overflow: hidden; }
.dzc-swhead { display: flex; align-items: center; gap: 7px; }
.dzc-bulb { width: 22px; height: 22px; flex: none; border-radius: 50%;
            display: grid; place-items: center; background: rgba(255,255,255,.16); }
.dzc-bulb svg { width: 13px; height: 13px; }
.dzc-bulb.on { background: var(--kh-lit); color: #4a3200; }
.dzc-swname { font-size: 11px; font-weight: 650; line-height: 1.2;
              overflow: hidden; display: -webkit-box;
              -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dzc-gangs { display: flex; flex-wrap: wrap; gap: 4px; }
.dzc-gang { font-size: 9.5px; padding: 2px 6px; border-radius: 999px;
            background: rgba(255,255,255,.14); white-space: nowrap; }
.dzc-gang.on { background: var(--kh-lit); color: #4a3200; font-weight: 600; }

.dzc-missing { display: grid; place-items: center; padding: 8px; font-size: 10.5px;
               text-align: center; background: var(--bad); }

.dz-size {
  position: absolute; left: 6px; top: 5px; z-index: 2;
  font-size: 10px; font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,.45); color: #fff; padding: 1px 6px; border-radius: 999px;
}
.dz-x { z-index: 2; }
.dz-grip-rb { z-index: 2; }

.dzi-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dzi-photos .hint { grid-column: 1 / -1; }
.dzi-photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
             background: var(--surface-2); }
.dzi-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dzi-photo-x {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border: 0;
  border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 10px;
  cursor: pointer; line-height: 1;
}

/* ---------- designer: toolbar, tile chrome, appearance controls ---------- */

.dzf-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
             flex-wrap: wrap; }
.dzf-toolsep { width: 1px; height: 20px; background: var(--line); }
.dzf-hint { margin-left: auto; font-size: 12px; color: var(--ink-300); }

.dzf-tile {
  background: var(--t-bg, #16202e);
  color: var(--t-fg, #fff);
  border-color: var(--t-border, rgba(255,255,255,.14));
  border-width: var(--t-border-w, 1px);
  border-radius: var(--t-radius, 9px);
  opacity: var(--t-opacity, 1);
}
.dzf-tile.t-plain { background: transparent; border-color: transparent; }
.dzf-camera, .dzf-slideshow, .dzf-quad, .dzf-photos { background: var(--t-bg, #05080e); }

.dzf-x {
  position: absolute; top: 4px; right: 4px; z-index: 5; width: 22px; height: 22px;
  border: 0; border-radius: 50%; cursor: pointer; font-size: 11px; line-height: 1;
  background: rgba(0,0,0,.55); color: #fff; opacity: 0; transition: opacity .15s;
}
.dzf-tile.selected .dzf-x, .dzf-tile:hover .dzf-x { opacity: 1; }
.dzf-x:hover { background: var(--bad); }

.dzc-fill { width: 100%; height: 100%; display: flex; }

.dzi-subhead { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
               color: var(--ink-300); margin-top: 6px; font-weight: 700; }
.dzi-row { display: flex; align-items: center; gap: 8px; }
.dzi-row .lbl { flex: 1; margin: 0; }
.dzi-colour {
  width: 34px; height: 28px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: none; cursor: pointer; flex: none;
}
.dzi-slider { display: flex; flex-direction: column; gap: 3px; }
.dzi-sliderhead { display: flex; align-items: center; justify-content: space-between; }
.dzi-sliderhead .lbl { margin: 0; }
.dzi-val { font-size: 11.5px; color: var(--ink-300); font-variant-numeric: tabular-nums; }
.dzi-range { width: 100%; accent-color: var(--brand-600); }

/* The shared widget renderer needs a colour to work from inside the designer. */
.dzf-tile .kw { color: var(--t-fg, #fff); }
.dzf-clock, .dzf-weather { background: var(--t-bg, #4b3fb0); }

/* ---------- the tablet frame ---------- */

.dzf-device {
  position: relative; width: 100%; max-width: 100%;
  padding: 26px 22px 30px; border-radius: 30px;
  background: linear-gradient(160deg, #2c3442, #171c24 60%, #0f1319);
  box-shadow: 0 0 0 1px rgba(255,255,255,.07) inset,
              0 1px 0 rgba(255,255,255,.12) inset,
              0 18px 40px rgba(10,20,40,.35);
}
.dzf-screen { position: relative; border-radius: 12px; overflow: hidden;
              box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
.dzf-lens {
  position: absolute; top: 11px; left: 50%; transform: translateX(-50%);
  width: 7px; height: 7px; border-radius: 50%;
  background: #0a0d12; box-shadow: 0 0 0 2px rgba(255,255,255,.05);
}
.dzf-homebar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: 74px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.18);
}
/* Portrait tablets are held the other way up, so the lens moves to the side. */
.dzf-stage.dz-portrait .dzf-device { padding: 22px 26px 22px 30px; }

/* ---------- preview mode ---------- */

.dzf-wrap.previewing .dzf-inspector { display: none; }
.dzf-wrap.previewing .dzf-tile { cursor: default; border-color: var(--t-border, transparent); }
.dzf-wrap.previewing .dzf-tile.dzf-camera,
.dzf-wrap.previewing .dzf-tile.dzf-slideshow,
.dzf-wrap.previewing .dzf-tile.dzf-quad { border-color: var(--t-border, transparent); }
.dzf-wrap.previewing .dzf-canvas { max-height: 74vh; }
.dzf-wrap.previewing .dzf-main { max-width: 1100px; margin: 0 auto; }

/* A portrait canvas sizes from its height, so the bezel has to shrink to it
   rather than stretch across the page. */
.dzf-stage.dz-tall { justify-items: center; }
.dzf-stage.dz-tall .dzf-device { width: auto; max-width: 100%; }
.dzf-stage.dz-tall .dzf-screen { display: grid; place-items: center; }
.dzf-canvas { max-width: 100%; }


/* The designer honours the same two colours, so a tile previewed as lit is the
   same yellow it will be on the wall. */
.dzf-tile .kw { --kw-accent: var(--t-accent, var(--kh-lit)); }

/* Online / offline chips carry the dot in the same two colours. */
.chip-ok .dot { background: var(--kh-online); }
.chip-bad .dot { background: var(--kh-offline); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block;
             margin-right: 5px; vertical-align: -1px; }

.dzi-bgpick { grid-template-columns: repeat(4, 1fr); }
.dzi-pick { border: 2px solid transparent; padding: 0; cursor: pointer;
            background: var(--surface-2); }
.dzi-pick.sel { border-color: var(--brand-500); }
.dzi-none { display: grid; place-items: center; width: 100%; height: 100%;
            font-size: 10px; color: var(--ink-300); }
/* The designer shows the same photo backdrop the panel will. */
/* The designer shows the same backdrop; background-color must not sit on top
   of the layered background-image, so only the colour fallback is set here. */
.dzf-tile.has-image { background-color: var(--t-bg, #16202e); }

.dzf-tile.sky-tile {
  background-image:
    linear-gradient(100deg, rgba(8,10,14,.58), rgba(8,10,14,.74) 60%, rgba(8,10,14,.86)),
    var(--t-image);
  background-size: cover, cover; background-position: center, center;
}

/* ---------------- scenes ----------------
   A scene is a sparse list: only the gangs you name are in it. The editor has
   to make "not in the scene" look deliberate rather than unfinished, which is
   why every gang shows its live state alongside the choice. */

.row-icon { flex: none; display: grid; place-items: center; width: 34px; height: 34px;
            border-radius: 9px; background: var(--surface-2); color: var(--ink-600); }
.row-icon svg { width: 18px; height: 18px; }

.scene-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
             margin: 14px 0 6px; }
.scene-bar .chip { font-weight: 600; }

/* .modal-body is itself a flex column that scrolls, so everything in here has
   to opt out of shrinking. Without flex:none the device blocks are squeezed to
   fit instead of overflowing, which silently crushes the per-light rows to
   nothing and leaves the modal with nothing to scroll. One scroller, on the
   modal body -- a nested one here would mean two scrollbars fighting. */
.scene-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px;
              flex: none; }

.scene-dev { flex: none; border: 1px solid var(--line); border-radius: 12px;
             overflow: hidden; }
.scene-dev-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.scene-dev-head .row-actions { margin-left: auto; }

.gang-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line);
}
.gang-row:first-child { border-top: 0; }
.gang-row .row-actions { margin-left: auto; }
/* The three states are a real choice, so give them room rather than squeezing
   them into icons the first-time user has to decode. */
.gang-row .seg button { padding: 5px 11px; font-size: 12.5px; }

@media (max-width: 620px) {
  .gang-row, .scene-dev-head { align-items: flex-start; }
  .gang-row .row-actions, .scene-dev-head .row-actions { margin-left: 0; width: 100%; }
  .gang-row .seg { width: 100%; }
  .gang-row .seg button { flex: 1; }
}

/* ---------------- ordered list (scenes on a panel tile) ----------------
   The order here is the order on the wall, so it needs to be visible and
   movable, not inferred from a set of checkboxes. */

.order-list { display: flex; flex-direction: column; gap: 6px; }
.order-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2);
}
.order-ico { flex: none; display: grid; place-items: center; width: 22px; height: 22px;
             color: var(--ink-500); }
.order-ico svg { width: 15px; height: 15px; }
.order-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 550;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-row .btn { flex: none; }
.order-row .btn:disabled { opacity: .3; }

/* A copy button confirming on the spot, rather than only in a toast. */
.btn.ok-flash { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

/* ---------------- automations ----------------
   Four blocks: when / and only if / then / otherwise. The keyword badge is
   deliberately loud — the structure of a rule should be readable before any
   of the detail is. */

.blk { border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
       margin-bottom: 10px; overflow: hidden; flex: none; }
.blk-h { display: flex; align-items: center; gap: 10px; padding: 10px 14px;
         border-bottom: 1px solid var(--line); background: var(--surface-2); }
.blk-h .sub { color: var(--text-muted); font-size: 12.5px; margin-left: auto; }
.blk-b { padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; }

/* Not .kw — widgets.css already owns that for the panel widget faces, and
   inheriting it turns this badge into a full-size flex box. */
.kword { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
         padding: 3px 10px; border-radius: 999px; color: #fff; flex: none; }
.kword-when { background: #2b6fd8; }
.kword-if   { background: #7b4bd8; }
.kword-then { background: var(--ok); }
.kword-else { background: #b4690e; }

.arow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.arow .input { width: auto; }
.arow .input.narrow { width: 112px; }
.arow .w { color: var(--text-muted); font-size: 13px; }
.arow select.src { background: #f1ebfe; border-color: transparent; color: #6b3fc9;
                   font-weight: 600; }
.arow select.act { background: var(--ok-bg); border-color: transparent; color: #1a7a4a;
                   font-weight: 600; }
.arow select.op { color: var(--text-muted); }
.xbtn { margin-left: auto; border: 0; background: none; color: var(--ink-300);
        font-size: 16px; line-height: 1; padding: 4px 6px; cursor: pointer; }
.xbtn:hover { color: var(--bad); }
.addrow { align-self: flex-start; border: 0; background: none; padding: 2px 0;
          font-size: 13px; font-weight: 600; color: var(--brand-600); cursor: pointer; }

.days { display: flex; gap: 5px; flex-wrap: wrap; }
.day { width: 34px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
       background: var(--surface); font-size: 12px; font-weight: 600;
       color: var(--text-muted); cursor: pointer; }
.day.on { background: var(--brand-600); color: #fff; border-color: transparent; }

.say { background: var(--ink-900); color: #e8eef7; border-radius: 12px;
       padding: 13px 16px; font-size: 14px; line-height: 1.8; flex: none; }
.say b { color: #fff; }

/* The sentence, in the list and in the live preview. */
.sent { font-size: 14px; line-height: 1.85; margin: 3px 0 4px; }
.apill { display: inline-block; padding: 1px 8px; border-radius: 7px; font-weight: 650;
         font-size: 12.5px; margin: 0 1px; }
.pill-t { background: var(--brand-100); color: var(--brand-600); }
.pill-s { background: #fff4e0; color: #b4690e; }
.pill-d { background: #f1ebfe; color: #6b3fc9; }
.pill-c { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.row-item.faded .sent, .row-item.faded .row-title { opacity: .5; }

/* The enable toggle. */
.tgl { width: 42px; height: 24px; border-radius: 999px; background: var(--ink-200);
       border: 0; position: relative; flex: none; cursor: pointer; transition: background .15s; }
.tgl::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
              border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm);
              transition: left .15s; }
.tgl.on { background: var(--ok); }
.tgl.on::after { left: 21px; }
