:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --brand-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #1a2233; --text: #e5e7eb; --muted: #94a3b8;
    --border: #253047; --brand: #3b82f6; --brand-2: #60a5fa; --brand-soft: #172554;
    --ok: #22c55e; --ok-soft: #052e16; --warn: #f59e0b; --warn-soft: #3b2604; --bad: #f87171; --bad-soft: #3f0d0d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

/* top bar + nav */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), #7c3aed); display: grid; place-items: center; color: #fff; font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; color: var(--muted); text-align: right; line-height: 1.2; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: .92rem; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .ico { display: none; }
@media (max-width: 720px) {
  .nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; justify-content: space-around; background: var(--surface);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .nav a { display: flex; flex-direction: column; align-items: center; font-size: .72rem; padding: 4px 10px; gap: 2px; }
  .nav .ico { display: block; font-size: 1.25rem; line-height: 1; }
  main { padding-bottom: 84px !important; }
  .topbar .who .name { display: none; }
}

main { max-width: 1400px; margin: 0 auto; padding: 18px 16px 40px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); } }

/* forms */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 9px 14px; transition: background .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 9px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.iconbtn { border: none; background: transparent; cursor: pointer; font-size: 1.05rem; padding: 4px 6px; border-radius: 8px; color: var(--text); }
.iconbtn:hover { background: var(--surface-2); }

/* banners & pills */
.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 500; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--brand-soft); color: var(--brand); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--brand-soft); color: var(--brand); }

/* dialer */
.idline { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.idline .box { flex: 1 1 200px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.idline .box .v { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.numrow { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px; }
.numrow input { font-size: 1.3rem; font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.check { min-height: 22px; margin: 8px 0 4px; font-size: .9rem; }
.check.ok { color: var(--ok); } .check.bad { color: var(--bad); }
.price { font-size: .9rem; color: var(--muted); }
.price b { color: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; max-width: 340px; margin-inline: auto; }
.keypad button { font: 600 1.35rem var(--font); padding: 12px 0; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.keypad button small { display: block; font-size: .6rem; color: var(--muted); letter-spacing: .12em; font-weight: 600; }
.keypad button:active { background: var(--brand-soft); }
.callbtn { width: 100%; max-width: 340px; display: flex; margin: 6px auto 0; padding: 16px; font-size: 1.15rem; border-radius: 999px;
  background: var(--ok); border-color: var(--ok); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--ok) 35%, transparent); }
.callbtn:hover { background: color-mix(in srgb, var(--ok) 85%, #000); }
.note { font-size: .88rem; color: var(--muted); text-align: center; margin: 12px auto 0; max-width: 420px; }
.notice { border-left: 4px solid var(--brand); background: var(--brand-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }

.status { text-align: center; padding: 8px 0; }
.status .label { font-size: 1.35rem; font-weight: 700; margin: 6px 0 2px; }
.status .detail { color: var(--muted); min-height: 1.2em; }
.status .timer { font: 700 2.6rem var(--font); font-variant-numeric: tabular-nums; margin: 6px 0; letter-spacing: .02em; }
.status .who { font-weight: 600; font-size: 1.05rem; }
.steps { display: flex; justify-content: space-between; gap: 4px; margin: 16px 0 10px; }
.steps .s { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); }
.steps .s::before { content: ""; display: block; height: 6px; border-radius: 6px; background: var(--border); margin-bottom: 6px; }
.steps .s.done::before { background: var(--ok); }
.steps .s.now::before { background: var(--brand); animation: pulse 1.2s ease-in-out infinite; }
.steps .s.fail::before { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
.hangup { margin-top: 10px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface); position: sticky; top: 0; }
tr.missed td { background: color-mix(in srgb, var(--bad-soft) 60%, transparent); }
tr.long td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td audio { width: 220px; height: 34px; vertical-align: middle; }
.actions { white-space: nowrap; }
@media (max-width: 720px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
  table.responsive td { border: none; padding: 4px 10px; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  table.responsive td::before { content: attr(data-l); color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left; }
  table.responsive td.num { text-align: right; }
  td audio { width: 100%; }
}

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }

/* admin */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 6px 12px; font: 600 .88rem var(--font); cursor: pointer; }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
pre.json { background: var(--surface-2); border-radius: 10px; padding: 10px; font: .78rem/1.4 var(--mono); overflow-x: auto; margin: 0; max-height: 220px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 10px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); color: #fff; }
.secret { font-family: var(--mono); background: var(--warn-soft); padding: 10px; border-radius: 10px; word-break: break-all; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; font-size: 1.4rem; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.err { color: var(--bad); min-height: 1.3em; font-size: .9rem; margin: 6px 0; }
.btn.block { width: 100%; }
#view-dialer, #view-costs { max-width: 1100px; margin: 0 auto; }
td audio { min-width: 200px; }
