:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --ink: #0f1c2e;
  --muted: #5b6878;
  --line: #d8dee6;
  --line-soft: #e8ecf1;
  --brand: #17406b;
  --brand-ink: #ffffff;
  --focus: #2b6fd6;
  --amber: #8f4b00;
  --amber-bg: #fff1dc;
  --amber-edge: #e08a1e;
  --green: #17683a;
  --green-bg: #e1f3e7;
  --red: #a8261d;
  --red-bg: #fde8e6;
  --blue-bg: #e6eefb;
  --radius: 6px;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141c;
    --surface: #151d28;
    --ink: #e8edf3;
    --muted: #9aa7b6;
    --line: #273241;
    --line-soft: #1e2835;
    --brand: #7db0ee;
    --brand-ink: #0b1420;
    --focus: #7db0ee;
    --amber: #f0b35c;
    --amber-bg: #35260f;
    --amber-edge: #d98a1f;
    --green: #7fd49b;
    --green-bg: #132a1c;
    --red: #f29a92;
    --red-bg: #3a1a18;
    --blue-bg: #16263b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- shell ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none;
}
.brand::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--amber-edge);
}
#userbox { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }

.wrap { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; min-height: 38px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn[aria-disabled="true"], .btn:disabled { opacity: .5; pointer-events: none; }
.linkbtn {
  background: none; border: 0; padding: 0; font: inherit; color: var(--brand);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- sign-in ---------- */
.hero { max-width: 720px; padding-top: 72px; }
.hero h1 { font-size: 2.1rem; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 16px; font-weight: 700; max-width: 22ch; }
.hero p { max-width: 60ch; color: var(--muted); font-size: 16px; margin: 0 0 20px; }
.hero .actions { margin: 24px 0 14px; }
.hero .fine { font-size: 13px; }
.connect-form { margin: 24px 0 14px; }
.connect-form label { display: block; font-weight: 600; margin-bottom: 6px; }
.connect-form .actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
.connect-form select { min-width: 260px; }

.notice {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius);
  background: var(--surface); padding: 10px 14px; margin: 0 0 14px; max-width: 64ch;
}
.notice strong { display: block; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.notice.warn { border-left-color: var(--amber-edge); background: var(--amber-bg); color: var(--ink); }
.notice.err { border-left-color: var(--red); background: var(--red-bg); }
.notice .btn { margin-top: 8px; }

/* ---------- folder picker ---------- */
.panel {
  max-width: 720px; margin: 40px auto 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.panel h1 { font-size: 1.5rem; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
.panel > p { margin: 0 0 18px; color: var(--muted); max-width: 60ch; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 14px 0 8px; min-height: 32px; }
.crumbs .sep { color: var(--muted); }
.crumbs .use { margin-left: auto; }
.field {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; min-height: 38px;
}
.field:hover { border-color: var(--muted); }
.panel .field { width: 100%; }
.folder-list { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); max-height: 320px; overflow: auto; }
.folder-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--line-soft);
}
.folder-row:last-child { border-bottom: 0; }
.folder-row .name { font-weight: 600; text-align: left; text-decoration: none; color: var(--ink); }
.folder-row .name:hover { text-decoration: underline; }
.checkline { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0 0; color: var(--muted); max-width: 60ch; }
.checkline input { margin-top: 4px; }

/* ---------- toolbar, tiles, filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 18px; }
.watching { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.toolbar .right { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.syncstate { color: var(--muted); font-size: 13px; display: inline-flex; gap: 12px; }

.tiles { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .num { font-size: 2rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 13px; }
.tile.lead { border-left: 5px solid var(--amber-edge); background: var(--amber-bg); }
.tile.lead .num { font-size: 2.6rem; color: var(--amber); }
.tile.lead .label, .tile.lead .sub { color: var(--ink); }
.tile .sub.bad { color: var(--red); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0;
  padding: 8px 14px; min-height: 38px; cursor: pointer; border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.filters .search { flex: 1 1 220px; min-width: 180px; max-width: 340px; }
.filters label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- table ---------- */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1180px; }
th {
  text-align: left; font-weight: 600; font-size: 13px; color: var(--muted);
  padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--blue-bg); }
tr:last-child td { border-bottom: 0; }
tr.followup td:first-child { box-shadow: inset 4px 0 0 var(--amber-edge); }
tr.error td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.processing td { color: var(--muted); }
td.when, td.phone, td.play { white-space: nowrap; font-variant-numeric: tabular-nums; }
.playbtn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
td.name { font-weight: 600; min-width: 110px; }
td.summary { min-width: 200px; max-width: 340px; }
td.summary .clamp { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--muted); font-weight: 400; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap; margin: 0 6px 4px 0;
}
.chip.followup { background: var(--amber-bg); color: var(--amber); }
.chip.done { background: var(--green-bg); color: var(--green); }
.chip.proc { background: var(--blue-bg); color: var(--brand); }
.chip.fail, .chip.overdue { background: var(--red-bg); color: var(--red); }
.chip.result { background: var(--line-soft); color: var(--ink); white-space: nowrap; }
.chip.result.admission_confirmed { background: var(--green-bg); color: var(--green); }
.chip.result.in_person_meeting { background: var(--blue-bg); color: var(--brand); }
.chip.result.follow_up_call { background: var(--amber-bg); color: var(--amber); }
td.purpose { min-width: 160px; max-width: 240px; }
td.purpose .clamp { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td.feedback { min-width: 150px; max-width: 220px; }
.fb { font-weight: 600; }
.fb.ok { color: var(--green); }
.fb.missed { color: var(--red); }
.sent { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.sent::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sent.satisfied::before { background: var(--green); }
.sent.unsatisfied::before { background: var(--red); }
.sent.neutral::before { background: var(--amber-edge); }

/* ---------- call details drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 35, .45); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 11; width: min(560px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; padding: 20px 22px 32px;
}
.drawer header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; letter-spacing: -0.01em; }
.drawer .meta { color: var(--muted); font-size: 13px; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.drawer .meta span { margin-right: 14px; }
.drawer h3 { font-size: 14px; margin: 22px 0 6px; }
.drawer p { margin: 0; max-width: 62ch; }
.drawer .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.checks li { display: flex; gap: 8px; align-items: baseline; }
.checks .mark { font-weight: 700; flex: 0 0 4.6em; }
.checks .ok .mark { color: var(--green); }
.checks .bad .mark { color: var(--red); }
.checks .na .mark { color: var(--muted); }
.issues { margin: 0; padding-left: 18px; }
.transcript {
  white-space: pre-wrap; word-break: break-word; margin: 0; padding: 12px;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--radius);
  font: 14px/1.55 var(--font); max-height: 340px; overflow: auto;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; min-width: 0; }
.form-row .field { width: 100%; min-width: 0; }
.form-row .field { color: var(--ink); font-size: 15px; }
.form-msg { color: var(--red); font-size: 13px; margin-top: 6px; min-height: 1em; }
.audio-player { width: 100%; margin: 4px 0 2px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius);
  font-weight: 600; opacity: 0; pointer-events: none;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  #toast { transition: opacity .2s; }
}

@media (max-width: 760px) {
  .wrap { padding: 16px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.lead { grid-column: 1 / -1; }
  .hero { padding-top: 32px; }
  .hero h1 { font-size: 1.7rem; }
  .form-row { grid-template-columns: 1fr; }
}
.chip.redflag { background: var(--red-bg); color: var(--red); }
.redflags { border: 1px solid var(--red); border-left-width: 4px; border-radius: var(--radius); background: var(--red-bg); padding: 10px 14px; }
.redflags h3 { color: var(--red); }
.redflags ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
.redflags blockquote { margin: 4px 0 0; padding-left: 10px; border-left: 2px solid var(--red); font-style: italic; }

/* sign-in */
.login-form { display: grid; gap: 6px; max-width: 360px; margin: 24px 0 14px; }
.login-form label { font-weight: 600; margin-top: 8px; }
.login-form .field { width: 100%; }
.login-form .actions { margin: 10px 0 0; }

/* phones (admin) */
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.devices li.na strong { color: var(--muted); }
.device-form { display: grid; gap: 6px; max-width: 360px; }
.device-form label { font-weight: 600; }
.notice.token code.token-value { display: block; margin-top: 8px; padding: 8px; overflow-wrap: anywhere; user-select: all; font-size: 13px; background: var(--surface); border-radius: var(--radius); }
