/* Windows: devices, all rooms, room settings, scene editor and small questions.
   The same dialogs also become full pages (dialog.sheet.as-page, shell.css), so
   everything inside reads well at page width too. Keep selectors low here. */
.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--text);
  font-size: inherit;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--sheen), var(--sheet-lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in var(--med) var(--ease); }
.sheet.wide { width: min(820px, calc(100vw - 24px)); }
/* base.css .small is a button size; a small sheet is only narrower */
.sheet.small { width: min(420px, calc(100vw - 24px)); min-height: 0; }

.sheet::backdrop {
  background: rgba(4, 6, 11, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } }

.sheet-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 10px 24px;
}
.sheet-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 1.15rem; font-weight: 640; letter-spacing: -0.015em; }
.sheet-head .ghost { min-height: 34px; padding: 0 12px; color: var(--muted); font-size: 0.82rem; background: transparent; border-color: transparent; }
.sheet-head .ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); border-color: var(--line); }

.sheet-body { min-height: 0; padding: 6px 24px 24px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-body > h2 { margin: 6px 0 8px; font-size: 1.12rem; font-weight: 640; letter-spacing: -0.015em; }
.sheet.small .sheet-body { padding-top: 22px; }
.sheet.small .sheet-body > p { margin: 0; line-height: 1.5; }
.sheet .sheet-body .row.end { margin-top: 20px; }

/* Sections: a heading in ink, more air above than below, a hairline between */
.sheet section { margin: 0; }
.sheet-body > section + section, .sheet-body > section + .notice { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.sheet section > h3, .sheet-body > h3 {
  margin: 28px 0 10px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.sheet section > h3:first-child, .sheet-body > h3:first-child { margin-top: 0; }
.sheet .hint { max-width: 70ch; }
/* At page width a switch or a single field stays near its label */
.sheet-body > .hint + button { margin-top: 12px; }
.sheet-body > .row.between, .sheet-body > .toggle, .sheet section > .toggle, .device-body > .toggle, .device-body > .field, .device .fold .toggle { max-width: 640px; }
.sheet section > .hint:first-of-type { margin: 0 0 12px; }
.sheet input[type="text"], .sheet input[type="email"], .sheet input[type="password"] { margin-top: 8px; }
.sheet .row input[type="text"] { flex: 1 1 170px; width: auto; margin-top: 0; }
.sheet .field > input { margin-top: 5px; }
.short { flex: 0 1 150px !important; }

/* Tab moved elsewhere: a calm question with one way back */
.released .sheet-head { padding-top: 22px; }
.released p { margin: 0 0 20px; color: var(--muted); line-height: 1.55; }
.released-actions { display: flex; justify-content: flex-end; }

.notice {
  max-width: 80ch;
  margin: 0 0 16px;
  padding: 11px 14px;
  color: var(--warn);
  font-size: 0.86rem;
  line-height: 1.45;
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 26%, transparent);
  border-radius: var(--r-sm);
}

/* ---------- Status capsules ---------- */
.pill {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.pill::before { content: ""; flex: none; width: 7px; height: 7px; background: currentColor; border-radius: 50%; }
.pill.online { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: color-mix(in srgb, var(--ok) 24%, transparent); }
.pill.connecting { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 24%, transparent); }
.pill.connecting::before { animation: pill-wait 1.4s ease-in-out infinite; }
.pill.offline { color: var(--bad-ink); background: color-mix(in srgb, var(--bad) 10%, transparent); border-color: color-mix(in srgb, var(--bad) 26%, transparent); }
@keyframes pill-wait { 50% { opacity: 0.25; } }

.feedback { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.feedback[data-state="ok"] { color: var(--ok); }
.feedback[data-state="bad"] { color: var(--bad-ink); }
.feedback[data-state="pending"] { color: var(--warn); }

/* ---------- Device cards ---------- */
.device-list { display: grid; gap: 10px; }
.device-list > p.muted { margin: 0; font-size: 0.9rem; }
.device {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  padding: 14px 14px 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sheen);
  transition: border-color var(--fast), background var(--fast);
}
.device-list > .device { margin-bottom: 0; }
.device:hover { border-color: var(--edge-strong); }
/* Something is wrong: the whole card says so, quietly */
.device:has(> .device-heading .pill.offline) { background: color-mix(in srgb, var(--bad) 4%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 18%, var(--line)); }
.device:has(> .device-heading .pill.offline) .device-heading strong { color: color-mix(in srgb, var(--text) 82%, var(--bad-ink)); }

.device-heading { min-width: 0; gap: 12px; }
.device-heading > div:first-child { min-width: 0; }
.device-heading strong { display: block; font-size: 0.98rem; font-weight: 620; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.device-heading small.muted { margin-top: 2px; font-size: 0.78rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.device-title { min-width: 0; gap: 12px; }
.device-power { flex: 0 0 112px; margin-left: auto; }
.device-power .toggle { min-height: 34px; color: var(--muted); font-size: 0.82rem; }
.device-head-actions { display: inline-flex; flex: none; flex-direction: row-reverse; align-items: center; gap: 10px; }

/* The fold button draws its own chevron; the glyph text stays for assistive tech and tests */
.device-fold {
  position: relative;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  color: transparent;
  font-size: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  transition: background var(--fast), border-color var(--fast);
}
.device-fold::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -5px 0 0 -5px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform var(--med) var(--ease), border-color var(--fast);
}
.device-fold[aria-expanded="true"]::before { transform: translate(1px, -2px) rotate(45deg); }
.device-fold:hover { background: var(--surface-hover); border-color: var(--line); }
.device-fold:hover::before { border-color: var(--text); }
.device-fold:active { background: var(--surface-press); }

.device-body { display: grid; gap: 10px; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.device-body[hidden] { display: none; }
.device-body > .hint:first-child { margin: 0; font-variant-numeric: tabular-nums; }
.device-body > * { min-width: 0; }
.device-body .slider { margin-top: 4px; }
.device .row.wrap { margin-block: 2px; }
.device .primary { justify-self: start; }
.device .fold { margin-top: 2px; }
.device .fold[open] > summary { color: var(--text); }
.device .fold > :not(summary) { margin-bottom: 12px; }
.device-body .chip[aria-pressed] { min-height: 32px; }

/* Who is driving the LEDs right now. Cyan only for this app's own live stream. */
.stream-note {
  display: flex;
  align-items: baseline;
  gap: 10px;
  max-width: 80ch;
  padding: 9px 12px;
  font-size: 0.84rem;
  line-height: 1.45;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.stream-note::before { content: ""; flex: none; width: 7px; height: 7px; background: currentColor; border-radius: 50%; transform: translateY(-1px); }
.stream-note[data-kind="foreign"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); border-color: color-mix(in srgb, var(--warn) 22%, transparent); }
.stream-note[data-kind="own"] { color: var(--cyan); background: color-mix(in srgb, var(--cyan) 7%, transparent); border-color: color-mix(in srgb, var(--cyan) 22%, transparent); }
.stream-note[data-kind="overridden"] { color: var(--ok); background: color-mix(in srgb, var(--ok) 7%, transparent); border-color: color-mix(in srgb, var(--ok) 20%, transparent); }

/* Segments sit in wells, not cards, so nothing is a card inside a card */
.segment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 10px; margin-bottom: 4px; }
.segment { display: grid; align-content: start; gap: 2px; padding: 12px 14px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r-sm); }
.segment .fields { margin-top: 2px; }
.segment .fold { margin-top: 8px; }
.fields.three { grid-template-columns: 2fr 1fr 1fr; }
.fields.three input { margin: 0; }

.preset-list { display: grid; gap: 0; margin: 0 0 8px; padding: 0; font-size: 0.86rem; font-variant-numeric: tabular-nums; list-style: none; }
.preset-list li { min-height: 40px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.preset-list li:last-child { border-bottom: 0; }

.segments { width: 100%; margin-bottom: 8px; border-collapse: collapse; font-size: 0.8rem; }
.segments th { padding: 2px 4px; color: var(--muted); font-weight: 500; text-align: left; }
.segments td { padding: 2px 4px; }
.segments input { min-height: 30px; padding: 0 6px; font-size: 0.8rem; }
.segments td input[type="number"] { width: 72px; }

.hue-light-controls { align-items: center; gap: 8px 16px; }
.hue-light-controls .slider { flex: 1 1 220px; margin: 0; }
.hue-light-controls input[type="color"] { width: 40px; height: 32px; }
.hue-light { display: grid; gap: 6px; padding-block: 10px; border-top: 1px solid var(--line); }
.hue-light .hint { margin: 0; }

/* ---------- Zones in the room, finding and adding ---------- */
.zone-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 4px 16px; }
.zone-map > p { grid-column: 1 / -1; margin: 0; }
.zone-row { min-width: 0; }
.fold.tight { margin-top: 6px; border: 0; }
.fold.tight summary { padding: 4px 0; font-size: 0.78rem; }
.fold.tight .row { gap: 6px; }
.fold.tight input[type="number"] { min-height: 32px; padding: 0 8px; font-size: 0.82rem; }
.check { gap: 6px; font-size: 0.78rem; white-space: nowrap; }
.check input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--violet); }

.scan-results { max-width: 900px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 0.88rem; }
.scan-results li { min-height: 48px; margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.scan-results li:first-child { border-top: 1px solid var(--line); }
.scan-results li small { font-variant-numeric: tabular-nums; }

.follow-list { display: grid; gap: 0; }
.follow-list > .toggle { padding-block: 6px; border-bottom: 1px solid var(--line); }
.follow-list > .toggle:last-child { border-bottom: 0; }
.editor-room { padding: 2px 0 6px; border-bottom: 1px solid var(--line); }

/* ---------- More lights: a tile per brand, and the connected lights ---------- */
.brand-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  margin-block: 12px 16px;
}
.brand-tile {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 550;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sheen);
  transition: background var(--fast), border-color var(--fast), transform var(--fast) var(--ease);
}
.brand-tile:hover { background: var(--surface-hover); border-color: var(--edge-strong); }
.brand-tile:active { background: var(--surface-press); transform: scale(0.97); }

/* The brand's name carries the tile; its letter mark is reduced to a quiet colour dot */
.brand-mark {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  overflow: hidden;
  font-size: 0;
  background: color-mix(in srgb, var(--brand) 70%, var(--muted));
  border-radius: 50%;
}
.brand-tile .brand-mark { display: none; }
.net-light .device-body > .fields { margin-top: -6px; }

.found-lights { display: grid; gap: 6px; }
.found-light { min-height: 48px; padding: 6px 8px 6px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); }
.connect-form { display: grid; gap: 4px; }
.connect-form .remember { margin-top: 10px; color: var(--muted); font-size: 0.8rem; white-space: normal; }

/* ---------- Phones ---------- */
@media (max-width: 1100px) {
  .device-fold { width: 40px; height: 40px; }
  .device-power .toggle, .check { min-height: 40px; }
  .preset-list li .mini, .scan-results li .mini, .device .mini { min-height: 36px; }
}

@media (max-width: 560px) {
  .sheet-head { padding: 16px 14px 8px 18px; }
  .sheet-body { padding: 4px 18px 20px; }
  .device { padding: 12px 12px 12px 14px; }
  .device-heading { flex-wrap: wrap; row-gap: 4px; }
  .device-heading > div:first-child { flex: 1 1 0; }
  .device-power { flex: 1 0 100%; order: 3; margin-left: 0; }
  .device-power .toggle { justify-content: flex-start; }
  .fields.three { grid-template-columns: 1fr 1fr; }
  .fields.three > :first-child { grid-column: 1 / -1; }
  .brand-tiles { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  .brand-tile { min-height: 88px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .pill.connecting::before { animation: none; }
  .brand-tile:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .sheet { background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .sheet::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
