@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --sidebar-bg: #171717;
  --sidebar-border: rgba(255,255,255,0.08);
  --sidebar-text: #ececec;
  --sidebar-muted: #8e8ea0;
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-active: rgba(16,163,127,0.16);

  --accent: #10a37f;
  --accent-dim: rgba(16,163,127,0.14);
  --accent-hover: #0e8f6f;

  --main-bg: #212121;
  --card-bg: #2a2a2a;
  --card-border: rgba(255,255,255,0.08);
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
  --card-shadow-hover: 0 8px 24px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.08);

  --text-primary: #ececec;
  --text-secondary: #b4b4b8;
  --text-muted: #8e8ea0;

  --border: rgba(255,255,255,0.09);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Topic colors (dark-friendly translucent chips) */
  --models-bg: rgba(167,139,250,0.16); --models-text: #c4b5fd;
  --agents-bg: rgba(96,165,250,0.16);  --agents-text: #93c5fd;
  --infra-bg: rgba(250,204,21,0.14);   --infra-text:  #fde047;
  --research-bg: rgba(74,222,128,0.14); --research-text: #86efac;
  --policy-bg: rgba(248,113,113,0.14);  --policy-text:  #fca5a5;
  --os-bg: rgba(45,212,191,0.14);       --os-text:      #5eead4;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--main-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ──────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
  z-index: 100;
}

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.logo-icon {
  font-size: 20px;
  line-height: 1;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--sidebar-text);
  letter-spacing: -0.3px;
}

.logo-sub {
  font-size: 11px;
  color: var(--sidebar-muted);
  font-weight: 400;
  letter-spacing: 0.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 0;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 22px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 0 8px;
  margin-bottom: 8px;
}

/* Role Buttons */
.role-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.role-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  opacity: 0.75;
}

.role-btn:hover {
  background: var(--sidebar-hover);
  opacity: 1;
}

.role-btn.active {
  background: var(--sidebar-active);
  color: #6ee7b7;
  font-weight: 500;
  opacity: 1;
}

.role-icon {
  font-size: 16px;
  line-height: 1;
}

/* Topic Checkboxes */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.topic-item:hover {
  background: var(--sidebar-hover);
}

.topic-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.topic-pill {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  cursor: pointer;
}

.topic-pill.models       { background: var(--models-bg);   color: var(--models-text); }
.topic-pill.agents       { background: var(--agents-bg);   color: var(--agents-text); }
.topic-pill.infrastructure { background: var(--infra-bg);  color: var(--infra-text); }
.topic-pill.research     { background: var(--research-bg); color: var(--research-text); }
.topic-pill.policy       { background: var(--policy-bg);   color: var(--policy-text); }
.topic-pill.opensource   { background: var(--os-bg);       color: var(--os-text); }

.topic-item input:not(:checked) ~ .topic-pill {
  opacity: 0.35;
  filter: grayscale(0.3);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--sidebar-border);
}

.stats-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--sidebar-text);
  line-height: 1.1;
}

.stat-label {
  font-size: 10px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--sidebar-border);
}

.last-updated {
  font-size: 11px;
  color: var(--sidebar-muted);
  line-height: 1.4;
}

/* ─── Main Content ────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--main-bg);
}

/* ─── Top Bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px 16px;
  background: var(--main-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.today-date {
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-group {
  display: flex;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.toggle-btn.active {
  background: #40414f;
  color: var(--text-primary);
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.refresh-btn:hover { background: var(--accent-hover); }
.refresh-btn:active { transform: scale(0.97); }
.refresh-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.refresh-icon {
  display: inline-block;
  font-size: 16px;
  transition: transform 0.5s;
}

.refresh-btn.spinning .refresh-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── API Banner ──────────────────────────────────────────── */
.api-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 28px 0;
  padding: 12px 16px;
  background: rgba(250,204,21,0.08);
  border: 1px solid rgba(250,204,21,0.25);
  border-radius: var(--radius);
  font-size: 13px;
  color: #fde047;
}

.api-banner code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.api-banner a { color: #fde047; }

/* ─── Stories ─────────────────────────────────────────────── */
.stories-container {
  padding: 20px 28px 40px;
  flex: 1;
}

.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
  align-items: stretch;
  grid-auto-rows: 1fr;
}

/* ─── Skeleton ────────────────────────────────────────────── */
.skeleton-card {
  height: 220px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Story Card ──────────────────────────────────────────── */
.story-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.16);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Source badge */
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}

/* Category-based source colors */
.source-badge.cat-research    { background: rgba(74,222,128,0.13);  color: #86efac; }
.source-badge.cat-industry    { background: rgba(96,165,250,0.13);  color: #93c5fd; }
.source-badge.cat-company     { background: rgba(167,139,250,0.13); color: #c4b5fd; }
.source-badge.cat-community   { background: rgba(250,204,21,0.13);  color: #fde047; }
.source-badge.cat-open-source { background: rgba(45,212,191,0.13);  color: #5eead4; }
.source-badge.cat-education   { background: rgba(251,146,60,0.13);  color: #fdba74; }
.source-badge.cat-social      { background: rgba(244,114,182,0.13); color: #f9a8d4; }
.source-badge.cat-newsletter  { background: rgba(52,211,153,0.13);  color: #6ee7b7; }

.story-author {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.story-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

.favorite-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  color: var(--text-muted);
  transition: color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.favorite-btn:hover {
  transform: scale(1.15);
  color: #f59e0b;
}

.favorite-btn.active {
  color: #f59e0b;
}

.story-card.is-read {
  opacity: 0.5;
}

.card-topics {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.topic-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  line-height: 1.5;
}

.topic-tag.models       { background: var(--models-bg);   color: var(--models-text); }
.topic-tag.agents       { background: var(--agents-bg);   color: var(--agents-text); }
.topic-tag.infrastructure { background: var(--infra-bg);  color: var(--infra-text); }
.topic-tag.research     { background: var(--research-bg); color: var(--research-text); }
.topic-tag.policy       { background: var(--policy-bg);   color: var(--policy-text); }
.topic-tag.open-source  { background: var(--os-bg);       color: var(--os-text); }

.story-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.story-title a {
  color: inherit;
  text-decoration: none;
}

.story-title a:hover {
  color: #6ee7b7;
}

.story-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  transition: color 0.2s;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.story-summary.personalized {
  color: var(--text-primary);
  padding: 10px 12px;
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.story-summary.loading {
  opacity: 0.5;
  font-style: italic;
}

/* Card Actions */
.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-dim);
  color: #5eead4;
  border-color: rgba(16,163,127,0.35);
}

.btn-primary:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary.done {
  background: rgba(34,197,94,0.14);
  color: #86efac;
  border-color: rgba(34,197,94,0.35);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: #3a3a3a;
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.18);
}

.btn-secondary.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  margin-left: auto;
  font-size: 12px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: #3a3a3a;
}

/* ─── Content Angles Panel ────────────────────────────────── */
.angles-panel {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.angles-loading {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.angles-loading::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.angles-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.angles-header::before {
  content: '✦';
  color: var(--accent);
}

.angle-block {
  margin-bottom: 12px;
}

.angle-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.angle-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  background: #262626;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.angle-copy-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn-copy {
  font-size: 11px;
  padding: 3px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-copy:hover {
  border-color: var(--accent);
  color: #5eead4;
}

.btn-copy.copied {
  background: rgba(34,197,94,0.14);
  border-color: rgba(34,197,94,0.35);
  color: #86efac;
}

.talking-points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.talking-points li {
  font-size: 12.5px;
  color: var(--text-secondary);
  padding: 5px 10px;
  background: #262626;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
  line-height: 1.5;
}

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
}

/* ─── Toast ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #2f2f2f;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideIn 0.25s ease;
  max-width: 320px;
}

.toast.success { border-left: 3px solid #4ade80; }
.toast.error   { border-left: 3px solid #f87171; }
.toast.info    { border-left: 3px solid #60a5fa; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

.toast.hiding {
  animation: fadeOut 0.25s ease forwards;
}

/* ─── Digest Button ───────────────────────────────────────── */
.digest-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 14px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--sidebar-muted);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.digest-btn:hover:not(:disabled) {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
  border-color: rgba(255,255,255,0.2);
}

.digest-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.digest-btn.sent {
  color: #4ade80;
  border-color: rgba(74,222,128,0.3);
}

/* ─── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ─── Mobile Menu Toggle ──────────────────────────────────── */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-primary);
  padding: 4px 8px;
  margin-right: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ─── Settings Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--card-border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-section h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.modal-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: #1f1f1f;
}

.modal-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 8px;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--card-border);
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .menu-toggle { display: inline-block; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); display: flex; }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .stories-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .stories-container { padding: 16px; }
}
