/* ── Pulse — Twitter Intelligence Dashboard ── */

:root {
  --bg: #07080a;
  --surface: #0e1015;
  --surface-2: #151820;
  --surface-3: #1c1f2a;
  --border: #1f2233;
  --border-hover: #2a2e44;
  --text: #c8ccd8;
  --text-dim: #6b7088;
  --text-bright: #eef0f6;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --accent-2: #f472b6;
  --accent-3: #34d399;
  --accent-4: #fbbf24;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

/* Noise overlay for texture */
.noise {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--accent); color: #fff; }

/* ── Header ── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}
.header-left { display: flex; align-items: baseline; gap: 0.8rem; }
h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--text-bright);
  font-weight: 400;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pulse-dot {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 12px var(--accent);
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}
.tagline {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.header-right { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }

select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
select:hover { border-color: var(--border-hover); }
select:focus { outline: none; border-color: var(--accent); }

/* ── Pill Buttons ── */
.pill-group { display: flex; gap: 2px; background: var(--surface); border-radius: var(--radius-sm); padding: 2px; }
.pill {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.pill:hover { color: var(--text); background: var(--surface-2); }
.pill.active { background: var(--accent); color: #fff; }

/* ── Stats Bar ── */
#stats-bar {
  display: flex;
  gap: 1px;
  margin-bottom: 1.5rem;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-cell {
  flex: 1;
  background: var(--surface);
  padding: 1rem;
  text-align: center;
  transition: background 0.2s;
}
.stat-cell:hover { background: var(--surface-2); }
.stat-num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--text-bright);
  line-height: 1.2;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.2rem;
}

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  transition: border-color 0.3s;
}
.panel:hover { border-color: var(--border-hover); }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text-bright);
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.badge-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--surface-3);
  color: var(--text-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
}

/* ── Trends ── */
.trend-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.8rem;
}
.trend-item:last-child { border: none; }
.trend-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  min-width: 1.2rem;
  padding-top: 0.1rem;
}
.trend-body { flex: 1; }
.trend-topic { color: var(--text-bright); font-weight: 500; font-size: 0.9rem; }
.trend-desc { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.15rem; }
.badge-engagement {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  font-weight: 500;
}
.badge-engagement.high { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-engagement.medium { background: rgba(251,191,36,0.15); color: var(--accent-4); }

/* ── Topics ── */
.topic-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.6rem;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}
.topic-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.topic-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.topic-num {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--surface-3);
  position: absolute;
  top: -0.2rem; right: 0.6rem;
  font-style: italic;
}
.topic-title { font-weight: 600; color: var(--text-bright); font-size: 0.95rem; margin-bottom: 0.4rem; }
.topic-angle { color: var(--accent-2); font-size: 0.8rem; margin-bottom: 0.3rem; }
.topic-rationale { color: var(--text-dim); font-size: 0.8rem; line-height: 1.5; }
.topic-sources { margin-top: 0.5rem; font-size: 0.8rem; }
.topic-sources a { color: var(--accent); text-decoration: none; }
.topic-sources a:hover { text-decoration: underline; }
.topic-actions { display: flex; gap: 0.5rem; margin-top: 0.7rem; flex-wrap: wrap; }
.btn-draft {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.35rem 0.7rem; border-radius: 6px; font-size: 0.78rem; cursor: pointer;
  background: var(--accent); color: #fff; border: none; text-decoration: none;
  font-family: var(--font-body); transition: all 0.2s;
}
.btn-draft:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-draft.btn-secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
.btn-draft.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.badge-new {
  display: inline-block; font-family: var(--font-mono); font-size: 0.6rem;
  background: rgba(52,211,153,0.15); color: var(--accent-3); padding: 0.1rem 0.4rem;
  border-radius: 3px; margin-left: 0.4rem; font-weight: 600; vertical-align: middle;
}
.badge-cont {
  display: inline-block; font-size: 0.7rem; margin-left: 0.3rem; vertical-align: middle;
}
.badge-contested {
  display: inline-block; font-family: var(--font-mono); font-size: 0.6rem;
  background: rgba(251,191,36,0.15); color: var(--accent-4); padding: 0.1rem 0.4rem;
  border-radius: 3px; margin-left: 0.3rem; font-weight: 600; vertical-align: middle;
}

/* ── Tree View ── */
#tree-view details { margin-left: 0.8rem; margin-bottom: 0.2rem; }
#tree-view > details { margin-left: 0; }
#tree-view summary {
  cursor: pointer;
  padding: 0.4rem 0;
  font-weight: 500;
  color: var(--text-bright);
  font-size: 0.9rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
#tree-view summary::before {
  content: '›';
  font-size: 1rem;
  color: var(--accent);
  transition: transform 0.2s;
  display: inline-block;
  width: 0.8rem;
}
#tree-view details[open] > summary::before { transform: rotate(90deg); }
#tree-view details details summary { color: var(--text); font-weight: 400; font-size: 0.85rem; }
.tree-point {
  padding: 0.3rem 0 0.3rem 1.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-left: 1px solid var(--border);
  margin-left: 0.35rem;
  line-height: 1.5;
}
.tree-point .source { display: inline; }
.tree-point .source a { color: var(--accent); text-decoration: none; font-size: 0.75rem; }
.tree-point .source a:hover { text-decoration: underline; }

/* ── Entity Cards ── */
#entity-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.entity-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  transition: border-color 0.2s;
}
.entity-card:hover { border-color: var(--accent); }
.entity-name { font-weight: 500; color: var(--text-bright); font-size: 0.85rem; }
.entity-ctx { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.2rem; line-height: 1.45; }

/* ── Tweets ── */
#tweet-search {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
  transition: border-color 0.2s;
}
#tweet-search:focus { outline: none; border-color: var(--accent); }
#tweet-search::placeholder { color: var(--text-dim); }

.tweet-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.tweet-card:hover { background: var(--surface-2); margin: 0 -0.5rem; padding-left: 0.5rem; padding-right: 0.5rem; border-radius: var(--radius-sm); }
.tweet-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
}
.tweet-body { min-width: 0; }
.tweet-meta { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.2rem; }
.tweet-author-link {
  color: var(--text-bright);
  font-weight: 500;
  font-size: 0.85rem;
  text-decoration: none;
}
.tweet-author-link:hover { color: var(--accent); }
.tweet-time { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); }
.tweet-content {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.55;
  display: block;
  text-decoration: none;
  margin-bottom: 0.3rem;
}
.tweet-content:hover { color: var(--text-bright); }
.tweet-metrics {
  display: flex;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}
.tweet-metrics span { display: flex; align-items: center; gap: 0.2rem; }

#load-more {
  width: 100%;
  margin-top: 0.8rem;
  padding: 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
#load-more:hover { border-color: var(--accent); color: var(--accent); }

/* ── Drafts ── */
.draft-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.2rem;
  margin-bottom: 0.8rem;
}
.draft-card h1, .draft-card h2, .draft-card h3 { font-family: var(--font-display); color: var(--text-bright); margin: 1rem 0 0.5rem; font-weight: 400; }
.draft-card h1 { font-size: 1.4rem; }
.draft-card h2 { font-size: 1.15rem; }
.draft-card p { margin-bottom: 0.8rem; }
.draft-card ul { padding-left: 1.2rem; margin-bottom: 0.8rem; }
.draft-card code { background: var(--surface-3); padding: 0.15rem 0.35rem; border-radius: 3px; font-family: var(--font-mono); font-size: 0.85em; }
.draft-card strong { color: var(--text-bright); }
.draft-card em { color: var(--accent-2); }
.draft-card blockquote { border-left: 2px solid var(--accent); padding-left: 0.8rem; color: var(--text-dim); margin: 0.5rem 0; }

/* ── Footer ── */
footer {
  display: flex;
  justify-content: space-between;
  padding: 1.5rem 0;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.panel { animation: fadeUp 0.4s ease-out both; }
.panel:nth-child(2) { animation-delay: 0.05s; }
.panel:nth-child(3) { animation-delay: 0.1s; }
.panel:nth-child(4) { animation-delay: 0.15s; }
.panel:nth-child(5) { animation-delay: 0.2s; }

/* ── Mobile ── */
@media (max-width: 768px) {
  body { padding: 0.8rem; }
  h1 { font-size: 1.4rem; }
  .tagline { display: none; }
  .header-right { width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  #stats-bar { flex-wrap: wrap; }
  .stat-cell { min-width: calc(50% - 1px); }
  .panel { padding: 1rem; }
  .tweet-card { grid-template-columns: 1fr; }
  .tweet-avatar { display: none; }
  .tweet-metrics { flex-wrap: wrap; gap: 0.6rem; }
  #entity-cards { grid-template-columns: 1fr; }
  .pill { padding: 0.3rem 0.5rem; font-size: 0.7rem; }
  .topic-num { display: none; }
  footer { flex-direction: column; gap: 0.3rem; }
}

@media (max-width: 480px) {
  #stats-bar { flex-direction: column; }
  .stat-cell { padding: 0.6rem; display: flex; justify-content: space-between; align-items: center; }
  .stat-num { font-size: 1.2rem; }
}
