:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14181f;
  --ink-2: #5b6573;
  --line: #e7eaef;
  --accent: #3b5bfd;
  --accent-ink: #ffffff;
  --green: #12a150;
  --amber: #c97a00;
  --red: #d23b3b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,24,31,.04), 0 4px 16px rgba(20,24,31,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.app { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; }

/* topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -.02em; font-weight: 650; }
.brand .sub { margin: 1px 0 0; color: var(--ink-2); font-size: 12.5px; }
.brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--ink-2); transition: background .3s; }
.brand .dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(18,161,80,.13); }
.run-state { display: flex; align-items: center; gap: 16px; }
.run-meta { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-2); text-align: right; }
.run-meta b { color: var(--ink); font-weight: 600; }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px; border-radius: 999px; background: #eef0f4; font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.pill .pdot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.running { background: rgba(18,161,80,.12); color: var(--green); }
.pill.running .pdot { animation: pulse 1.4s ease-in-out infinite; }
.pill.idle { background: #eef0f4; color: var(--ink-2); }
.pill.paused { background: rgba(201,122,0,.13); color: var(--amber); }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .35; transform: scale(.8);} }

/* card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 14px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--ink-2); font-size: 12.5px; }

/* controls */
.controls { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.ctl-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field { display: inline-flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--ink-2); font-weight: 500; }
.field.small input { width: 56px; }
.field.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.field input[type=number], .field input[type=text], .field input[type=tel] {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 13px; background: #fff; color: var(--ink); width: 110px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,91,253,.12); }

/* buttons */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 15px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; transition: transform .08s, background .15s, border-color .15s, box-shadow .15s; }
.btn:hover { background: #f3f5f8; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: #2f4ce0; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: #f0f2f6; color: var(--ink); }
.btn.full { width: 100%; margin-top: 4px; }
.btn.tiny { padding: 4px 9px; font-size: 11.5px; }
.btn[data-on="true"] { background: rgba(210,59,59,.1); color: var(--red); border-color: rgba(210,59,59,.25); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 3px; padding: 16px 18px; }
.stat .snum { font-size: 27px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .slabel { color: var(--ink-2); font-size: 12px; font-weight: 500; }

/* grid */
.grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 18px; }

/* table */
.table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; padding: 0 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td { padding: 11px 12px; border-bottom: 1px solid #f1f3f6; vertical-align: top; }
tbody tr { animation: fadein .3s ease; }
tbody tr:hover { background: #fafbfc; }
@keyframes fadein { from { opacity: 0; transform: translateY(2px);} to { opacity:1; transform:none;} }
.lead-name { font-weight: 600; }
.lead-sub { color: var(--ink-2); font-size: 11.5px; }
td.summary { max-width: 280px; color: var(--ink-2); font-size: 12px; }
td.empty { text-align: center; color: var(--ink-2); padding: 30px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* status badge */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.pending { background: #eef0f4; color: var(--ink-2); }
.badge.called { background: rgba(59,91,253,.1); color: var(--accent); }
.badge.meeting { background: rgba(18,161,80,.13); color: var(--green); }
.badge.short, .badge.noans, .badge.busy, .badge.vmail { background: rgba(201,122,0,.13); color: var(--amber); }
.badge.failed { background: rgba(210,59,59,.1); color: var(--red); }
.badge.dnc { background: rgba(210,59,59,.08); color: var(--red); }
.badge.retry { background: rgba(201,122,0,.16); color: var(--amber); }
.badge.retry::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: middle; animation: pulse 1.4s ease-in-out infinite; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* test call */
.testcall .field { display: flex; width: 100%; margin-bottom: 10px; }
.testcall .field input { width: 100%; }
.testmsg { font-size: 12.5px; margin: 10px 0 0; min-height: 16px; }
.testmsg.ok { color: var(--green); } .testmsg.err { color: var(--red); }

/* agents */
.agents { margin-bottom: 18px; }
.seg { display: inline-flex; background: #eef0f4; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; color: var(--ink-2); font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 8px; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }
.seg button:hover { color: var(--ink); }
.seg button.active { background: #fff; color: var(--accent); box-shadow: var(--shadow); }
.agent-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.agent-row { display: flex; align-items: center; gap: 14px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 11px; transition: border-color .15s, background .15s; }
.agent-row:hover { background: #fafbfc; }
.agent-row.is-active { border-color: rgba(59,91,253,.35); background: rgba(59,91,253,.03); }
.agent-row .a-id { width: 34px; height: 34px; border-radius: 9px; background: #eef0f4; color: var(--ink-2); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.agent-row.is-active .a-id { background: rgba(59,91,253,.12); color: var(--accent); }
.agent-row .a-main { flex: 1; min-width: 0; }
.agent-row .a-name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.agent-row .a-sub { color: var(--ink-2); font-size: 12px; margin-top: 1px; }
.tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: #eef0f4; color: var(--ink-2); }
.tag.lead { background: rgba(18,161,80,.13); color: var(--green); }

.agent-editor { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; animation: fadein .25s ease; }
.ed-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ed-head strong { font-size: 14.5px; }
.ed-head .btn { margin-left: auto; }
.field.full { display: flex; width: 100%; margin-bottom: 12px; }
.field.full input, .field.full textarea { width: 100%; }
#edPrompt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.6; resize: vertical; min-height: 220px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; color: var(--ink); background: #fcfcfd; transition: border-color .15s, box-shadow .15s; }
#edPrompt:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,91,253,.12); }
.ed-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ed-actions { display: flex; align-items: center; gap: 8px; }
.select { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; background: #fff; color: var(--ink); }

/* logs */
.logstream { background: #0f1320; color: #cdd6e6; border-radius: 10px; padding: 12px; height: 280px; overflow-y: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 1.6; }
.logline { white-space: pre-wrap; word-break: break-word; }
.logline .lt { color: #6b7689; margin-right: 7px; }
.logline.error { color: #ff9a9a; }

@media (max-width: 940px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
