/* Design tokens: light, with a dark override. Carried over from the layout mockup. */
:root {
  --side: #f2f2f7; --pane: #ffffff; --line: #d8d8dc; --ink: #000000; --mute: #8a8a8e;
  --out: #0a7cff; --in: #e9e9eb; --sel: #0a7cff; --field: #e3e3e8; --rail: #e5e5ea;
  --tile-a: #0a7cff; --tile-b: #b4570a; --tile-c: #4f7a28; --bad: #d70015; --badge: #ff3b30;
  --av-top: #a5a9b3; --av-bottom: #84878f;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --side: #2c2c2e; --pane: #1c1c1e; --line: #3a3a3c; --ink: #ffffff; --mute: #98989d;
    --out: #0a84ff; --in: #3a3a3c; --sel: #0a84ff; --field: #3a3a3c; --rail: #232325;
    --tile-a: #0a84ff; --tile-b: #c76a1c; --tile-c: #5c8c30; --bad: #ff6961; --badge: #ff453a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--pane); color: var(--ink); font: 13px/1.35 var(--font); -webkit-text-size-adjust: 100%; }
svg { display: block; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input, textarea { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
[hidden] { display: none !important; }

.boot { padding: 24px; color: var(--mute); }

/* Window */
#app { height: 100%; }
.app { display: flex; height: 100vh; height: 100dvh; background: var(--pane); overflow: hidden; }
.app-banner { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 5; padding: 3px 12px; border-radius: 0 0 8px 8px; background: var(--field); color: var(--mute); font-size: 11px; }

/* Number rail */
.rail { width: 76px; flex: none; background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0 10px; overflow-y: auto; }
.tile { position: relative; width: 60px; padding: 8px 2px 6px; border-radius: 10px; text-align: center; font-size: 11px; line-height: 1.2; color: var(--mute); }
.tile b { display: block; width: 38px; height: 30px; line-height: 30px; margin: 0 auto 4px; border-radius: 8px; font-size: 11.5px; font-weight: 600; color: #fff; }
.tile.a b { background: var(--tile-a); }
.tile.b b { background: var(--tile-b); }
.tile.c b { background: var(--tile-c); }
.tile.on { background: var(--pane); color: var(--ink); }
.tile.log b { background: none; color: var(--mute); height: 22px; line-height: 22px; display: flex; align-items: center; justify-content: center; margin-bottom: 2px; }
.tile.log.on b { color: var(--sel); }
.tile span.lbl { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; border-radius: 8px; background: var(--badge); color: #fff; font-size: 10px; font-weight: 600; text-align: center; }
.rail .spacer { flex: 1; }
.rail-pills { display: none; }

/* Conversation list */
.side { width: 250px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 8px 12px; gap: 8px; }
.side-top strong { display: block; font-weight: 600; }
.side-top small { color: var(--mute); font-size: 11px; }
.side-top h1 { display: none; margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; }
.pencil { color: var(--sel); flex: none; padding: 4px; margin: -4px; border-radius: 6px; }
.search { display: block; margin: 0 10px 8px; padding: 3px 8px; border: 0; border-radius: 6px; background: var(--field); color: var(--ink); font-size: 12px; width: calc(100% - 20px); }
.search::placeholder { color: var(--mute); }
.rows { flex: 1; overflow-y: auto; padding: 0 6px; overscroll-behavior: contain; }
.row { position: relative; display: flex; gap: 8px; padding: 7px 8px 7px 14px; border-radius: 8px; width: 100%; color: inherit; text-decoration: none; }
.row.on { background: var(--sel); color: #fff; }
.dot { position: absolute; left: 3px; top: 20px; width: 8px; height: 8px; border-radius: 50%; background: var(--sel); }
.row.on .dot { background: #fff; }
.av { flex: none; width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(var(--av-top), var(--av-bottom)); color: #fff; font-size: 13px; font-weight: 500; display: flex; align-items: center; justify-content: center; }
.row-main { min-width: 0; flex: 1; }
.row-head { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.row-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { flex: none; font-size: 11px; color: var(--mute); }
.row-text { color: var(--mute); font-size: 12px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.row.on .row-time, .row.on .row-text { color: rgba(255, 255, 255, .85); }
.list-note { padding: 18px 14px; color: var(--mute); text-align: center; }
.more { display: block; margin: 6px auto 10px; padding: 4px 12px; border-radius: 12px; background: var(--field); color: var(--mute); font-size: 12px; }
.me { display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12px; }
.me .av { width: 24px; height: 24px; font-size: 10px; }
.me span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me button { color: var(--sel); font-size: 12px; }

/* Thread */
.thread { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--pane); position: relative; }
.thread-top { position: relative; text-align: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.thread-top .back { display: none; }
.thread-top .who { display: block; width: 100%; font-weight: 600; text-align: center; }
.thread-top .who:hover { color: var(--sel); }
.thread-top .who-edit { width: 70%; max-width: 320px; text-align: center; border: 1px solid var(--line); border-radius: 6px; background: var(--field); padding: 1px 6px; font-weight: 600; }
.thread-top .av { display: none; }
.thread-top small { color: var(--mute); font-size: 11px; display: block; }
.thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--mute); padding: 20px; text-align: center; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; padding: 10px 16px; overscroll-behavior: contain; }
.msgs > :first-child { margin-top: auto; }
.when { align-self: center; color: var(--mute); font-size: 11px; margin: 2px 0 8px; }
.b { position: relative; max-width: 74%; padding: 6px 11px; border-radius: 16px; line-height: 1.28; margin-bottom: 3px; overflow-wrap: anywhere; white-space: pre-wrap; flex: none; }
.b::before, .b::after { content: ""; position: absolute; bottom: -1px; height: 14px; }
.b.o { align-self: flex-end; background: var(--out); color: #fff; }
.b.o::before { right: -5px; border-right: 13px solid var(--out); border-bottom-left-radius: 11px 10px; transform: translateY(-1px); }
.b.o::after { right: -11px; width: 11px; background: var(--pane); border-bottom-left-radius: 7px; transform: translateY(-2px); }
.b.i { align-self: flex-start; background: var(--in); color: var(--ink); }
.b.i::before { left: -5px; border-left: 13px solid var(--in); border-bottom-right-radius: 11px 10px; transform: translateY(-1px); }
.b.i::after { left: -11px; width: 11px; background: var(--pane); border-bottom-right-radius: 7px; transform: translateY(-2px); }
/* Only the last bubble in a run keeps its tail. */
.b.notail::before, .b.notail::after { display: none; }
.by { align-self: flex-end; color: var(--mute); font-size: 11px; margin: 0 2px 10px; }
.by.left { align-self: flex-start; }
.by.bad { color: var(--bad); }
.by button { text-decoration: underline; text-underline-offset: 2px; color: inherit; }
.gap { height: 7px; flex: none; }
.older { align-self: center; flex: none; margin: 0 0 10px; padding: 4px 12px; border-radius: 12px; background: var(--field); color: var(--mute); font-size: 12px; }
.fresh { position: absolute; left: 50%; transform: translateX(-50%); bottom: 64px; padding: 5px 12px; border-radius: 14px; background: var(--sel); color: #fff; font-size: 12px; font-weight: 600; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.banner { margin: 0; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--side); color: var(--mute); text-align: center; font-size: 12px; }
.banner.bad { color: var(--bad); }

.compose { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px 10px; }
.box { flex: 1; min-width: 0; resize: none; max-height: 140px; border: 1px solid var(--line); border-radius: 16px; padding: 5px 12px; background: var(--pane); line-height: 1.3; overflow-y: auto; display: block; }
.box:disabled { background: var(--side); color: var(--mute); }
.send { flex: none; width: 26px; height: 26px; margin-bottom: 1px; border-radius: 50%; background: var(--out); color: #fff; display: flex; align-items: center; justify-content: center; }
.send:disabled { background: var(--field); color: var(--mute); cursor: default; }
.hint { padding: 0 16px 6px; color: var(--mute); font-size: 11px; text-align: right; margin-top: -4px; }
.hint.bad { color: var(--bad); text-align: left; }

/* New message */
.field { display: flex; gap: 6px; align-items: baseline; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.field > span { color: var(--mute); flex: none; }
.field input { flex: 1; min-width: 0; border: 0; background: none; padding: 0; }
.field .err { color: var(--bad); font-size: 12px; }
.err { color: var(--bad); }
.b .empty, .row-text.empty { opacity: .6; font-style: italic; }
.me-err { margin: 0; }
.new-top { display: grid; grid-template-columns: 70px 1fr 70px; align-items: center; padding: 10px 12px 8px; border-bottom: 1px solid var(--line); text-align: center; font-weight: 600; }
.new-top button { color: var(--sel); font-weight: 400; }
.new-top button:last-child { text-align: right; }

/* Admin screens: Activity and Setup */
.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--pane); overflow: auto; }
.admin-page { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.log-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.log-top strong { font-size: 14px; font-weight: 600; margin-right: auto; }
.pick { display: flex; align-items: center; gap: 4px; padding: 3px 9px; border: 0; border-radius: 6px; background: var(--field); color: var(--ink); font-size: 12px; white-space: nowrap; max-width: 100%; }
select.pick { appearance: auto; padding: 3px 6px; }
input.pick.cust { width: 150px; }
.pick input[type="date"] { border: 0; background: none; padding: 0; font-size: 12px; color: var(--ink); }
button.pick:disabled { opacity: .6; cursor: default; }
.ran { color: var(--mute); font-size: 12px; }
.admin-body { flex: 1; padding: 2px 14px 20px; }
.admin-body h2 { margin: 16px 0 6px; font-size: 13px; font-weight: 600; }
.admin-body p { margin: 4px 0; }
.log-scroll { overflow-x: auto; margin: 0 -8px; padding: 2px 0; }
.log-table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 12.5px; }
.log-table th { text-align: left; font-weight: 500; color: var(--mute); font-size: 11.5px; padding: 7px 8px 5px; white-space: nowrap; }
.log-table td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.log-table td.t { color: var(--mute); white-space: nowrap; }
.log-table td.t a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.log-table td.w, .log-table td.what { white-space: nowrap; }
.log-table .snip { color: var(--mute); }
.log-table .bad, .bad { color: var(--bad); }
.alert { padding: 8px 10px; border-radius: 8px; background: var(--field); margin: 10px 0 !important; }
.alert small { display: block; color: var(--mute); font-size: 11px; }
.checks, .nums, .texts { list-style: none; margin: 0; padding: 0; }
.checks li { padding: 5px 0; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.checks .mark { flex: none; width: 14px; font-weight: 700; }
.checks .ok .mark { color: var(--tile-c); }
.checks .bad .mark { color: var(--bad); }
.num { padding: 7px 0; border-top: 1px solid var(--line); }
.num-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.num-did { width: 120px; flex: none; }
.num-label { flex: 1; min-width: 120px; max-width: 260px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); }
.num-on { display: flex; gap: 5px; align-items: center; color: var(--mute); }
.num-note { font-size: 12px; margin: 4px 0 0 !important; }
.texts li { padding: 7px 0; border-top: 1px solid var(--line); }
.text-head, .text-seen { color: var(--mute); font-size: 11.5px; }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0; }
.texts .sent .text-body { color: var(--sel); }

/* Notifications */
.notify, .notify-note { margin: 0; padding: 6px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--mute); }
.notify-btn { color: var(--sel); font-size: 12px; font-weight: 600; }
.notify-btn:disabled { opacity: .6; cursor: default; }
.notify .notify-note { padding: 4px 0 0; border: 0; }
.notify-note.bad { color: var(--bad); }

/* Sign-in */
.login-page { display: flex; align-items: center; justify-content: center; background: var(--side); }
.login { width: min(340px, calc(100% - 32px)); background: var(--pane); border-radius: 14px; padding: 28px 24px; text-align: center; }
.login h1 { margin: 0 0 18px; font-size: 22px; }
.login-error { margin: 0 0 14px; color: var(--bad); }
.login-btn { display: block; padding: 10px 14px; border-radius: 10px; background: var(--out); color: #fff; font-size: 15px; font-weight: 600; text-decoration: none; }
.demo-people { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.demo-people .login-btn { width: 100%; }
.demo-note { color: var(--mute); font-size: 12px; margin: 14px 0 0; }

/* Phones: one screen at a time */
@media (max-width: 699px) {
  body { font-size: 15px; }
  .rail { display: none; }
  .side { width: 100%; border-right: 0; padding-top: env(safe-area-inset-top); }
  .thread { width: 100%; padding-top: env(safe-area-inset-top); }
  .app[data-screen="thread"] .side, .app[data-screen="new"] .side, .app[data-screen="admin"] .side { display: none; }
  .app[data-screen="list"] .thread { display: none; }
  .app[data-screen="admin"] .admin-main { padding-top: env(safe-area-inset-top); }
  .app[data-screen="list"] .admin-main { display: none; }
  .app[data-screen="thread"] .admin-main, .app[data-screen="new"] .admin-main { display: none; }
  .side-top { padding: 14px 14px 6px; }
  .side-top .titles { display: none; }
  .side-top h1 { display: block; }
  .rail-pills { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 14px 8px; }
  .pill { position: relative; padding: 5px 12px; border-radius: 15px; background: var(--field); font-size: 13px; font-weight: 500; }
  .pill.on { background: var(--sel); color: #fff; }
  .pill .count { top: -6px; right: -6px; }
  .search { margin: 0 14px 8px; width: calc(100% - 28px); font-size: 16px; padding: 6px 10px; }
  .rows { padding: 0 6px; }
  .row { padding: 9px 8px 9px 16px; }
  .av { width: 40px; height: 40px; font-size: 14px; }
  .row-text { font-size: 14px; }
  .row-time { font-size: 12px; }
  .me { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .log-top { padding: 10px 14px; }
  .num-did { width: 100%; }
  .num-label { max-width: none; font-size: 16px; }
  .pick { font-size: 14px; }
  input.pick.cust, select.pick, .pick input[type="date"], .field input, .who-edit { font-size: 16px; }
  .admin-body { padding: 2px 14px calc(20px + env(safe-area-inset-bottom)); }
  .thread-top { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; padding: 8px 8px 7px; }
  .thread-top .back { display: block; color: var(--sel); font-size: 30px; line-height: 1; text-align: left; padding: 0 0 4px 6px; }
  .thread-top .center { min-width: 0; }
  .thread-top .av { display: flex; width: 30px; height: 30px; font-size: 11px; margin: 0 auto 2px; }
  .b { max-width: 82%; }
  .box { font-size: 16px; }
  .compose { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .send { width: 32px; height: 32px; }
  .fresh { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

a.tile, a.pill, a.pencil, a.back { text-decoration: none; }
a.tile { display: block; }
a.pill { color: inherit; }
.linkish { text-decoration: underline; text-underline-offset: 2px; color: inherit; }
.admin-back { display: none; padding: 12px 14px 0; color: var(--sel); text-decoration: none; font-size: 15px; }
@media (max-width: 699px) { .admin-back { display: block; } }
.thread-empty p { max-width: 36ch; }

.first-run { display: flex; flex-direction: column; align-items: center; gap: 14px; }
