:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #141824;
  --muted: #6b7285;
  --border: #e4e7ef;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 16px; }
.logo { background: var(--primary); color: #fff; border-radius: 8px; padding: 4px 7px; font-size: 13px; }
.topbar-right { display: flex; gap: 12px; align-items: center; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.btn { border: 1px solid transparent; background: var(--primary); color: #fff; padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: #eef0f6; }
.btn.danger { background: transparent; color: var(--red); border-color: #f3c4c4; }
.btn.green { background: var(--green); }
.btn.amber { background: var(--amber); }
.btn.sm { padding: 6px 10px; font-size: 13px; }

label { display: block; font-weight: 500; margin-bottom: 6px; }
input, textarea, select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
input:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error { color: var(--red); margin: 8px 0; }

.auth-wrap { max-width: 400px; margin: 8vh auto; }
.auth-wrap .brand { justify-content: center; margin-bottom: 20px; font-size: 20px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0; font: inherit; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.campaign-list { display: grid; gap: 12px; }
.campaign-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; cursor: pointer; }
.campaign-item:hover { border-color: #c7d2fe; }
a.campaign-item { color: inherit; }
tbody tr.static { cursor: default; }
tbody tr.static:hover { background: none; }
.progress { height: 6px; background: #eef0f6; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--primary); transition: width .4s; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; background: #eef0f6; color: var(--muted); }
.badge.running, .badge.dialing { background: #dbeafe; color: var(--blue); }
.badge.completed, .badge.connected, .badge.yes { background: #dcfce7; color: var(--green); }
.badge.paused, .badge.no_answer, .badge.busy, .badge.maybe { background: #fef3c7; color: var(--amber); }
.badge.failed, .badge.timeout, .badge.no { background: #fee2e2; color: var(--red); }
.badge.dialing::before { content: '●'; margin-right: 4px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbff; }
td.wrap { white-space: normal; max-width: 320px; color: var(--muted); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; color: var(--muted); }
.dropzone.over, .dropzone:hover { border-color: var(--primary); background: #f5f5ff; }
.dropzone.has-file { border-style: solid; border-color: var(--green); color: var(--text); }
.preview { margin-top: 10px; font-size: 13px; }

#banner .banner { padding: 10px 24px; text-align: center; font-size: 13px; }
.banner.warn { background: #fef3c7; color: #92400e; }
.banner.info { background: #e0e7ff; color: #3730a3; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--card); border-left: 1px solid var(--border); box-shadow: -8px 0 30px rgba(0,0,0,.08); z-index: 20; overflow-y: auto; padding: 24px; }
.drawer .close { float: right; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 12px 0 20px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.bubble { padding: 8px 12px; border-radius: 12px; margin: 6px 0; max-width: 85%; line-height: 1.4; }
.bubble.agent { background: #eef0ff; }
.bubble.user { background: #f1f5f1; margin-left: auto; }
.bubble .who { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #141824; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  #org-name { display: none; }
}
