:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfbfc;
  --line: #e3e6ea;
  --ink: #14171a;
  --ink-2: #5b6572;
  --ink-3: #8b95a3;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --live: #17994f;
  --live-bg: #e6f5ec;
  --talk: #d9822b;
  --talk-bg: #fdf0e2;
  --danger: #c3352b;
  --danger-bg: #fceceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 23, 26, 0.06), 0 4px 14px rgba(20, 23, 26, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1c2128;
    --line: #2a313a;
    --ink: #e8ecf1;
    --ink-2: #9aa5b1;
    --ink-3: #6e7a88;
    --accent: #4c8dff;
    --live: #3fb950;
    --live-bg: #122a1a;
    --talk: #e3a047;
    --talk-bg: #2e2417;
    --danger: #f0655a;
    --danger-bg: #2d1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

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

#login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

#login form {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.brand span { font-size: 12px; color: var(--ink-3); font-family: var(--mono); }
.sub { color: var(--ink-2); font-size: 13px; margin: 0 0 22px; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.field { margin-bottom: 14px; }

button.primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: default; }

.error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 13px;
  margin-bottom: 14px;
}

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

header.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
header.top .brand { margin: 0; }

.stats { display: flex; gap: 20px; margin-left: auto; flex-wrap: wrap; }
.stat { text-align: right; }
.stat b { display: block; font-size: 19px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }

.linkish {
  background: none;
  border: none;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
  padding: 0;
}

/* Households run the full width at the top; the supporting cards sit under
   them in two columns. */
main {
  display: grid;
  gap: 18px;
  padding: 18px 22px 60px;
  align-items: start;
}

.cols {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  align-items: start;
}

.col { display: grid; gap: 18px; align-content: start; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }

section.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
section.card > h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin: 0;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}
section.card > h2 button { margin-left: auto; }

.pad { padding: 14px 16px; }

/* channels */
.chan {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}
.chan:last-child { border-bottom: none; }
.chan .nm { font-weight: 600; font-size: 14px; }
.chan .meta { font-size: 12px; color: var(--ink-3); }
.chan .grow { flex: 1; min-width: 0; }
.tag {
  font-size: 10px;
  font-family: var(--mono);
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-3);
}

/* devices table */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  font-weight: 600;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.mono { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-3); }
.dot.on { background: var(--live); box-shadow: 0 0 0 3px var(--live-bg); }
.dot.talking { background: var(--talk); box-shadow: 0 0 0 3px var(--talk-bg); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.live { background: var(--live-bg); border-color: transparent; color: var(--live); font-weight: 600; }
.pill.talk { background: var(--talk-bg); border-color: transparent; color: var(--talk); font-weight: 600; }

select.assign { padding: 5px 8px; border-radius: 6px; min-width: 150px; }

button.ghost {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }

/* activity feed */
#feed { max-height: 320px; overflow-y: auto; font-family: var(--mono); font-size: 12px; }
#feed div { padding: 6px 16px; border-bottom: 1px solid var(--line); color: var(--ink-2); }
#feed div:first-child { color: var(--ink); }
#feed time { color: var(--ink-3); margin-right: 8px; }

.empty { padding: 26px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  padding: 22px;
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal p.note { margin: 0 0 18px; color: var(--ink-2); font-size: 13px; }
.row { display: flex; gap: 10px; margin-top: 6px; }
.row button { flex: 1; }

code.secret {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  word-break: break-all;
  margin: 8px 0 16px;
}

/* household tree */
.kid {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 6px 18px;
  font-size: 13px;
  color: var(--ink-2);
  border-left: 2px solid var(--line);
  margin-left: 3px;
}
.kid:first-of-type { margin-top: 8px; }
.kid .meta { color: var(--ink-3); font-size: 12px; }
.kid.parent-radio { color: var(--ink); font-weight: 500; }

button.mini-inline {
  margin-left: auto;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-3);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 11px;
  cursor: pointer;
}
button.mini-inline:hover { border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------- household cards */

.household-card {
  border-bottom: 1px solid var(--line);
  padding: 6px 0 10px;
}
.household-card:last-child { border-bottom: none; }

.household-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 8px;
}
.household-head .hname { font-weight: 600; font-size: 15px; }
.household-head .meta { font-size: 12px; color: var(--ink-3); }
.household-head .grow { flex: 1; min-width: 0; }

.urow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 30px;
  flex-wrap: wrap;
}
.urow:hover { background: var(--panel-2); }
.urow .grow { flex: 1; min-width: 140px; }
.urow .unm { font-size: 14px; }
.urow .meta { font-size: 12px; color: var(--ink-3); }
.urow select.assign { min-width: 130px; }
.urow button.ghost { padding: 4px 9px; font-size: 12px; }

.qr {
  display: block;
  margin: 4px auto 12px;
  width: 210px;
  height: 210px;
  border-radius: 10px;
  /* The symbol needs its own white ground regardless of the page theme. */
  background: #fff;
  padding: 6px;
}

/* The "optional, shown instead of First L." note beside a nickname field. */
.field label .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.6;
}

/* A household card collapses to its headline. The head is the hit target, so
   it gets a pointer and a caret that turns when the card is open. */
.household-head { cursor: pointer; user-select: none; }
.household-head:hover { background: var(--panel-2); }

.caret {
  display: inline-block;
  width: 12px;
  text-align: center;
  color: var(--ink-3);
  transition: transform 0.12s;
}

.caret.open { transform: rotate(90deg); }
