:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --ink-2: #5b6170;
  --ink-3: #8a90a0;
  --line: #e3e5ea;
  --brand: #1c2b53;
  --gold: #c9a95c;
  --brand-ink: #ffffff;
  --green: #12805c;
  --green-bg: #e3f5ee;
  --amber: #a3600a;
  --amber-bg: #fdf1dc;
  --red: #c4314b;
  --red-bg: #fbe7ea;
  --blue-bg: #eceff6;
  --grey-bg: #eef0f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 12px; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: 2px; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 550; }
.tabs button.active { background: var(--blue-bg); color: var(--brand); }

/* layout */
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.grid-agent { display: grid; grid-template-columns: 300px 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-agent { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }

/* controls */
button, .btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
button:hover:not(:disabled) { border-color: #c9ccd4; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover:not(:disabled) { background: #26386b; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.big { padding: 12px 18px; font-size: 15px; }
button.block { width: 100%; }
button.sm { padding: 4px 10px; font-size: 12px; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #d9c48f; border-color: var(--brand); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field + .field { margin-top: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink); font-weight: 500; }
.check input { width: auto; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--grey-bg); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ready { background: var(--green-bg); color: var(--green); }
.pill.dialing, .pill.connecting { background: var(--blue-bg); color: var(--brand); }
.pill.on_call { background: var(--amber-bg); color: var(--amber); }
.pill.wrap_up { background: #f1e8fd; color: #6b3fc4; }
.pill.paused { background: var(--grey-bg); color: var(--ink-2); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--grey-bg); color: var(--ink-2); }
.tag.human, .tag.interested, .tag.forwarded { background: var(--green-bg); color: var(--green); }
.tag.machine, .tag.callback { background: #f1e8fd; color: #6b3fc4; }
.tag.abandoned, .tag.failed, .tag.bad_number, .tag.do_not_call, .tag.wrong_number { background: var(--red-bg); color: var(--red); }
.tag.busy, .tag.no_answer { background: var(--amber-bg); color: var(--amber); }

/* lead card */
.lead-empty { text-align: center; padding: 48px 16px; color: var(--ink-3); }
.lead-empty .big-icon { font-size: 36px; margin-bottom: 8px; }
.lead-name { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.lead-sub { color: var(--ink-2); margin-top: 2px; }
.lead-phone { font-size: 18px; font-weight: 600; margin-top: 10px; font-variant-numeric: tabular-nums; }
.call-status { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; margin: 16px 0; font-weight: 600; }
.call-status.on_call { background: var(--amber-bg); color: var(--amber); }
.call-status.wrap_up { background: #f1e8fd; color: #6b3fc4; }
.call-status.dialing { background: var(--blue-bg); color: var(--brand); }
.call-status .timer { margin-left: auto; font-size: 20px; font-variant-numeric: tabular-nums; }
.ringing-list { list-style: none; padding: 0; margin: 8px 0 0; }
.ringing-list li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { opacity: 1; transform: scale(1);} 70% { opacity: .2; transform: scale(1.6);} 100% { opacity: 1; transform: scale(1);} }
.script { background: #fafbfc; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; white-space: pre-wrap; line-height: 1.5; }
.dispo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dispo-grid button.selected { background: var(--brand); border-color: var(--brand); color: #fff; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.history li:first-child { border-top: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--ink-2); font-weight: 550; }
.stat.warn .v { color: var(--red); }
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-stats div { background: #fafbfc; border-radius: 8px; padding: 8px 10px; }
.mini-stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 12px; color: var(--ink-2); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--ink-2); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login .brand { justify-content: center; font-size: 18px; margin-bottom: 20px; }

/* misc */
.banner { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.banner.info { background: var(--blue-bg); color: #1f3d9e; }
.banner.warn { background: var(--amber-bg); color: var(--amber); }
.banner.err { background: var(--red-bg); color: var(--red); }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: all .2s; max-width: 360px; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
body.disconnected::after { content: "Reconnecting…"; position: fixed; top: 0; left: 50%; transform: translateX(-50%); background: var(--amber); color: #fff; padding: 4px 12px; border-radius: 0 0 8px 8px; font-size: 12px; z-index: 60; }
.kbd { font-family: ui-monospace, monospace; font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--ink-2); }
.section-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.section-grid .card + .card { margin-top: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .35); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { width: 100%; max-width: 380px; }

/* Merrill Connect branding */
.brand-logo { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; display: block; }
.login .brand-logo { width: 44px; height: 44px; border-radius: 10px; }
.topbar { border-bottom: 3px solid var(--gold); }
.tabs button.active { background: #f6f0e0; color: var(--brand); box-shadow: inset 0 -2px 0 var(--gold); }
.brand { color: var(--brand); }
