:root {
  --bg: #f2f0e9;
  --panel: #faf9f4;
  --panel-2: #eceae1;
  --ink: #14150f;
  --ink-soft: #3d3f34;
  --muted: #66695c;
  --line: #dedacd;
  --line-strong: #c9c4b4;
  --accent: #e8441c;
  --ok: #12734a;
  --danger: #c0331a;
  --shadow: 0 1px 2px rgba(20, 21, 15, .04), 0 12px 32px rgba(20, 21, 15, .07);
  --sans: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --r: 10px;
}

html[data-theme="dark"] {
  --bg: #0d0f0c;
  --panel: #141611;
  --panel-2: #1a1d16;
  --ink: #ecebdf;
  --ink-soft: #c9c8b9;
  --muted: #9a9d8e;
  --line: #262a21;
  --line-strong: #363c2d;
  --accent: #ff5a33;
  --ok: #55c98e;
  --danger: #ff6a4d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: baseline; gap: 7px; user-select: none; }
.brand-mark {
  width: 11px; height: 11px; background: var(--accent); border-radius: 2px;
  display: inline-block; transform: translateY(-1px);
}
.brand-word { font-weight: 750; letter-spacing: .13em; font-size: 15px; }
.brand-sub { font-size: 11px; letter-spacing: .22em; color: var(--muted); font-weight: 600; }
.brand-lg .brand-word { font-size: 20px; }
.brand-lg .brand-sub { font-size: 12px; }

/* ---------- topbar ---------- */
.topbar {
  height: 60px; display: flex; align-items: center; gap: 24px;
  padding: 0 22px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.line-chip {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .02em;
  color: var(--ink-soft); padding: 5px 10px; border: 1px solid var(--line);
  border-radius: 999px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 15%, transparent); }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px;
  border-radius: 8px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); height: calc(100dvh - 60px); }
.rail {
  border-right: 1px solid var(--line); background: var(--panel);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 10px 11px; border-radius: 8px; font-size: 14px; text-align: left;
}
.nav-item svg { color: var(--muted); flex: none; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.is-active { background: var(--ink); color: var(--panel); }
.nav-item.is-active svg { color: var(--panel); }
.nav-badge {
  margin-left: auto; background: var(--accent); color: #fff; font-size: 11px;
  font-weight: 700; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; display: grid; place-items: center;
}
.nav-item.is-active .nav-badge { background: var(--accent); }
.rail-foot {
  margin-top: auto; padding: 12px 11px; font-size: 11.5px; color: var(--muted);
  display: flex; align-items: center; gap: 7px; border-top: 1px solid var(--line);
  letter-spacing: .01em;
}
.mini-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); }
.mini-dot.on { background: var(--ok); }

.main { min-width: 0; overflow: hidden; background: var(--bg); }
.view { display: none; height: 100%; overflow: auto; }
.view.is-active { display: block; }

/* ---------- messages ---------- */
.split { display: grid; grid-template-columns: 336px minmax(0, 1fr); height: 100%; }
.threads {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 14px; gap: 12px;
}
.pane-head h1 { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.page-head { padding: 26px 30px 18px; border-bottom: 1px solid var(--line); }
.head-actions { display: flex; align-items: center; gap: 12px; }

.search-wrap {
  margin: 0 20px 10px; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 7px 10px; color: var(--muted);
}
.search-wrap input { border: 0; background: transparent; outline: none; width: 100%; font-size: 13.5px; }
.thread-list { overflow-y: auto; overflow-x: hidden; padding: 4px 12px 16px; flex: 1; min-width: 0; }
.thread-item {
  width: 100%; border: 0; background: transparent; text-align: left;
  display: grid; grid-template-columns: 38px minmax(0, 1fr) 22px; gap: 11px;
  padding: 11px 8px; border-radius: 9px; align-items: center;
}
.thread-item:hover { background: var(--panel-2); }
.thread-item.is-active { background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--panel); font-size: 12.5px; font-weight: 650;
  letter-spacing: .02em; font-family: var(--mono);
}
.thread-main { min-width: 0; }
.thread-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.thread-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time { font-size: 11px; color: var(--muted); font-family: var(--mono); flex: none; }
.thread-preview {
  display: block;
  font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 1px;
}
.thread-preview.unread { color: var(--ink); font-weight: 500; }
.thread-count {
  font-size: 10.5px; font-weight: 700; background: var(--accent); color: #fff;
  border-radius: 9px; min-width: 17px; height: 17px; display: grid; place-items: center;
  padding: 0 4px;
}

.conversation { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.conv-empty {
  margin: auto; text-align: center; color: var(--muted); max-width: 280px;
}
.conv-empty p + p { margin-top: 6px; font-size: 13.5px; }
.conv-empty .btn { margin-top: 16px; }
.eyebrow {
  font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--muted); font-weight: 650;
}
.conv-head {
  display: flex; align-items: center; gap: 13px; padding: 16px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.conv-head .avatar { width: 36px; height: 36px; }
.back-btn { display: none; margin-left: -6px; }
.conv-id { min-width: 0; }
.conv-id h2 { font-size: 15.5px; font-weight: 650; letter-spacing: -.01em; }
.conv-id p { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.conv-tools { margin-left: auto; display: flex; gap: 6px; }
.conv-body { flex: 1; overflow: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 3px; }
.day-sep { text-align: center; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 18px 0 10px; }
.bubble-row { display: flex; margin-top: 2px; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row > div {
  display: flex; flex-direction: column; align-items: flex-start;
  max-width: min(72%, 520px); min-width: 0;
}
.bubble-row.out > div { align-items: flex-end; }
.bubble {
  width: fit-content; max-width: 100%; padding: 9px 13px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--line); font-size: 14px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble-row.out .bubble { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.bubble-meta {
  display: flex; gap: 8px; align-items: center;
  font-size: 10.5px; color: var(--muted); margin-top: 4px; font-family: var(--mono);
}
.bubble-row.out .bubble-meta { color: color-mix(in srgb, var(--panel) 60%, var(--ink)); }
.bubble-status { text-transform: uppercase; letter-spacing: .08em; font-size: 9.5px; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 20px 14px; }
.composer textarea {
  width: 100%; resize: none; border: 1px solid var(--line); background: var(--bg);
  border-radius: 9px; padding: 11px 13px; outline: none; min-height: 46px; max-height: 160px;
  font-size: 14px; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--line-strong); }
.composer-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.composer-foot .counter { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-left: auto; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font-size: 13.5px; font-weight: 600; background: var(--panel-2); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--ink); color: var(--panel); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- calls ---------- */
.call-list { padding: 8px 18px 30px; }
.call-row {
  display: grid; grid-template-columns: 30px minmax(0, 1fr) 62px 178px;
  gap: 14px; align-items: center; padding: 13px 12px;
  border-bottom: 1px solid var(--line); font-size: 13.5px;
}
.call-row:hover { background: var(--panel); }
.call-icon { color: var(--muted); display: grid; place-items: center; }
.call-icon.in { color: var(--ok); }
.call-icon.missed { color: var(--danger); }
.call-who { min-width: 0; }
.call-who strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-who span { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.call-mid { font-size: 12px; color: var(--muted); font-family: var(--mono); text-align: right; }
.call-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.call-tags { width: 78px; display: flex; justify-content: flex-end; }
.tag {
  font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700;
  padding: 3px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted);
}
.tag.missed { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.tag.voicemail { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.rec-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 50%;
  width: 27px; height: 27px; display: grid; place-items: center; color: var(--ink-soft);
}
.rec-btn:hover { border-color: var(--line-strong); }
.call-row.is-live { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* ---------- dial ---------- */
.dial-wrap {
  display: grid; grid-template-columns: minmax(320px, 380px) minmax(240px, 320px);
  gap: 56px; justify-content: center; padding: 44px 30px; height: 100%;
}
.dial-card { max-width: 380px; width: 100%; }
.dial-display { display: flex; align-items: center; gap: 10px; margin: 10px 0 2px; min-height: 48px; }
.dial-number {
  flex: 1; font-family: var(--mono); font-size: clamp(24px, 3.2vw, 34px);
  letter-spacing: .01em; overflow-wrap: anywhere; min-width: 0;
}
.dial-del { flex: none; }
.dial-hint { color: var(--muted); font-size: 12.5px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 22px 0; }
.keypad button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  aspect-ratio: 1.35; padding: 0; font-family: var(--mono); font-size: 21px; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.keypad button span { font-size: 8.5px; letter-spacing: .12em; color: var(--muted); font-family: var(--sans); }
.keypad button:hover { border-color: var(--line-strong); background: var(--panel-2); }
.keypad button:active { transform: translateY(1px); }
.key-del { justify-content: center; font-size: 16px !important; }
.dial-mode { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.dial-mode-label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-right: auto; }
.dial-mode label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); }
.dial-mode input { accent-color: var(--ink); }
.btn-call {
  width: 100%; padding: 13px; background: var(--ink); color: var(--panel);
  font-size: 15px; border-radius: 10px;
}
.recents { padding-top: 6px; }
.recents ul { margin-top: 10px; }
.recent-row {
  width: 100%; border: 0; background: transparent; display: flex; align-items: center;
  gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left;
  font-size: 13.5px;
}
.recent-row:hover { background: var(--panel); }
.recent-row .mono { font-size: 11.5px; color: var(--muted); margin-left: auto; }
.recent-dir { color: var(--muted); display: grid; place-items: center; }
.recent-dir.in { color: var(--ok); }
.recent-dir.missed { color: var(--danger); }

/* ---------- segmented ---------- */
.segmented { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.segmented button {
  border: 0; background: transparent; padding: 6px 11px; font-size: 12px; color: var(--muted);
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.is-on { background: var(--ink); color: var(--panel); }

/* ---------- settings ---------- */
.settings-grid {
  columns: 2 340px; column-gap: 16px; padding: 24px 30px 60px;
}
.settings-grid .card { break-inside: avoid; margin: 0 0 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; font-weight: 650; margin-bottom: 14px; letter-spacing: -.01em; }
.facts { display: grid; gap: 10px; }
.facts > div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; }
.facts dt { font-size: 11.5px; color: var(--muted); }
.facts dd { font-size: 12.5px; overflow-wrap: anywhere; }
.help { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.stack { display: grid; gap: 12px; }
.toggle-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line);
}
.toggle-row small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ink); margin-top: 2px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 11.5px; color: var(--muted); }
.field input, .field textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 9px 11px; outline: none; font-size: 14px; width: 100%;
}
.field input:focus, .field textarea:focus { border-color: var(--line-strong); }
.form-error { color: var(--danger); font-size: 12px; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- call layer ---------- */
.call-layer {
  position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 50; padding: 20px;
}
.call-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 26px 24px; text-align: center; box-shadow: var(--shadow);
}
.call-name { font-size: 24px; letter-spacing: -.02em; margin: 8px 0 2px; }
.call-meta { color: var(--muted); font-size: 12.5px; font-family: var(--mono); }
.call-timer { font-family: var(--mono); font-size: 15px; margin-top: 14px; color: var(--ink-soft); }
.call-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; }
.round-btn {
  width: 76px; height: 76px; border-radius: 50%; border: 0; color: #fff;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 650;
  letter-spacing: .02em;
}
.round-btn.ok { background: var(--ok); }
.round-btn.danger { background: var(--danger); }
.round-btn:hover { filter: brightness(1.06); }
.pill-btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px;
  padding: 0 22px; height: 44px; font-size: 13px; font-weight: 600; align-self: center;
}
.pill-btn.is-on { background: var(--ink); color: var(--panel); }
.call-note { margin-top: 14px; font-size: 11.5px; color: var(--muted); }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 11, 8, .45); display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal-card { width: min(480px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { font-size: 17px; font-weight: 650; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; }
.counter { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 8px;
  font-size: 13px; z-index: 80; box-shadow: var(--shadow);
}

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; background: var(--bg); }
.login-card {
  width: min(360px, calc(100vw - 40px)); background: var(--panel); border: 1px solid var(--line);
  padding: 30px 28px 24px; border-radius: 14px; box-shadow: var(--shadow);
}
.login-lede { color: var(--muted); font-size: 13.5px; margin: 14px 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 58px; }
  .rail {
    order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line);
    padding: 6px 8px; gap: 4px; justify-content: space-around;
  }
  .nav-item { flex-direction: column; gap: 3px; font-size: 10px; padding: 6px 8px; align-items: center; width: auto; flex: 1; }
  .nav-item svg { width: 18px; height: 18px; }
  .nav-badge { position: absolute; margin: -22px 0 0 22px; }
  .rail-foot { display: none; }
  .main { order: 1; }
  .split { grid-template-columns: 1fr; position: relative; }
  .threads { border-right: 0; }
  .conversation { display: none; position: absolute; inset: 0; z-index: 5; }
  .split.show-conv .conversation { display: flex; }
  .split.show-conv .threads { visibility: hidden; }
  .conv-head { padding: 12px 16px; }
  .back-btn { display: grid; }
  .conv-body { padding: 16px; }
  .page-head { padding: 18px 16px; }
  .call-list { padding: 6px 8px 20px; }
  .call-row { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .call-mid { display: none; }
  .call-tags { width: auto; }
  .settings-grid { padding: 16px; columns: 1; }
  .dial-wrap { grid-template-columns: 1fr; gap: 30px; padding: 24px 18px; height: auto; }
  .recents { display: none; }
  .topbar { padding: 0 14px; gap: 10px; height: 54px; }
  .shell { height: calc(100dvh - 54px); }
  .line-chip { font-size: 11px; padding: 4px 8px; }
}