:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #18232d;
  --muted: #5d6b78;
  --border: #d7dfe6;
  --accent: #0b6fa4;
  --accent-2: #0b8f6a;
  --warn: #a86400;
  --error: #b3261e;
  --live: #12805c;
  --shadow: 0 8px 28px rgba(16, 35, 50, 0.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151a;
    --surface: #161e25;
    --surface-2: #1c2730;
    --text: #e8eef3;
    --muted: #9babb8;
    --border: #2a3843;
    --accent: #64c3f2;
    --accent-2: #5cd6ae;
    --warn: #f0b35b;
    --error: #ff8a80;
    --live: #57d6a6;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 4vw, 42px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.connection { display: flex; align-items: center; gap: 10px; }
.updated { color: var(--muted); font-size: 12px; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 650;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.pill.live { color: var(--live); border-color: color-mix(in srgb, var(--live) 35%, var(--border)); }
.pill.pending { color: var(--warn); }
.pill.error { color: var(--error); }

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 4vw, 42px) 40px;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1 1 260px; }
.field span { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }

select, input, .button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  min-height: 36px;
}
input[type="search"] { width: 100%; }
select:focus, input:focus, .button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 2px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.check input { min-height: auto; accent-color: var(--accent); }
.button {
  cursor: pointer;
  font-weight: 650;
  background: var(--surface);
}
.button:hover { background: var(--surface-2); }
.button.small { min-height: 30px; padding: 4px 10px; }

.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  border-radius: 8px;
  color: var(--text);
}
.notice code { font-family: var(--mono); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
  max-height: min(68vh, 760px);
}

table { width: 100%; border-collapse: collapse; min-width: 880px; }

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--muted);
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  vertical-align: top;
  white-space: nowrap;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tbody tr.live { background: color-mix(in srgb, var(--live) 7%, transparent); }
tbody tr.live td:first-child { box-shadow: inset 3px 0 0 var(--live); }

td.call { font-weight: 750; }
td.target { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
td.name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.col-num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.col-time { width: 92px; }
.col-net { width: 108px; }
.col-mode { width: 62px; }
.col-state { width: 74px; }
.col-seen { width: 74px; }

.net-badge, .mode-badge, .state-badge {
  display: inline-block;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.mode-badge { text-transform: uppercase; }
.state-badge.active { color: var(--live); border-color: color-mix(in srgb, var(--live) 40%, var(--border)); }
.state-badge.ended { color: var(--muted); }
.kind-presence .state-badge, .kind-badge {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.empty {
  display: grid;
  gap: 4px;
  place-items: center;
  padding: 44px 18px;
  color: var(--muted);
  text-align: center;
}
.empty strong { color: var(--text); font-size: 15px; }

.panel-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.panel-foot a { margin-left: auto; }
.muted { color: var(--muted); }

.sources { margin-top: 18px; }
.sources h2 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.live .dot { background: var(--live); }
.chip.degraded .dot { background: var(--warn); }
.chip.error .dot { background: var(--error); }
.chip .chip-rows { color: var(--muted); font-variant-numeric: tabular-nums; }

.detail-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: min(84vh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.detail-dialog::backdrop { background: rgba(4, 10, 16, 0.55); }
.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-head p { margin: 2px 0 0; }
.detail-body { padding: 6px 18px 16px; overflow: auto; }
.detail-grid {
  display: grid;
  grid-template-columns: minmax(110px, 160px) 1fr;
  gap: 6px 14px;
  font-size: 13px;
}
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }
.detail-extra { padding: 0 18px 18px; }
.detail-extra summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.detail-extra pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: auto;
  font: 11.5px/1.5 var(--mono);
  max-height: 260px;
}

@media (max-width: 1050px) {
  .col-name, .col-mode, .col-seen { display: none; }
  table { min-width: 620px; }
  td.target { max-width: 220px; }
}

@media (max-width: 760px) {
  table { min-width: 560px; }
  td.target { max-width: 160px; }
  .topbar { align-items: start; }
  .connection { flex-direction: column; align-items: end; gap: 3px; }
  .updated { font-size: 11px; }
  .toolbar { gap: 8px; }
  .field.grow { flex-basis: 100%; order: 1; }
  .check { min-height: 32px; }
}
