/* The frame of the app: colour tokens for light and dark, type, the header,
   the tab bar, buttons, forms, cards, sheets and messages. One accent (a
   deep teal, unlike Home Assistant's blue, so our panel reads as ours inside
   it) for actions and "on"; red only for danger. */

:root {
  color-scheme: light dark;
  --bg: #f2f4f5;
  --surface: #ffffff;
  --surface-2: #e8ecee;
  --surface-3: #d5dcdf;
  --line: #d9dfe2;
  --text: #13181b;
  --text-2: #4a555c;
  --text-3: #66737a;
  --accent: #0a6c70;
  --accent-strong: #075659;
  --accent-soft: #d6eded;
  --on-accent: #ffffff;
  --ok: #18774a;
  --ok-soft: #dcf1e5;
  --warn: #8a5300;
  --warn-soft: #fbedd5;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --on-danger: #ffffff;
  --glow: #ffcd6b;
  --shadow: 0 1px 2px rgb(16 24 32 / 6%), 0 2px 10px rgb(16 24 32 / 5%);
  --radius: 14px;
  --radius-s: 10px;
  --bar-h: 56px;
  --tabs-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1214;
    --surface: #171c1f;
    --surface-2: #20272b;
    --surface-3: #313a40;
    --line: #283035;
    --text: #e6ebee;
    --text-2: #a7b2b8;
    --text-3: #87949b;
    --accent: #52c3be;
    --accent-strong: #74d3cf;
    --accent-soft: #143b3b;
    --on-accent: #042322;
    --ok: #62d399;
    --ok-soft: #133122;
    --warn: #f0b552;
    --warn-soft: #382a10;
    --danger: #ff8b80;
    --danger-soft: #3d1815;
    --on-danger: #2b0603;
    --glow: #f4b94e;
    /* Elevation in the dark is a lighter surface, not a shadow. */
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--surface-3) transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, textarea { caret-color: var(--accent); }
h1, h2, h3, p { overflow-wrap: anywhere; }
[hidden] { display: none !important; }
/* Words for screen readers only: who speaks in the chat, what a reading is. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-lg { width: 40px; height: 40px; stroke-width: 1.5; }

/* The frame. */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
/* Which hub this is, over the page's title: one tap opens the switcher
   (hubs.js). Small enough that the title keeps the line on a phone. */
.bar-head {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.bar-hub {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  align-self: flex-start;
  max-width: 100%;
  min-height: 22px;
  margin: 0 0 0 -4px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: 600 13px/1.2 var(--font);
  cursor: pointer;
}
.bar-hub:hover { background: var(--accent-soft); }
.bar-hub-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-s { width: 16px; height: 16px; }
.bar-title {
  margin: 0;
  min-width: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-actions { margin-left: auto; display: flex; align-items: center; }
.path-chip {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--line);
}
.path-chip.path-lan { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.path-chip.path-relay { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }

.live-dot {
  width: 10px;
  height: 10px;
  margin: 0 12px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background-color 0.2s;
}
.live-dot[data-state="live"] { background: var(--ok); }
.live-dot[data-state="reconnecting"] { background: var(--warn); }
.live-dot[data-state="stale"] { background: var(--danger); }

.main {
  max-width: 1040px;
  margin: 0 auto;
  /* --toasts-h (toast.js): the foot of the page stays clear of the toasts. */
  padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--tabs-h) + env(safe-area-inset-bottom) + 28px + var(--toasts-h, 0px)) max(16px, env(safe-area-inset-left));
  outline: none;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .icon { stroke-width: 2.2; }

body:not(.signed-in) .bar,
body:not(.signed-in) .tabs { display: none; }
body:not(.signed-in) .main { padding-bottom: 32px; }

.banners { max-width: 1040px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
}
.banner > p { flex: 1 1 200px; margin: 0; }
.banner > .icon { color: var(--accent); }
.banner-error { background: var(--danger-soft); }
.banner-error > .icon { color: var(--danger); }
.banner-actions { display: flex; gap: 8px; margin-left: auto; }

.live-pill {
  position: fixed;
  top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px);
  left: 50%;
  z-index: 25;
  width: max-content;
  max-width: min(92vw, 520px);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 18%);
}

/* Buttons. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-s);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn .icon { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); color: var(--on-danger); }
.btn.danger-quiet { background: var(--danger-soft); color: var(--danger); }
.btn.small { padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }
.page-actions { margin-bottom: 12px; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.icon-btn.primary { background: var(--accent); color: var(--on-accent); }
.icon-btn.round { border-radius: 50%; background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.45; cursor: default; }

@media (hover: hover) {
  .btn.primary:not(:disabled):hover, .icon-btn.primary:not(:disabled):hover { background: var(--accent-strong); }
  .btn.secondary:not(:disabled):hover, .icon-btn.round:not(:disabled):hover { background: var(--surface-3); }
  .icon-btn:not(.primary):not(.round):not(:disabled):hover { background: var(--surface-2); }
}

.badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: var(--on-danger);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.badge.inline { position: static; }

/* Forms. */

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16 px keeps iOS from zooming into a field */
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"], input[type="radio"] {
  width: 22px;
  height: 22px;
  min-height: 0;
  margin: 1px 0 0;
  padding: 0;
  flex: none;
  accent-color: var(--accent);
}
input[readonly] { background: var(--surface-2); }

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span:first-child { font-size: 14px; font-weight: 600; color: var(--text-2); }
.form-error { margin: 0; color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }
.check, .radio {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 10px 0;
  cursor: pointer;
}
.check > span, .radio > span { display: flex; flex-direction: column; gap: 2px; }
.check.small { min-height: 44px; padding: 10px 0; font-size: 14px; }
.hint { color: var(--text-2); font-size: 13px; margin: 0; }
.muted { color: var(--text-2); margin: 0; }
.center { text-align: center; }

/* Surfaces. */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.block { margin-bottom: 24px; }
.block-title { margin: 8px 2px 10px; font-size: 17px; font-weight: 650; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 10px; }
.stack-s > p { margin: 0; }
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 16px;
  color: var(--text-2);
  text-align: center;
}
.empty > p { max-width: 38ch; margin: 0; }
.note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 14px;
}
.note > .icon { color: var(--text-2); width: 20px; height: 20px; }

/* Sheets. */

dialog.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: auto;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--text);
}
dialog.sheet::backdrop { background: rgb(6 10 12 / 55%); }
.sheet-title { margin: 0 0 8px; font-size: 19px; font-weight: 650; }
.sheet-body { margin: 0 0 8px; color: var(--text-2); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sheet-actions > :only-child { grid-column: 1 / -1; }
@media (min-width: 600px) {
  dialog.sheet { margin: auto; border-radius: 18px; padding-bottom: 20px; }
}

/* Messages. */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 480px);
  transform: translateX(-50%);
  pointer-events: none;
}
body:not(.signed-in) .toasts { bottom: calc(16px + env(safe-area-inset-bottom)); }
/* On the chat page messages rise above the composer, not over it. */
body:has(.composer) .toasts { bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 84px); }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
  pointer-events: auto;
}
.toast .icon { width: 20px; height: 20px; }
.toast-error { background: var(--danger); color: var(--on-danger); }
/* A notice's own button ("show the fresh data") takes the notice's colour:
   the page's button colours vanish on its background. */
.toast:has(.toast-action) { flex-wrap: wrap; }
.toast > span { flex: 1 1 70%; }
.toast .toast-action {
  flex: none;
  margin-left: 30px;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  white-space: nowrap;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .toast { animation: fade-up 0.18s ease-out; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fade-up { from { transform: translateY(8px); opacity: 0.6; } to { transform: none; opacity: 1; } }
