/* Tokens. Light is the default; dark is set by <html data-theme="dark">. */
:root {
  --bg: #edf0f5;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --ink: #0e1a2b;
  --mute: #5b6b82;
  --line: #dce2ea;
  --accent: #0d7c74;
  --accent-hover: #0a6963;
  --accent-ink: #ffffff;
  --accent-soft: #d8f1ee;
  --ok: #0d7c74;
  --warn: #a35a00;
  --warn-soft: #fdeccb;
  --bad: #c8362f;
  --bad-hover: #a92b25;
  --btn-bg: #ffffff;
  --btn-hover: #f1f4f8;
  --console: #0e1a2b;
  --shadow: 0 1px 2px rgba(14, 26, 43, .06), 0 8px 24px rgba(14, 26, 43, .06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #080f1a;
  --surface: #101a2a;
  --surface-2: #16233a;
  --ink: #e8eef7;
  --mute: #8fa1ba;
  --line: #22324b;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-ink: #052a26;
  --accent-soft: #0f3a3a;
  --ok: #2dd4bf;
  --warn: #f5b049;
  --warn-soft: #3a2a0c;
  --bad: #ef5b53;
  --bad-hover: #f47b74;
  --btn-bg: #16233a;
  --btn-hover: #1d2d49;
  --console: #0c2133;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  transition: background-color .2s, color .2s;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spacer { flex: 1; }
.muted { color: var(--mute); }
.error { color: var(--bad); margin: 0; min-height: 1.3em; }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background:
    linear-gradient(var(--accent-ink), var(--accent-ink)) 5px 8px / 2px 6px no-repeat,
    linear-gradient(var(--accent-ink), var(--accent-ink)) 9px 5px / 2px 12px no-repeat,
    linear-gradient(var(--accent-ink), var(--accent-ink)) 13px 7px / 2px 8px no-repeat,
    linear-gradient(var(--accent-ink), var(--accent-ink)) 17px 9px / 2px 4px no-repeat,
    var(--accent);
}
.who { font-size: 13px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }

/* Controls */
input, select {
  font: inherit; color: var(--ink);
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--mute); }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  font: inherit; font-weight: 500;
  padding: 9px 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--btn-bg); color: var(--ink);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.danger:hover:not(:disabled) { background: var(--bad-hover); border-color: var(--bad-hover); }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 8px; }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 5px 12px 5px 9px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--btn-bg); color: var(--ink);
  cursor: pointer;
  transition: background-color .15s;
}
.theme-toggle:hover { background: var(--btn-hover); }
.theme-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle.floating { position: fixed; top: 16px; right: 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--mute);
  font-size: 12px; font-weight: 500;
}
.chip.ok { background: var(--accent-soft); color: var(--ok); }
.chip.ok::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

/* Sign-in */
.login { max-width: 380px; margin: 16vh auto 0; padding: 0 20px; display: grid; gap: 12px; }
.login h1 { margin: 14px 0 0; font-size: 28px; letter-spacing: -.02em; line-height: 1.15; }
.login p { margin: 0; }
.login .btn { padding: 11px 16px; }

/* Incoming banner */
.banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--warn-soft); color: var(--ink); border-radius: 12px; }
.banner span { flex: 1; font-weight: 500; }

/* Live call console: the one loud element on the page */
.call {
  --ink: #e8eef7; --mute: #9fb0c7; --line: #2a3b57;
  --btn-bg: #18283f; --btn-hover: #213450; --surface: #12233a; --surface-2: #18283f;
  background: var(--console);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.call-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.call-name { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.call-meta { color: var(--mute); margin-top: 2px; }
.call-side { display: flex; align-items: center; gap: 14px; }
.timer { font-size: 40px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.call .chip { background: var(--surface-2); }
.call .chip.ok { background: rgba(45, 212, 191, .14); color: #2dd4bf; }
.call .chip.ok::before { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, .55); }
  100% { box-shadow: 0 0 0 8px rgba(45, 212, 191, 0); }
}

.vm-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 22px 0 10px; font-weight: 600; }
.delay { font-weight: 400; color: var(--mute); display: flex; align-items: center; gap: 8px; }
.call select { background: var(--surface-2); color: var(--ink); border-color: var(--line); padding: 6px 10px; }

.vm-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.vm-buttons .btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 14px 16px 12px; text-align: left;
  font-size: 15px; font-weight: 600;
  border-radius: 14px;
}
.vm-buttons .btn small {
  font-size: 11px; font-weight: 500; line-height: 1;
  padding: 4px 7px; border-radius: 6px;
  border: 1px solid currentColor; opacity: .7;
}
.vm-buttons .btn.primary { background: #2dd4bf; border-color: #2dd4bf; color: #052a26; }
.vm-buttons .btn.primary:hover:not(:disabled) { background: #5eead4; border-color: #5eead4; }

.call-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* Leads */
.leads { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.list-head { display: flex; gap: 10px; margin-bottom: 14px; }
.list-head input { flex: 1; min-width: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { text-align: left; font-weight: 500; color: var(--mute); font-size: 13px; padding: 6px 12px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td:first-child { font-weight: 600; }
th.num, td.num { text-align: right; }
td.actions { text-align: right; white-space: nowrap; }
tr.dnc td { color: var(--mute); text-decoration: line-through; }
tr.dnc td.actions { text-decoration: none; }
.warn-text { color: var(--warn); font-weight: 500; }
.empty { margin: 16px 4px 4px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  max-width: 90vw; padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .who { display: none; }
  main { padding: 16px; }
  .call { padding: 18px; }
  .timer { font-size: 32px; }
  .call-name { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Waiting for the beep */
.vm-status { margin: 12px 2px 0; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.vm-status.wait::before { content: ""; flex: none; width: 9px; height: 9px; border-radius: 50%; background: #2dd4bf; animation: pulse 1.6s ease-out infinite; }
.vm-status.bad { color: #ff8a80; }
.vm-buttons .btn.waiting { box-shadow: 0 0 0 2px #2dd4bf; }
