:root {
  --bg: #0f1720; --panel: #17212c; --panel-2: #1f2b38; --line: #2a3846;
  --text: #e8eef4; --muted: #8a9bab; --accent: #2f9e6e; --accent-2: #38b47f;
  --out: #2f7fd1; --in: #243241; --red: #d9473f; --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.error { color: #ff8a80; min-height: 1.2em; font-size: 14px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo { font-size: 44px; width: 84px; height: 84px; margin: 0 auto 8px; border-radius: 24px;
  display: grid; place-items: center; background: var(--accent); }
.login-card form { display: grid; gap: 10px; margin-top: 20px; }
.login-card input, .search input { width: 100%; padding: 14px 16px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); outline: none; }
.btn { padding: 13px 16px; border-radius: 14px; background: var(--panel-2); width: 100%; margin-top: 8px; }
.btn.primary { background: var(--accent); font-weight: 600; }
.btn.danger { color: #ff8a80; } .btn.ghost { background: transparent; }

/* layout */
#app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.topbar h1 { margin: 0; font-size: 26px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.pill.ok { background: rgba(47,158,110,.18); color: #6fd6a4; }
.pill.bad { background: rgba(217,71,63,.18); color: #ff8a80; }
.view { flex: 1; overflow-y: auto; position: relative; }
.search { padding: 4px 16px 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:active { background: var(--panel); }
.avatar { flex: 0 0 44px; height: 44px; border-radius: 50%; background: var(--panel-2); display: grid; place-items: center; font-weight: 600; }
.li-main { flex: 1; min-width: 0; }
.li-top { display: flex; justify-content: space-between; gap: 8px; }
.li-name { font-weight: 600; } .li-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.li-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li.unread .li-name::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--out); margin-left: 6px; vertical-align: middle; }
.li-call { font-size: 20px; padding: 6px; }
.missed .li-name { color: #ff8a80; }
.empty { text-align: center; padding: 40px 24px; color: var(--muted); }
.fab { position: fixed; right: 18px; bottom: calc(84px + var(--safe-b)); width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); font-size: 24px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line);
  background: var(--panel); padding-bottom: var(--safe-b); }
.tabs button { padding: 8px 0 10px; display: grid; justify-items: center; font-size: 20px; color: var(--muted); position: relative; }
.tabs button span { font-size: 11px; margin-top: 2px; }
.tabs button.active { color: var(--accent-2); }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--red); color: #fff; font-size: 11px;
  font-style: normal; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: grid; place-items: center; }

/* thread */
.thread { display: flex; flex-direction: column; overflow: hidden; }
.thread-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.thread-who { flex: 1; min-width: 0; display: grid; }
.thread-who input { background: transparent; border: 0; outline: none; font-weight: 600; font-size: 17px; padding: 4px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; cursor: pointer; }
.icon-btn.call { font-size: 18px; }
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 80%; padding: 9px 13px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 6px; }
.bubble.in { align-self: flex-start; background: var(--in); border-bottom-left-radius: 6px; }
.bubble a { color: inherit; }
.bubble img, .bubble video { display: block; max-width: 100%; border-radius: 12px; margin-bottom: 4px; }
.file-chip { display: flex; width: fit-content; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.12); text-decoration: none; margin-bottom: 4px; }
.meta { font-size: 11px; color: var(--muted); align-self: flex-end; margin: -2px 4px 4px; }
.meta.in { align-self: flex-start; } .meta.fail { color: #ff8a80; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px; background: var(--bg); border: 1px solid var(--line); outline: none; }
.send { width: 42px; height: 42px; border-radius: 50%; background: var(--out); font-size: 18px; }
.send:disabled { opacity: .5; }
.docs-toggle { display: flex; gap: 6px; align-items: center; padding: 4px 12px calc(6px + var(--safe-b)); background: var(--panel); }
.attach-tray { display: flex; gap: 8px; padding: 8px; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); }
.att { position: relative; flex: 0 0 auto; width: 72px; height: 72px; border-radius: 12px; background: var(--panel-2);
  display: grid; place-items: center; font-size: 11px; text-align: center; overflow: hidden; padding: 4px; }
.att img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.att button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.7); font-size: 11px; z-index: 2; }
.att .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent-2); z-index: 2; }

/* calls: history / recordings */
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; margin: 4px 16px 10px; background: var(--panel); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px; border-radius: 10px; color: var(--muted); font-size: 14px; }
.seg button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.rec-bar { display: flex; gap: 6px; padding: 0 16px 8px; }
.rec-bar input { flex: 1; padding: 11px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); outline: none; }
.rec { flex-wrap: wrap; cursor: default; }
.rec .li-call { width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2); font-size: 16px; display: grid; place-items: center; text-decoration: none; }
.rec .player { flex-basis: 100%; }
.rec .player audio { width: 100%; height: 40px; margin-top: 6px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.rec-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* keypad */
.keypad-view { display: flex; flex-direction: column; align-items: center; padding: 20px 16px; gap: 14px; }
.dial-number { width: 100%; max-width: 340px; text-align: center; font-size: 30px; background: transparent; border: 0; outline: none; letter-spacing: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 22px; justify-content: center; }
.key { width: 76px; height: 76px; border-radius: 50%; background: var(--panel-2); display: grid; place-content: center; font-size: 28px; line-height: 1; }
.key small { font-size: 10px; color: var(--muted); letter-spacing: 2px; margin-top: 2px; }
.dial-actions { display: grid; grid-template-columns: repeat(3, 76px); gap: 22px; justify-content: center; }
.dial-actions #dialBtn { grid-column: 2; }
.round { width: 72px; height: 72px; border-radius: 50%; font-size: 26px; display: grid; place-content: center; justify-items: center; }
.round small { font-size: 11px; margin-top: 4px; }
.green { background: var(--accent); } .red { background: var(--red); } .ghost { background: var(--panel-2); }
.ghost.on { background: #e8eef4; color: #0f1720; }

/* call screen */
.call-screen { position: fixed; inset: 0; z-index: 50; background: linear-gradient(180deg, #13202d, #0a1016);
  display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 70px 20px calc(50px + var(--safe-b)); }
.call-top { text-align: center; } .call-top h2 { font-size: 32px; margin: 8px 0; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.call-actions { display: flex; gap: 40px; }
.small-pad .key { width: 64px; height: 64px; font-size: 24px; }
.small-pad { grid-template-columns: repeat(3, 64px); }

/* sheet + toast (old) */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; display: flex; align-items: flex-end; }
.sheet-card { width: 100%; background: var(--panel); border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + var(--safe-b)); }
.sheet-card h3 { margin: 0 0 6px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: #e8eef4; color: #0f1720;
  padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: 90%; font-size: 14px; }

@media (min-width: 900px) {
  #app { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .fab { right: calc(50% - 242px); }
}

/* ---- lines, templates, voicemail, panels ---- */
.pad { padding: 8px 16px; } .stack { display: grid; gap: 10px; }
.line-chip { color: #6cb6ff; font-size: 15px; padding: 6px 10px; border-radius: 10px; display: inline-flex; align-items: center; gap: 6px; }
.line-chip::after { content: "⇅"; font-size: 13px; opacity: .8; }
.line-chip.small { font-size: 12px; padding: 0 4px; justify-self: start; }
.greet { font-size: 22px; font-weight: 700; margin: 4px 0 0; }
.tabs .center b { font-size: 20px; width: 46px; height: 32px; border-radius: 12px; display: grid; place-items: center; background: var(--panel-2); }
.tabs .center.active b { background: rgba(47,158,110,.25); }
.menu { margin: 8px 16px 14px; background: var(--panel); border-radius: 16px; overflow: hidden; }
.menu > button, .menu > label { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: 16px; }
.menu > button span { flex: 1; } .menu > *:last-child { border-bottom: 0; }
.menu .danger { color: #ff8a80; }
.menu .switch-row { margin: 0; }
.panel { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.panel-head { display: grid; grid-template-columns: 52px 1fr 64px; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 18px; text-align: center; }
.panel-head > :last-child { justify-self: end; }
.panel-body { flex: 1; overflow-y: auto; padding-bottom: calc(24px + var(--safe-b)); }
.text-btn { color: #6cb6ff; font-size: 16px; padding: 8px 10px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .field textarea { padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); outline: none; color: var(--text); resize: vertical; }
.row { display: flex; gap: 8px; } .row .btn { margin-top: 0; text-align: center; }
.tag { background: var(--panel-2); color: #6cb6ff; border-radius: 8px; padding: 2px 8px; font-size: 13px; margin: 2px 0; }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; display: flex; align-items: flex-end; }
.sheet-card { width: 100%; max-height: 80dvh; display: flex; flex-direction: column; background: var(--panel); border-radius: 20px 20px 0 0; padding: 8px 0 calc(12px + var(--safe-b)); }
.sheet-card.tall { height: 80dvh; }
.sheet-head { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; padding: 4px 8px; }
.sheet-head h3 { margin: 0; text-align: center; font-size: 17px; }
.sheet-head > :last-child { justify-self: end; }
.sheet-search { margin: 6px 16px 8px; padding: 11px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); outline: none; }
.sheet-card .list { overflow-y: auto; }
.check { color: #6cb6ff; font-size: 20px; }
.star { color: #f5c542; }
.tpl-prev { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); flex: 0 0 10px; }
.vm-detail { flex-basis: 100%; display: grid; gap: 8px; padding-top: 6px; }
.vm-detail audio { width: 100%; height: 40px; }
.vm-actions { display: flex; gap: 8px; } .vm-actions .btn { margin: 0; padding: 10px; font-size: 14px; }
.li-sub b { font-weight: 500; color: var(--text); }
.missed .li-sub { color: #ff8a80; }
.list li.day { display: block; border: 0; padding: 14px 0 4px; text-align: center; font-size: 12px; color: var(--muted); cursor: default; }
.list li.day:active { background: none; }
.vm-actions .btn { flex: 1; text-align: center; white-space: nowrap; text-decoration: none; }
.vm-actions .btn:nth-child(n+3) { flex: 0 0 48px; }
