:root {
  --bg: #f6f5f7;
  --card: #ffffff;
  --text: #1d1b20;
  --muted: #67636d;
  --line: #e4e1e8;
  --brand: #c62828;
  --brand-text: #ffffff;
  --ok: #2e7d32;
  --ok-bg: #e7f4e8;
  --no: #b3261e;
  --no-bg: #fbe9e7;
  --unk-bg: #eeecf0;
  --in: #2e7d32;
  --out: #1565c0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141218; --card: #1f1d23; --text: #ece9f0; --muted: #a8a3ad; --line: #34313a;
    --brand: #ef9a9a; --brand-text: #3b0909; --ok: #81c784; --ok-bg: #1d3320; --no: #f2b8b5; --no-bg: #3c1d1b;
    --unk-bg: #2b2930; --in: #81c784; --out: #90caf9; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2 { margin: 0 0 .6rem; font-weight: 600; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--no); min-height: 1.2em; }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-height: 38px; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: .45rem .9rem; cursor: pointer; min-height: 38px; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--no); }
button:disabled { opacity: .5; cursor: default; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: .7rem; }
.login-card label { display: grid; gap: .25rem; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 500; flex-wrap: wrap; }
.brand { display: grid; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: var(--text); text-decoration: none; padding: .4rem .7rem; border-radius: 8px; }
.topbar nav a.active { background: var(--unk-bg); font-weight: 600; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
label.inline { display: inline-flex; gap: .4rem; align-items: center; }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-form input:not([type=file]) { flex: 1; min-width: 180px; }

.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap > input { margin: .75rem; width: calc(100% - 1.5rem); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--unk-bg); }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; }

.msgbody { white-space: pre-wrap; word-break: break-word; max-width: 42rem; }
.dir { font-weight: 700; }
.dir.in { color: var(--in); }
.dir.out { color: var(--out); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.no { background: var(--no-bg); color: var(--no); }
.badge.unk { background: var(--unk-bg); color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.phone h3 { margin: 0; font-size: 1.05rem; }
.phone .meta { margin: .3rem 0 .8rem; }
.phone form { display: grid; gap: .5rem; }
.phone .switch { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.phone .actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.pending { color: var(--out); font-size: .85rem; }
.pair-result { margin-top: 1rem; padding: 1rem; border-radius: 10px; background: var(--unk-bg); }
.pair-code { font: 700 2rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .15em; }

.map { height: 320px; border-radius: 10px; z-index: 0; }
.map.tall { height: 480px; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; display: flex; justify-content: flex-end; }
.drawer-panel { width: min(760px, 100%); height: 100%; overflow-y: auto; background: var(--bg); padding: 16px; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
audio { width: 100%; margin: .5rem 0; }
.summary { white-space: pre-wrap; }
details summary { cursor: pointer; color: var(--muted); }
.transcript { white-space: pre-wrap; max-height: 300px; overflow-y: auto; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 2000; max-width: calc(100% - 32px); }

@media (max-width: 640px) {
  th:nth-child(7), td:nth-child(7), th:nth-child(8), td:nth-child(8) { display: none; }
  .kv { grid-template-columns: 1fr; }
}
