:root,
[data-theme="dark"] {
  --bg: #0b1118;
  --bg-glow: #142033;
  --panel: #121a24;
  --surface: #0d141d;
  --surface-2: #0a1018;
  --line: #243041;
  --text: #e7eef8;
  --muted: #8ea0b8;
  --accent: #1f9d73;
  --accent-2: #2f7fd4;
  --danger: #d45b5b;
  --warn: #d4a72f;
  --code: #9ec7ff;
  --btn-fg: #ffffff;
  --topbar-bg: rgba(8, 12, 18, 0.8);
  --badge-bg: #1d2a3a;
  --wire: #314457;
  --file-fg: #c5d0de;
  --status-ok-bg: rgba(31, 157, 115, 0.2);
  --status-ok-fg: #7ddeb8;
  --status-bad-bg: rgba(212, 91, 91, 0.2);
  --status-bad-fg: #f0a0a0;
  --status-info-bg: rgba(47, 127, 212, 0.2);
  --status-info-fg: #9ec7ff;
  --tone-invite: #9cc7ff;
  --tone-trying: #c5d0dc;
  --tone-progress: #f0d48a;
  --tone-ok: #8fe0c0;
  --tone-ack: #d5e0ec;
  --tone-bad: #f0a0a0;
  --tone-trying-border: #5b6b7c;
  --tone-ack-border: #6a7f96;
  --mono-muted: #b7c6d8;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f3f6fa;
  --bg-glow: #d9e6f5;
  --panel: #ffffff;
  --surface: #eef2f7;
  --surface-2: #e6ecf4;
  --line: #cfd8e6;
  --text: #152033;
  --muted: #5c6b80;
  --accent: #168a63;
  --accent-2: #246db8;
  --danger: #c43d3d;
  --warn: #b8860b;
  --code: #1a5fb4;
  --btn-fg: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --badge-bg: #e4ebf4;
  --wire: #b7c5d6;
  --file-fg: #44566d;
  --status-ok-bg: rgba(22, 138, 99, 0.14);
  --status-ok-fg: #0f6b4a;
  --status-bad-bg: rgba(196, 61, 61, 0.12);
  --status-bad-fg: #9f1d1d;
  --status-info-bg: rgba(36, 109, 184, 0.12);
  --status-info-fg: #175cd3;
  --tone-invite: #175cd3;
  --tone-trying: #5c6b80;
  --tone-progress: #8a6508;
  --tone-ok: #0f6b4a;
  --tone-ack: #3d4f63;
  --tone-bad: #9f1d1d;
  --tone-trying-border: #9aa8ba;
  --tone-ack-border: #8a9aaf;
  --mono-muted: #44566d;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(circle at top, var(--bg-glow) 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.tabs {
  display: flex;
  gap: 0.35rem;
}
.tab-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0.35rem 0.7rem;
}
.tab-btn.active {
  color: var(--text);
  border-color: var(--accent);
}
.tab-panel { display: none; }
.tab-panel.active { display: contents; }
.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 1rem;
}
.kv dt { color: var(--muted); }
.sip-card code {
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.field-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.35;
}
.test-preview {
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  display: grid;
  gap: 0.35rem;
}
.test-preview strong {
  color: var(--text);
  font-weight: 600;
}
.test-preview code {
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: var(--code);
}
.trunk-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.trunk-line-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.55rem;
  min-width: 0;
  flex: 1;
}
.trunk-line-name {
  color: var(--text);
  margin-right: 0.15rem;
}
.trunk-line-main code { color: var(--code); }
.trunk-line-note {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trunk-line-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}
.trunk-line-actions .ghost {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}
@media (max-width: 720px) {
  .trunk-line {
    flex-direction: column;
    align-items: stretch;
  }
  .trunk-line-actions { justify-content: flex-end; }
}
.userpass-field { display: none; }
.userpass-field.visible { display: grid; }
.badge {
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--muted);
  font-size: 0.75rem;
}
.layout {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  max-width: 1100px;
  margin: 0 auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.form-grid {
  display: grid;
  gap: 0.75rem 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}
.form-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 860px) {
  .form-grid--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .form-grid,
  .form-grid--3 {
    grid-template-columns: 1fr;
  }
}
.span-full {
  grid-column: 1 / -1;
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.15rem;
}
.form-actions button {
  min-width: 160px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 0;
}
input, select, button {
  font: inherit;
}
input, select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
button {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--btn-fg);
  cursor: pointer;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
button.danger-btn { color: var(--danger); border-color: rgba(212, 91, 91, 0.45); }
button.danger-btn:hover { background: rgba(212, 91, 91, 0.12); }
.theme-toggle {
  min-width: 2.4rem;
  padding: 0.4rem 0.55rem;
  line-height: 1;
  font-size: 1rem;
}
.theme-toggle .theme-icon-light { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-dark { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-light { display: inline; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }
.hidden { display: none !important; }
.tests-list { display: grid; gap: 0.6rem; }
.test-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.test-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  margin-top: 0.35rem;
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.status {
  font-size: 0.8rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
}
.status.completed { background: var(--status-ok-bg); color: var(--status-ok-fg); }
.status.failed { background: var(--status-bad-bg); color: var(--status-bad-fg); }
.status.in_progress, .status.ringing, .status.dialing, .status.preparing, .status.queued {
  background: var(--status-info-bg); color: var(--status-info-fg);
}
.transcript {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: pre-wrap;
}
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  position: relative;
}
.auth-theme {
  position: absolute;
  top: 1rem;
  right: 1rem;
}
.auth-card {
  width: min(380px, 92vw);
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.debug-log {
  margin-top: 0.85rem;
}
.callflow-log {
  margin-top: 1.1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.callflow-log summary {
  color: var(--accent);
}
.callflow-log .debug-log-list {
  max-height: 560px;
}
.sip-callflow-log {
  margin-top: 1.1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.sip-callflow-log summary {
  color: var(--accent);
}
.cf-ladder {
  display: grid;
  gap: 0.15rem;
  margin: 0.4rem 0 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  max-height: 520px;
  overflow: auto;
  font-size: 0.82rem;
}
.cf-head,
.cf-row {
  display: grid;
  grid-template-columns: 4.5rem minmax(7rem, 1fr) 2.2rem minmax(7rem, 1fr);
  gap: 0.35rem;
  align-items: center;
}
.cf-head {
  margin-bottom: 0.35rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed var(--line);
}
.cf-head .cf-us,
.cf-head .cf-peer {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.cf-rel {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.cf-us { text-align: right; }
.cf-peer { text-align: left; }
.cf-wire {
  display: grid;
  place-items: center;
  position: relative;
  min-height: 1.6rem;
}
.cf-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--wire);
  transform: translateX(-50%);
}
.cf-arrow {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  background: var(--surface-2);
  padding: 0.1rem 0;
}
.cf-pill {
  display: inline-block;
  max-width: 100%;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cf-row.tone-invite .cf-pill { border-color: var(--accent-2); color: var(--tone-invite); }
.cf-row.tone-trying .cf-pill { border-color: var(--tone-trying-border); color: var(--tone-trying); }
.cf-row.tone-progress .cf-pill { border-color: var(--warn); color: var(--tone-progress); }
.cf-row.tone-ok .cf-pill { border-color: var(--accent); color: var(--tone-ok); }
.cf-row.tone-ack .cf-pill { border-color: var(--tone-ack-border); color: var(--tone-ack); }
.cf-row.tone-bad .cf-pill { border-color: var(--danger); color: var(--tone-bad); }
.cf-ascii {
  margin: 0.35rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  overflow: auto;
  max-height: 220px;
  color: var(--mono-muted);
}
.debug-log summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.debug-log-list {
  display: grid;
  gap: 0.5rem;
  max-height: 420px;
  overflow: auto;
}
.debug-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: var(--surface-2);
}
.debug-row.debug-error { border-color: rgba(212, 91, 91, 0.5); }
.debug-row.debug-warn { border-color: rgba(212, 167, 47, 0.5); }
.debug-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.debug-detail {
  margin: 0.4rem 0 0;
  padding: 0.5rem;
  font-size: 0.75rem;
  max-height: 180px;
  overflow: auto;
  background: var(--surface);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

.import-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}
.import-row input[type="file"] {
  max-width: 100%;
  color: var(--file-fg);
}

.area-picker {
  position: relative;
}
.area-picker .area-search {
  width: 100%;
}
.area-results {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 240px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
.area-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.7rem;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.area-option:last-child { border-bottom: none; }
.area-option:hover { background: var(--surface); }
.area-selected {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
}
.area-picker-label { position: relative; }

.plans-list { display: grid; gap: 0.55rem; }
.plan-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.plan-row.active { border-color: var(--accent); }
.plan-actions { display: flex; gap: 0.35rem; flex-shrink: 0; flex-wrap: wrap; }
.inline-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.inline-check input { width: auto; }
.browse-search {
  max-width: 220px;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.browse-list {
  display: grid;
  gap: 0.35rem;
  max-height: 420px;
  overflow: auto;
  margin-top: 0.75rem;
}
.browse-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.browse-main {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  min-width: 0;
}
.browse-row code { color: var(--code); }
.browse-lens {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
