/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;
  --accent:       #2563eb;
  --radius:       10px;
  --shadow:       0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);

  /* bias palette */
  --bias-left-bg:          #dbeafe; --bias-left-text:        #1e40af;
  --bias-center-left-bg:   #ede9fe; --bias-center-left-text: #6d28d9;
  --bias-center-bg:        #d1fae5; --bias-center-text:      #065f46;
  --bias-center-right-bg:  #fef3c7; --bias-center-right-text:#92400e;
  --bias-right-bg:         #fee2e2; --bias-right-text:       #991b1b;
  --bias-unclear-bg:       #f1f5f9; --bias-unclear-text:     #475569;

  /* misinfo palette */
  --misinfo-low-bg:     #d1fae5; --misinfo-low-text:    #065f46;
  --misinfo-medium-bg:  #fef3c7; --misinfo-medium-text: #92400e;
  --misinfo-high-bg:    #fee2e2; --misinfo-high-text:   #991b1b;
  --misinfo-unclear-bg: #f1f5f9; --misinfo-unclear-text:#475569;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  background: #0f172a;
  color: white;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid #1e293b;
}
.header-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.header-brand { display: flex; align-items: baseline; gap: 14px; }
header h1    { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.updated     { font-size: 13px; opacity: .5; }
.header-meta { font-size: 13px; opacity: .4; margin-left: auto; white-space: nowrap; }

/* ── Controls ──────────────────────────────────────────────────────────────── */
.controls {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  position: sticky;
  top: 51px;
  z-index: 99;
}
.controls-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-row-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-faint);
  min-width: 40px;
}

.bias-filters, .topic-filters { display: flex; gap: 6px; flex-wrap: wrap; }

/* Bias filter buttons */
.filter-btn {
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: #94a3b8; color: var(--text); }
.filter-btn.active                          { background: #0f172a; border-color: #0f172a; color: white; }
.filter-btn[data-bias="left"].active        { background: var(--bias-left-text);         border-color: var(--bias-left-text);         color: white; }
.filter-btn[data-bias="center-left"].active { background: var(--bias-center-left-text);  border-color: var(--bias-center-left-text);  color: white; }
.filter-btn[data-bias="center"].active      { background: var(--bias-center-text);        border-color: var(--bias-center-text);        color: white; }
.filter-btn[data-bias="center-right"].active{ background: var(--bias-center-right-text); border-color: var(--bias-center-right-text); color: white; }
.filter-btn[data-bias="right"].active       { background: var(--bias-right-text);         border-color: var(--bias-right-text);         color: white; }
.filter-btn[data-bias="unclear"].active     { background: var(--bias-unclear-text);       border-color: var(--bias-unclear-text);       color: white; }

/* Topic filter buttons */
.topic-btn {
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  white-space: nowrap;
}
.topic-btn:hover { border-color: #94a3b8; color: var(--text); }
.topic-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

.location-wrap { display: flex; align-items: center; }
#location-input {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  width: 240px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
#location-input:focus { border-color: var(--accent); }

#search {
  align-self: flex-end;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  width: 220px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
  margin-left: auto;
}
#search:focus { border-color: var(--accent); }

/* ── Tab bar ───────────────────────────────────────────────────────────────── */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  position: sticky;
  top: 127px;
  z-index: 98;
}
.tab-bar-inner { max-width: 1200px; margin: 0 auto; display: flex; gap: 0; }
.tab {
  padding: 10px 20px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 60px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Article list ──────────────────────────────────────────────────────────── */
.section-label { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; font-weight: 500; }
#articles, #fact-checks { display: flex; flex-direction: column; gap: 12px; }

/* ── Article card ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.card:hover { border-color: #cbd5e1; }
.card.misinfo-high   { border-left: 3px solid #dc2626; }
.card.misinfo-medium { border-left: 3px solid #d97706; }

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.rank   { font-size: 12px; font-weight: 700; color: var(--text-faint); min-width: 20px; }
.domain { font-size: 12px; color: var(--text-muted); text-decoration: none; font-weight: 500; }
.domain:hover { color: var(--accent); }
.dot    { color: var(--text-faint); font-size: 11px; }
.time   { font-size: 12px; color: var(--text-faint); margin-left: auto; }

.badge-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }

/* Bias badge */
.bias-badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
}
.bias-badge.left         { background: var(--bias-left-bg);         color: var(--bias-left-text); }
.bias-badge.center-left  { background: var(--bias-center-left-bg);  color: var(--bias-center-left-text); }
.bias-badge.center       { background: var(--bias-center-bg);        color: var(--bias-center-text); }
.bias-badge.center-right { background: var(--bias-center-right-bg); color: var(--bias-center-right-text); }
.bias-badge.right        { background: var(--bias-right-bg);         color: var(--bias-right-text); }
.bias-badge.unclear      { background: var(--bias-unclear-bg);       color: var(--bias-unclear-text); }

/* Misinformation badge */
.misinfo-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
}
.misinfo-badge.low     { background: var(--misinfo-low-bg);     color: var(--misinfo-low-text); }
.misinfo-badge.medium  { background: var(--misinfo-medium-bg);  color: var(--misinfo-medium-text); }
.misinfo-badge.high    { background: var(--misinfo-high-bg);    color: var(--misinfo-high-text); }
.misinfo-badge.unclear { display: none; }
.misinfo-badge.low     { display: none; } /* only show medium/high */

/* Confidence dots */
.conf-dots { display: inline-flex; gap: 2px; margin-left: 2px; }
.conf-dot  { width: 5px; height: 5px; border-radius: 50%; }
.conf-dot.filled { background: currentColor; opacity: .8; }
.conf-dot.empty  { background: currentColor; opacity: .2; }

/* Fact check badge */
.fc-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
  background: #fdf2f8; color: #9d174d;
}

.card-title { font-size: 16px; font-weight: 600; line-height: 1.35; margin-bottom: 8px; letter-spacing: -.1px; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { color: var(--accent); }

.summary { font-size: 13px; color: var(--text-muted); margin-bottom: 9px; line-height: 1.6; }

.why-matters {
  font-size: 13px; color: #334155;
  background: #f8fafc; border-left: 3px solid #cbd5e1;
  padding: 7px 11px; border-radius: 0 5px 5px 0;
  margin-bottom: 10px; line-height: 1.5;
}
.why-label { font-weight: 600; color: var(--accent); margin-right: 5px; }

.misinfo-indicators {
  font-size: 12px; color: var(--misinfo-high-text);
  background: var(--misinfo-high-bg);
  border-left: 3px solid #dc2626;
  padding: 6px 10px; border-radius: 0 4px 4px 0;
  margin-bottom: 9px; line-height: 1.5;
}
.misinfo-indicators.medium {
  color: var(--misinfo-medium-text);
  background: var(--misinfo-medium-bg);
  border-left-color: #d97706;
}
.misinfo-indicators-label { font-weight: 700; margin-right: 4px; }

.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.tag  { font-size: 11px; padding: 2px 9px; background: #f1f5f9; border-radius: 99px; color: var(--text-muted); font-weight: 500; }

.score-row {
  display: flex; align-items: center; gap: 8px;
  padding-top: 4px; border-top: 1px solid #f1f5f9; margin-top: 6px;
}
.score-label { font-size: 11px; color: var(--text-faint); font-weight: 500; }
.score-bar   { flex: 1; height: 3px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.score-fill  { height: 100%; background: var(--accent); border-radius: 99px; }
.score-value { font-size: 11px; color: var(--text-faint); font-weight: 700; width: 28px; text-align: right; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar { display: flex; flex-direction: column; gap: 14px; }
.sidebar-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.sidebar-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-faint); margin-bottom: 12px;
}

/* Disinformation watch */
#disinfo-block { border-color: #fecaca; }
#disinfo-block .sidebar-title { color: #991b1b; }
.disinfo-item { padding: 10px 0; border-bottom: 1px solid #fee2e2; }
.disinfo-item:first-child { padding-top: 0; }
.disinfo-item:last-child  { border-bottom: none; padding-bottom: 0; }
.disinfo-item-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; line-height: 1.3; }
.disinfo-item-title a { color: inherit; text-decoration: none; }
.disinfo-item-title a:hover { color: var(--accent); }
.disinfo-item-risk  { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.disinfo-item-risk.high   { color: #991b1b; }
.disinfo-item-risk.medium { color: #92400e; }
.disinfo-flags { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* Topics */
.topic-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.topic-item:first-child { padding-top: 0; }
.topic-item:last-child  { border-bottom: none; padding-bottom: 0; }
.topic-title { font-size: 13px; font-weight: 500; line-height: 1.3; margin-bottom: 4px; }
.topic-meta  { font-size: 11px; color: var(--text-faint); margin-bottom: 6px; }
.topic-tags  { display: flex; flex-wrap: wrap; gap: 4px; }
.topic-tag   { font-size: 10px; padding: 1px 7px; background: #f1f5f9; border-radius: 99px; color: var(--text-muted); }

/* Bias chart */
.chart-row  { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.chart-row:last-child { margin-bottom: 0; }
.chart-label { font-size: 12px; font-weight: 500; min-width: 88px; }
.chart-track { flex: 1; height: 12px; background: #f1f5f9; border-radius: 3px; overflow: hidden; }
.chart-fill  { height: 100%; border-radius: 3px; transition: width .4s; }
.chart-count { font-size: 12px; font-weight: 700; color: var(--text-muted); min-width: 18px; text-align: right; }
.chart-fill.left         { background: var(--bias-left-bg);         outline: 1px solid var(--bias-left-text); }
.chart-fill.center-left  { background: var(--bias-center-left-bg);  outline: 1px solid var(--bias-center-left-text); }
.chart-fill.center       { background: var(--bias-center-bg);        outline: 1px solid var(--bias-center-text); }
.chart-fill.center-right { background: var(--bias-center-right-bg); outline: 1px solid var(--bias-center-right-text); }
.chart-fill.right        { background: var(--bias-right-bg);         outline: 1px solid var(--bias-right-text); }
.chart-fill.unclear      { background: var(--bias-unclear-bg);       outline: 1px solid #cbd5e1; }

.about-block p { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ── State messages ────────────────────────────────────────────────────────── */
.state-msg {
  padding: 48px 24px; text-align: center; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
}
.state-msg strong { display: block; font-size: 16px; margin-bottom: 6px; color: var(--text); }

/* ── Dark mode ─────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --surface: #1e293b; --border: #334155;
    --text: #f1f5f9; --text-muted: #94a3b8; --text-faint: #64748b;
    --bias-unclear-bg: #1e293b; --bias-unclear-text: #94a3b8;
    --misinfo-unclear-bg: #1e293b; --misinfo-unclear-text: #94a3b8;
  }
  header { background: #020617; border-color: #0f172a; }
  .controls, .tab-bar { background: #1e293b; }
  .why-matters { background: #0f172a; border-color: #334155; color: #cbd5e1; }
  .tag, .topic-tag, .chart-track { background: #0f172a; }
  .score-row { border-color: #334155; }
  #search, #location-input { background: #0f172a; color: var(--text); border-color: var(--border); }
  .card:hover { border-color: #475569; }
  #disinfo-block { border-color: #7f1d1d; background: #1c0a0a; }
  .disinfo-item { border-color: #7f1d1d; }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: -1; }
  .header-meta { display: none; }
  #search { width: 100%; margin-left: 0; }
  .tab-bar { top: auto; position: static; }
  .controls { position: static; }
}
@media (max-width: 540px) {
  .filter-row { flex-direction: column; align-items: flex-start; }
  #search { width: 100%; }
  #location-input { width: 100%; }
}
