:root {
  --bg: #0a0e17;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-dim: #8b94a7;
  --accent: #6c8cff;
  --accent-2: #9b6cff;
  --green: #34d399;
  --yellow: #fbbf24;
  --orange: #fb923c;
  --red: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(1100px 700px at 85% -12%, #18203a 0%, transparent 60%),
    radial-gradient(800px 560px at -8% 112%, #221a36 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px; flex-shrink: 0; padding: 22px 14px;
  background: var(--surface); backdrop-filter: blur(14px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; padding: 0 6px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--text-dim); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  text-align: left; padding: 10px 12px; border-radius: 10px;
  background: transparent; border: none; color: var(--text-dim);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s; font-family: inherit;
}
.nav-ico { font-size: 16px; width: 20px; text-align: center; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.disabled { opacity: 0.35; pointer-events: none; cursor: not-allowed; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(108,140,255,0.18), rgba(155,108,255,0.18));
  color: var(--text); box-shadow: inset 0 0 0 1px var(--border);
}
.sidebar-footer { margin-top: auto; padding-top: 14px; }

/* ---------- Main / topbar ---------- */
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; backdrop-filter: blur(14px);
  background: rgba(10,14,23,0.72); z-index: 10; flex-wrap: wrap;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.agency-select { max-width: 220px; font-weight: 600; }
.range-control { display: flex; align-items: center; gap: 8px; }
.range-custom { display: none; align-items: center; gap: 6px; }

.pill {
  font-size: 12px; padding: 5px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.ok { color: var(--green); }
.pill.err { color: var(--red); }
.pill.running { color: var(--accent); }

.content { padding: 24px 28px; }
.loading { color: var(--text-dim); padding: 48px; text-align: center; }

/* ---------- Form controls ---------- */
.input, .select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 10px; font-family: inherit; font-size: 13px;
}
.input.wide { width: 100%; }
.input.small, .select.small { padding: 7px 10px; font-size: 12.5px; }
.input::placeholder { color: var(--text-dim); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%238b94a7' d='M6 8L2 4h8z'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center;
}
.select option { background-color: #11151f; color: var(--text); }

.btn {
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 7px 11px; font-size: 12.5px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(248,113,113,0.3); }
.btn.danger:hover { background: rgba(248,113,113,0.12); border-color: var(--red); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 6px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1; }
.field > span, .field-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.field.check { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.field.check > span { text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; }
.field.check input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.filter-checks { margin-top: 12px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-field label { font-size: 13px; font-weight: 600; }
.form-field .hint { font-size: 12px; color: var(--text-dim); }
.form-msg { font-size: 12.5px; min-height: 16px; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 720px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; backdrop-filter: blur(12px);
}
.card h3 { font-size: 12.5px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; }
.subtitle-card { padding: 14px 18px; }
.subtitle-card p { font-size: 13.5px; line-height: 1.5; }
.filter-card { margin: 16px 0; }

.stat { display: flex; flex-direction: column; gap: 5px; }
.stat .value { font-size: 28px; font-weight: 800; }
.stat .label { font-size: 13px; color: var(--text-dim); }
.stat .sub { font-size: 12px; color: var(--text-dim); }

.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 12px; }
.detail-title { font-size: 19px; font-weight: 700; margin: 14px 0 16px; }
.detail-title .small, .small { font-size: 12.5px; }
.muted { color: var(--text-dim); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
td.mono { font-variant-numeric: tabular-nums; }
table.kv td { padding: 8px 10px; }
.empty { padding: 28px; text-align: center; color: var(--text-dim); }
.filter-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.link { color: var(--accent); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--red); }
.chat-row { cursor: pointer; }

.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-dim); white-space: nowrap; }
.template-text { font-family: monospace; font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.tmpl-block { padding: 10px 0; border-bottom: 1px solid var(--border); }
.tmpl-block:last-child { border-bottom: none; }

/* ---------- Badges / score ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.excellent, .badge.good { background: rgba(52,211,153,0.16); color: var(--green); }
.badge.needs_attention { background: rgba(251,191,36,0.16); color: var(--yellow); }
.badge.critical { background: rgba(248,113,113,0.16); color: var(--red); }

.score-cell { display: flex; align-items: center; gap: 8px; }
.score-bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; width: 70px; }
.score-bar > span { display: block; height: 100%; border-radius: 999px; }
.score-num { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 24px; }

.chart-box { position: relative; height: 270px; }
.radar-box { position: relative; height: 300px; max-width: 400px; margin: 0 auto; }

/* ---------- Chat reader ---------- */
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 10px 0 16px; flex-wrap: wrap; }
.chat-transcript { max-height: 62vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.bubble-row { display: flex; }
.bubble-row.fan { justify-content: flex-start; }
.bubble-row.op { justify-content: flex-end; }
.bubble { max-width: 72%; padding: 9px 12px; border-radius: 14px; }
.bubble-row.fan .bubble { background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble-row.op .bubble { background: linear-gradient(135deg, rgba(108,140,255,0.22), rgba(155,108,255,0.22)); border-bottom-right-radius: 4px; }
.bubble-text { font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bubble-meta { font-size: 10.5px; color: var(--text-dim); margin-top: 4px; }
.bubble-tr { font-size: 13px; line-height: 1.45; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); color: var(--text-dim); white-space: pre-wrap; word-break: break-word; font-style: italic; }

/* ---------- AI copilot ---------- */
.copilot-card .copilot-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.copilot-card .copilot-head h3 { margin: 0; }
.copilot-persona { margin-top: 8px; display: grid; gap: 4px; }
.copilot-facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.copilot-variant { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.copilot-variant.chosen { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.copilot-variant-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.copilot-variant-text { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.copilot-compose textarea { font-family: inherit; }
.copilot-editor { border-top: 1px solid var(--border); padding-top: 12px; }
.copilot-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------- Agencies ---------- */
.agency-card { margin-bottom: 14px; }
.agency-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.webhook-box { margin-top: 12px; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.webhook-url { font-family: monospace; font-size: 12px; word-break: break-all; color: var(--accent); }

/* ---------- Progress ---------- */
.progress-holder { margin-top: 14px; }
.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.progress-head .pct { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.progress-state { font-size: 12.5px; }
.progress-state.idle { color: var(--text-dim); }
.progress-state.running { color: var(--accent); }
.progress-state.done { color: var(--green); }
.progress-state.failed { color: var(--red); }
.progress-track { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress-track > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.progress-track.indeterminate > span { width: 35% !important; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.progress-detail { margin-top: 10px; }
.totals-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 16px; }
@media (max-width: 900px) { .totals-grid { grid-template-columns: repeat(3, 1fr); } }
.tcell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px; text-align: center; }
.tcell .tv { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tcell .tl { font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }

/* ---------- AI report ---------- */
.ai-grid { display: grid; gap: 16px; grid-template-columns: 1.4fr 1fr; }
@media (max-width: 1100px) { .ai-grid { grid-template-columns: 1fr; } }
.ai-banner { border-color: rgba(248,113,113,0.4); background: rgba(248,113,113,0.08); }
.ai-focus { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.ai-focus label { font-size: 13px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ai-focus input { accent-color: var(--accent); width: 16px; height: 16px; }
.ai-cost { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.ai-cost .cost-line { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 13px; }
.ai-cost .cost-line strong { color: var(--green); font-size: 16px; }
.ai-report-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.ai-summary-row { display: flex; gap: 20px; align-items: flex-start; padding: 6px 0; }
.ai-score { flex: 0 0 104px; text-align: center; padding: 16px; background: linear-gradient(135deg, rgba(108,140,255,0.10), rgba(155,108,255,0.10)); border: 1px solid var(--border); border-radius: 14px; }
.ai-score-val { font-size: 42px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.ai-summary-text { flex: 1; min-width: 0; }
.ai-summary-text p { font-size: 14px; line-height: 1.55; margin-bottom: 10px; }
.ai-headlines { padding-left: 18px; }
.ai-headlines li { margin: 5px 0; font-size: 13px; }
.ai-h { font-size: 14px; font-weight: 700; margin: 20px 0 10px; }
.ai-cols { gap: 16px; }
.ai-cols ul, .ai-mistakes, .ai-missed { padding-left: 18px; }
.ai-cols li, .ai-mistakes li, .ai-missed li { margin: 6px 0; font-size: 13px; line-height: 1.5; }
.ai-op-list { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .ai-op-list { grid-template-columns: 1fr; } .ai-summary-row { flex-direction: column; } }
.ai-op-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.ai-op-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ai-revenue { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.ai-revenue-big { font-size: 26px; font-weight: 800; color: var(--red); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.ai-actions { list-style: none; display: grid; gap: 8px; }
.ai-actions li { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.ai-scripts { display: grid; gap: 10px; }
.ai-script { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.ai-script-head { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; align-items: center; }
.ai-script-body { font-family: inherit; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; margin: 0; background: rgba(108,140,255,0.06); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 8px; }
.ai-chat-box { margin: 14px 0; }

/* ---------- Chats: selection + fan links ---------- */
.ai-settings-inline { margin: 14px 0; }
.ai-settings-inline .filter-row { align-items: flex-end; }
.selbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin: 14px 0; padding: 12px 16px; }
.selbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#chats-batch-report { margin-bottom: 14px; }
.cb-col { width: 38px; text-align: center; }
.chat-cb { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
tbody tr.selected { background: rgba(108,140,255,0.12); }
.fan-cell { display: flex; align-items: center; gap: 8px; }
.fan-cell .chat-ext { font-size: 13px; }
.open-chat { white-space: nowrap; }

/* ---------- Detailed parse progress ---------- */
.progress-meta { margin-top: 14px; display: grid; gap: 6px; }
.pmeta-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; padding: 7px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; }
.pmeta-row .mono { font-variant-numeric: tabular-nums; }
.skip-warn { margin-top: 16px; padding: 12px 14px; background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.32); border-radius: 12px; }
.skip-warn-head { font-weight: 700; font-size: 13.5px; color: var(--yellow); margin-bottom: 8px; }
.skip-warn ul { list-style: none; display: grid; gap: 6px; margin: 0 0 8px; padding: 0; }
.skip-warn li { font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
