:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2433;
  --muted: #6b7486;
  --line: #e3e7ee;
  --brand: #2f5bea;
  --brand-ink: #ffffff;
  --ok: #17915a;
  --warn: #c27c0e;
  --bad: #d13b3b;
  --soft: #eef2fd;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --card: #1a2029; --text: #e6e9ef; --muted: #98a1b2; --line: #2a3240;
    --brand: #5b80ff; --soft: #1f2a40; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
[hidden] { display: none !important; }
a { color: var(--brand); }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1em; margin: 4px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

/* buttons & inputs */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px;
  font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.green { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.red { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.on { background: var(--soft); border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 4px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand.big { font-size: 20px; margin-bottom: 20px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--brand);
  color: #fff; font-size: 12px; font-weight: 700; }

/* shell */
.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 18px; background: var(--card);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); }
nav a.active { background: var(--soft); color: var(--brand); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.switch { display: flex; white-space: nowrap; align-items: center; gap: 6px; margin: 0; color: var(--text); cursor: pointer; }
.switch input { width: auto; margin: 0; }
.pill { padding: 3px 10px; border-radius: 99px; background: var(--line); font-size: 12px; }
.pill.ready { background: #d7f3e5; color: #0d6b41; }
.pill.connecting { background: #fbefd6; color: #8a5a07; }
.pill.error { background: #f8dcdc; color: #9b2424; }
@media (prefers-color-scheme: dark) {
  .pill.ready { background: #123d2a; color: #7fe0b0; }
  .pill.connecting { background: #3d2f12; color: #f0c46c; }
  .pill.error { background: #3f1a1a; color: #f39c9c; }
}

.layout { display: grid; grid-template-columns: 1fr 330px; gap: 16px; padding: 16px; align-items: start; }
.view { min-width: 0; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .phone { order: -1; }
}

/* toolbar + tables */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 160px; }
.toolbar .btn { flex: 0 0 auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { padding: 12px 14px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--card); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
td .btn { margin-right: 4px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--soft); font-size: 12px; margin: 1px 2px 1px 0; }
.st-answered { color: var(--ok); }
.st-missed, .st-failed, .st-no-agents, .st-busy, .st-no-answer { color: var(--bad); }
.st-sent-to-ghl { color: var(--warn); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: var(--muted); }
.panel { padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.note { background: var(--soft); border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 13px; line-height: 1.5; }
.note.warn { background: #fbefd6; color: #6b4605; }
@media (prefers-color-scheme: dark) { .note.warn { background: #3d2f12; color: #f0c46c; } }

/* phone */
.side { position: sticky; top: 16px; display: grid; gap: 12px; }
.phone { padding: 16px; }
.phone .number { font-size: 20px; text-align: center; letter-spacing: .5px; padding: 10px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.keypad button { padding: 10px 0; font-size: 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); cursor: pointer; line-height: 1.1; }
.keypad button small { display: block; font-size: 9px; color: var(--muted); letter-spacing: 1px; min-height: 10px; }
.keypad button:hover { border-color: var(--brand); }
.callcard { text-align: center; padding: 8px 0; }
.callcard .who { font-size: 18px; font-weight: 650; }
.callcard .sub { color: var(--muted); margin: 2px 0 6px; }
.callcard .timer { font-size: 26px; font-variant-numeric: tabular-nums; margin: 10px 0; }
.callcard .state { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.incoming { animation: pulse 1.2s infinite; border-radius: 10px; padding: 12px; }
@keyframes pulse { 0%, 100% { background: transparent; } 50% { background: var(--soft); } }
.phone-foot { margin-top: 10px; font-size: 12px; color: var(--muted); text-align: center; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

/* campaigns, AI, captions */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.tabs a.active { background: var(--soft); color: var(--brand); font-weight: 600; }
.click-card { cursor: pointer; } .click-card:hover { border-color: var(--brand); }
.modal-card.wide { max-width: 820px; }
.days { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 10px; }
.tag.bad { background: #f8dcdc; color: #9b2424; } .tag.ai { background: #e6defc; color: #4b2aa8; }
.score { display: inline-block; min-width: 26px; text-align: center; padding: 1px 6px; border-radius: 6px; background: var(--soft); font-weight: 600; font-size: 12px; }
.score.big { font-size: 20px; padding: 6px 10px; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialer-head { display: flex; justify-content: space-between; align-items: center; font-weight: 650; margin-bottom: 10px; }
.lead-card .who { font-size: 18px; font-weight: 650; } .lead-card .sub { color: var(--muted); margin-bottom: 6px; }
.script { margin: 8px 0; font-size: 13px; line-height: 1.5; } .script summary { cursor: pointer; color: var(--brand); }
.small { font-size: 12px; } .rec { color: var(--bad); }
.assist { padding: 12px; } .assist-head { font-weight: 650; margin-bottom: 6px; }
.caps { max-height: 260px; overflow-y: auto; font-size: 13px; }
.cap { margin: 3px 0; } .cap.partial { opacity: .6; } .cap.contact b, .cap.speaker b { color: var(--brand); }
.tip { margin-top: 8px; background: var(--soft); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.transcript { margin-top: 10px; font-size: 13px; max-height: 320px; overflow-y: auto; } .transcript summary { cursor: pointer; color: var(--brand); }
