:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #17202b;
  --muted: #5d6877;
  --accent: #1f5bd8;
  --accent-ink: #ffffff;
  --accent-soft: #e5edfc;
  --ok: #17734a;
  --ok-soft: #e1f3e9;
  --warn: #9a5800;
  --warn-soft: #fcefd9;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 6px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e27;
    --surface-2: #1f2833;
    --border: #2d3846;
    --text: #e6ebf1;
    --muted: #96a2b2;
    --accent: #6b9bff;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a47;
    --ok: #4cc58a;
    --ok-soft: #12301f;
    --warn: #f0b04a;
    --warn-soft: #3a2a10;
    --danger: #ff7a6e;
    --danger-soft: #3d1715;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px 14px; font-size: 15px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.plain::before { display: none; }
.pill:empty { display: none; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Inputs */
input[type="text"], input[type="date"], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 72px; }
label { font-weight: 600; font-size: 13px; }
.field { display: grid; gap: 6px; margin-top: 14px; }
.req { color: var(--warn); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; margin-left: 4px; }
.form-error { margin-top: 12px; padding: 9px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }

/* ---------------- Agent popup ---------------- */
.agent-shell { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; flex: none;
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
.agent-meta { display: grid; justify-items: end; gap: 4px; min-width: 0; }
.agent-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.agent-main { flex: 1; padding: 12px 16px 16px; display: grid; gap: 12px; align-content: start; }
.agent-foot { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); }
.conn { margin-left: auto; font-size: 12px; color: var(--muted); }
.conn.down { color: var(--danger); font-weight: 600; }

.idle { text-align: center; padding: 48px 16px; color: var(--muted); }
.idle-icon { font-size: 30px; margin-bottom: 8px; }

.call-card { padding: 14px; display: grid; gap: 10px; border-left: 4px solid var(--warn); }
.call-card.live { border-left-color: var(--ok); }
.call-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.call-number { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; word-break: break-all; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--muted); }
.notes-hint { font-size: 12px; color: var(--muted); }

.dispo { padding: 16px; border-top: 4px solid var(--warn); }
.dispo-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.dispo-head .eyebrow { color: var(--warn); }
.dispo-meta { display: grid; justify-items: end; gap: 4px; text-align: right; font-size: 13px; }
fieldset { border: 0; padding: 0; margin: 14px 0 0; min-width: 0; }
legend { font-weight: 600; font-size: 13px; padding: 0; margin-bottom: 6px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label, .chip {
  position: relative; display: inline-flex; align-items: center; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px;
}
.seg input, .chip input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked), .chip:has(input:checked) {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.seg label:has(input:focus-visible), .chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.outcomes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.chip { justify-content: flex-start; min-height: 38px; }
.chip.suggest { border-style: dashed; border-color: var(--warn); }
.chip .tag { margin-left: auto; font-size: 10px; font-weight: 700; color: var(--warn); text-transform: uppercase; }
.chip:has(input:checked) .tag { color: inherit; }
.submit-row { margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-weight: 600; box-shadow: var(--shadow); z-index: 10;
}

/* Picker */
.picker { max-width: 460px; width: calc(100% - 32px); margin: 40px auto; padding: 24px; display: grid; gap: 14px; }
.agent-list { display: grid; gap: 8px; }
.agent-btn {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); text-decoration: none; background: var(--surface);
}
.agent-btn:hover { background: var(--surface-2); }
.agent-btn span:last-child { display: grid; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1 1 140px; width: auto; min-width: 0; }
.inline-form .btn { flex: none; }
.login-form .field:first-child { margin-top: 0; }
input[type="password"] { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

/* ---------------- Supervisor & simulator ---------------- */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; display: grid; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.alert .kpi-value { color: var(--warn); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; align-items: start; }
.panel { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-body { padding: 12px 14px; }
.empty { padding: 18px 14px; color: var(--muted); text-align: center; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.notes { max-width: 260px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.filters { display: flex; gap: 8px; align-items: center; }
.filters select { width: auto; padding: 5px 8px; }

.sim-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.sim-form .field { margin: 0; }
.sim-agents { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.sim-agent { padding: 12px; display: grid; gap: 8px; }
.sim-agent-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 13px; }
