:root {
  --bg: #f8fafd; --surface: #ffffff; --surface2: #eef2f8; --line: #dde3ea; --text: #1f1f1f; --muted: #5f6368;
  --primary: #0b57d0; --on-primary: #fff; --tonal: #d3e3fd; --on-tonal: #041e49;
  --in: #e9eef6; --out: #0b57d0; --on-out: #fff; --danger: #b3261e; --ok: #146c2e; --call: #188038;
  --radius: 16px; --shadow: 0 1px 3px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.06);
  font-family: "Google Sans", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --surface: #1b1d23; --surface2: #262a31; --line: #333842; --text: #e3e3e3; --muted: #a8adb4;
    --primary: #a8c7fa; --on-primary: #062e6f; --tonal: #0842a0; --on-tonal: #d3e3fd;
    --in: #2a2f37; --out: #a8c7fa; --on-out: #062e6f; --danger: #f2b8b5; --ok: #6dd58c; --call: #6dd58c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; }
code { background: var(--surface2); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }
h1 { font-size: 24px; font-weight: 500; margin: 0 0 12px; }
h2 { font-size: 17px; font-weight: 500; margin: 18px 0 8px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { color: var(--text); font-size: 15px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; color: var(--text); margin: 6px 0; }

.btn { border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer; background: transparent; color: var(--primary); font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.tonal { background: var(--tonal); color: var(--on-tonal); }
.btn.call { background: var(--call); color: #fff; }
.btn.decline { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; padding: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn:hover { background: var(--surface2); }
.icon-btn.on { background: var(--tonal); color: var(--on-tonal); }

.logo { display: inline-block; width: 28px; height: 28px; border-radius: 50%; background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8.6 6.2l1.6 3.3-1.3 1.2c.8 1.7 2.1 3 3.8 3.8l1.2-1.3 3.3 1.6-.5 2.6c-5.4.2-10.6-5-10.4-10.4z'/%3E%3C/svg%3E") center/70% no-repeat; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 500; padding: 8px 12px 18px; }
.brand.big { font-size: 24px; justify-content: center; padding-bottom: 8px; }

/* sign-in */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 28px; width: min(440px, 100%); }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { text-align: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.rail { width: 216px; flex: none; display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; }
.nav { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 11px 16px; border-radius: 999px; cursor: pointer; text-align: left; position: relative; color: var(--text); }
.nav:hover { background: var(--surface2); }
.nav.active { background: var(--tonal); color: var(--on-tonal); font-weight: 500; }
.nav .ico { width: 22px; text-align: center; font-weight: 700; }
.badge { margin-left: auto; background: var(--primary); color: var(--on-primary); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.phone-state { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.phone-state .dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa0a6; }
.phone-state.ok .dot { background: var(--ok); }
.phone-state.bad .dot { background: var(--danger); }
main { flex: 1; min-width: 0; padding: 12px 12px 12px 0; }
.view { height: 100%; }
.page { background: var(--surface); border-radius: 24px; height: 100%; overflow: auto; padding: 22px 26px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.card { background: var(--bg); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 18px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 10px 0; }
.inline-form label { min-width: 180px; flex: 1; }
.row-btns { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; padding: 8px; }

/* messages */
.split { display: flex; height: 100%; gap: 12px; }
.list-pane { width: 360px; flex: none; background: var(--surface); border-radius: 24px; display: flex; flex-direction: column; overflow: hidden; }
.pane-head { display: flex; gap: 8px; padding: 14px 14px 8px; }
.pane-head select { flex: 1; min-width: 0; }
.search { margin: 0 14px 8px; border-radius: 999px; background: var(--surface2); border-color: transparent; }
.conv-list { overflow: auto; flex: 1; padding: 0 6px 10px; }
.conv { display: flex; gap: 12px; padding: 10px; border-radius: 14px; cursor: pointer; align-items: center; }
.conv:hover { background: var(--surface2); }
.conv.active { background: var(--tonal); color: var(--on-tonal); }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.conv .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--muted); flex: none; }
.conv .snippet { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .name, .conv.unread .snippet { font-weight: 700; color: var(--text); }
.avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 500; position: relative; background: #7b61ff; }
.avatar .line-dot { position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--surface); font-size: 9px; display: flex; align-items: center; justify-content: center; }
.thread-pane { flex: 1; min-width: 0; background: var(--surface); border-radius: 24px; overflow: hidden; display: flex; }
.empty-thread { margin: auto; color: var(--muted); }
.thread { display: flex; flex-direction: column; width: 100%; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.thread-head .title { font-weight: 500; font-size: 16px; }
.grow { flex: 1; min-width: 0; }
.back { display: none; }
.messages { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 3px; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 6px; }
.msg { max-width: min(560px, 78%); display: flex; flex-direction: column; position: relative; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 14px; border-radius: 20px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.38; }
.msg.in .bubble { background: var(--in); border-bottom-left-radius: 6px; }
.msg.out .bubble { background: var(--out); color: var(--on-out); border-bottom-right-radius: 6px; }
.msg img { max-width: 260px; max-height: 320px; border-radius: 16px; margin: 2px 0; cursor: zoom-in; display: block; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin: 2px 8px 6px; }
.msg .meta.failed { color: var(--danger); cursor: pointer; }
.msg .del { position: absolute; top: 2px; opacity: 0; border: 0; background: var(--surface2); border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: 12px; }
.msg.in .del { right: -32px; }
.msg.out .del { left: -32px; }
.msg:hover .del { opacity: 1; }
.attachments { display: flex; gap: 8px; padding: 8px 16px 0; }
.attachments .att { position: relative; }
.attachments img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; }
.attachments button { position: absolute; top: -6px; right: -6px; border: 0; border-radius: 50%; width: 22px; height: 22px; background: var(--danger); color: #fff; cursor: pointer; font-size: 11px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px 14px; }
.composer textarea { flex: 1; resize: none; border-radius: 22px; background: var(--surface2); border-color: transparent; max-height: 160px; padding: 11px 16px; }
.composer .send { width: 44px; height: 44px; padding: 0; font-size: 18px; }

/* calls */
.call-list { display: flex; flex-direction: column; }
.call { display: flex; align-items: center; gap: 14px; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.call .kind { width: 24px; text-align: center; }
.call.missed .name { color: var(--danger); }

/* number cards */
.line-card { background: var(--bg); border-radius: var(--radius); padding: 14px; display: flex; gap: 12px; align-items: flex-start; }
.line-card .icon { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; flex: none; }
.line-card .title { font-weight: 500; }
.state { font-size: 12.5px; }
.state.ok { color: var(--ok); } .state.bad { color: var(--danger); }

/* dialer + call bar */
.dialer { position: fixed; right: 20px; bottom: 20px; width: 300px; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; z-index: 20; }
.dialer header { display: flex; justify-content: space-between; align-items: center; }
.dial-number { font-size: 24px; text-align: center; letter-spacing: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keypad button { border: 0; background: var(--surface2); border-radius: 50%; aspect-ratio: 1.3; font-size: 20px; cursor: pointer; }
.keypad button small { display: block; font-size: 9px; color: var(--muted); letter-spacing: 1px; }
.keypad.small { grid-column: 1 / -1; width: 220px; }
.callbar { position: fixed; left: 50%; transform: translateX(-50%); top: 14px; background: var(--surface); box-shadow: var(--shadow); border-radius: 22px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; z-index: 30; min-width: 360px; max-width: 95vw; }
.callbar .title { font-weight: 500; }
.call-actions { display: flex; gap: 6px; align-items: center; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #303134; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; max-width: 90vw; }

dialog { border: 0; border-radius: 24px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.sel { border-color: var(--text); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; }

/* phones */
@media (max-width: 860px) {
  .rail { position: fixed; bottom: 0; left: 0; right: 0; width: auto; flex-direction: row; padding: 6px; background: var(--surface); z-index: 10; justify-content: space-around; box-shadow: 0 -1px 0 var(--line); }
  .rail .brand, .nav span:not(.ico), .phone-state .txt { display: none; }
  .nav { padding: 10px 14px; }
  .rail-foot { margin: 0; flex-direction: row; padding: 0; align-items: center; }
  .rail-foot .btn { padding: 8px 12px; }
  main { padding: 0 0 62px; }
  .page, .list-pane, .thread-pane { border-radius: 0; }
  .split { gap: 0; }
  .list-pane { width: 100%; }
  .thread-pane { display: none; }
  .split.open .list-pane { display: none; }
  .split.open .thread-pane { display: flex; }
  .back { display: inline-flex; }
  .dialer { left: 8px; right: 8px; bottom: 70px; width: auto; }
  .callbar { min-width: 0; width: 95vw; }
  .msg .del { opacity: .6; }
}
