:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #18212b;
  --muted: #6b7785;
  --line: #e3e8ee;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --red: #c2410c;   --red-bg: #fdeee6;
  --amber: #a16207; --amber-bg: #fdf4dc;
  --green: #15803d; --green-bg: #e5f5ea;
  --blue: #1d4ed8;  --blue-bg: #e6edfd;
  --grey-bg: #eef1f4;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --card: #1a2129; --ink: #e6ebf0; --muted: #94a0ad; --line: #2a333d;
    --brand: #2dd4bf; --brand-ink: #0b1f1c;
    --red: #fb923c; --red-bg: #3a2118; --amber: #facc15; --amber-bg: #352d12;
    --green: #4ade80; --green-bg: #15301f; --blue: #93b4fd; --blue-bg: #1b2643; --grey-bg: #242c35;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 14px; }
small, .muted { color: var(--muted); }
code { background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); }
.topbar nav a.active, .topbar nav a:hover { background: var(--grey-bg); color: var(--ink); text-decoration: none; }
.me { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.me form { margin: 0; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead p { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.pad { padding: 16px 16px 0; }
.empty { padding: 40px; text-align: center; color: var(--muted); margin: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }

label { display: block; font-weight: 550; margin-bottom: 12px; }
label small { display: block; font-weight: 400; margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input, select {
  display: block; width: 100%; margin-top: 5px; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
label.check input { width: auto; margin: 0; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--grey-bg); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.actions { display: flex; gap: 8px; align-items: end; }
form.inline { display: inline; margin: 0; }
form.inline select { display: inline-block; width: auto; margin: 0; padding: 4px 8px; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; align-items: end; }
.filters label { margin-bottom: 12px; font-size: 13px; }
.filters .actions { margin-bottom: 12px; }
.speed { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; color: var(--muted); }
.speed select { width: auto; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stats.compact { grid-template-columns: repeat(3, 1fr); margin: 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); }
.stats.compact .stat { background: var(--grey-bg); border: 0; }
.stat span { display: block; font-size: 22px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.warn span { color: var(--red); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--grey-bg); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--grey-bg) 50%, transparent); }
tr.dim td { opacity: .55; }
td.rec, th.rec { min-width: 300px; }

.player { display: flex; align-items: center; gap: 8px; }
.player audio { height: 36px; width: 100%; min-width: 220px; }
.dl { font-size: 18px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--ink); }
.dl:hover { background: var(--grey-bg); text-decoration: none; }

.dir { font-size: 13px; font-weight: 550; white-space: nowrap; }
.dir.incoming { color: var(--blue); }
.dir.outgoing { color: var(--green); }
.dir.missed, .dir.rejected { color: var(--red); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.grey { background: var(--grey-bg); color: var(--muted); }
a.badge:hover { text-decoration: none; filter: brightness(.95); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash.ok { background: var(--green-bg); color: var(--green); }
.flash.err { background: var(--red-bg); color: var(--red); }

.pager { display: flex; justify-content: center; align-items: center; gap: 14px; color: var(--muted); }

.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 10px; line-height: 1.5; }
.btn.full { text-align: center; }

.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin-bottom: 4px; }

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 16px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .wrap { padding: 16px; }
  /* Tables become stacked cards on phones */
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  td { border: 0; padding: 4px 14px; display: flex; gap: 12px; }
  td[data-l]::before { content: attr(data-l); flex: 0 0 90px; color: var(--muted); font-size: 12px; font-weight: 600; }
  td.rec { min-width: 0; }
  .player audio { min-width: 0; }
}
