:root {
  color-scheme: light dark;
  --bg: #f3f5f8; --panel: #ffffff; --text: #181c20; --muted: #5d6873; --line: #dde2e8;
  --accent: #1f6feb; --on: #f2a900; --good: #1a7f37; --bad: #b42318; --warn: #9a6700;
  --tone-orange: #c2480a; --tone-yellow: #9a6700; --star: #f2a900;
  --nav-h: 62px; --rail-w: 92px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1215; --panel: #1a1e23; --text: #e8ebee; --muted: #98a3ae; --line: #2b3239;
          --accent: #4c8dff; --on: #f2b632; --good: #3fb950; --bad: #f85149; --warn: #d29922;
          --tone-orange: #ff7a30; --tone-yellow: #f2d032; --star: #f2b632; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

#shell { min-height: 100%; display: flex; flex-direction: column; }
#top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); }
#top h1 { margin: 0; font-size: 22px; flex: 1; }
#back { background: none; border: 0; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); cursor: pointer; }
.age { color: var(--muted); font-size: 13px; }
.status { margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.status.bad { border-color: var(--bad); color: var(--bad); }
.status.warn { border-color: var(--warn); }
#main { flex: 1; padding: 4px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transition: opacity .2s; }
#main.stale { opacity: .55; }

/* navigation: bottom bar on phones, left rail on tablets */
#nav { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; display: flex; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line);
       padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 2px; }
#nav a { flex: 1 0 64px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 10px; color: var(--muted); font-size: 11px; }
#nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.nav-icon { font-size: 22px; line-height: 1.1; }
@media (min-width: 900px) {
  #shell { padding-left: var(--rail-w); }
  #nav { right: auto; top: 0; width: var(--rail-w); flex-direction: column; overflow-y: auto; border-top: 0; border-right: 1px solid var(--line); padding: calc(12px + env(safe-area-inset-top)) 6px 12px; }
  #nav a { flex: 0 0 auto; }
  #main { padding-bottom: 32px; max-width: 1400px; }
}

/* sections and tiles */
.section { margin: 0 0 22px; }
.section h2 { margin: 0 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.group { margin-bottom: 18px; }
.group h3 { margin: 0 0 8px; font-size: 17px; }
.hint { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.grid.rooms { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }

.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; min-height: 96px; }
.tile.on { border-color: var(--on); box-shadow: inset 0 0 0 1px var(--on); }
.tile.secure { border-style: dashed; }
.tile-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; height: 100%; padding: 12px 40px 12px 12px; background: none; border: 0; text-align: left; cursor: pointer; border-radius: 14px; }
.tile-main .art { margin: 0 0 6px; }
.details-art { display: flex; justify-content: center; padding: 10px 0 18px; }
.tile-name { font-weight: 600; overflow-wrap: anywhere; }
.tile-state { font-size: 20px; }
.tile.on .tile-state { color: var(--on); }
.tile-meta { color: var(--muted); font-size: 12px; margin-top: auto; }
.star { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.star[aria-pressed="true"] { color: var(--on); }
.star:disabled { opacity: .5; }
.room { display: flex; flex-direction: column; gap: 4px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; min-height: 84px; }
.room-name { font-weight: 600; }
.room-count { color: var(--muted); font-size: 13px; }

/* a tile highlighted in its glow's colour */
.tile.tone-blue { --on: var(--accent); }
.tile.tone-green { --on: var(--good); }
.tile.tone-red { --on: var(--bad); }
.tile.tone-deep-orange { --on: var(--tone-orange); }
.tile.tone-yellow { --on: var(--tone-yellow); }
.tile[class*="tone-"] .star[aria-pressed="true"] { color: var(--star); }

/* status chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip { flex: 0 0 auto; display: flex; flex-direction: column; padding: 8px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; min-width: 96px; }
.chip-label { font-size: 12px; color: var(--muted); }
.chip-value { font-weight: 600; font-size: 17px; }
.chip.good .chip-value { color: var(--good); }
.chip.armed { border-color: var(--tone-orange); }
.chip.armed .chip-value { color: var(--tone-orange); }
.chip.warn { border-color: var(--tone-yellow); }
.chip.warn .chip-value { color: var(--tone-yellow); }
.chip.bad { border-color: var(--bad); }
.chip.bad .chip-value { color: var(--bad); }

/* settings */
.settings { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.setting { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-name { display: flex; align-items: center; gap: 6px; }
.setting-move button { width: 40px; height: 40px; margin-left: 4px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; font-size: 18px; cursor: pointer; }
.setting-move button:disabled { opacity: .35; }
input[type="checkbox"] { width: 22px; height: 22px; }

/* details */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); width: min(520px, calc(100% - 24px)); padding: 18px; max-height: calc(100vh - 32px); overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 10px; font-size: 19px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: 14px; }
.actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; }

/* assistant */
.assistant { max-width: 720px; display: flex; flex-direction: column; gap: 12px; }
.assistant .status { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.assistant .hint { margin: 0; }
.row-buttons button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.say { max-width: 90%; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); align-self: flex-start; }
.say.user { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.say p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.say .did { margin-top: 6px; font-size: 13px; color: var(--good); }
.ask { display: flex; gap: 8px; align-items: flex-end; }
.ask textarea { flex: 1; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); resize: vertical; }
.ask .primary:disabled { opacity: .5; }
.link-row { background: none; border: 0; padding: 8px 0; text-align: left; flex: 1; cursor: pointer; overflow-wrap: anywhere; }

/* wall tablets in landscape: bigger touch targets */
@media (min-width: 900px) and (orientation: landscape) { body { font-size: 17px; } .tile { min-height: 110px; } }

/* sign-in */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.login h1 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.login input { font: inherit; font-size: 17px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.login-error { min-height: 1.4em; margin: 0; color: var(--bad); font-size: 14px; }
.login .primary { padding: 12px; font-size: 17px; }
.login .primary:disabled { opacity: .6; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.secondary { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; cursor: pointer; }

/* the hidden attribute must always win over layout rules (e.g. #shell is a flex box) */
[hidden] { display: none !important; }

.login-remote { margin: 0; padding: 12px; border-radius: 10px; border: 1px solid var(--warn); font-size: 15px; }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }

.primary-link { display: block; text-align: center; background: var(--accent); color: #fff; border-radius: 10px; padding: 12px; font-size: 17px; }
