/* Visual System & Color Palette (OKLCH-based Dark Theme) */
:root {
  color-scheme: dark;
  
  /* Color Tokens */
  --bg: oklch(13% 0.015 240);
  --card: oklch(16% 0.02 245);
  --card-hover: oklch(18% 0.025 245);
  --muted: oklch(70% 0.02 240);
  --text: oklch(95% 0.01 240);
  --text-dark: oklch(85% 0.015 240);
  --line: oklch(23% 0.02 245);
  --accent: oklch(80% 0.12 205);
  --accent-dim: oklch(80% 0.12 205 / 0.12);
  --accent-glow: oklch(80% 0.12 205 / 0.04);
  --hot: oklch(76% 0.16 45);
  --hot-dim: oklch(76% 0.16 45 / 0.15);
  
  /* Font Stacks */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-serif: 'Literata', Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, oklch(18% 0.03 240), var(--bg) 45%);
  font-family: var(--font-sans);
  line-height: 1.6;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

/* Header & Navigation */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: oklch(13% 0.015 240 / 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.top-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.brand {
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

nav a {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

nav a:hover, nav a.on {
  color: var(--text);
  background: var(--line);
}

nav a.admin-link {
  border: 1px solid var(--line);
}

nav a.admin-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Main Container */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* Hero Section */
.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(135deg, oklch(80% 0.12 205 / 0.08), oklch(76% 0.16 45 / 0.05));
  margin-bottom: 32px;
}

.hero-text h1 {
  font-size: clamp(1.75rem, 4.5vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.75px;
  line-height: 1.1;
  margin: 0 0 12px 0;
  text-wrap: balance;
}

.hero-text p {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0;
  max-width: 65ch;
  line-height: 1.5;
}

.stats {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.stat-badge {
  background: oklch(100% 0 0 / 0.03);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 0.9rem;
  color: var(--text-dark);
}

.stat-badge b {
  color: var(--accent);
  font-weight: 700;
}

/* Search Area */
.search {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.search-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  color: var(--muted);
  pointer-events: none;
}

.search input, input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px 14px 44px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.search input:focus, input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--card-hover);
}

button, .primary-btn {
  background: var(--accent);
  color: oklch(10% 0.02 205);
  border: 0;
  border-radius: 14px;
  padding: 14px 24px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover, .primary-btn:hover {
  background: oklch(85% 0.1 205);
  box-shadow: 0 4px 12px oklch(80% 0.12 205 / 0.2);
}

/* Category Chips */
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.chip-item {
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 8px 16px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip-item:hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--card-hover);
}

.chip-item.on {
  color: oklch(10% 0.02 205);
  background: var(--accent);
  border-color: var(--accent);
}

.chip-count {
  font-size: 0.75rem;
  background: oklch(100% 0 0 / 0.1);
  padding: 2px 6px;
  border-radius: 99px;
  color: inherit;
}

.chip-item.on .chip-count {
  background: oklch(0% 0 0 / 0.12);
}

/* Card Grid System */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

/* Card Styling */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.card:hover {
  border-color: oklch(80% 0.12 205 / 0.4);
  box-shadow: 0 8px 30px var(--accent-glow);
  background-color: var(--card-hover);
}

.card-image-wrapper {
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: oklch(10% 0.01 240);
  position: relative;
}

.card-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Metadata */
.meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.category-tag {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
}

.source-tag {
  background: oklch(100% 0 0 / 0.04);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-dark);
}

.time-tag {
  margin-left: auto;
  font-size: 0.75rem;
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
}

.hot-score {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--hot-dim);
  color: var(--hot);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
}

.flame-icon {
  flex-shrink: 0;
}

/* Card Title and Description */
.card h2 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 12px 0;
  color: var(--text);
  text-wrap: pretty;
}

.card h2 a:hover {
  color: var(--accent);
}

.summary-text {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--text-dark);
  line-height: 1.55;
  margin: 0 0 24px 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre-line;
  flex: 1;
}

.card:hover .summary-text {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
}

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  border-top: 1px dashed var(--line);
  padding-top: 16px;
  font-size: 0.88rem;
  font-weight: 600;
}

.source-link {
  color: var(--muted);
}

.source-link:hover {
  color: var(--text);
}

.story-link {
  color: var(--accent);
}

.story-link:hover {
  color: oklch(85% 0.1 205);
  text-decoration: underline;
}

/* Hero (Featured) Card Special Styling */
@media (min-width: 860px) {
  .hero-card {
    grid-column: span 2;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
  }
  
  .hero-card .card-image-wrapper {
    height: 100%;
    aspect-ratio: auto;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  
  .hero-card .card-content {
    padding: 32px;
  }
  
  .hero-card h2 {
    font-size: 1.75rem;
  }
  
  .hero-card .summary-text {
    font-size: 0.98rem;
    -webkit-line-clamp: 6;
  }
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  border: 1px dashed var(--line);
  border-radius: 20px;
  color: var(--muted);
}

/* Pagination */
.pager {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  margin: 40px 0;
  flex-wrap: wrap;
}

.pager-btn {
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 10px 20px;
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.pager-btn:hover {
  border-color: var(--accent);
  background: var(--card-hover);
  color: var(--accent);
}

.pager-info {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Footer */
footer {
  border-top: 1px solid var(--line);
  background: oklch(10% 0.01 240);
  padding: 40px 20px;
  text-align: center;
}

.footer-content p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* ==========================================
   Story Details Page
   ========================================== */
.story-page-container {
  max-width: 760px;
  margin: 0 auto;
}

.back-nav {
  margin-bottom: 24px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.back-btn:hover {
  color: var(--text);
}

.story-detail-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
  margin-bottom: 32px;
}

.story-detail-panel .meta {
  margin-bottom: 20px;
  font-size: 0.82rem;
}

.story-detail-panel h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 800;
  line-height: 1.25;
  margin: 0 0 24px 0;
  color: var(--text);
  text-wrap: balance;
}

.story-image-wrapper {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 28px;
  border: 1px solid var(--line);
}

.story-image-wrapper img {
  width: 100%;
  height: auto;
  display: block;
}

.summary-section {
  background: var(--accent-glow);
  border-left: 4px solid var(--accent);
  padding: 20px 24px;
  border-radius: 12px;
  margin-bottom: 32px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.summary-content {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--text-dark);
  margin: 0;
  white-space: pre-line;
  text-wrap: pretty;
}

.story-detail-panel .actions {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
  display: block;
}

/* Related Section & Stream */
.related-section h2 {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 0 0 16px 0;
  color: var(--text);
  letter-spacing: -0.25px;
}

.related-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 40px;
}

.stream-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 140px 1fr 120px;
  gap: 16px;
  align-items: center;
  transition: all 0.2s ease;
}

.stream-row:hover {
  border-color: var(--accent);
  background: var(--card-hover);
  box-shadow: 0 4px 15px var(--accent-glow);
}

.source-badge {
  background: oklch(100% 0 0 / 0.04);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
  display: block;
}

.stream-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}

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

.stream-time {
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Admin Digest Form */
.admin-digest-form {
  background: oklch(100% 0 0 / 0.02);
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 18px;
}

.admin-digest-form .form-wrapper {
  display: flex;
  gap: 12px;
}

.admin-digest-form input {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.admin-digest-form button {
  background: oklch(100% 0 0 / 0.05);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.admin-digest-form button:hover {
  background: var(--accent);
  color: oklch(10% 0.02 205);
  border-color: var(--accent);
}

/* ==========================================
   Responsive Viewports
   ========================================== */
@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    align-items: stretch;
    padding: 24px;
    border-radius: 20px;
  }
  
  .stats {
    margin-top: 12px;
    align-self: flex-start;
  }
  
  .search {
    flex-direction: column;
  }
  
  .stream-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 16px;
  }
  
  .stream-time {
    text-align: left;
  }
  
  .story-detail-panel {
    padding: 24px;
  }
  
  .admin-digest-form .form-wrapper {
    flex-direction: column;
  }
}

/* ==========================================
   Admin Panel Styles (Preserved & Adjusted)
   ========================================== */
.panel {
  background: rgba(18, 23, 34, 0.86);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  margin: 16px 0;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}

.config-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: .9rem;
}

.config-grid input, .config-grid select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c1018;
  color: var(--text);
}

.muted {
  color: var(--muted);
}

/* Redesigned Admin Dashboard Styles */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.admin-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.admin-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 99px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: #10b981;
}

.admin-status-pill.inactive {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.admin-status-pill .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

.header-actions {
  display: flex;
  gap: 10px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin: 20px 0 30px 0;
}

.admin-card {
  background: rgba(18, 23, 34, 0.85);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.admin-card h3 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  color: var(--accent);
}

.chart-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  justify-content: center;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chart-bar-label {
  width: 80px;
  font-size: 13px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.chart-bar-wrapper {
  flex: 1;
  background: rgba(37, 48, 68, 0.4);
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
}

.chart-bar-value {
  width: 30px;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  color: var(--text);
}

.chart-svg {
  width: 100%;
  height: 140px;
}

.chart-svg text {
  font-family: inherit;
}

.stat-box-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  flex: 1;
}

.stat-box {
  background: rgba(37, 48, 68, 0.2);
  border: 1px solid rgba(37, 48, 68, 0.4);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-box .num {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.stat-box .num.success { color: #10b981; }
.stat-box .num.warning { color: #f59e0b; }
.stat-box .num.danger { color: #ef4444; }

.stat-box .label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.admin-split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: start;
}

.admin-split-col h2 {
  font-size: 20px;
  margin: 0 0 16px 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  color: var(--text);
}

@media (max-width: 990px) {
  .admin-split {
    grid-template-columns: 1fr;
  }
}

/* Collapsible Panel details summary */
details.panel summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

details.panel summary::-webkit-details-marker {
  display: none;
}

details.panel[open] .details-icon {
  transform: rotate(180deg);
}

/* Infinite Scroll Loader */
.infinite-scroll-trigger {
  text-align: center;
  padding: 30px 20px;
  margin: 30px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  color: var(--muted);
  border-top: 1px dashed var(--line);
}

.loading-spinner {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

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

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

.loading-end {
  font-size: 0.95rem;
  color: var(--muted);
}
