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

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== Theme Variables ===== */
[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2130;
  --bg-card-hover: #252839;
  --bg-header: #141620;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #6b7280;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --border: #2a2d3a;
  --shadow: rgba(0, 0, 0, 0.4);
  --tab-bg: transparent;
  --tab-active-bg: #4fc3f7;
  --tab-active-text: #0f1117;
  --badge-bg: rgba(79, 195, 247, 0.15);
  --badge-text: #4fc3f7;
  --spinner-color: #4fc3f7;
}

[data-theme="light"] {
  --bg-primary: #f5f6fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f2f5;
  --bg-header: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #555770;
  --text-muted: #8b8da3;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --border: #e0e2e8;
  --shadow: rgba(0, 0, 0, 0.08);
  --tab-bg: transparent;
  --tab-active-bg: #1a73e8;
  --tab-active-text: #ffffff;
  --badge-bg: rgba(26, 115, 232, 0.1);
  --badge-text: #1a73e8;
  --spinner-color: #1a73e8;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px var(--shadow);
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 60px;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 28px;
  color: var(--accent);
}

.logo-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

/* ===== Source Tabs ===== */
.source-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  justify-content: center;
}

.source-tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  background: var(--tab-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.tab.active {
  background: var(--tab-active-bg);
  color: var(--tab-active-text);
  border-color: var(--tab-active-bg);
}

/* ===== Theme Toggle ===== */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.2s;
  position: relative;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-icon {
  font-size: 18px;
  position: absolute;
  transition: opacity 0.3s, transform 0.3s;
}

[data-theme="dark"] .theme-icon.moon {
  opacity: 1;
  transform: rotate(0);
}

[data-theme="dark"] .theme-icon.sun {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="light"] .theme-icon.sun {
  opacity: 1;
  transform: rotate(0);
}

[data-theme="light"] .theme-icon.moon {
  opacity: 0;
  transform: rotate(-90deg);
}

/* ===== Main Content ===== */
.main-content {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ===== Featured Section ===== */
.featured-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 32px;
}

.featured-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.featured-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow);
}

.featured-card .card-image {
  width: 100%;
  height: 280px;
  object-fit: cover;
  display: block;
}

.featured-card .card-body {
  padding: 20px;
}

.featured-card .card-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
}

.featured-card .card-title:hover {
  color: var(--accent);
}

.featured-card .card-excerpt {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Articles Grid ===== */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.article-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
}

.article-card .card-image-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  overflow: hidden;
  background: var(--bg-secondary);
}

.article-card .card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.article-card:hover .card-image {
  transform: scale(1.05);
}

.card-image.fallback-logo {
  object-fit: contain;
  padding: 24px;
  background: var(--bg-secondary);
}

.article-card .card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

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

.source-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

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

.article-card .card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-card .card-title:hover {
  color: var(--accent);
}

.article-card .card-excerpt {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: auto;
}

/* ===== Source-specific badge colors ===== */
.source-badge.bleepingcomputer { background: rgba(237, 85, 59, 0.15); color: #ed553b; }
.source-badge.thehackernews { background: rgba(0, 166, 81, 0.15); color: #00a651; }
.source-badge.hackread { background: rgba(231, 76, 60, 0.15); color: #e74c3c; }
.source-badge.certse { background: rgba(0, 112, 192, 0.15); color: #0070c0; }

/* ===== Loading ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  color: var(--text-muted);
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--spinner-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-message {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .articles-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 860px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
    gap: 12px;
  }

  .source-tabs {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    padding-bottom: 4px;
  }

  .featured-section {
    grid-template-columns: 1fr;
  }

  .articles-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 540px) {
  .articles-grid {
    grid-template-columns: 1fr;
  }

  .featured-card .card-image {
    height: 200px;
  }

  .featured-card .card-title {
    font-size: 17px;
  }

  .tab {
    font-size: 12px;
    padding: 5px 12px;
  }
}
