/* News2Me Theme System - Light & Dark Mode */

/* CSS Custom Properties for Theme Colors */
:root {
  /* Light theme (default) */
  --theme-bg-primary: #ffffff;
  --theme-bg-secondary: #f8f9fa;
  --theme-bg-tertiary: #e9ecef;
  --theme-text-primary: #212529;
  --theme-text-secondary: #6c757d;
  --theme-text-muted: #8e8e93;
  --theme-border: #dee2e6;
  --theme-border-light: #f1f3f4;
  
  /* Navigation */
  --theme-nav-bg: #343a40;
  --theme-nav-text: #ffffff;
  --theme-nav-text-hover: #f8f9fa;
  
  /* Cards and Components */
  --theme-card-bg: #ffffff;
  --theme-card-border: #dee2e6;
  --theme-card-shadow: rgba(0, 0, 0, 0.1);
  --theme-card-hover-shadow: rgba(0, 0, 0, 0.15);
  
  /* Form Elements */
  --theme-input-bg: #ffffff;
  --theme-input-border: #ced4da;
  --theme-input-focus-border: #86b7fe;
  --theme-input-focus-shadow: rgba(13, 110, 253, 0.25);
  
  /* Buttons */
  --theme-btn-primary-bg: #0d6efd;
  --theme-btn-primary-border: #0d6efd;
  --theme-btn-primary-hover-bg: #0b5ed7;
  --theme-btn-secondary-bg: #6c757d;
  --theme-btn-secondary-border: #6c757d;
  
  /* Status Colors */
  --theme-success: #198754;
  --theme-success-bg: #d1e7dd;
  --theme-warning: #fd7e14;
  --theme-warning-bg: #fff3cd;
  --theme-danger: #dc3545;
  --theme-danger-bg: #f8d7da;
  --theme-info: #0dcaf0;
  --theme-info-bg: #d1ecf1;
  
  /* Hover Effects */
  --theme-hover-bg: #f8f9fa;
  --theme-hover-border: #dee2e6;
  
  /* Footer */
  --theme-footer-bg: #343a40;
  --theme-footer-text: #ffffff;
}

/* Dark theme */
[data-theme="dark"] {
  --theme-bg-primary: #1a1a1a;
  --theme-bg-secondary: #2d2d2d;
  --theme-bg-tertiary: #3a3a3a;
  --theme-text-primary: #ffffff;
  --theme-text-secondary: #b3b3b3;
  --theme-text-muted: #8e8e93;
  --theme-border: #444444;
  --theme-border-light: #333333;
  
  /* Navigation */
  --theme-nav-bg: #121212;
  --theme-nav-text: #ffffff;
  --theme-nav-text-hover: #f8f9fa;
  
  /* Cards and Components */
  --theme-card-bg: #2d2d2d;
  --theme-card-border: #444444;
  --theme-card-shadow: rgba(0, 0, 0, 0.3);
  --theme-card-hover-shadow: rgba(0, 0, 0, 0.4);
  
  /* Form Elements */
  --theme-input-bg: #3a3a3a;
  --theme-input-border: #555555;
  --theme-input-focus-border: #86b7fe;
  --theme-input-focus-shadow: rgba(13, 110, 253, 0.25);
  
  /* Buttons */
  --theme-btn-primary-bg: #0d6efd;
  --theme-btn-primary-border: #0d6efd;
  --theme-btn-primary-hover-bg: #0b5ed7;
  --theme-btn-secondary-bg: #6c757d;
  --theme-btn-secondary-border: #6c757d;
  
  /* Status Colors - Slightly muted for dark theme */
  --theme-success: #20c997;
  --theme-success-bg: rgba(32, 201, 151, 0.2);
  --theme-warning: #fd7e14;
  --theme-warning-bg: rgba(253, 126, 20, 0.2);
  --theme-danger: #dc3545;
  --theme-danger-bg: rgba(220, 53, 69, 0.2);
  --theme-info: #0dcaf0;
  --theme-info-bg: rgba(13, 202, 240, 0.2);
  
  /* Hover Effects */
  --theme-hover-bg: #3a3a3a;
  --theme-hover-border: #555555;
  
  /* Footer */
  --theme-footer-bg: #121212;
  --theme-footer-text: #ffffff;

  /* Bootstrap 5.3 color tokens — html is :root, so Bootstrap’s light :root
     --bs-* values still apply when only data-theme is set. Tables, dropdowns,
     and other BS components read these; mirror dark tokens here so UI stays
     correct even if data-bs-theme or theme-head.js is missing or cached old. */
  color-scheme: dark;
  --bs-body-bg: var(--theme-bg-primary);
  --bs-body-color: var(--theme-text-primary);
  --bs-body-color-rgb: 255, 255, 255;
  --bs-body-bg-rgb: 26, 26, 26;
  --bs-emphasis-color: var(--theme-text-primary);
  --bs-emphasis-color-rgb: 255, 255, 255;
  --bs-secondary-color: rgba(255, 255, 255, 0.75);
  --bs-secondary-color-rgb: 255, 255, 255;
  --bs-secondary-bg: var(--theme-bg-secondary);
  --bs-secondary-bg-rgb: 45, 45, 45;
  --bs-tertiary-color: rgba(255, 255, 255, 0.5);
  --bs-tertiary-color-rgb: 255, 255, 255;
  --bs-tertiary-bg: var(--theme-bg-tertiary);
  --bs-tertiary-bg-rgb: 58, 58, 58;
  --bs-border-color: var(--theme-border);
  --bs-border-color-translucent: rgba(255, 255, 255, 0.15);
}

/* Base Theme Styles */
html, body {
  background-color: var(--theme-bg-primary) !important;
  color: var(--theme-text-primary) !important;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Ensure body background applies */
body.bg-light {
  background-color: var(--theme-bg-primary) !important;
}

/* Navigation Theming */
.navbar-dark {
  background-color: var(--theme-nav-bg) !important;
}

.navbar-dark .navbar-brand,
.navbar-dark .navbar-nav .nav-link {
  color: var(--theme-nav-text) !important;
}

.navbar-dark .navbar-nav .nav-link:hover {
  color: var(--theme-nav-text-hover) !important;
}

/* Card Theming */
.card {
  background-color: var(--theme-card-bg) !important;
  border-color: var(--theme-card-border) !important;
  box-shadow: 0 1px 3px var(--theme-card-shadow);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  color: var(--theme-text-primary) !important;
}

.card:hover {
  box-shadow: 0 2px 8px var(--theme-card-hover-shadow);
}

.card-header {
  background-color: var(--theme-bg-secondary) !important;
  border-bottom-color: var(--theme-border) !important;
  color: var(--theme-text-primary) !important;
}

.card-footer {
  background-color: var(--theme-bg-secondary) !important;
  border-top-color: var(--theme-border) !important;
  color: var(--theme-text-primary) !important;
}

.card-body {
  background-color: var(--theme-card-bg);
  color: var(--theme-text-primary) !important;
}

/* Form Element Theming */
.form-control,
.form-select {
  background-color: var(--theme-input-bg) !important;
  border-color: var(--theme-input-border) !important;
  color: var(--theme-text-primary) !important;
}

.form-control:focus,
.form-select:focus {
  background-color: var(--theme-input-bg) !important;
  border-color: var(--theme-input-focus-border) !important;
  box-shadow: 0 0 0 0.25rem var(--theme-input-focus-shadow) !important;
  color: var(--theme-text-primary) !important;
}

.form-control::placeholder {
  color: var(--theme-text-muted) !important;
}

.form-label {
  color: var(--theme-text-primary) !important;
}

.form-text {
  color: var(--theme-text-muted) !important;
}

/* Button Theming */
.btn-primary {
  background-color: var(--theme-btn-primary-bg);
  border-color: var(--theme-btn-primary-border);
}

.btn-primary:hover {
  background-color: var(--theme-btn-primary-hover-bg);
  border-color: var(--theme-btn-primary-hover-bg);
}

.btn-secondary {
  background-color: var(--theme-btn-secondary-bg);
  border-color: var(--theme-btn-secondary-border);
}

.btn-outline-primary {
  color: var(--theme-btn-primary-bg);
  border-color: var(--theme-btn-primary-bg);
}

.btn-outline-primary:hover {
  background-color: var(--theme-btn-primary-bg);
  border-color: var(--theme-btn-primary-bg);
}

/* Table Theming */
.table {
  color: var(--theme-text-primary) !important;
  background-color: var(--theme-card-bg);
}

.table th {
  background-color: var(--theme-bg-secondary) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text-primary) !important;
}

.table td {
  border-color: var(--theme-border) !important;
  color: var(--theme-text-primary) !important;
}

.table-hover tbody tr:hover {
  background-color: var(--theme-hover-bg) !important;
  color: var(--theme-text-primary) !important;
}

/* Striped rows: Bootstrap 5.3 uses --bs-table-bg-type + inset box-shadow on
   tr > *. Keep defaults; ensure html gets data-bs-theme from theme-head.js
   with data-theme so --bs-table-* tokens match dark/light mode. */

/* Alert Theming */
.alert-success {
  background-color: var(--theme-success-bg);
  border-color: var(--theme-success);
  color: var(--theme-success);
}

.alert-warning {
  background-color: var(--theme-warning-bg);
  border-color: var(--theme-warning);
  color: var(--theme-warning);
}

.alert-danger {
  background-color: var(--theme-danger-bg);
  border-color: var(--theme-danger);
  color: var(--theme-danger);
}

.alert-info {
  background-color: var(--theme-info-bg);
  border-color: var(--theme-info);
  color: var(--theme-info);
}

/* Badge Theming */
.badge {
  color: inherit;
}

.badge.bg-secondary {
  background-color: var(--theme-bg-tertiary) !important;
  color: var(--theme-text-primary) !important;
  border: 1px solid var(--theme-border);
}

.badge.bg-primary {
  background-color: var(--theme-btn-primary-bg) !important;
  color: white !important;
}

.badge.bg-success {
  background-color: var(--theme-success) !important;
  color: white !important;
}

.badge.bg-warning {
  background-color: var(--theme-warning) !important;
  color: white;
}

.badge.bg-danger {
  background-color: var(--theme-danger) !important;
  color: white;
}

.badge.bg-info {
  background-color: var(--theme-info) !important;
  color: white;
}

.badge.bg-light {
  background-color: var(--theme-bg-tertiary) !important;
  color: var(--theme-text-primary) !important;
}

/* Allow explicit text-dark override on coloured badges */
.badge.text-dark {
  color: #1a1a1a !important;
}

/* Border Theming */
.border {
  border-color: var(--theme-border) !important;
}

.border-bottom {
  border-bottom-color: var(--theme-border) !important;
}

/* Text Color Theming */
.text-muted {
  color: var(--theme-text-muted) !important;
}

.text-dark {
  color: var(--theme-text-primary) !important;
}

.text-secondary {
  color: var(--theme-text-secondary) !important;
}

/* Card Elements */
.card-title {
  color: var(--theme-text-primary) !important;
}

.card-text {
  color: var(--theme-text-secondary) !important;
}

/* Additional Bootstrap overrides */
.bg-white {
  background-color: var(--theme-bg-primary) !important;
}

.bg-light {
  background-color: var(--theme-bg-secondary) !important;
  color: var(--theme-text-primary) !important;
}

/* Article placeholders and image areas */
.article-placeholder,
.article-placeholder-small {
  background-color: var(--theme-bg-secondary) !important;
  color: var(--theme-text-secondary) !important;
}

/* Badge theming */
.badge.bg-light {
  background-color: var(--theme-bg-tertiary) !important;
  color: var(--theme-text-primary) !important;
  border: 1px solid var(--theme-border);
}

.badge.bg-light.text-dark {
  background-color: var(--theme-bg-tertiary) !important;
  color: var(--theme-text-primary) !important;
}

/* Sidebar and filter styling */
.sticky-top .card {
  background-color: var(--theme-card-bg) !important;
  color: var(--theme-text-primary) !important;
}

.sticky-top .card-header {
  background-color: var(--theme-bg-secondary) !important;
  color: var(--theme-text-primary) !important;
}

/* Article meta information */
.article-meta,
.small.text-muted {
  color: var(--theme-text-muted) !important;
}

/* Links in cards */
.card a {
  color: var(--theme-text-primary);
}

.card a:hover {
  color: var(--theme-btn-primary-bg);
}

/* Section backgrounds */
.py-5 {
  background-color: var(--theme-bg-secondary) !important;
}

/* Welcome section styling */
.bg-light.py-5 {
  background-color: var(--theme-bg-secondary) !important;
  color: var(--theme-text-primary) !important;
}

.list-group-item {
  background-color: var(--theme-card-bg) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text-primary) !important;
}

.list-group-item-action:hover,
.list-group-item-action:focus,
.list-group-item:hover {
  background-color: var(--theme-hover-bg) !important;
  color: var(--theme-text-primary) !important;
}

/* Container and main content areas */
.container,
.container-fluid {
  color: var(--theme-text-primary);
}

main {
  background-color: var(--theme-bg-primary);
  color: var(--theme-text-primary);
}

/* Small text and muted elements */
.small {
  color: var(--theme-text-secondary) !important;
}

.small.text-muted {
  color: var(--theme-text-muted) !important;
}

/* Header elements */
h1, h2, h3, h4, h5, h6 {
  color: var(--theme-text-primary) !important;
}

/* Lead text */
.lead {
  color: var(--theme-text-secondary) !important;
}

/* Article-specific styling */
.article-card .card-title {
  color: var(--theme-text-primary) !important;
}

.article-card .card-text {
  color: var(--theme-text-secondary) !important;
}

/* Icon colors in placeholders */
.article-placeholder i,
.article-placeholder-small i {
  color: var(--theme-text-muted) !important;
}

/* Footer Theming */
footer.bg-dark {
  background-color: var(--theme-footer-bg) !important;
  color: var(--theme-footer-text);
}

/* Theme Toggle Button */
.theme-toggle {
  background: none;
  border: 1px solid var(--theme-border);
  color: var(--theme-text-primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

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

.theme-toggle i {
  font-size: 1.1rem;
  transition: transform 0.3s ease;
}

.theme-toggle:hover i {
  transform: scale(1.1);
}

/* Hover Effects for Interactive Elements */
.hover-bg-light:hover {
  background-color: var(--theme-hover-bg) !important;
}

/* Dropdown Theming */
.dropdown-menu {
  background-color: var(--theme-card-bg);
  border-color: var(--theme-card-border);
  box-shadow: 0 4px 16px var(--theme-card-shadow);
}

.dropdown-item {
  color: var(--theme-text-primary);
}

.dropdown-item:hover {
  background-color: var(--theme-hover-bg);
  color: var(--theme-text-primary);
}

.dropdown-divider {
  border-top-color: var(--theme-border);
}

/* Modal Theming */
.modal-content {
  background-color: var(--theme-card-bg);
  border-color: var(--theme-card-border);
}

.modal-header {
  border-bottom-color: var(--theme-border);
}

.modal-footer {
  border-top-color: var(--theme-border);
}

/* Pagination Theming */
.page-link {
  background-color: var(--theme-card-bg);
  border-color: var(--theme-border);
  color: var(--theme-text-primary);
}

.page-link:hover {
  background-color: var(--theme-hover-bg);
  border-color: var(--theme-hover-border);
  color: var(--theme-text-primary);
}

.page-item.active .page-link {
  background-color: var(--theme-btn-primary-bg);
  border-color: var(--theme-btn-primary-border);
}

/* Breadcrumb Theming */
.breadcrumb {
  background-color: var(--theme-bg-secondary);
}

.breadcrumb-item + .breadcrumb-item::before {
  color: var(--theme-text-muted);
}

/* Custom Scrollbar for Dark Mode */
[data-theme="dark"] ::-webkit-scrollbar {
  width: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--theme-bg-secondary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--theme-border);
  border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--theme-text-muted);
}

/* Smooth transitions for theme changes — scoped to common surfaces to avoid
   laggy hovers/inputs and unintended animations on every element. */
html,
body,
main,
.card,
.card-header,
.card-footer,
.card-body,
.navbar,
.modal-content,
.dropdown-menu,
.list-group-item,
.alert,
.btn,
.badge,
.form-control,
.form-select,
.form-check-input,
.table,
.page-link,
.breadcrumb,
.theme-toggle,
footer {
  transition: background-color 0.25s ease, color 0.25s ease,
              border-color 0.25s ease, box-shadow 0.2s ease;
}

/* Print styles - always use light theme for printing */
@media print {
  :root {
    --theme-bg-primary: #ffffff;
    --theme-bg-secondary: #f8f9fa;
    --theme-text-primary: #212529;
    --theme-text-secondary: #6c757d;
    --theme-border: #dee2e6;
    --theme-card-bg: #ffffff;
    --theme-card-border: #dee2e6;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --theme-border: #000000;
    --theme-text-muted: #4a4a4a;
  }
  
  [data-theme="dark"] {
    --theme-border: #ffffff;
    --theme-text-muted: #cccccc;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Consumer editorial palette sync with public.css */
body.public-site {
  --theme-bg-primary: var(--paper-bg, #f7f7f5);
  --theme-bg-secondary: var(--paper-card, #ffffff);
  --theme-text-primary: var(--paper-ink, #1a1a1a);
  --theme-text-secondary: var(--paper-muted, #5c6370);
  --theme-text-muted: var(--paper-muted, #5c6370);
  --theme-border: var(--paper-rule, #e2e4e8);
  --theme-card-bg: var(--paper-card, #ffffff);
  --theme-card-border: var(--paper-rule, #e2e4e8);
  --theme-btn-primary-bg: var(--paper-accent, #0f766e);
  --theme-btn-primary-border: var(--paper-accent, #0f766e);
  --theme-btn-primary-hover-bg: var(--paper-accent-hover, #0d5f59);
  --theme-input-focus-border: var(--paper-accent, #0f766e);
  --theme-input-focus-shadow: var(--paper-accent-soft, rgba(15, 118, 110, 0.14));
  --theme-footer-bg: var(--paper-nav-bg, #f7f7f5);
  --theme-footer-text: var(--paper-muted, #5c6370);
  background-color: var(--paper-bg, #f7f7f5);
  color: var(--paper-ink, #1a1a1a);
}

body.public-site .card {
  background: var(--paper-card);
  border-color: var(--paper-rule);
}

body.public-site .dropdown-menu {
  border-color: var(--paper-rule);
}