/* ================ BASE STYLES ================ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #1e293b;
  --accent: #f59e0b;
  --light: #f8fafc;
  --dark: #0f172a;
  --gray: #64748b;
  --light-gray: #e2e8f0;
  --border-radius: 8px;
  --transition: all 0.3s ease;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--light);
  color: var(--dark);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

h1, h2, h3, h4, h5 {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  line-height: 1.3;
}

a {
  text-decoration: none;
  color: inherit;
  transition: var(--transition);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ================ UTILITY CLASSES ================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ================ HEADER & NAVIGATION ================ */
.blog-header {
  background: linear-gradient(135deg, var(--secondary), var(--dark));
  color: white;
  padding: 4rem 0 3rem;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.blog-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxkZWZzPjxwYXR0ZXJuIGlkPSJwYXR0ZXJuIiB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHBhdHRlcm5UcmFuc2Zvcm09InJvdGF0ZSg0NSkiPjxyZWN0IHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0icmdiYSgyNTUsMjU1LDI1NSwwLjAzKSIvPjwvcGF0dGVybj48L2RlZnM+PHJlY3QgZmlsbD0idXJsKCNwYXR0ZXJuKSIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIvPjwvc3ZnPg==');
  opacity: 0.4;
}

.blog-header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  position: relative;
}

.blog-header h1 a {
  color: white;
}

.blog-header h1 a:hover {
  color: var(--accent);
}

.blog-header .subtitle {
  font-size: 1.1rem;
  opacity: 0.8;
  margin: 0;
  position: relative;
}

/* Breadcrumb */
.breadcrumb ol {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.breadcrumb li {
  display: flex;
  align-items: center;
}

.breadcrumb li:not(:last-child)::after {
  content: '/';
  margin-left: 0.5rem;
  color: rgba(255,255,255,0.5);
}

.breadcrumb a {
  color: var(--accent);
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* ================ MAIN CONTENT LAYOUT ================ */
.blog-container {
  display: flex;
  gap: 2rem;
  margin: 2rem auto;
}

.posts-list {
  flex: 1;
  min-width: 0; /* Prevent flex overflow */
}

.sidebar {
  width: 300px;
  position: sticky;
  top: 20px;
  align-self: flex-start;
}

/* ================ BLOG POST CARDS ================ */
.post-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
  overflow: hidden;
  transition: var(--transition);
}

.post-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.post-thumbnail {
  height: 220px;
  overflow: hidden;
  position: relative;
  background-color: #f1f5f9;
}

.post-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease, opacity 0.3s ease;
}

.post-thumbnail img[loading="lazy"] {
  opacity: 0;
}

.post-thumbnail img.loaded {
  opacity: 1;
}

.post-card:hover .post-thumbnail img {
  transform: scale(1.05);
}

.post-content {
  padding: 1.5rem;
}

.post-meta {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--gray);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.post-date {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.reading-time {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.post-title {
  font-size: 1.8rem;
  margin: 0.5rem 0 1rem;
  line-height: 1.3;
}

.post-title a:hover {
  color: var(--primary);
}

.post-excerpt {
  color: var(--gray);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.read-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-weight: 500;
  transition: var(--transition);
}

.read-more-btn:hover {
  color: var(--primary-dark);
  gap: 0.7rem;
}

/* ================ FILTER BAR ================ */
.filter-bar {
  background: rgba(255,255,255,0.1);
  padding: 1rem;
  border-radius: var(--border-radius);
  margin: 2rem 0;
  backdrop-filter: blur(5px);
  position: relative;
}

.search-wrapper {
  position: relative;
  margin-bottom: 1rem;
}

.search-input {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  font-family: 'Poppins', sans-serif;
  transition: var(--transition);
  background: rgba(255,255,255,0.1);
  color: white;
}

.search-input::placeholder {
  color: rgba(255,255,255,0.7);
}

.search-input:focus {
  outline: 2px solid var(--accent);
  background: rgba(255,255,255,0.2);
}

.search-clear {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
}

.search-input:not(:placeholder-shown) + .search-clear {
  opacity: 1;
  pointer-events: auto;
}

.search-clear:hover {
  color: white;
}

.search-spinner {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: var(--transition);
}

.searching .search-spinner {
  opacity: 1;
}

@keyframes spin {
  to { transform: translateY(-50%) rotate(360deg); }
}

.filter-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 0.9rem;
  transition: var(--transition);
  color: white;
}

.filter-btn.active {
  background: var(--accent);
  color: var(--dark);
}

.filter-btn:hover:not(.active) {
  background: rgba(255,255,255,0.2);
}

/* ================ PAGINATION ================ */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 3rem 0;
  flex-wrap: wrap;
  gap: 1rem;
}

.pagination-btn {
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  background: var(--light-gray);
  color: var(--secondary);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  font-family: 'Poppins', sans-serif;
}

.pagination-btn:hover {
  background: #e2e8f0;
}

.pagination-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pagination-btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.page-numbers {
  display: flex;
  gap: 0.5rem;
}

.page-numbers a, 
.page-numbers span {
  padding: 0.5rem 1rem;
  border-radius: 4px;
}

.page-numbers a {
  color: var(--secondary);
  background: var(--light-gray);
  cursor: pointer;
  transition: var(--transition);
}

.page-numbers a.active {
  background: var(--primary);
  color: white;
}

.page-numbers a:hover:not(.active) {
  background: #e2e8f0;
}

.page-numbers span.ellipsis {
  color: #94a3b8;
  display: flex;
  align-items: center;
}

/* ================ SIDEBAR ================ */
.sidebar-widget {
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.sidebar-widget h3 {
  font-size: 1.2rem;
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--secondary);
}

.subscribe-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-group {
  position: relative;
}

.subscribe-form input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--light-gray);
  border-radius: 6px;
  font-family: 'Poppins', sans-serif;
  transition: var(--transition);
}

.subscribe-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-error {
  color: #dc2626;
  font-size: 0.8rem;
  margin-top: 0.25rem;
  display: none;
}

.subscribe-form button {
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.subscribe-form button:hover {
  background: var(--primary-dark);
}

.btn-text {
  display: inline-block;
  transition: transform 0.3s ease;
}

.btn-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
}

.loading .btn-text {
  transform: translateY(30px);
}

.loading .btn-spinner {
  opacity: 1;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: #f1f5f9;
  border-radius: 50px;
  font-size: 0.8rem;
  color: var(--secondary);
  transition: var(--transition);
}

.tag:hover {
  background: var(--primary);
  color: white;
}

/* ================ FOOTER ================ */
.blog-footer {
  background: #f8fafc;
  padding: 2rem 0;
  margin-top: 3rem;
  border-top: 1px solid #e2e8f0;
}

.blog-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-nav {
  display: flex;
  gap: 1.5rem;
}

.footer-nav a {
  color: var(--gray);
  transition: var(--transition);
}

.footer-nav a:hover {
  color: var(--primary);
}

.theme-toggle {
  margin-bottom: 1rem;
}

#themeSwitcher {
  background: #f1f5f9;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Poppins', sans-serif;
  transition: var(--transition);
}

#themeSwitcher:hover {
  background: #e2e8f0;
}

/* ================ DARK MODE ================ */
.dark-mode {
  background: var(--dark);
  color: #e2e8f0;
}

.dark-mode .blog-header {
  background: linear-gradient(135deg, #0f172a, #020617);
}

.dark-mode .post-card,
.dark-mode .sidebar-widget {
  background: #1e293b;
  color: #e2e8f0;
}

.dark-mode .post-title a,
.dark-mode .footer-nav a,
.dark-mode .breadcrumb a {
  color: #93c5fd;
}

.dark-mode .post-excerpt,
.dark-mode .post-date,
.dark-mode .reading-time {
  color: #94a3b8;
}

.dark-mode .subscribe-form input {
  background: #334155;
  border-color: #475569;
  color: #f8fafc;
}

.dark-mode .tag {
  background: #334155;
  color: #e2e8f0;
}

.dark-mode .tag:hover {
  background: var(--primary);
}

.dark-mode .pagination-btn,
.dark-mode .filter-btn:not(.active),
.dark-mode .page-numbers a:not(.active) {
  background: #334155;
  color: #e2e8f0;
}

.dark-mode .pagination-btn:hover,
.dark-mode .filter-btn:hover:not(.active),
.dark-mode .page-numbers a:hover:not(.active) {
  background: #475569;
}

.dark-mode #themeSwitcher {
  background: #334155;
  color: #e2e8f0;
}

.dark-mode #themeSwitcher:hover {
  background: #475569;
}

.dark-mode .theme-text::after {
  content: "Light Mode";
}

.dark-mode #themeSwitcher i {
  transform: rotate(180deg);
}

/* ================ RESPONSIVE STYLES ================ */
@media (max-width: 992px) {
  .blog-container {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    position: static;
    margin-bottom: 2rem;
  }
}

@media (max-width: 768px) {
  .blog-header {
    padding: 3rem 0 2rem;
  }
  
  .blog-header h1 {
    font-size: 2rem;
  }
  
  .post-title {
    font-size: 1.5rem;
  }
  
  .pagination {
    flex-direction: column;
  }
  
  .page-numbers {
    order: -1;
    margin-bottom: 1rem;
  }
  
  .post-card:hover {
    transform: scale(1.02);
  }
  
  .footer-nav {
    gap: 1rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .post-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .reading-time {
    margin-left: 0;
  }
  
  .filter-options {
    justify-content: center;
  }
  
  .filter-btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .page-numbers a, 
  .page-numbers span {
    padding: 0.5rem 0.75rem;
  }
}