:root {
  color-scheme: light;
  --theme-page-bg: #f8fafc;
  --theme-surface: rgba(255, 255, 255, 0.95);
  --theme-surface-strong: #f1f5f9;
  --theme-text: #0f172a;
  --theme-muted: #475569;
  --theme-border: #e2e8f0;
  --theme-shadow: 0 20px 30px rgba(0, 0, 10, 0.08);
}

body {
  overflow-x: hidden;
  max-width: 100vw;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --theme-page-bg: #0f172a; /* Slate 900 */
  --theme-surface: rgba(15, 23, 42, 0.75);
  --theme-surface-strong: rgba(30, 41, 59, 0.85); /* Slate 800 */
  --theme-text: #f8fafc; /* Slate 50 */
  --theme-muted: #94a3b8; /* Slate 400 */
  --theme-border: rgba(51, 65, 85, 0.6); /* Slate 700 */
  --theme-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  
  /* Update CSS variables used in inline styles and home.ejs */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --secondary-color: rgba(30, 41, 59, 0.85);
  --border-color: rgba(51, 65, 85, 0.6);
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.92)),
    url("https://static.vecteezy.com/system/resources/previews/002/289/261/large_2x/school-education-seamless-pattern-education-symbols-sketch-backdrop-with-school-supplies-back-to-school-icons-doodle-line-art-notebook-background-vector.jpg") !important;
  background-repeat: repeat !important;
  background-size: 80rem 80rem !important;
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] .main-card,
:root[data-theme="dark"] .auth-card,
:root[data-theme="dark"] .analytics-container,
:root[data-theme="dark"] .chart-container,
:root[data-theme="dark"] .url-info-card,
:root[data-theme="dark"] .text-card,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .table-container,
:root[data-theme="dark"] .empty-state,
:root[data-theme="dark"] .section-card {
  background: var(--theme-surface) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid var(--theme-border) !important;
  color: var(--theme-text) !important;
  box-shadow: var(--theme-shadow) !important;
}

:root[data-theme="dark"] .header {
  background: rgba(2, 6, 23, 0.65) !important;
  backdrop-filter: blur(12px) !important;
  border: 1px solid rgba(51, 65, 85, 0.4) !important;
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] h1,
:root[data-theme="dark"] h2,
:root[data-theme="dark"] h3,
:root[data-theme="dark"] h4,
:root[data-theme="dark"] h5,
:root[data-theme="dark"] h6,
:root[data-theme="dark"] .page-title,
:root[data-theme="dark"] .section-title,
:root[data-theme="dark"] .auth-card h2 {
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] p,
:root[data-theme="dark"] label,
:root[data-theme="dark"] .page-subtitle,
:root[data-theme="dark"] .text-muted,
:root[data-theme="dark"] .redirect-url,
:root[data-theme="dark"] .dest-link,
:root[data-theme="dark"] .text-preview,
:root[data-theme="dark"] .empty-state,
:root[data-theme="dark"] .form-check-label {
  color: var(--theme-muted) !important;
}

:root[data-theme="dark"] .url-input,
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .toolbar .search-box,
:root[data-theme="dark"] .toolbar select {
  background: var(--theme-surface-strong) !important;
  border: 1px solid var(--theme-border) !important;
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] .url-input::placeholder,
:root[data-theme="dark"] .form-control::placeholder,
:root[data-theme="dark"] textarea::placeholder,
:root[data-theme="dark"] .toolbar .search-box::placeholder {
  color: #64748b !important;
}

:root[data-theme="dark"] .table,
:root[data-theme="dark"] .data-table,
:root[data-theme="dark"] .table > :not(caption) > * > * {
  background-color: transparent !important;
  color: var(--theme-text) !important;
  border-color: rgba(51, 65, 85, 0.4) !important;
}

:root[data-theme="dark"] .table tbody tr,
:root[data-theme="dark"] .table tbody tr:nth-child(even),
:root[data-theme="dark"] .data-table tbody tr {
  background-color: transparent !important;
}

:root[data-theme="dark"] .table tbody tr:hover,
:root[data-theme="dark"] .table tbody td:hover,
:root[data-theme="dark"] .data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.05) !important;
}

:root[data-theme="dark"] .table tbody td,
:root[data-theme="dark"] .data-table tbody td {
  border-color: rgba(51, 65, 85, 0.4) !important;
}

:root[data-theme="dark"] .short-id {
  background: rgba(30, 41, 59, 0.8) !important;
  color: #818cf8 !important;
}

:root[data-theme="dark"] .type-badge.url {
  color: #34d399 !important;
  background: rgba(16, 185, 129, 0.2) !important;
}

:root[data-theme="dark"] .type-badge.text {
  color: #93c5fd !important;
  background: rgba(59, 130, 246, 0.2) !important;
}

:root[data-theme="dark"] .nav-tabs {
  border-color: var(--theme-border) !important;
}

:root[data-theme="dark"] .nav-tabs .nav-link {
  color: var(--theme-muted) !important;
}

:root[data-theme="dark"] .nav-tabs .nav-link.active {
  background: var(--theme-surface-strong) !important;
  border-color: var(--theme-border) var(--theme-border) var(--theme-surface-strong) !important;
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] .page-link {
  background: var(--theme-surface-strong) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

:root[data-theme="dark"] .page-item.active .page-link {
  background: #6366f1 !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
}

:root[data-theme="dark"] a:not(.btn):not(.navbar-brand):not(.badge-custom):not(.short-link) {
  color: #818cf8;
}

:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .dropdown-menu {
  background: rgba(30, 41, 59, 0.95) !important;
  backdrop-filter: blur(12px) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

.theme-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2000;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 92px;
  height: 42px;
  padding: 0 0.8rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22);
  font: 600 0.85rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.28);
}

.theme-toggle::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: inset -5px -5px 0 rgba(255, 255, 255, 0.55);
  flex: 0 0 auto;
  transition: all 0.3s ease;
}

:root[data-theme="dark"] .theme-toggle {
  background: rgba(30, 41, 59, 0.92);
  color: #f8fafc;
  border-color: rgba(51, 65, 85, 0.8);
}

:root[data-theme="dark"] .theme-toggle::before {
  background: #e2e8f0;
  box-shadow: inset -6px -2px 0 #94a3b8;
}

@media (max-width: 640px) {
  .theme-toggle {
    right: 0.75rem;
    bottom: 0.75rem;
    min-width: 84px;
    height: 38px;
    font-size: 0.8rem;
  }
}

/* ===== GLOBAL RESPONSIVE FIXES ===== */

/* Prevent ANY horizontal overflow site-wide */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw;
  width: 100%;
}

/* Ads & iframes must never overflow their containers */
iframe, img, video, embed, object {
  max-width: 100% !important;
  height: auto;
}

/* Force iframes with fixed widths to respect container */
iframe[width], iframe[style*="width"] {
  max-width: 100% !important;
}

/* Ad containers should be responsive */
div[style*="text-align: center"],
div[style*="text-align:center"] {
  max-width: 100vw;
  overflow-x: hidden !important;
  box-sizing: border-box;
}

/* Theme toggle must not cause overflow */
.theme-toggle {
  max-width: calc(100vw - 2rem);
}

/* ===== NAVBAR RESPONSIVE ===== */

/* Tablet: stack nav items better */
@media (max-width: 992px) {
  .navbar .container-custom {
    padding: 0.5rem 0.75rem;
  }

  .navbar .d-flex.align-items-center {
    gap: 0.35rem !important;
  }

  .navbar .text-truncate {
    max-width: 100px !important;
    font-size: 0.85rem;
  }
}

/* Mobile: stack nav items vertically */
@media (max-width: 576px) {
  .navbar .container-custom {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    gap: 0.5rem !important;
    padding: 0.5rem;
  }

  .navbar .navbar-brand {
    font-size: 1.15rem !important;
  }

  .navbar .d-flex.align-items-center {
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem !important;
  }

  .navbar .text-truncate {
    max-width: 140px !important;
    font-size: 0.8rem;
  }

  .navbar .btn {
    font-size: 0.78rem;
    padding: 0.3rem 0.6rem;
  }
}

/* ===== FOOTER RESPONSIVE ===== */
@media (max-width: 768px) {
  footer .container,
  footer .container-custom {
    flex-direction: column !important;
    text-align: center;
    gap: 1rem;
  }

  footer .d-flex.gap-3 {
    justify-content: center !important;
    flex-wrap: wrap;
  }

  footer .d-flex.gap-3 a[style*="width: 60px"],
  footer .d-flex.gap-3 a[style*="width: 45px"] {
    width: 40px !important;
    height: 40px !important;
  }

  footer .fw-bold {
    font-size: 0.9rem;
  }
}

/* ===== BLOG RESPONSIVE ===== */
@media (max-width: 768px) {
  .blog-grid {
    grid-template-columns: 1fr !important;
    gap: 1.25rem !important;
  }

  .blog-card-content {
    padding: 1.25rem !important;
  }

  .blog-title {
    font-size: 1.2rem !important;
  }

  .blog-excerpt {
    font-size: 0.9rem;
  }

  .header {
    margin: 20px auto !important;
    padding: 20px 16px !important;
  }

  .header h1 {
    font-size: 2rem !important;
  }

  .header p {
    font-size: 0.95rem !important;
  }

  /* Blog post content */
  .post-container {
    padding: 1.5rem 1rem !important;
  }

  .post-title {
    font-size: 1.6rem !important;
  }

  .recent-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1.5rem !important;
  }

  .header p {
    font-size: 0.85rem !important;
  }

  .blog-title {
    font-size: 1.05rem !important;
  }

  .post-title {
    font-size: 1.35rem !important;
  }
}

/* ===== ANALYTICS RESPONSIVE ===== */
@media (max-width: 768px) {
  .analytics-container {
    padding: 1rem !important;
    margin: 0 0.5rem;
  }

  .stats-number {
    font-size: 1.75rem !important;
  }

  .stats-label {
    font-size: 0.78rem !important;
  }

  .chart-container {
    padding: 1rem !important;
  }

  .chart-container canvas {
    max-height: 250px;
  }
}

/* ===== REDIRECT PAGE RESPONSIVE ===== */
@media (max-width: 768px) {
  .glass-card {
    padding: 1.5rem 1rem !important;
  }

  .title-heading {
    font-size: 1.2rem !important;
  }

  .timer-circle {
    width: 90px !important;
    height: 90px !important;
  }

  .timer-num {
    font-size: 2.25rem !important;
  }

  .dest-url {
    font-size: 0.85rem;
  }

  .ad-sticky-bottom {
    min-height: 50px !important;
    padding: 0.25rem !important;
  }
}

/* ===== TEXT VIEWER RESPONSIVE ===== */
@media (max-width: 768px) {
  .text-card {
    margin: 0 0.5rem;
  }

  .text-card .card-body {
    padding: 1.25rem !important;
  }
}

/* ===== TABLE RESPONSIVE (GLOBAL) ===== */
@media (max-width: 768px) {
  .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}
