/* ── CSS Variables ── */
:root {
  /* Modern gradient dark theme */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --card-bg: rgba(17, 24, 39, 0.7);

  /* Accent colors - vibrant indigo/purple */
  --accent-primary: #818cf8;
  --accent-secondary: #a78bfa;
  --accent-tertiary: #6366f1;
  --accent-glow: rgba(129, 140, 248, 0.15);

  /* International accent - green */
  --accent-intl: #57b96b;
  --accent-intl-glow: rgba(87, 185, 107, 0.15);

  /* Text */
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;

  /* Glassmorphism */
  --glass-bg: rgba(17, 24, 39, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 32px rgba(129, 140, 248, 0.2);

  /* Source colors */
  --source-cbs: #3b82f6;
  --source-cbc: #38bdf8;
  --source-abc: #f97316;
  --source-nbc4: #22c55e;
  --source-other: #6b7280;

  /* International source colors */
  --source-bbc: #bb0000;
  --source-aljazeera: #c79a00;
  --source-france24: #002fa7;
  --source-npr: #1a9e6e;
  --source-toi: #e84118;
  --source-rt: #1a6b3a;
  --source-scmp: #b45309;
  --source-guardian: #005689;

  /* Borders */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* ── Base ── */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1f35 100%);
  color: var(--text-primary);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* Animated background dots */
body::before {
  content: '';
  position: fixed;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background: radial-gradient(circle, rgba(129, 140, 248, 0.05) 1px, transparent 1px);
  background-size: 50px 50px;
  animation: backgroundScroll 60s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes backgroundScroll {
  0%   { transform: translate(0, 0); }
  100% { transform: translate(50px, 50px); }
}

/* ── Layout ── */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  position: relative;
  z-index: 1;
}

/* ── Header ── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 16px;
}

.header h1 {
  margin: 0;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* ── Tab Bar ── */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0;
}

.tab-btn {
  padding: 10px 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  position: relative;
  bottom: -1px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active-us {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  background: rgba(129, 140, 248, 0.08);
}

.tab-btn.active-intl {
  color: var(--accent-intl);
  border-bottom-color: var(--accent-intl);
  background: rgba(87, 185, 107, 0.08);
}

.tab-count {
  display: inline-block;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75rem;
  margin-left: 6px;
  font-weight: 700;
}

/* ── Toolbar ── */
.toolbar {
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  box-shadow: var(--shadow-md);
}

/* Mobile filter toggle */
.filter-toggle {
  display: none;
  width: 100%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.filter-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  width: 100%;
}

.toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.2s;
}

.toolbar input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.toolbar select,
.toolbar button {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.toolbar button:hover,
.toolbar select:hover {
  background: rgba(0, 0, 0, 0.5);
  border-color: var(--accent-primary);
}

.toolbar button.active {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  border-color: transparent;
  font-weight: 600;
}

/* ── Buttons ── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-width: 150px;
}

.stat-icon { font-size: 1.5rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent-primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── News Grid ── */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  align-items: stretch;
}

/* ── News Card ── */
.msg {
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.msg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top left, var(--accent-glow), transparent 60%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.msg:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  border-color: var(--accent-primary);
}

.msg:hover::before { opacity: 1; }

/* Source stripe */
.msg::after {
  content: '';
  position: absolute;
  inset: 0;
  border-left: 4px solid var(--source-other);
  border-radius: var(--radius-lg);
  pointer-events: none;
}

.msg.source-cbs::after   { border-left-color: var(--source-cbs); }
.msg.source-cbc::after   { border-left-color: var(--source-cbc); }
.msg.source-abc::after   { border-left-color: var(--source-abc); }
.msg.source-nbc4::after  { border-left-color: var(--source-nbc4); }

/* International source stripes */
.msg.source-bbc::after       { border-left-color: var(--source-bbc); }
.msg.source-aljazeera::after { border-left-color: var(--source-aljazeera); }
.msg.source-france24::after  { border-left-color: var(--source-france24); }
.msg.source-npr::after       { border-left-color: var(--source-npr); }
.msg.source-toi::after       { border-left-color: var(--source-toi); }
.msg.source-rt::after        { border-left-color: var(--source-rt); }
.msg.source-scmp::after      { border-left-color: var(--source-scmp); }
.msg.source-guardian::after  { border-left-color: var(--source-guardian); }

.msg.source-bbc:hover,
.msg.source-aljazeera:hover,
.msg.source-france24:hover,
.msg.source-npr:hover,
.msg.source-toi:hover,
.msg.source-rt:hover,
.msg.source-scmp:hover,
.msg.source-guardian:hover {
  box-shadow: var(--shadow-md), 0 0 0 1px var(--accent-intl), 0 0 24px var(--accent-intl-glow);
}

/* International card glow tint */
.msg.intl-card::before {
  background: radial-gradient(circle at top left, var(--accent-intl-glow), transparent 60%);
}

.msg.intl-card:hover {
  border-color: var(--accent-intl);
  box-shadow: var(--shadow-lg), 0 0 32px rgba(87, 185, 107, 0.2);
}

/* ── Card Content ── */
.msg-main-title {
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  position: relative;
  z-index: 1;
}

.msg-main-title a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color 0.2s;
}

.msg-main-title a:hover { color: var(--accent-primary); }

.meta-line {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  position: relative;
  z-index: 1;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  border: 1px solid rgba(75, 85, 99, 0.6);
  padding: 3px 10px;
  background: rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  font-size: 0.75rem;
}

.meta-pill-label { opacity: 0.7; }
.meta-pill-value { color: var(--text-secondary); font-weight: 600; }

.meta-pill-source {
  border-color: var(--accent-primary);
  background: rgba(129, 140, 248, 0.15);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-pill-source.intl-source {
  border-color: var(--accent-intl);
  background: rgba(87, 185, 107, 0.15);
}

.meta-pill-new {
  border-color: #16a34a;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.4);
  animation: pulse 2s infinite;
}

.meta-pill-feed {
  border-color: rgba(87, 185, 107, 0.5);
  background: rgba(87, 185, 107, 0.12);
  color: #86efac;
  font-weight: 600;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.8; }
}

blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid rgba(129, 140, 248, 0.3);
  color: var(--text-secondary);
  white-space: normal;
  word-wrap: break-word;
  font-size: 0.85rem;
  max-height: 4.5em;
  overflow: hidden;
  opacity: 0.9;
  position: relative;
  z-index: 1;
}

/* ── Embed Card ── */
.embed-card {
  margin-top: 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-md);
  padding: 10px;
  border: 1px solid rgba(75, 85, 99, 0.6);
  position: relative;
  z-index: 1;
}

.embed-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.embed-title a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s;
}

.embed-title a:hover { color: var(--accent-secondary); }

.embed-snippet {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 3.5em;
  overflow: hidden;
  opacity: 0.9;
}

.embed-image-wrapper {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  margin-top: 6px;
}

.embed-image-wrapper img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* ── Empty State ── */
.empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 40px;
  grid-column: 1 / -1;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out;
  backdrop-filter: blur(10px);
  padding: 20px;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: linear-gradient(135deg, rgba(26, 31, 53, 0.95), rgba(17, 24, 39, 0.95));
  backdrop-filter: blur(16px);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(129, 140, 248, 0.3);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(129, 140, 248, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transform: scale(0.9);
  transition: transform 0.3s ease-out;
}

.modal-backdrop.open .modal { transform: scale(1); }

.modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(31, 41, 55, 0.6);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
  flex: 1;
}

.modal-close {
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.5);
  color: var(--text-primary);
  transform: rotate(90deg);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal-meta-pill {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  padding: 6px 12px;
  border: 1px solid rgba(75, 85, 99, 0.6);
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.modal-meta-pill strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.modal-image-wrapper {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}

.modal-image-wrapper img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.modal-content {
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(31, 41, 55, 0.6);
  display: flex;
  justify-content: flex-end;
}

.modal-link-btn {
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  color: white;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
  transition: all 0.3s;
}

.modal-link-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.7);
}

.modal-link-btn .icon { font-size: 1.1rem; }

/* ── Archive Viewer ── */
.archive-list {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 20px;
}

.archive-item {
  padding: 12px;
  border-bottom: 1px solid rgba(75, 85, 99, 0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: var(--radius-sm);
}

.archive-item:hover { background: rgba(129, 140, 248, 0.1); }
.archive-item:last-child { border-bottom: none; }

.archive-feed-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  margin-left: 8px;
}

.archive-feed-badge.us   { background: rgba(129,140,248,0.2); color: #a5b4fc; }
.archive-feed-badge.intl { background: rgba(87,185,107,0.2);  color: #86efac; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .header h1 { font-size: 1.5rem; }
  .list { grid-template-columns: 1fr; }
  .stat-card { min-width: 100%; }

  .filter-toggle { display: block; }
  .toolbar-controls { display: none; }
  .toolbar-controls.show {
    display: flex;
    flex-direction: column;
  }

  .toolbar input[type="text"],
  .toolbar select,
  .toolbar button {
    width: 100%;
    min-width: 100%;
  }

  .modal {
    border-radius: 0;
    max-height: 100vh;
    margin: 0;
  }

  .modal-backdrop { padding: 0; }

  .tab-btn {
    padding: 8px 14px;
    font-size: 0.85rem;
  }
}

/* ── Back to Top Button ── */
#backToTopBtn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  color: white;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;

  /* Hidden by default */
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

#backToTopBtn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

#backToTopBtn:hover {
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.7);
  transform: translateY(-2px);
}

#backToTopBtn:focus-visible {
  outline: 3px solid var(--accent-secondary);
  outline-offset: 3px;
}

/* Mobile — nudge left so it doesn't overlap any browser UI chrome */
@media (max-width: 768px) {
  #backToTopBtn {
    bottom: 20px;
    right: 16px;
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }
}
