:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --fg: #1b2230;
  --muted: #5d6678;
  --line: #dde2ea;
  --accent: #1f6feb;
  --accent-fg: #ffffff;
  --green: #1a7f37;
  --red: #cf222e;
  --amber: #9a6700;
  --key: #eef1f5;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #181c22;
    --fg: #e7eaef;
    --muted: #9aa3b2;
    --line: #2a3039;
    --accent: #4c8dff;
    --green: #2ea043;
    --red: #f85149;
    --amber: #d29922;
    --key: #222831;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { max-width: 400px; margin: 0 auto; padding: 12px 16px 24px; }
[hidden] { display: none !important; }
svg { display: block; }

/* header */
.bar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: 8px; }
.who { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.who-sub { font-size: 12px; font-weight: 400; color: var(--muted); }
.bar-actions { display: flex; gap: 4px; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.bad { background: var(--red); }

/* basics */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; }
label.check input { width: auto; margin: 0; }
input, select { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; }
details { margin-bottom: 12px; font-size: 13px; color: var(--muted); }
summary { cursor: pointer; margin-bottom: 8px; }

button { font: inherit; color: var(--fg); background: var(--key); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; min-height: 40px; }
button:hover:not(:disabled) { filter: brightness(0.96); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.wide { width: 100%; }
button.text { background: none; border: 0; color: var(--accent); padding: 8px; }
button.icon { background: none; border: 0; padding: 8px; min-width: 40px; display: grid; place-items: center; }
button.icon svg { width: 22px; height: 22px; fill: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 0; min-width: 72px; }

/* round buttons: call, hang up, answer */
button.round { width: 60px; height: 60px; min-height: 0; padding: 0; border-radius: 50%; display: grid; place-items: center; border: 0; }
button.round svg { width: 28px; height: 28px; fill: #fff; }
button.call, button.answer { background: var(--green); }
button.end { background: var(--red); }

.notice { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--amber); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.setup { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.setup button { text-align: left; background: var(--card); border-left: 4px solid var(--accent); font-size: 14px; }

/* tabs */
.tabs { display: flex; gap: 4px; background: var(--key); border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: none; min-height: 34px; border-radius: 7px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; margin-left: 4px; }

/* dial pad */
.dial-label { font-size: 13px; color: var(--accent); font-weight: 600; text-align: center; margin-bottom: 6px; }
.number { font-size: 26px; text-align: center; letter-spacing: 0.04em; margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-height: 52px; }
.number:hover { border-color: var(--muted); }
.number:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.number::placeholder { color: var(--muted); }
.number.tones { color: var(--accent); border-color: var(--accent); }
.pad { display: grid; grid-template-columns: repeat(3, 64px); justify-content: center; gap: 12px 26px; margin: 10px 0 14px; }
.pad button { width: 64px; height: 64px; min-height: 0; padding: 0; border-radius: 50%; border: 0; font-size: 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pad button small { font-size: 9px; letter-spacing: 0.14em; color: var(--muted); margin-top: 2px; min-height: 10px; }
.dial-actions { display: grid; grid-template-columns: repeat(3, 64px); justify-content: center; gap: 0 26px; align-items: center; }
.dial-actions > * { justify-self: center; }
.dial-actions button.round { width: 64px; height: 64px; }
.call-caption { text-align: center; font-size: 12px; color: var(--muted); min-height: 18px; margin-top: 4px; }

/* call cards */
.call-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; }
.call-card.incoming { border-color: var(--green); box-shadow: 0 0 0 2px color-mix(in srgb, var(--green) 30%, transparent); }
.call-card.held { background: color-mix(in srgb, var(--amber) 6%, var(--card)); }
.conf-label { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin: 4px 0 6px; }
.call-top { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--key); color: var(--muted); display: grid; place-items: center; font-weight: 600; flex: none; }
.avatar svg { width: 22px; height: 22px; fill: var(--muted); }
.call-id { min-width: 0; flex: 1; }
.call-name { font-weight: 600; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-state { font-size: 14px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.call-state.live { color: var(--green); font-weight: 600; }
.call-state.hold { color: var(--amber); font-weight: 600; }
.ctrls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.ctl { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; min-height: 0; font-size: 12px; color: var(--muted); }
.ctl .disc { width: 48px; height: 48px; border-radius: 50%; background: var(--key); display: grid; place-items: center; }
.ctl svg { width: 22px; height: 22px; fill: var(--fg); }
.ctl.on .disc { background: var(--accent); }
.ctl.on svg { fill: var(--accent-fg); }
.ctl.on { color: var(--accent); font-weight: 600; }
.ctl:hover:not(:disabled) .disc { filter: brightness(0.95); }
.ctl:hover:not(:disabled) { filter: none; }
.end-row { display: flex; justify-content: center; gap: 48px; margin-top: 14px; }
.end-row .labelled { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.call-card .wide + .end-row, .call-card .primary { margin-top: 12px; }
.sub { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

/* recents */
.recents { padding: 12px 8px; }
.recents-head { display: flex; justify-content: space-between; align-items: center; padding: 0 8px 6px; }
#recents-list { list-style: none; margin: 0; padding: 0; }
.rec { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; border-radius: 8px; padding: 8px; text-align: left; min-height: 52px; }
.rec:hover:not(:disabled) { background: var(--key); filter: none; }
.rec svg { width: 18px; height: 18px; fill: var(--muted); flex: none; }
.rec.missed svg { fill: var(--red); }
.rec-id { flex: 1; min-width: 0; }
.rec-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec.missed .rec-name { color: var(--red); }
.rec-sub { font-size: 12px; color: var(--muted); }
.rec-when { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
#recents-empty { padding: 8px; margin: 0; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--fg); padding: 18px; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin-bottom: 10px; }
dialog .row { margin-top: 8px; }
