:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #263449;
  --accent: #0b5cff;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --green: #16a34a;
  --red: #dc2626;
  --chrome-z: 30;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-chrome {
  position: sticky;
  top: 0;
  z-index: var(--chrome-z);
  flex: 0 0 auto;
  background: var(--bg);
  padding: 12px 16px 0;
  border-bottom: 1px solid rgba(148,163,184,.12);
}

.app-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.topbar__right { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 700; font-size: 20px; }
.brand span { color: var(--muted); font-weight: 400; }

.status { font-size: 13px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.status--online { background: rgba(22,163,74,.2); color: #4ade80; }
.status--offline { background: rgba(148,163,184,.2); color: var(--muted); }
.btn--online {
  flex: 0 0 auto; padding: 8px 12px; font-size: 13px; border-radius: 999px;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
}
.btn--online[hidden] { display: none; }

.panel { background: var(--panel); border-radius: 16px; padding: 16px; }

.dialer__display {
  width: 100%; font-size: 24px; text-align: center; padding: 12px; border-radius: 12px;
  border: 1px solid var(--panel-2); background: var(--panel-2); color: var(--text); margin-bottom: 14px;
}

.dialer__pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  padding: 16px; font-size: 20px; border: none; border-radius: 12px; cursor: pointer;
  background: var(--panel-2); color: var(--text); transition: background .15s;
}
.key:hover { background: #33475f; }

.dialer { position: relative; min-height: 420px; }
.dialer__stack { position: relative; min-height: 400px; }
.dialer__actions, .dialer__toolbar { display: flex; gap: 10px; margin-top: 14px; align-items: stretch; }
.btn { flex: 1; padding: 14px; font-size: 16px; border: none; border-radius: 12px; cursor: pointer; color: #fff; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--call, .btn--accept { background: var(--green); }
.btn--hangup, .btn--reject { background: var(--red); }
.btn--mute {
  flex: 0 1 38%;
  max-width: 150px;
  background: var(--panel-2);
}
.btn--cog {
  flex: 0 0 52px;
  width: 52px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
}
.btn--call { background: var(--accent); }

.settings { position: relative; margin-left: auto; }
.settings__menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 140px;
  background: #0b1220;
  border: 1px solid rgba(148,163,184,.25);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
  z-index: 5;
}
.settings__item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.settings__item:hover { background: var(--panel-2); }
.settings__item--danger { color: #fca5a5; }
.settings__item--danger:hover { background: rgba(220, 38, 38, 0.18); }
.settings__sep {
  height: 1px;
  margin: 6px 4px;
  background: rgba(148,163,184,.2);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: var(--panel);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.overlay[hidden] { display: none !important; }
.overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.overlay__title { font-weight: 700; font-size: 18px; }
.overlay__close {
  border: none;
  background: var(--panel-2);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.overlay__log {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  color: var(--muted);
  overflow-y: auto;
  flex: 1;
}
.overlay__log li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(148,163,184,.12);
}

.incoming { text-align: center; }
.incoming__label { color: var(--muted); font-size: 13px; }
.incoming__from { font-size: 22px; font-weight: 600; margin: 6px 0 14px; }
.incoming__actions { display: flex; gap: 10px; }

.audio__hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.4; }
.audio__field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.audio__field select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-2);
  background: var(--panel-2); color: var(--text); font-size: 14px;
}
.btn--test { background: var(--panel-2); margin-top: 4px; }

.sip-status {
  font-size: 13px; line-height: 1.5; margin-bottom: 12px; color: var(--text);
}
.sip-status code, .sip-secret code {
  font-size: 12px; word-break: break-all;
}
.sip-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sip-secret {
  background: var(--panel-2); border-radius: 10px; padding: 12px; margin-bottom: 12px;
  font-size: 13px; line-height: 1.5;
}
.sip-secret__warn { color: #fbbf24; margin-bottom: 8px; font-weight: 600; }
.sip-secret__pw { user-select: all; }
.sip-hints {
  margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.45;
}

.navtabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: var(--panel); border-radius: 14px; padding: 6px;
  margin-bottom: 10px;
}
.navtab {
  border: none; background: transparent; color: var(--muted); font-size: 13px;
  padding: 10px 4px; border-radius: 10px; cursor: pointer;
}
.navtab--active { background: var(--panel-2); color: var(--text); font-weight: 600; }

.subnav {
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.subnav[hidden] { display: none !important; }
.subnav--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--panel);
  border-radius: 12px;
  padding: 4px;
  flex: 1;
}
/* .seg { display: grid } would otherwise override the HTML hidden attribute. */
.seg[hidden] { display: none !important; }
.seg__btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
}
.seg__btn--active {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}

.view-toggle {
  display: inline-flex;
  gap: 4px;
  background: var(--panel);
  border-radius: 12px;
  padding: 4px;
  flex: 0 0 auto;
}
.view-toggle__btn {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.view-toggle__btn--active {
  background: var(--panel-2);
  color: var(--text);
}

.dir__hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.4; }
.dir__input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-2);
  background: var(--panel-2); color: var(--text); font-size: 14px; margin-bottom: 10px;
}
.dir__input--flush {
  margin: 0;
  background: var(--panel);
}
.dir__list { display: flex; flex-direction: column; gap: 8px; }
.dir__list--scroll { /* body scrolls; keep lists open-ended */ }
.dir__empty { color: var(--muted); font-size: 13px; padding: 12px 4px; }
.dir__row {
  display: flex; align-items: center; gap: 8px; background: var(--panel-2);
  border-radius: 12px; padding: 4px;
}
.dir__row--door { outline: 1px solid rgba(11, 92, 255, 0.35); }
.dir__meta {
  flex: 1; text-align: left; border: none; background: transparent; color: inherit;
  padding: 10px 12px; cursor: pointer; border-radius: 10px;
}
.dir__meta:hover { background: rgba(255,255,255,.04); }
.dir__name { display: block; font-weight: 600; color: var(--text); }
.dir__sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.dir__actions { display: flex; gap: 2px; padding-right: 4px; }
.dir__icon {
  border: none; background: transparent; color: var(--muted); font-size: 18px;
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
}
.dir__icon--on { color: #fbbf24; }
.dir__icon--danger { color: #f87171; font-size: 22px; line-height: 1; }
.dir__add { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(148,163,184,.15); }
.dir__add-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.vm-list { display: flex; flex-direction: column; gap: 8px; }
.vm-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  background: var(--panel-2);
  color: inherit;
  border-radius: 12px;
  padding: 12px 14px;
}
.vm-row--unread { outline: 1px solid rgba(11, 92, 255, 0.45); }
.vm-row__main {
  text-align: left;
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.vm-row__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.vm-row__from { font-weight: 600; }
.vm-row__meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.vm-row__preview {
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vm-expose { display: flex; flex-direction: column; gap: 16px; }
.vm-card {
  background: var(--panel-2);
  border-radius: 14px;
  padding: 16px;
}
.vm-card--unread { outline: 1px solid rgba(11, 92, 255, 0.45); }
.vm-card__from { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.vm-card__meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.vm-card__transcript {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}
.vm-card__actions, .vm-row .vm-card__actions {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.vm-card__actions .btn, .vm-row .vm-card__actions .btn {
  flex: 0 0 auto;
  padding: 7px 11px;
  font-size: 12px;
}
.btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: inherit;
}
.btn--danger {
  background: transparent;
  border: 1px solid rgba(180, 40, 40, 0.45);
  color: #a32020;
}
.vm-card--focus { outline: 2px solid var(--accent); }
.vm-audio { margin: 10px 0 14px; }
.vm-audio__player { width: 100%; }
.vm-audio__pending { font-size: 12px; color: var(--muted); }
