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

body {
  background: #0a0a0a;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.88rem;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Nav ────────────────────────────────────────────────────────────────────── */
nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid #1a1a1a;
  position: sticky;
  top: 0;
  background: rgba(10,10,10,0.95);
  backdrop-filter: blur(8px);
  z-index: 50;
}
.spacer { flex: 1; }
#nav-auth{position:relative;}
#nav-auth-btn{background:none;border:1px solid #252525;border-radius:6px;color:#555;font-size:0.78rem;padding:5px 12px;cursor:pointer;font-family:inherit;text-decoration:none;display:inline-block;transition:color .2s,border-color .2s;}
#nav-auth-btn:hover{color:#888;border-color:#333;}
#nav-auth-btn.authed{color:#4ade80;border-color:rgba(74,222,128,0.25);}
#nav-auth-dropdown{display:none;position:absolute;top:calc(100% + 8px);right:0;background:#111;border:1px solid #1e1e1e;border-radius:8px;min-width:180px;padding:6px;z-index:100;}
#nav-auth-dropdown.open{display:block;}
.nav-dd-item{display:block;padding:8px 12px;color:#666;font-size:0.8rem;text-decoration:none;border-radius:5px;background:none;border:none;width:100%;text-align:left;cursor:pointer;font-family:inherit;transition:background .1s,color .1s;}
.nav-dd-item:hover{background:#161616;color:#ccc;}
.nav-dd-item.danger:hover{color:#f87171;}

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
  padding: 44px 0 36px;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.eyebrow {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: #4ade80;
  margin-bottom: 8px;
}
h1 {
  font-size: 1.7rem;
  font-weight: 300;
  color: #f0f0f0;
  letter-spacing: -0.02em;
}
.subtitle {
  color: #555;
  font-size: 0.84rem;
  margin-top: 6px;
  max-width: 540px;
}
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 7px;
  font-size: 0.82rem;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: opacity .15s;
  text-decoration: none;
  display: inline-block;
}
.btn-primary  { background: #4ade80; color: #0a0a0a; }
.btn-secondary {
  background: #111;
  border: 1px solid #222;
  color: #888;
}
.btn-secondary:hover { color: #fff; border-color: #444; }

/* ── Stats strip ────────────────────────────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: #1a1a1a;
  border: 1px solid #1a1a1a;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 36px;
}
.stat-card {
  background: #0d0d0d;
  padding: 20px 24px;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 300;
  color: #e0e0e0;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.stat-label {
  font-size: 0.72rem;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}
.clr-green { color: #4ade80; }
.clr-red   { color: #f87171; }
.clr-blue  { color: #60a5fa; }

/* ── Section wrapper ────────────────────────────────────────────────────────── */
.section {
  margin-top: 40px;
}
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}
.section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #444;
}
.section-sub {
  color: #2a2a2a;
  margin-left: 8px;
}

/* ── Topic cards ────────────────────────────────────────────────────────────── */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.topic-card {
  background: #0d0d0d;
  border: 1px solid #1a1a1a;
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .15s;
}
.topic-card:hover { border-color: #2a2a2a; }
.topic-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.topic-name {
  font-size: 0.84rem;
  color: #c0c0c0;
  font-weight: 500;
  line-height: 1.3;
}
.topic-key {
  font-family: monospace;
  font-size: 0.7rem;
  color: #333;
  margin-top: 2px;
}
.topic-desc {
  font-size: 0.8rem;
  color: #555;
  line-height: 1.5;
}
.topic-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ── Channel badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  border: 1px solid;
  white-space: nowrap;
}
.badge-email   { color: #888;    border-color: #2a2a2a;               background: #111; }
.badge-sms     { color: #a78bfa; border-color: rgba(167,139,250,0.3); background: rgba(167,139,250,0.07); }
.badge-always  { color: #60a5fa; border-color: rgba(96,165,250,0.3);  background: rgba(96,165,250,0.07); }
.badge-opt-in  { color: #4ade80; border-color: rgba(74,222,128,0.3);  background: rgba(74,222,128,0.07); }

/* ── Topic sparklines ───────────────────────────────────────────────────────── */
.topic-row {
  display: grid;
  grid-template-columns: 240px 1fr 80px;
  align-items: center;
  gap: 14px;
  padding: 6px 0;
}
.topic-row-label {
  font-size: 0.82rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topic-bar-track {
  background: #111;
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
}
.topic-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: #4ade80;
  transition: width .4s ease;
}
.topic-bar-fill.has-failed {
  background: linear-gradient(90deg, #4ade80 var(--sent-pct), #f87171 var(--sent-pct));
}
.topic-count {
  font-size: 0.78rem;
  color: #555;
  text-align: right;
  white-space: nowrap;
}

/* ── Sparkline ──────────────────────────────────────────────────────────────── */
.spark-wrap {
  background: #0d0d0d;
  border: 1px solid #1a1a1a;
  border-radius: 8px;
  padding: 16px 20px;
}
#spark-canvas { width: 100%; display: block; }

/* ── Preferences CTA (logged-in) ────────────────────────────────────────────── */
.prefs-cta {
  background: #0d0d0d;
  border: 1px solid #1a1a1a;
  border-radius: 10px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.prefs-cta-text strong {
  display: block;
  color: #c0c0c0;
  font-size: 0.88rem;
  margin-bottom: 4px;
}
.prefs-cta-text span { color: #555; font-size: 0.82rem; }

/* ── Channels explainer ─────────────────────────────────────────────────────── */
.channels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.channel-card {
  background: #0d0d0d;
  border: 1px solid #1a1a1a;
  border-radius: 10px;
  padding: 18px 20px;
}
.channel-icon {
  font-size: 1.4rem;
  margin-bottom: 10px;
}
.channel-name {
  font-size: 0.9rem;
  color: #c0c0c0;
  font-weight: 500;
  margin-bottom: 6px;
}
.channel-desc { font-size: 0.8rem; color: #555; line-height: 1.5; }

/* ── Loading / empty ────────────────────────────────────────────────────────── */
.loading-text { color: #333; font-size: 0.82rem; padding: 16px 0; }

/* ── Auth section (sign-in CTA for guests) ──────────────────────────────────── */
.signin-prompt {
  background: #0d0d0d;
  border: 1px solid #1e1e1e;
  border-radius: 10px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.signin-prompt p { font-size: 0.84rem; color: #666; }
.signin-prompt strong { color: #aaa; }

/* ── Search overlay ─────────────────────────────────────────────────────────── */
#search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
#search-overlay.open { display: flex; }
#search-box {
  background: #111;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  width: 560px;
  max-width: 90vw;
  overflow: hidden;
}
#search-input-overlay {
  width: 100%;
  background: none;
  border: none;
  padding: 16px 20px;
  font-size: 1rem;
  color: #e0e0e0;
  font-family: inherit;
  outline: none;
}
#search-divider { height: 1px; background: #1e1e1e; }
#search-results { max-height: 320px; overflow-y: auto; }
#search-empty, #search-hint { padding: 12px 20px; font-size: 0.78rem; color: #444; }
#search-hint { display: flex; gap: 16px; border-top: 1px solid #1a1a1a; }

@media (max-width: 700px) {
  .stats-strip { grid-template-columns: 1fr 1fr; }
  .topic-grid  { grid-template-columns: 1fr; }
  .channels-grid { grid-template-columns: 1fr; }
  .topic-row   { grid-template-columns: 120px 1fr 60px; }
  #app { padding: 0 16px 60px; }
  .prefs-cta   { flex-direction: column; align-items: flex-start; }
  .signin-prompt { flex-direction: column; align-items: flex-start; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
