:root {
  color-scheme: light;
  --page:           #f9f8fc;
  --surface-1:      #fdfcfe;
  --text-primary:   #17151f;
  --text-secondary: #55516b;
  --text-muted:     #8d89a3;
  --gridline:       #e6e2f2;
  --baseline:       #c9c4dc;
  --border:         rgba(23,21,31,0.10);

  --brand:          #8b6cd9;
  --brand-dark:     #6d4fc0;
  --brand-soft:     #efe9fb;

  --good:           #0ca30c;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;

  --radius: 14px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------------- topbar ---------------- */
.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.brand {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px;
  background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-primary);
  font-family: inherit;
  white-space: nowrap;
}
.brand-mark { color: var(--brand); }
.topbar-actions { display: flex; gap: 4px; flex-wrap: wrap; white-space: nowrap; }
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 13px; padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.link-btn:hover { background: var(--gridline); }

.history-panel {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.history-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-secondary); margin-bottom: 8px;
}
.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.history-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-family: inherit;
}
.history-item:hover { background: var(--brand-soft); }
.history-item-title { font-size: 13px; font-weight: 600; }
.history-item-sub { font-size: 12px; color: var(--text-muted); }

/* ---------------- layout ---------------- */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ---------------- hero / search ---------------- */
.hero {
  text-align: center;
  margin: 0 0 28px;
  padding: 48px 24px 40px;
  background: linear-gradient(180deg, var(--brand-soft) 0%, rgba(239,233,251,0) 100%);
  border-radius: 0 0 28px 28px;
}
.hero h1 { font-size: 32px; margin: 0 0 28px; max-width: 640px; margin-inline: auto; }

.hero-audiences {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 340px));
  justify-content: center;
  gap: 20px;
  max-width: 760px;
  margin-inline: auto;
}
.hero-audience {
  text-align: left;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.hero-audience-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--brand-dark);
  background: var(--brand-soft);
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.hero-audience p { color: var(--text-secondary); font-size: 14px; margin: 0; }

.search-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  box-shadow: 0 1px 2px rgba(23,21,31,0.05);
  max-width: 760px;
  margin: -30px auto 0;
  position: relative;
}
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 200px; }
.field-small { flex: 0 1 180px; }
.field-full { flex: 1 1 100%; }
.field label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.field-hint { font-weight: 400; color: var(--text-muted); }
.field-note { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }
.field input[type="text"], .field input[type="number"], .field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ---------------- days slider ---------------- */
.field input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
  margin: 6px 0 2px;
}
.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------------- platform checkboxes ---------------- */
.platform-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.platform-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px 7px 10px;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
}
.platform-pill:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.platform-pill input[type="checkbox"] { accent-color: var(--brand); margin: 0; }
.platform-pill-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background: var(--page);
}
.platform-pill-disabled input[type="checkbox"] { cursor: not-allowed; }
.pill-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--gridline);
  padding: 2px 6px;
  border-radius: 999px;
}

.form-error {
  max-width: 760px;
  margin: 12px auto 0;
  color: var(--critical);
  font-size: 14px;
  text-align: center;
}

/* ---------------- buttons ---------------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--gridline); }
.btn-disabled { opacity: 0.45; cursor: not-allowed; }
.btn-disabled:hover { background: #fff; }
.btn-search { padding: 10px 22px; }
.search-icon { font-size: 14px; }
.btn-back {
  background: none; border: none; cursor: pointer; font-family: inherit;
  color: var(--text-secondary); font-weight: 600; font-size: 13px;
  padding: 0 0 8px; display: block;
}
.btn-back:hover { color: var(--brand-dark); }

/* ---------------- loading ---------------- */
.loading-card {
  max-width: 480px;
  margin: 60px auto;
  text-align: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--gridline);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card h2 { font-size: 18px; margin: 0 0 20px; }
.steps { list-style: none; padding: 0; margin: 0; text-align: left; display: inline-block; }
.steps li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; color: var(--text-muted); font-size: 14px;
}
.step-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--gridline); flex: none;
}
.steps li.active { color: var(--text-primary); font-weight: 600; }
.steps li.active .step-dot { background: var(--brand); }
.steps li.done { color: var(--text-secondary); }
.steps li.done .step-dot { background: var(--good); }
.loading-hint { color: var(--text-muted); font-size: 13px; margin: 20px 0 16px; }

/* ---------------- report header ---------------- */
.report-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 16px;
  margin-bottom: 20px;
}
.report-header h2 { margin: 0 0 4px; font-size: 24px; }
.report-meta { margin: 0; color: var(--text-secondary); font-size: 14px; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.source-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.source-chip {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--brand-soft);
  padding: 3px 9px;
  border-radius: 999px;
}

.mock-banner {
  background: #fff7e8;
  border: 1px solid var(--warning);
  color: #7a5200;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 20px;
}

/* ---------------- stat tiles ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile .stat-label {
  font-size: 12px; color: var(--text-secondary); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.stat-tile .stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-tile .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-good { background: var(--good); }
.status-warning { background: var(--warning); }
.status-serious { background: var(--serious); }
.status-critical { background: var(--critical); }

/* ---------------- panels ---------------- */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}
.panel h3 { margin: 0 0 4px; font-size: 15px; }
.panel-sub { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }

.panel-recommend {
  background: linear-gradient(180deg, var(--brand-soft) 0%, var(--surface-1) 140%);
  border-color: #d9cdf3;
}

/* ---------------- recommendations ---------------- */
.recommend-list { list-style: none; margin: 0; padding: 0; counter-reset: rec; }
.recommend-item {
  counter-increment: rec;
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.recommend-item:last-child { border-bottom: none; }
.recommend-item::before {
  content: counter(rec);
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.recommend-body { flex: 1; }
.recommend-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.recommend-detail { font-size: 13px; color: var(--text-secondary); }
.recommend-stat { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------------- rating bar chart ---------------- */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 160px;
  margin-top: 16px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-count { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.bar-fill { width: 100%; max-width: 40px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 3px; }
.bar-label { margin-top: 8px; font-size: 12px; color: var(--text-muted); }

/* ---------------- stacked sentiment bar ---------------- */
.stacked-bar {
  display: flex;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 16px;
  gap: 2px;
}
.stacked-seg { height: 100%; min-width: 2px; }
.seg-positive { background: var(--good); }
.seg-neutral { background: var(--baseline); }
.seg-negative { background: var(--critical); }
.sentiment-legend { display: flex; gap: 18px; margin-top: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---------------- priority overview chart ---------------- */
.priority-chart { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 6px; }
.priority-row { display: flex; align-items: center; gap: 10px; }
.priority-label { flex: 0 0 160px; font-size: 12px; color: var(--text-secondary); }
.priority-track {
  flex: 1;
  height: 10px;
  background: var(--gridline);
  border-radius: 999px;
  overflow: hidden;
}
.priority-fill { height: 100%; border-radius: 999px; min-width: 4px; }
.priority-value { flex: 0 0 44px; text-align: right; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------------- download picker ---------------- */
.download-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.download-picker-compact { margin-top: 0; }
.download-picker-compact .platform-pill { padding: 7px 12px; font-size: 13px; }

/* ---------------- issue cards ---------------- */
.issue-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.issue-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.issue-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  background: #fff;
  flex-wrap: wrap;
}
.issue-summary:hover { background: #fafafd; }
.severity-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  padding: 4px 9px; border-radius: 999px;
  color: #fff; flex: none;
}
.severity-critical { background: var(--critical); }
.severity-high { background: var(--serious); }
.severity-medium { background: var(--warning); color: #4a3400; }
.severity-low { background: var(--good); }
.severity-none { background: var(--gridline); color: var(--text-secondary); }

.issue-title { font-weight: 600; font-size: 14px; flex: 1 1 160px; }
.issue-quickstats { font-size: 12px; color: var(--text-muted); flex: 2 1 260px; }
.issue-caret { color: var(--text-muted); font-size: 12px; }

.trend-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  flex: none;
  background: var(--gridline);
  color: var(--text-secondary);
}
.trend-worsening { background: #fbeaea; color: var(--critical); }
.trend-improving { background: #e8f6e8; color: var(--good); }
.trend-stable { background: var(--gridline); color: var(--text-secondary); }

.issue-detail {
  padding: 4px 16px 18px;
  background: #fff;
  border-top: 1px solid var(--gridline);
  font-size: 13px;
  color: var(--text-secondary);
}
.issue-detail .detail-row { margin: 10px 0; }
.issue-detail .detail-label { font-weight: 700; color: var(--text-primary); display: block; margin-bottom: 2px; }
.issue-detail .confidence { color: var(--text-muted); font-size: 12px; }
.evidence-quote {
  border-left: 3px solid var(--brand);
  padding: 6px 12px;
  margin: 6px 0;
  background: var(--page);
  font-style: italic;
  border-radius: 0 6px 6px 0;
}
.no-ai-note {
  font-size: 12px; color: var(--text-muted); font-style: italic;
}

.finding-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.finding-tag {
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
}

/* ---------------- competitor cards ---------------- */
.competitor-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.competitor-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.competitor-header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.competitor-name { font-weight: 700; font-size: 14px; }
.competitor-mentions { font-size: 12px; color: var(--text-muted); }
.competitor-note { font-size: 13px; color: var(--text-secondary); margin: 4px 0 10px; }
.competitor-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.competitor-columns ul { margin: 4px 0 0; padding-left: 18px; }
.competitor-columns li { margin: 2px 0; }

@media (max-width: 640px) {
  .hero h1 { font-size: 26px; }
  .search-card { flex-direction: column; align-items: stretch; }
  .report-header { flex-direction: column; }
}
