:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #17171a;
  --muted: #6b6a70;
  --line: #e6e4df;
  --accent: #1f4fd8;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --bubble-in: #efeee9;
  --danger: #c4372b;
  --ok: #1d8a4f;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --panel: #1b1b1e;
    --ink: #ecebe8;
    --muted: #9a99a0;
    --line: #2b2b30;
    --accent: #6d8ff5;
    --accent-ink: #0d0f17;
    --accent-soft: #1e2640;
    --bubble-in: #26262b;
    --danger: #ef6b5f;
    --ok: #4cc283;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 Inter, system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; justify-content: flex-end; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; margin-top: 8px; }
a { color: var(--accent); }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }
.error { color: var(--danger); font-size: 14px; }
.dev-hint { background: var(--accent-soft); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.sidebar .brand { padding: 0 8px 16px; }
.tab { all: unset; cursor: pointer; padding: 9px 10px; border-radius: 8px; font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.tab:hover { background: var(--bg); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 12px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px; }
.balance { display: flex; flex-direction: column; }
.balance strong { font-size: 22px; }
.phone-status { font-size: 12px; color: var(--muted); }
.phone-status.on { color: var(--ok); }
.main { overflow: auto; padding: 24px; }
.view { display: flex; flex-direction: column; gap: 16px; height: 100%; }
.pane-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.num-card { display: flex; flex-direction: column; gap: 10px; }
.num-card .e164 { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.empty { color: var(--muted); display: grid; place-items: center; height: 100%; text-align: center; padding: 24px; }

/* Messages */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: 100%; min-height: 0; }
.list-pane, .thread-pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.list-pane .pane-head, .thread .pane-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow: auto; }
.conv-list li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.conv-list li:hover, .conv-list li.active { background: var(--bg); }
.conv-list .top { display: flex; justify-content: space-between; gap: 8px; }
.conv-list .peer { font-weight: 600; }
.conv-list .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list li.unread .preview { color: var(--ink); font-weight: 600; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.bubbles { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 16px; word-wrap: break-word; }
.bubble .text { white-space: pre-wrap; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .meta { font-size: 11px; opacity: .7; margin-top: 2px; }
.compose { display: flex; gap: 8px; padding: 12px 16px 4px; border-top: 1px solid var(--line); }
.compose textarea { flex: 1; resize: none; max-height: 140px; }
.compose-meta { padding: 0 16px 10px; }

/* Calls */
.dialer { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table td.right, .table th.right { text-align: right; }
.st-completed, .st-answered { color: var(--ok); }
.st-missed, .st-failed { color: var(--danger); }

.callbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 18px; display: flex; gap: 24px; align-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.15); width: min(560px, calc(100% - 32px)); justify-content: space-between;
}
.toast { position: fixed; top: 16px; right: 16px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; max-width: 360px; z-index: 10; }
.toast.err { background: var(--danger); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); padding: 24px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); align-items: center; }
  .sidebar .brand, .sidebar-foot .phone-status { display: none; }
  .tab { white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; }
  .balance strong { font-size: 15px; }
  .main { padding: 16px; }
  .split { grid-template-columns: 1fr; }
  .dialer { grid-template-columns: 1fr; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(6), .table td:nth-child(6) { display: none; }
}
