/* ===== Design Tokens ===== */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;

  --text-primary: #f0f6fc;
  --text-secondary: #b1bac4;
  --text-tertiary: #7d8590;

  --border-color: #30363d;

  --brand-primary: #2b0a3d;
  --brand-dark: #180422;
  --brand-accent: #8b5cf6;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --transition: 0.2s ease;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ===== Base ===== */
html {
  scroll-behavior: smooth;
}

body {
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
header {
  background:
    radial-gradient(circle at top left, rgba(139, 92, 246, 0.15), transparent 45%),
    linear-gradient(135deg, var(--brand-primary), var(--brand-dark));
  color: white;
  padding: 1.5rem 2rem 1rem;
  box-shadow: var(--shadow-lg);
}

.header-content {
  max-width: 1440px;
  margin: 0 auto;
}

.logo {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.site-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
}

[data-theme="dark"] .site-logo {
  content: url("../security-libre-devops-white.png");
}

.logo-text {
  text-align: center;
}

.logo h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
}

.logo .subtitle {
  margin-top: 0.35rem;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.88);
}

.logo-spacer {
  width: 72px;
}

/* ===== Header Actions ===== */
.header-actions {
  display: flex;
  justify-content: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

/* ===== Search ===== */
.search-box {
  width: 100%;
  max-width: 760px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.8;
}

.search-box input {
  width: 100%;
  padding: 0.95rem 1rem 0.95rem 3rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: white;
  font-size: 1rem;
  outline: none;
  backdrop-filter: blur(12px);
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.72);
}

/* ===== Buttons ===== */
#bookmarks-toggle,
#theme-toggle,
.rss-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: white;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(10px);
}

#bookmarks-toggle,
.rss-button {
  padding: 0.75rem 1.2rem;
  border-radius: 999px;
  font-size: 0.95rem;
  text-decoration: none;
}

#theme-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.4rem;
}

#bookmarks-toggle:hover,
#theme-toggle:hover,
.rss-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

#bookmarks-toggle.active {
  background: rgba(139, 92, 246, 0.35);
  border-color: var(--brand-accent);
}

/* ===== Stats ===== */
.stats-bar {
  max-width: 1440px;
  margin: 1rem auto 0;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.82);
}

/* ===== Filters ===== */
.filters {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.8rem 1.5rem;
}

.filter-section-title {
  max-width: 1440px;
  margin: 0 auto 0.5rem;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.filter-scroll {
  max-width: 1440px;
  margin: 0 auto;
  overflow-x: auto;
}

.filter-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
  padding-bottom: 0.25rem;
}

.pill {
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.85rem;
}

.pill.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: white;
}

.pill .count {
  margin-left: 0.4rem;
  opacity: 0.85;
}

/* ===== Main ===== */
main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.controls-right {
  display: flex;
  gap: 0.75rem;
}

#date-filter,
#sort-by {
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 12px;
}

/* ===== Loading State ===== */
.loading {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 2rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

.loading.visible {
  display: flex;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--brand-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== No Results State ===== */
.no-results {
  display: none;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.8;
}

.no-results.visible {
  display: block;
}

/* ===== Grid ===== */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1rem;
}

/* ===== Cards ===== */
.article-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  transition: all var(--transition);
}

.article-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.blog-tag {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.bookmark-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  line-height: 1;
}

.bookmark-btn.bookmarked {
  color: #f59e0b;
}

.article-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0.8rem 0 0.5rem;
}

.article-title a {
  color: var(--text-primary);
  text-decoration: none;
}

.article-title a:hover {
  color: var(--brand-accent);
}

.article-meta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.article-summary {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Footer ===== */
footer {
  padding: 2rem;
  text-align: center;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-color);
  margin-top: 2rem;
  font-size: 0.9rem;
  line-height: 1.8;
}

footer a {
  color: var(--brand-accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  header {
    padding: 1rem 1rem 1.25rem;
  }

  .logo {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 0.75rem;
  }

  .logo-spacer {
    display: none;
  }

  .site-logo {
    width: 60px;
    height: 60px;
  }

  .logo h1 {
    font-size: 2rem;
    text-align: center;
  }

  .logo .subtitle {
    font-size: 0.95rem;
    max-width: 320px;
  }

  .header-actions {
    margin-top: 1rem;
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
  }

  .stats-bar {
    font-size: 0.85rem;
    gap: 0.75rem;
    text-align: center;
  }

  main {
    padding: 1rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .controls-right {
    width: 100%;
  }

  .controls-right select {
    flex: 1;
  }

  .articles-grid {
    grid-template-columns: 1fr;
  }

  .article-card {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .logo h1 {
    font-size: 1.75rem;
  }

  .logo .subtitle {
    font-size: 0.88rem;
  }

  .search-box input {
    font-size: 0.95rem;
    padding: 0.85rem 1rem 0.85rem 2.75rem;
  }

  #bookmarks-toggle,
  .rss-button {
    width: 100%;
    justify-content: center;
  }

  #theme-toggle {
    align-self: center;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 999px;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eaeef2;

  --text-primary: #1c2128;
  --text-secondary: #424a53;
  --text-tertiary: #656d76;

  --border-color: #d0d7de;

  --shadow-sm: 0 1px 3px rgba(31, 35, 40, 0.12);
  --shadow-md: 0 4px 12px rgba(31, 35, 40, 0.15);
  --shadow-lg: 0 12px 32px rgba(31, 35, 40, 0.2);
}

/*
 * In light mode, inactive pills need an explicit background/color
 * because --bg-primary is now near-white.
 * NOTE: this rule has the same specificity as .pill.active, and because
 * it comes later in the file it would normally win — so we MUST also
 * re-declare .pill.active underneath it to keep dark-bg + white text.
 */
[data-theme="light"] .pill {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Must come AFTER the rule above to win the specificity tie */
[data-theme="light"] .pill.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: white;
}

[data-theme="light"] #date-filter,
[data-theme="light"] #sort-by {
  background: var(--bg-secondary);
  color: var(--text-primary);
}