* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary-blue: #0ea5e9;
  --primary-teal: #14b8a6;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

html[data-theme="dark"] {
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --bg-primary: #1e293b;
  --bg-secondary: #0f172a;
  --bg-subtle: #334155;
  --border-color: #334155;
}

body {
  font-family: 'Outfit', 'Segoe UI', 'Roboto', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
}

/* --- Header --- */
.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-text {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.hamburger {
  display: none;
  font-size: 1.5rem;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  z-index: 1201;
}

.search-container {
  flex: 1 1 320px;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  padding: 0.6rem 1rem 0.6rem 2.75rem;
  font-size: 1rem;
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgb(14 165 233 / 0.2);
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s ease;
}
.user-link:hover {
  background-color: var(--bg-subtle);
  color: var(--primary-blue);
}

.theme-toggle-btn, .refresh-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-weight: 500;
  white-space: nowrap;
}
.theme-toggle-btn {
  font-size: 1.25rem;
  width: 44px;
  height: 44px;
}
.refresh-btn {
  font-size: 1rem;
  padding: 0.6rem 1rem;
  gap: 0.5rem;
}
.theme-toggle-btn:hover, .refresh-btn:hover {
  background: var(--bg-subtle);
  color: var(--primary-blue);
}
.refresh-text {
  font-size: 0.95rem;
}

/* --- Main Layout --- */
.main-container {
  max-width: 1280px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 2rem;
  align-items: start;
}

/* --- Sidebars --- */
.sidebar {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  position: sticky;
  top: 90px;
  box-shadow: var(--shadow-sm);
}

.sidebar h3 {
  margin-bottom: 1.25rem;
  font-size: 1.2rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.trending-topics {
  display: flex; flex-direction: column; gap: 0.5rem;
}
.trending-topic {
  padding: 0.75rem 1rem; border-radius: var(--radius-md);
  cursor: pointer; transition: all 0.2s ease;
  font-size: 0.95rem; color: var(--text-secondary);
  word-break: break-word; font-weight: 500;
}
.trending-topic:hover {
  background: var(--bg-subtle);
  color: var(--primary-blue);
}
.stats-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.85rem 0; border-bottom: 1px solid var(--border-color);
}
.stats-item:last-child { border: none; }
.stats-label { color: var(--text-secondary); font-size: 0.9rem; }
.stats-value { color: var(--text-primary); font-weight: 600; font-size: 0.9rem; }

/* --- News Feed --- */
.news-feed {
  display: flex; flex-direction: column; gap: 1.5rem; min-width: 0;
}
.news-card {
  background: var(--bg-primary); border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.news-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
}
.news-image {
  width: 100%; height: 240px; object-fit: cover;
  background-color: var(--bg-secondary);
  transition: transform 0.3s ease;
}
.news-card:hover .news-image {
  transform: scale(1.03);
}
.news-content {
  padding: 1.5rem;
}
.news-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 1rem;
}
.news-source {
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-teal));
  color: white; padding: 0.25rem 0.75rem; border-radius: var(--radius-xl);
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.news-date {
  color: var(--text-muted); font-size: 0.85rem; white-space: nowrap;
}
.news-title {
  font-size: 1.3rem; font-weight: 600; margin-bottom: 0.75rem;
  line-height: 1.4; color: var(--text-primary);
  text-decoration: none; display: block;
}
.news-title:hover { color: var(--primary-blue); }
.news-description {
  color: var(--text-secondary); margin-bottom: 1.25rem;
  font-size: 0.95rem; line-height: 1.6;
}
.news-actions {
  display: flex; gap: 0.75rem; align-items: center;
}
.action-btn {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem;
  border: 1px solid var(--border-color); background: transparent;
  border-radius: var(--radius-lg); cursor: pointer; transition: all 0.2s ease;
  font-size: 0.9rem; font-weight: 500; color: var(--text-secondary);
}
.action-btn i { font-size: 1rem; }
.action-btn:hover, .action-btn.active {
  background-color: #e0f2fe; border-color: var(--primary-blue); color: var(--primary-blue);
}
html[data-theme="dark"] .action-btn:hover, html[data-theme="dark"] .action-btn.active {
  background-color: var(--bg-subtle); border-color: var(--primary-blue); color: var(--primary-blue);
}

/* --- Loader, Error, PWA --- */
.loading {
  text-align: center; padding: 4rem 2rem; color: var(--text-muted);
  font-size: 1.1rem; display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
}
.loading::before {
  content: ''; width: 2.5rem; height: 2.5rem; border: 4px solid var(--border-color);
  border-radius: 50%; border-top-color: var(--primary-blue);
  animation: spin 1s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.install-prompt {
  /* ... existing styles are good ... */
}

/* --- Drawer --- */
.trending-drawer {
  position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto;
  width: 80vw; max-width: 320px; background: var(--bg-primary);
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2); z-index: 1200;
  transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
}
.trending-drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: var(--bg-primary); z-index: 1;
}
.drawer-close {
  background: none; border: none; font-size: 2rem; color: var(--text-primary);
  cursor: pointer; line-height: 1; padding: 0.5rem;
}
#drawerTrendingTopics { padding: 1.5rem; }
.drawer-user-links {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.drawer-user-links .user-link { padding: 0.75rem 0; font-size: 1.1rem; }
.drawer-user-links .show-mobile { display: inline !important; }
.drawer-backdrop {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.4); z-index: 1199;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* --- Responsive --- */
.hide-mobile { display: flex; align-items: center; gap: 0.5rem; }
.show-mobile { display: none; }

@media (max-width: 1024px) {
  .main-container { grid-template-columns: 240px 1fr; gap: 1.5rem; }
  #right-sidebar { display: none; }
  .logo-text { display: none; }
}

@media (max-width: 768px) {
  .header-content { padding: 0.75rem 1rem; gap: 1rem; }
  .main-container { grid-template-columns: 1fr; padding: 0 1rem; margin-top: 1rem; }
  #left-sidebar { display: none; }
  .hamburger { display: block; }
  .user-links, .refresh-text { display: none; }
  .hide-mobile { display: none; }
  .search-container { margin: 0; }
  .search-input { font-size: 0.95rem; }
}

@media (max-width: 480px) {
  .header-content { gap: 0.5rem; }
  .search-input { padding: 0.5rem 0.5rem 0.5rem 2.25rem; font-size: 0.9rem; }
  .search-icon { font-size: 1rem; left: 0.75rem;}
  .theme-toggle-btn, .refresh-btn { width: 40px; height: 40px; padding: 0; }
  .refresh-btn i { font-size: 1rem; }
}

.news-card {
  /* Add padding to the card itself */
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem; /* Space between elements */
}

.news-image {
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
}

.news-actions {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem; /* Space between action icons */
}

/* --- Action Button Icon-Only Style --- */
.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 1rem;
  color: var(--text-secondary);
  transition: color 0.2s ease, transform 0.2s ease;
}

.action-btn:hover {
  color: var(--accent-color);
  transform: scale(1.1);
}

.action-btn.active {
  color: var(--accent-color);
}

/* Hide the text labels like "Like", "Bookmark", etc. */
.action-btn span {
  display: none;
}

/* Style for the icon itself */
.action-btn i {
  font-size: 1.25rem;
}

/* Keep the like and comment counts visible */
.action-btn .like-count,
.action-btn .comment-count {
  display: inline-block; /* This overrides the general 'span' rule */
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-left: -0.1em; /* Adjust spacing */
}

/* --- Comment Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background-color: var(--background-color);
  color: var(--text-primary);
  padding: 1.5rem;
  border-radius: 0.75rem;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
    opacity: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
}

.comment-list {
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 0.5rem; /* For scrollbar spacing */
}

.comment-item {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.comment-item .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--accent-color-light);
  color: var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.comment-item .comment-body {
  display: flex;
  flex-direction: column;
}

.comment-item .comment-body strong {
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-right: 0.5em;
}

.comment-item .comment-body span {
  font-size: 0.95rem;
  color: var(--text-secondary);
  word-break: break-word;
}


.modal-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  margin-top: 1rem;
  flex-shrink: 0;
}

.comment-form {
  display: flex;
  gap: 0.5rem;
}

.comment-form input {
  flex-grow: 1;
  border: 1px solid var(--border-color);
  background-color: var(--background-alt);
  padding: 0.75rem;
  border-radius: 1.5rem;
  color: var(--text-primary);
  outline: none;
}

.comment-form input:focus {
    border-color: var(--accent-color);
}

.comment-form button {
  background-color: var(--accent-color);
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.comment-form button:hover {
    background-color: var(--accent-color-dark);
}

/* --- Toast Container --- */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* Allow clicks to pass through to elements underneath */
}

/* Style for individual toasts (already handled inline in JS for dynamic colors,
   but can add common styles here if needed) */
/* .toast-item { ... } */

/* Override background for the modal content if it's not picking up the theme variable */
/* This is a guess, your theme variable might be named differently */
.modal-content {
    background-color: var(--bg-primary); /* Or --bg-secondary depending on your theme */
    color: var(--text-primary);
}

/* Ensure img onerror works with a placeholder */
img[src=""], img:not([src]) {
    display: none;
}

/* ADD THESE STYLES for the Article Detail View */

.article-detail-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--background-color);
  z-index: 1500;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease-in-out;
  display: none; /* Initially hidden, controlled by JS */
}

/* State to show the detail view */
body.details-view-active .article-detail-view {
  transform: translateX(0);
  display: block;
}

/* Hide main content when detail view is active */
body.details-view-active main,
body.details-view-active .stats-bar {
  display: none;
}

.article-detail-header {
  padding: 1rem 1.5rem;
  background-color: var(--card-background-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.detail-back-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}
.detail-back-btn:hover {
    background-color: var(--hover-background-color);
}
.detail-back-btn i {
    margin-right: 0.5rem;
}

.article-detail-content {
  max-width: 800px;
  margin: 1rem auto;
  padding: 1rem 1.5rem;
}

.detail-image {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  background-color: var(--hover-background-color);
}

.detail-image[src=""] {
    display: none; /* Hide if no image */
}

.detail-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.detail-meta {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.detail-body-text {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-secondary);
  white-space: pre-wrap; /* Respects newlines in the summary */
  margin-bottom: 2.5rem;
}

.read-more-btn {
  display: inline-block;
  background-color: var(--accent-color);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 600;
  transition: background-color 0.2s;
}

.read-more-btn:hover {
  background-color: var(--accent-color-dark);
}

.read-more-btn i {
    margin-left: 0.5rem;
}

a, u {
  text-decoration: none;
}