:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --border: #272d36;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --accent: #60a5fa;
    --accent-ink: #0b1220;
    --ok: #34d399;
    --ok-bg: #06281f;
    --warn: #fbbf24;
    --warn-bg: #2a1f05;
    --danger: #f87171;
    --danger-bg: #2a1213;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.small { font-size: 0.85em; }
.muted { color: var(--muted); }
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); display: inline-block;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--bg); color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot-live { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }

/* ---------------------------------------------------------------- layout */
main.app { max-width: 1140px; margin: 0 auto; padding: 28px 24px 56px; }
main.centered { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 15px; margin: 0 0 4px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 28px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.empty { color: var(--muted); margin: 8px 0; }

/* ----------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-sub { color: var(--muted); font-size: 12px; opacity: 0.8; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
  padding: 0 12px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tr.row-off { opacity: 0.55; }
td.actions { white-space: nowrap; text-align: right; width: 1%; }
td.actions .btn { margin-left: 2px; }
.nowrap { white-space: nowrap; }
/* Long URLs must not push the action buttons off the table. */
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.numbers td { padding: 10px 10px; }
tr.flash-row { animation: flashrow 1.6s ease-out; }
@keyframes flashrow { from { background: color-mix(in srgb, var(--accent) 18%, transparent); } to { background: transparent; } }

/* ------------------------------------------------------------------ tags */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.tag-caller_hangup { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.tag-auto_hangup { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.tag-audio_played { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: transparent; }
.tag-audio_interrupted { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag-no_config, .tag-off { background: var(--bg); color: var(--muted); }
.tag-error { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.tag-mode-hangup { background: var(--bg); color: var(--text); }
.tag-mode-audio { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: transparent; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; cursor: pointer; line-height: 1.3;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; font-size: 13px; padding: 5px 10px; }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; font-size: 13px; padding: 5px 10px; }
.btn-danger:hover { background: var(--danger-bg); border-color: transparent; }
.linkbtn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
.linkbtn:hover { color: var(--text); text-decoration: underline; }
form.inline { display: inline; }

/* ----------------------------------------------------------------- forms */
.form .field { margin-bottom: 18px; }
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; }
input[type=text], input[type=url], input[type=password], input[type=number], input:not([type]), select {
  width: 100%; padding: 9px 11px; font: inherit;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent); }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 6px; }
.field.checkbox label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.field.checkbox input { width: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 18px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
table.headers td { padding: 6px 6px 6px 0; border: none; }
table.headers th { padding-bottom: 4px; }

.login { width: min(380px, 100%); }
.login h1 { display: flex; align-items: center; gap: 10px; font-size: 19px; margin-bottom: 4px; }
.login p { margin-top: 0; }
.login label { margin-top: 14px; }
.login .btn { width: 100%; margin-top: 20px; padding: 10px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }

/* ---------------------------------------------------------------- flashes */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

@media (max-width: 720px) {
  .topbar { height: auto; padding: 10px 16px; }
  .topbar-right { margin-left: 0; width: 100%; }
  main.app { padding: 20px 16px 40px; }
  td.actions { text-align: left; }
}

/* Announcement source picker on the number form. */
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.choice-option {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; font-weight: 400;
}
.choice-option:hover { border-color: var(--muted); }
.choice-option input { width: auto; margin-top: 3px; }
.choice-option small { color: var(--muted); }
.choice-option:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

textarea {
  width: 100%; padding: 9px 11px; font: inherit; line-height: 1.5;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; resize: vertical;
}
textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent); }

audio { width: 100%; max-width: 420px; margin-bottom: 6px; }
