:root {
  --brand: #0f6e5a;
  --brand-2: #14917a;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66736e;
  --line: #e2e7e5;
  --out: #0f6e5a;
  --in: #e8edeb;
  --danger: #d0342c;
  --ok: #1e9e4a;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --card: #172019; --text: #e8eeeb; --muted: #93a19b;
    --line: #26322d; --in: #233029; --out: #14917a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer;
}
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { color: var(--danger); }
button.wide { width: 100%; margin-top: 12px; }
input, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 24px; }
h3 { font-size: 16px; margin-bottom: 10px; }

.screen { height: 100%; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 16px;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; }
.row input, .row select { flex: 1; min-width: 0; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 16px; }
.note { color: var(--muted); margin: 0; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

/* login */
#login { display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card label { text-align: left; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.logo { width: 64px; height: 64px; margin: 0 auto; }

/* layout */
#app { display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--brand); color: #fff;
}
.me-name { font-weight: 600; }
.me-number { font-size: 14px; opacity: .85; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #f0b429; box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.status-dot.ok { background: #4ade80; }
.status-dot.bad { background: #f87171; }
#views { flex: 1; overflow-y: auto; position: relative; }
.view { display: none; min-height: 100%; padding-bottom: 20px; }
.view.active { display: block; }
.view[data-view="thread"].active { display: flex; flex-direction: column; height: 100%; padding: 0; }
.view-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 8px; gap: 8px; }
.icon-btn { border: none; background: transparent; font-size: 22px; padding: 6px 10px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.list.compact li { padding: 10px 0; cursor: default; flex-wrap: wrap; }
.list li .grow { flex: 1; min-width: 0; }
.list li .title { font-weight: 600; }
.list li .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .meta { color: var(--muted); font-size: 13px; text-align: right; }
.list li.unread .title::after { content: ""; display: inline-block; width: 8px; height: 8px; background: var(--brand-2); border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--in); display: grid; place-items: center;
  font-weight: 600; color: var(--brand); flex-shrink: 0;
}
.missed .title { color: var(--danger); }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--in); color: var(--muted); }
.list.compact button, .list.compact select { padding: 6px 10px; font-size: 14px; }
select { font: inherit; padding: 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }

/* thread */
.thread-head { padding: 8px 8px; border-bottom: 1px solid var(--line); background: var(--card); }
.thread-to { border: none; background: transparent; font-weight: 600; padding: 6px; }
.bubbles { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: var(--in); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.out { background: var(--out); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; }
.stamp { font-size: 11px; color: var(--muted); align-self: center; margin: 8px 0 2px; }
.bubble-status { font-size: 11px; color: var(--muted); align-self: flex-end; margin-top: -2px; }
.bubble-status.failed { color: var(--danger); }
.composer { display: flex; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--card); }
.composer textarea { resize: none; max-height: 120px; border-radius: 20px; }
.send { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex-shrink: 0; align-self: flex-end; }

.from-row { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); background: var(--card); }
.from-row.center { justify-content: center; border: none; background: transparent; padding-top: 18px; }
.from-row select { flex: 0 1 auto; }
.notice { background: #fff6e0; color: #6b4e00; border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.notice ul { margin: 6px 0 0 18px; padding: 0; }
@media (prefers-color-scheme: dark) { .notice { background: #3a3014; color: #f3dc9b; } }
.line-tag { font-size: 12px; color: var(--muted); }
.flag { font-size: 18px; }

/* keypad */
.dial-display { display: flex; align-items: center; padding: 28px 24px 8px; }
.dial-display input { border: none; background: transparent; font-size: 30px; text-align: center; letter-spacing: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 300px; margin: 10px auto; }
.keypad button {
  aspect-ratio: 1; border-radius: 50%; font-size: 28px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1; border: none; background: var(--card);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.keypad button small { font-size: 10px; letter-spacing: 2px; color: var(--muted); margin-top: 3px; }
.keypad.small { max-width: 240px; gap: 10px; }
.keypad.small button { font-size: 22px; background: rgba(255,255,255,.12); color: #fff; box-shadow: none; }
.keypad.small button small { color: rgba(255,255,255,.6); }
.call-btn {
  display: block; margin: 16px auto; width: 72px; height: 72px; border-radius: 50%; border: none;
  background: var(--ok); color: #fff; font-size: 30px;
}

/* tabs */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: var(--safe-b); }
.tabs button {
  flex: 1; border: none; border-radius: 0; background: transparent; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; position: relative;
}
.tabs button span { font-size: 20px; }
.tabs button.active { color: var(--brand-2); font-weight: 600; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px); background: var(--danger); color: #fff;
  font-style: normal; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; line-height: 18px;
}

/* call overlay */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: linear-gradient(180deg, #0b4d40, #082e27);
  color: #fff; display: flex; flex-direction: column; align-items: center; padding: calc(60px + var(--safe-t)) 20px calc(40px + var(--safe-b));
}
.call-who { font-size: 30px; font-weight: 600; text-align: center; }
.call-state { opacity: .8; margin-top: 6px; }
.call-timer { font-variant-numeric: tabular-nums; margin-top: 4px; opacity: .9; }
.incoming-actions, .active-actions { margin-top: auto; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.incoming-actions { flex-direction: row; justify-content: space-around; max-width: 320px; }
.row-actions { display: flex; gap: 22px; }
.round {
  width: 70px; height: 70px; border-radius: 50%; border: none; font-size: 26px; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.round small { font-size: 11px; margin-top: 2px; }
.round.accept { background: var(--ok); }
.round.decline { background: var(--danger); }
.round.ghost { background: rgba(255,255,255,.14); }
.round.ghost.on { background: #fff; color: #0b4d40; }
.round.big { width: 76px; height: 76px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90%;
}

.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 44px; box-sizing: border-box; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: 0; padding: 6px 10px; font-size: 18px; cursor: pointer; opacity: .5; }
.pw-eye.on { opacity: 1; }
