:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #1a2340;
  --line: #243055;
  --text: #e8ecf8;
  --muted: #8b96b8;
  --green: #22c55e;
  --green-2: #16a34a;
  --red: #ef4444;
  --red-2: #dc2626;
  --amber: #f59e0b;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }

.top {
  padding: 12px 18px 0; position: sticky; top: 0; z-index: 2;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; justify-content: space-between; max-width: 560px; margin: 0 auto; }
.tabs { display: flex; gap: 4px; max-width: 560px; margin: 10px auto 0; }
.tab {
  flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 9px 0 10px; font-weight: 600; position: relative;
}
.tab.on { color: var(--text); border-bottom-color: var(--green); }
.badge { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-left: 6px; vertical-align: middle; }
.me { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px #ef444422; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px #22c55e22; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; color: var(--muted); font-size: 14px; }

main { max-width: 560px; margin: 0 auto; padding: 18px 16px 40px; }
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 20px;
  text-align: center; margin-bottom: 18px;
}
.label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; display: flex; gap: 8px; align-items: center; justify-content: center; }
.caller { font-size: 30px; font-weight: 700; margin-top: 10px; letter-spacing: .3px; font-variant-numeric: tabular-nums; user-select: all; }
.place { color: var(--muted); min-height: 1.4em; }
.timer { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 6px; }
.actions { display: flex; gap: 14px; justify-content: center; margin-top: 22px; }
.btn {
  flex: 1; max-width: 200px; border: 0; border-radius: 14px; padding: 15px 10px;
  font-weight: 700; font-size: 17px; color: #fff;
}
.btn.answer { background: var(--green); }
.btn.answer:active { background: var(--green-2); }
.btn.hangup { background: var(--red); }
.btn.hangup:active { background: var(--red-2); }
.btn.vm, .btn.mute { background: #2a3558; }
.btn.mute.on { background: var(--amber); color: #111; }
.more { color: var(--amber); font-size: 14px; margin-top: 12px; min-height: 1em; }

.ring { border-color: #22c55e66; box-shadow: 0 0 0 0 #22c55e55; animation: glow 1.6s ease-out infinite; }
@keyframes glow { 0% { box-shadow: 0 0 0 0 #22c55e55; } 100% { box-shadow: 0 0 0 18px #22c55e00; } }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.talk { border-color: #22c55e44; }
.talk .timer { font-size: 22px; color: var(--text); }

.idle .hint { color: var(--muted); margin: 10px 0 0; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { background: #24304f; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; }

.meter { height: 6px; background: #0d1428; border-radius: 3px; overflow: hidden; margin: 14px auto 0; max-width: 320px; }
.meter-fill { height: 100%; width: 0; background: var(--green); border-radius: 3px; transition: width 90ms linear; }
.warn { color: var(--amber); font-size: 14px; margin: 10px 0 0; }
.mic-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.mic-row select {
  background: #0d1428; color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font: inherit; max-width: 240px; text-overflow: ellipsis;
}
.error { background: #ef44441a; border: 1px solid #ef444455; color: #fecaca; border-radius: 12px; padding: 10px 14px; font-size: 14px; }

.history h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; margin: 26px 4px 10px; }
#log { list-style: none; margin: 0; padding: 0; }
.ev { border-bottom: 1px solid var(--line); padding: 12px 4px; }
.ev-head { display: flex; align-items: baseline; gap: 10px; }
.ev-icon { width: 1.4em; text-align: center; }
.ev-title { font-weight: 600; flex: 1; font-variant-numeric: tabular-nums; }
.ev-time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ev-sub { color: var(--muted); font-size: 14px; margin-left: calc(1.4em + 10px); }
.ev-body { margin: 6px 0 0 calc(1.4em + 10px); white-space: pre-wrap; overflow-wrap: anywhere; }
.ev .copy { margin: 8px 0 0 calc(1.4em + 10px); }
.ev-rec { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 0 calc(1.4em + 10px); }
.ev-rec-label { color: var(--muted); font-size: 13px; }
.ev-rec audio { width: 100%; height: 36px; }
.empty { color: var(--muted); padding: 12px 4px; }

body.login { display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.login-card img { align-self: center; border-radius: 16px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card input {
  background: #0d1428; border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px;
  color: var(--text); font: inherit;
}
.login-card input:focus { outline: 2px solid #22c55e88; outline-offset: 1px; }
.login-card .btn { max-width: none; }

/* dialer */
.dialer { display: flex; gap: 8px; }
.dialer input {
  flex: 1; min-width: 0; background: #0d1428; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; color: var(--text); font: inherit; font-size: 18px; letter-spacing: .3px;
}
.dialer input:focus, .composer textarea:focus, #thread-to:focus { outline: 2px solid #22c55e88; outline-offset: 1px; }
.dialer .btn { flex: 0 0 auto; padding: 12px 16px; font-size: 16px; }
.idle .hint { margin-top: 14px; }

/* in-call keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 260px; margin: 16px auto 0; }
.keypad button { background: #24304f; border: 1px solid var(--line); border-radius: 12px; padding: 12px 0; font-size: 20px; font-weight: 600; }
.keypad button:active { background: #2f3d63; }
.dtmf { color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: 2px; min-height: 1.2em; margin-top: 8px; }
.talk .actions .btn { max-width: 150px; }

/* history actions */
.ev-actions { display: flex; gap: 8px; margin: 8px 0 0 calc(1.4em + 10px); }
.mini { background: #1c2644; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.mini:hover { color: var(--text); }

/* messages */
.row-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 4px 10px; }
.row-head h2 { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
#thread-list { list-style: none; margin: 0; padding: 0; }
.thread-item { border-bottom: 1px solid var(--line); padding: 12px 4px; cursor: pointer; }
.thread-item:hover { background: #ffffff06; }
.thread-item.unread-ish .ev-title::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 8px; vertical-align: middle; }
.thread-snippet { color: var(--muted); font-size: 14px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.thread-title { flex: 1; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
#thread-to {
  width: 100%; background: #0d1428; border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px;
  color: var(--text); font: inherit; margin-bottom: 10px;
}
.bubbles {
  display: flex; flex-direction: column; gap: 8px; max-height: calc(100dvh - 330px); min-height: 160px; overflow-y: auto;
  padding: 10px 2px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; overflow-wrap: anywhere; }
.bubble.in { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: #166534; border-bottom-right-radius: 5px; }
.bubble.out.failed { background: #7f1d1d; }
.bubble-text { white-space: pre-wrap; }
.bubble-meta { font-size: 11.5px; color: #ffffff99; margin-top: 4px; }
.bubble img { max-width: 100%; border-radius: 10px; margin-top: 6px; display: block; }
.bubble-file { color: inherit; display: block; margin-top: 6px; }
.bubble .copy { margin-top: 6px; }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.composer textarea {
  flex: 1; resize: none; background: #0d1428; border: 1px solid var(--line); border-radius: 14px; padding: 11px 14px;
  color: var(--text); font: inherit; line-height: 1.35; max-height: 160px;
}
.composer .btn { flex: 0 0 auto; padding: 11px 18px; font-size: 16px; }
.hint.small { font-size: 12.5px; color: var(--muted); margin: 10px 4px 0; }
#send-err { margin-top: 10px; }
