:root {
  --bg: #0b0c0e;
  --surface: #14161a;
  --surface-2: #1a1d22;
  --border: #24272d;
  --border-soft: #1c1f24;
  --text: #f0f1f4;
  --text-dim: #8a8f99;
  --text-mute: #4f535b;

  --accent: #ff6b4a;
  --accent-hover: #ff855f;
  --accent-soft: rgba(255,107,74,.12);

  --warm: #fbbf24;
  --teal: #5eead4;
  --purple: #a78bfa;
  --green: #4ade80;
  --red: #f87171;

  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14.5px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  background-image: radial-gradient(circle at 50% -20%, rgba(255,107,74,.06), transparent 50%);
}
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

/* Topnav */
.topnav {
  display: flex; align-items: center; gap: 28px;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11,12,14,.7);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
.topnav .brand {
  color: var(--text); font-weight: 700; font-size: 1em;
  letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono);
}
.topnav .brand::before {
  content: ''; display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}
.topnav ul {
  list-style: none; display: flex; gap: 2px; flex-wrap: wrap;
  margin: 0; padding: 0; flex: 1;
}
.topnav li a {
  color: var(--text-dim);
  padding: 9px 15px; border-radius: 7px;
  font-size: 0.95em; font-weight: 500;
  font-family: var(--mono);
  transition: background .15s, color .15s;
  letter-spacing: 0.01em;
}
.topnav li a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topnav li a.active { background: var(--surface-2); color: var(--accent); }

/* Dropdown nav */
.topnav li.has-dropdown { position: relative; }
.topnav li.has-dropdown > a .caret { margin-left: 5px; color: var(--text-mute); font-size: 0.8em; transition: transform .15s; display: inline-block; }
.topnav li.has-dropdown:hover > a .caret { color: var(--accent); transform: rotate(0deg); }
.topnav .dropdown {
  display: none; position: absolute; top: calc(100% + 8px); left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 200px;
  z-index: 100;
  box-shadow: 0 12px 32px rgba(0,0,0,.4);
  flex-direction: column !important;
  flex-wrap: nowrap !important;
}
.topnav .dropdown::before {
  content: ''; position: absolute; top: -8px; left: 16px;
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--border);
}
.topnav li.has-dropdown:hover .dropdown { display: flex; }
.topnav li.has-dropdown:focus-within .dropdown { display: flex; }
.topnav .dropdown li { width: 100%; }
.topnav .dropdown li a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px;
  border-radius: 7px;
  color: var(--text-dim);
  width: 100%;
}
.topnav .dropdown li a .dim {
  color: var(--text-mute);
  font-size: 0.8em;
  font-weight: 400;
}
.topnav .dropdown li a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.topnav .dropdown li a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.topnav .dropdown li a.active .dim {
  color: var(--accent);
  opacity: 0.6;
}
.topnav .logout button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 13px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82em;
  font-family: var(--mono);
  transition: all .15s;
}
.topnav .logout button:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-mute); }

.ams-clock {
  font-family: var(--mono);
  font-size: 0.86em;
  color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  letter-spacing: 0.05em;
  background: var(--surface-2);
}
.ams-clock .ams-clock-tz {
  color: var(--text-mute);
  font-size: 0.78em;
}
.ams-clock::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.nav-gear, .nav-logout {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  margin-left: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s, border-color .15s, transform .25s, background .15s;
}
.nav-gear:hover  { color: var(--accent); border-color: rgba(255,107,74,.4); text-decoration: none; }
.nav-gear:hover svg { transform: rotate(30deg); transition: transform .25s; }
.nav-gear svg { transition: transform .25s; }
.nav-gear.active { color: var(--accent); border-color: var(--accent); background: rgba(255,107,74,.08); }

.nav-logout {
  font-family: var(--mono); font-size: 1.1em; line-height: 1;
  padding: 0;
}
.nav-logout:hover { color: var(--red); border-color: rgba(248,113,113,.4); background: rgba(248,113,113,.06); }

.container { max-width: 1280px; margin: 0 auto; padding: 32px 32px 64px; }

/* Page head */
.page-head { margin-bottom: 32px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.page-head-text { flex: 1; }
.crumb {
  font-family: var(--mono);
  color: var(--text-mute);
  font-size: 0.85em;
  margin-bottom: 6px;
}
.crumb b { color: var(--accent); font-weight: 500; }
h1 {
  margin: 0; font-size: 2.1em; font-weight: 700;
  letter-spacing: -0.025em;
  display: inline-flex; align-items: center;
}
h1::after {
  content: ''; display: inline-block;
  width: 5px; height: 1em;
  background: var(--accent);
  margin-left: 12px;
  animation: blink 1.2s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
.tagline {
  color: var(--text-dim);
  margin: 10px 0 0;
  max-width: 620px;
  font-size: 0.96em;
}
h2 {
  font-size: 0.78em; font-weight: 600;
  margin: 36px 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-mute);
  font-family: var(--mono);
}
h2 .accent { color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer; font-size: 0.88em; font-weight: 500;
  transition: all .15s;
  text-decoration: none;
  font-family: var(--mono);
}
.btn.primary {
  background: var(--accent); color: white;
  box-shadow: 0 0 0 1px rgba(255,107,74,.5), 0 8px 20px rgba(255,107,74,.18);
}
.btn.primary:hover { background: var(--accent-hover); text-decoration: none; transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(255,107,74,.7), 0 10px 24px rgba(255,107,74,.28); }
.btn.secondary {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn.secondary:hover { background: var(--surface); border-color: var(--text-mute); text-decoration: none; color: var(--text); }
.btn.danger { background: transparent; color: var(--red); border-color: rgba(248,113,113,.4); }
.btn.danger:hover { background: rgba(248,113,113,.12); color: var(--red); text-decoration: none; }

.btn-icon { font-size: 0.9em; }

/* Metric grid */
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 24px 24px 22px;
  display: block; color: inherit;
  position: relative;
  transition: border-color .2s, transform .15s;
}
.metric-card:hover { border-color: var(--border); text-decoration: none; }
.metric-value {
  font-size: 3em; font-weight: 700; line-height: 1;
  letter-spacing: -0.04em;
  color: var(--text);
}
.metric-value.accent { color: var(--accent); }
.metric-value.warm { color: var(--warm); }
.metric-value.teal { color: var(--teal); }
.metric-value.purple { color: var(--purple); }
.metric-value.dim { color: var(--text-mute); }
.metric-label {
  margin-top: 16px;
  font-family: var(--mono);
  font-size: 0.74em;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.metric-label .sep { color: var(--text-mute); margin: 0 6px; }
.metric-sub {
  margin-top: 4px;
  color: var(--text-mute);
  font-size: 0.85em;
  font-family: var(--mono);
}

/* Section card (e.g. funnels) */
.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 22px 24px 24px;
}
.panel-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; }
.panel-head {
  font-family: var(--mono);
  font-size: 0.74em;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 18px;
}
.panel-head .sep { color: var(--text-mute); margin: 0 6px; }

/* Funnel bars */
.funnel { display: grid; gap: 14px; }
.funnel-row .funnel-row-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.92em;
  margin-bottom: 6px;
}
.funnel-row .funnel-row-head .name { color: var(--text); font-weight: 500; }
.funnel-row .funnel-row-head .nums {
  font-family: var(--mono); color: var(--text-dim); font-size: 0.92em;
}
.funnel-row .funnel-row-head .nums .pct { color: var(--text-mute); margin-left: 6px; }
.funnel-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.funnel-bar > div { height: 100%; border-radius: 2px; transition: width .4s ease; }
.funnel-bar.white > div { background: var(--text); }
.funnel-bar.accent > div { background: var(--accent); }
.funnel-bar.warm > div { background: var(--warm); }
.funnel-bar.teal > div { background: var(--teal); }
.funnel-bar.purple > div { background: var(--purple); }

/* Tables */
table.data {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  overflow: hidden;
  border-collapse: separate;
  border-spacing: 0;
}
table.data th, table.data td { padding: 13px 18px; text-align: left; font-size: 0.93em; }
table.data th {
  background: var(--surface-2);
  font-weight: 500; color: var(--text-dim);
  font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.18em;
  font-family: var(--mono);
  border-bottom: 1px solid var(--border-soft);
}
table.data tbody tr { transition: background .15s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody td { border-bottom: 1px solid var(--border-soft); }
table.data tbody tr:last-child td { border-bottom: none; }

.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  padding: 56px 24px;
  border-radius: 14px;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.95em;
}
.empty code { color: var(--accent); }

/* Forms */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 28px;
  max-width: 600px;
}
.form-row { margin-bottom: 20px; }
.form-row label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 500;
}
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95em;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-row .hint { font-size: 0.82em; color: var(--text-mute); margin-top: 8px; font-family: var(--mono); }
textarea { resize: vertical; min-height: 120px; font-family: var(--mono); }

input[type="checkbox"] { width: auto; margin-right: 8px; vertical-align: middle; accent-color: var(--accent); }
input[type="file"] {
  padding: 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.88em;
}
input[type="file"]::file-selector-button {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 6px; margin-right: 12px; cursor: pointer;
  font-family: var(--mono); font-size: 0.88em;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(255,107,74,.06), transparent 60%), var(--bg);
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 36px 32px;
  border-radius: 16px;
}
.login-box .brand-line {
  font-family: var(--mono);
  text-align: center;
  color: var(--text-mute);
  font-size: 0.85em;
  margin-bottom: 8px;
}
.login-box .brand-line b { color: var(--accent); font-weight: 500; }
.login-box h1 { font-size: 1.4em; margin: 0; text-align: center; display: block; }
.login-box h1::after { display: none; }
.login-box .sub { text-align: center; color: var(--text-dim); margin: 6px 0 28px; font-size: 0.88em; }
.login-box label {
  display: block; margin-bottom: 16px;
  font-family: var(--mono);
  font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--text-dim); font-weight: 500;
}
.login-box input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95em;
  background: var(--bg);
  color: var(--text);
  margin-top: 8px;
  font-family: inherit;
}
.login-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-box button {
  width: 100%; padding: 12px;
  background: var(--accent); color: white;
  border: none; border-radius: 8px;
  font-size: 0.92em; font-weight: 600;
  cursor: pointer; margin-top: 8px;
  font-family: var(--mono); letter-spacing: 0.04em;
}
.login-box button:hover { background: var(--accent-hover); }

.error {
  background: rgba(248,113,113,.08);
  border: 1px solid rgba(248,113,113,.25);
  color: var(--red);
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.88em;
  font-family: var(--mono);
}

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.72em; font-weight: 500;
  font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.badge.success { background: rgba(74,222,128,.1); color: var(--green); }
.badge.warning { background: rgba(251,191,36,.1); color: var(--warm); }
.badge.danger { background: rgba(248,113,113,.1); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.dim { background: var(--surface-2); color: var(--text-dim); }

/* Code */
code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.92em;
  color: var(--accent);
}

/* Sections (cards) two-column */
.split-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 800px) { .split-cards { grid-template-columns: 1fr; } }

/* Console (live log viewer) */
.console {
  background: #07080a;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 18px 20px;
  height: 460px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.84em;
  line-height: 1.55;
  color: var(--text-dim);
  position: relative;
}
.console::before {
  content: '● ● ●';
  display: block;
  color: var(--text-mute);
  font-size: 0.7em;
  letter-spacing: 2px;
  margin: -2px 0 12px;
}
.console-line { display: flex; gap: 10px; padding: 2px 0; word-break: break-all; }
.console-time { color: var(--text-mute); flex-shrink: 0; }
.console-sys { color: var(--accent); }
.console-ok  { color: var(--green); }
.console-warn { color: var(--warm); }
.console-err { color: var(--red); }
.console-log { color: var(--text-dim); }

/* Scrollable table wrapper (active calls) */
.scroll-table {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--surface);
}
.scroll-table table.data { border: none; border-radius: 0; }
.scroll-table table.data thead { position: sticky; top: 0; z-index: 1; background: var(--surface-2); }
.scroll-table table.data thead th { background: var(--surface-2); }

/* Two-column section for dashboard bottom */
.dash-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 1024px) { .dash-row { grid-template-columns: 1fr; } }

/* Hero start/stop buttons */
.btn-hero {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 28px;
  font-size: 1.05em; font-weight: 600;
  font-family: var(--mono);
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: 0.02em;
}
.btn-hero-start {
  background: linear-gradient(180deg, #4ade80, #2fb464);
  color: #062818;
  box-shadow: 0 0 0 1px rgba(74,222,128,.5), 0 10px 24px rgba(74,222,128,.2);
}
.btn-hero-start:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(74,222,128,.7), 0 14px 30px rgba(74,222,128,.32); }
.btn-hero-stop {
  background: linear-gradient(180deg, #f87171, #e04545);
  color: #2c0a0a;
  box-shadow: 0 0 0 1px rgba(248,113,113,.5), 0 10px 24px rgba(248,113,113,.2);
}
.btn-hero-stop:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(248,113,113,.7), 0 14px 30px rgba(248,113,113,.32); }

/* Action bar */
.action-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 24px;
  align-items: center;
}
.action-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92em; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.action-btn:hover {
  text-decoration: none;
  background: var(--surface-2);
  transform: translateY(-1px);
}
.action-btn .icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  font-size: 1em;
}
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.action-edit { color: var(--accent); border-color: rgba(255,107,74,.35); }
.action-edit:hover { background: rgba(255,107,74,.08); color: var(--accent-hover); }
.action-add  { color: var(--green); border-color: rgba(74,222,128,.35); }
.action-add:hover { background: rgba(74,222,128,.08); }
.action-upload { color: var(--teal); border-color: rgba(94,234,212,.35); }
.action-upload:hover { background: rgba(94,234,212,.08); }
.action-leads { color: var(--purple); border-color: rgba(167,139,250,.35); }
.action-leads:hover { background: rgba(167,139,250,.08); }
.action-delete { color: var(--red); border-color: rgba(248,113,113,.35); background: transparent; }
.action-delete:hover { background: rgba(248,113,113,.1); }
.action-test { color: var(--warm); border-color: rgba(251,191,36,.35); }
.action-test:hover { background: rgba(251,191,36,.08); }
.action-clear { color: var(--red); border-color: rgba(248,113,113,.35); }
.action-clear:hover:not(:disabled) { background: rgba(248,113,113,.1); }
.action-reset { color: var(--purple); border-color: rgba(167,139,250,.35); }
.action-reset:hover:not(:disabled) { background: rgba(167,139,250,.08); }

/* Modal */
dialog.modal {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 0;
  max-width: 540px; width: 100%;
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
dialog.modal::backdrop {
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(2px);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 1.2em; cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-form { padding: 20px 22px 22px; }

/* DTMF inline display */
.dtmf-keys {
  display: inline-flex; gap: 3px;
  font-family: var(--mono);
}
.dtmf-keys .key {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 600;
  font-size: 0.85em;
}

/* ============================================================================
   MOBILE — applies only at ≤ 760px (phones + small tablets in portrait).
   The desktop layout above stays untouched.
   ========================================================================== */
@media (max-width: 760px) {

  /* --- Top navigation --- */
  /* Collapses into: row 1 = brand + clock + gear + logout, row 2 = horizontally
     scrollable link strip. Dropdowns flatten to a single line so everything is
     reachable without hover (which doesn't exist on touch). */
  .topnav {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    align-items: center;
  }
  .topnav .brand { order: 1; flex: 0 0 auto; font-size: 0.92em; }
  .ams-clock    { order: 2; margin-left: auto; padding: 4px 8px; font-size: 0.72em; }
  .nav-gear     { order: 3; width: 28px; height: 28px; margin-left: 4px; }
  .nav-logout   { order: 4; width: 28px; height: 28px; margin-left: 4px; }
  .topnav > form { order: 4; margin-left: 4px; }
  .topnav ul {
    order: 5;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 4px;
    margin: 0 -4px;
  }
  .topnav ul::-webkit-scrollbar { height: 3px; }
  .topnav ul::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
  .topnav li { flex: 0 0 auto; }
  .topnav li a {
    padding: 7px 12px;
    font-size: 0.85em;
    white-space: nowrap;
  }

  /* Dropdowns: surface the children inline so touch users can reach them.
     The parent label still navigates (it has an href). Children render after
     it as additional pills, each with a small "·" label. */
  .topnav li.has-dropdown > a .caret { display: none; }
  .topnav .dropdown {
    display: contents;
    position: static;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    min-width: 0;
  }
  .topnav .dropdown::before { display: none; }
  .topnav li.has-dropdown:hover .dropdown,
  .topnav li.has-dropdown:focus-within .dropdown { display: contents; }
  .topnav .dropdown li a {
    padding: 7px 12px;
    font-size: 0.78em;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 7px;
  }
  .topnav .dropdown li a .dim { display: none; }

  /* --- Page chrome --- */
  .container { padding: 18px 14px 56px; }
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }
  .page-head h1 { font-size: 1.5em; }
  .page-head .tagline { font-size: 0.85em; }
  .page-head .btn,
  .page-head .btn.primary,
  .page-head .btn.secondary { align-self: flex-start; }

  /* --- Dashboard metric tiles: two per row instead of four --- */
  .metric-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 14px 12px; }
  .metric-value { font-size: 1.7em; }
  .metric-label { font-size: 0.7em; }
  .metric-sub   { font-size: 0.7em; }

  /* --- Dashboard side-by-side -> stacked (already at 1024px, but tighten) --- */
  .dash-row { gap: 18px; }

  /* --- Chart height: shorter so the rest fits in viewport --- */
  #cdrChart { max-height: 220px; }

  /* --- Tables: let them scroll horizontally instead of clipping --- */
  .data, table.data {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .data th, .data td { padding: 8px 10px; font-size: 0.85em; }
  .scroll-table { max-height: 60vh; }

  /* --- Campaign hero panel: stack status + buttons vertically --- */
  .campaign-hero {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 14px;
  }
  .campaign-hero .hero-actions { flex-wrap: wrap; }
  .btn-hero { padding: 10px 16px; font-size: 0.95em; }

  /* --- Action bar on campaign detail: horizontal scroll --- */
  .action-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .action-bar .action-btn { flex: 0 0 auto; white-space: nowrap; font-size: 0.82em; padding: 8px 12px; }

  /* --- Forms --- */
  .form-row label { font-size: 0.72em; }
  .form-row input, .form-row select, .form-row textarea { font-size: 16px; } /* prevent iOS zoom */
  .modal, .modal-form { max-width: 100% !important; }
  .modal { width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; border-radius: 0; }

  /* --- Filter chips on leads page wrap nicely --- */
  .chip-row { gap: 5px; }
  .chip { padding: 4px 9px; font-size: 0.72em; }

  /* --- Progress + dtmf widgets --- */
  .progress-bar { height: 12px; }
  .dtmf-keys .key { padding: 1px 5px; font-size: 0.78em; }

  /* --- Bigger touch targets (Apple/Material guideline ≥ 40px on small UIs) --- */
  .btn, .btn.primary, .btn.secondary, .btn.danger,
  button.btn-hero, .action-btn, .row-action-btn, .pause-btn {
    min-height: 40px;
    padding-top: 8px; padding-bottom: 8px;
    font-size: 0.88em;
  }
  /* Inline icon-only buttons stay tight so they don't dominate cells. */
  table .btn { min-height: 34px; padding: 6px 12px; font-size: 0.82em; }
  .btn-icon, .icon { font-size: 1.1em; }

  /* --- Campaign hero: sticky-ish behavior so Start/Pause is always reachable
        even when scrolled into details below. We only stick on phones. --- */
  .campaign-hero {
    position: sticky;
    top: 8px;
    z-index: 5;
  }
  .campaign-hero .hero-actions .btn-hero { flex: 1 1 auto; justify-content: center; }
  .progress-wrap { margin-top: 6px; }
  .progress-label { font-size: 0.74em; gap: 6px; }

  /* --- Brand label: hide the wordmark on truly narrow viewports so the
        coloured dot still anchors the nav but doesn't push items off-screen. --- */
  .topnav .brand { font-size: 0.9em; gap: 6px; }

  /* --- Clock pill: shorter on mobile, no "AMS" suffix needed --- */
  .ams-clock { padding: 4px 9px; gap: 4px; }
  .ams-clock .ams-clock-tz { display: none; }

  /* --- Action bar buttons: vertical icon + label looks cleaner when packed
        into a horizontal scroll strip. --- */
  .action-bar .action-btn {
    flex-direction: column;
    gap: 2px;
    min-width: 64px;
    padding: 8px 10px;
  }
  .action-bar .action-btn .icon { font-size: 1.2em; line-height: 1; }

  /* --- Audio player in recordings: clamp width so the whole row stays sane --- */
  audio { max-width: 100%; width: 100%; min-width: 200px; }

  /* --- Spy popup window: fill the screen when launched on a phone --- */
  .spy-box { padding: 18px; max-width: 100%; }
  .spy-actions { flex-direction: column; }
  .spy-actions input, .spy-actions button { width: 100%; }

  /* --- Permission tiles in user form: stack to a single column for tap
        comfort, give them larger touch areas. --- */
  .perm-grid { grid-template-columns: 1fr !important; }
  .perm-tile { padding: 14px; }

  /* --- Campaign + extension + queue pickers: single column too --- */
  .campaign-list { grid-template-columns: 1fr !important; max-height: 50vh; }
  .campaign-list label { padding: 8px 10px; min-height: 40px; }

  /* --- Login screen: vertically centered, padded for thumbs --- */
  .login-box,
  body > main.container > form[action="/admin/login"] {
    margin-top: 12vh;
  }

  /* --- Recordings list: hide the long "from" column (caller ID) on very
        narrow screens; "to" + duration + status remain. The number is in the
        recording filename and visible on play/download anyway. --- */
  @media (max-width: 540px) {
    .data thead th:nth-child(2),
    .data tbody td:nth-child(2) { display: none; }
  }

  /* --- Live calls table: same trick — hide the "agent" column on very
        narrow viewports because it's often empty (no agent yet) anyway. --- */
  /* (Same selector above already hits col 2 — both share the rule.) */

  /* --- Final tightening for true micro screens (≤ 380px) --- */
  @media (max-width: 380px) {
    .topnav .brand { font-size: 0; gap: 0; }   /* hide wordmark, keep the dot */
    .topnav .brand::before { width: 12px; height: 12px; }
    .nav-gear, .nav-logout { width: 30px; height: 30px; }
    .container { padding: 14px 10px 56px; }
    .metric-row { grid-template-columns: 1fr; }
    .metric-value { font-size: 1.5em; }
    .progress-bar { height: 10px; }
    .page-head h1 { font-size: 1.3em; }
    .ams-clock { font-size: 0.68em; padding: 4px 7px; }
  }

  /* --- Hide the page heading "tagline" on really small screens to save space --- */
  @media (max-width: 420px) {
    .page-head .tagline { display: none; }
    .crumb { font-size: 0.75em; }
  }
}

/* Themed scrollbars — dark track, orange accent thumb (matches the panel) */
* { scrollbar-width: thin; scrollbar-color: rgba(255,107,74,0.40) var(--surface-2, #1a1d23); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--surface-2, #1a1d23); border-radius: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,107,74,0.35); border-radius: 8px; border: 2px solid var(--surface-2, #1a1d23); }
::-webkit-scrollbar-thumb:hover { background: rgba(255,107,74,0.6); }
::-webkit-scrollbar-corner { background: var(--surface-2, #1a1d23); }

/* SMS button on the right of the nav (separate from the voice menu) */
.nav-sms { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 0.8em;
  color: var(--text-dim); border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px;
  padding: 7px 12px; margin-left: 8px; text-decoration: none; transition: .15s; white-space: nowrap; }
.nav-sms svg { width: 15px; height: 15px; }
.nav-sms:hover { color: var(--text); border-color: var(--accent); }
.nav-sms.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft, rgba(255,107,74,.12)); }
