/*
 * Optional dark theme for Padhlona — OFF by default, toggled by dark-theme.js.
 * Standalone file, does not modify any existing stylesheet.
 * Neutral charcoal surfaces with one blue action/focus accent.
 * Palette roles: https://www.radix-ui.com/colors/docs/palette-composition/understanding-the-scale
 * Layering: https://carbondesignsystem.com/guidelines/color/overview/
 * All rules are scoped under html.dark-mode so nothing changes until the
 * floating toggle button (bottom-right, injected by dark-theme.js) is clicked.
 */

html.dark-mode {
  color-scheme: dark;

  /* overrides the variable names used by login.css/complete_profile */
  --bg-color: #121212;
  --card-bg: #1c1c1e;
  --surface-muted: #222225;
  --surface-raised: #252528;
  --surface-hover: #29292d;
  --text-main: #e5e5e5;
  --text-secondary: #c7c7c9;
  --text-muted: #a1a1aa;
  /* Light accents suit links/focus; solid actions need a darker fill. */
  --primary: #8ab4f8;
  --primary-hover: #aecbfa;
  --primary-light: #202c40;
  --primary-solid: #315fc4;
  --primary-solid-hover: #3b6bd4;
  --on-primary: #ffffff;
  --border-color: #343438;
  --accent-border: #617b9e;
  --accent-glow: rgba(138, 180, 248, 0.07);
  /* Metadata stays neutral; color is reserved for actions and real status. */
  --accent-violet: var(--text-secondary);
  --accent-violet-bg: var(--surface-muted);
  --accent-violet-border: var(--border-color);
  --accent-blue: var(--primary);
  --accent-teal: var(--text-muted);
  --accent-teal-bg: var(--surface-muted);
  --accent-teal-border: var(--border-color);
  --premium: #d8b579;
  --premium-bg: #2c261d;
  --premium-border: #4a4031;
}

/* Page backgrounds stay below the lighter component layers, even when the
   template also gives the body a light-mode background utility. */
html.dark-mode body,
html.dark-mode body.bg-white,
html.dark-mode body.bg-slate-50,
html.dark-mode body.bg-slate-100 {
  background-color: var(--bg-color) !important;
  color: var(--text-main) !important;
}

html.dark-mode ::selection {
  background: var(--primary-solid);
  color: var(--on-primary);
}

html.dark-mode ::-webkit-scrollbar { width: 10px; height: 10px; }
html.dark-mode ::-webkit-scrollbar-track { background: var(--bg-color); }
html.dark-mode ::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 6px; }

/* Form controls (login, complete_profile, help_feedback, import pages) */
html.dark-mode input:not([type="checkbox"]):not([type="radio"]),
html.dark-mode textarea,
html.dark-mode select {
  background-color: var(--card-bg) !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}
html.dark-mode input::placeholder, html.dark-mode textarea::placeholder {
  color: var(--text-muted) !important;
  opacity: 1;
}

/* Legacy navbar appearance. The standalone navbar0 owns its theme styles. */
html.dark-mode .global-nav-wrapper:not([data-navbar0]) {
  background-color: var(--card-bg) !important;
  border-color: var(--border-color) !important;
}
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-brand,
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-hamburger {
  color: var(--text-main) !important;
}
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-hamburger:hover { background-color: var(--surface-hover) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-link { color: var(--text-muted) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-link:hover,
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-link.active { color: var(--primary) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-link.active { background-color: var(--primary-light) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-link.active svg { fill: var(--primary-light) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-mobile-menu {
  background-color: var(--card-bg) !important;
  border-color: var(--border-color) !important;
}
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-mobile-link { color: var(--text-muted) !important; }
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-mobile-link:hover,
html.dark-mode .global-nav-wrapper:not([data-navbar0]) .global-nav-mobile-link.active {
  background-color: var(--primary-light) !important;
  color: var(--primary) !important;
}

/* login.css / complete_profile hardcoded secondary button */
html.dark-mode .btn-secondary {
  background-color: var(--card-bg) !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}
html.dark-mode .btn-secondary:hover { background-color: var(--surface-hover) !important; }

/* dynamic_page.css / help_feedback.css toolbar controls */
html.dark-mode .hf-btn, html.dark-mode .hf-select, html.dark-mode .hf-color {
  background: var(--card-bg) !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}
html.dark-mode .hf-btn:hover { background: var(--surface-hover) !important; }
/* Only primary actions use solid blue; secondary controls stay neutral. */
html.dark-mode .btn-primary,
html.dark-mode .hf-btn-primary {
  background: var(--primary-solid) !important;
  color: var(--on-primary) !important;
  border-color: var(--primary-solid) !important;
  box-shadow: none;
}
html.dark-mode .btn-primary:hover,
html.dark-mode .hf-btn-primary:hover {
  background: var(--primary-solid-hover) !important;
  border-color: var(--primary-solid-hover) !important;
  box-shadow: none;
}
html.dark-mode :is(.hf-btn, .btn-primary, .btn-secondary, input, textarea, select):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
html.dark-mode #help-content[contenteditable="true"] { border-color: var(--accent-border) !important; }

/* preview.html / preview_news.html / import.html inline-styled admin pages */
html.dark-mode .question { background-color: var(--card-bg) !important; border-color: var(--border-color) !important; }

/* Tailwind utility classes used across home/profile/landing/questions/etc. */
html.dark-mode .bg-white { background-color: var(--card-bg) !important; }
html.dark-mode .bg-slate-50, html.dark-mode .bg-slate-100 { background-color: var(--surface-muted) !important; }
html.dark-mode .bg-slate-200 { background-color: var(--border-color) !important; }
html.dark-mode .hover\:bg-slate-50:hover, html.dark-mode .hover\:bg-slate-100:hover { background-color: var(--surface-hover) !important; }
html.dark-mode .hover\:bg-slate-200:hover { background-color: var(--border-color) !important; }

html.dark-mode .text-slate-900, html.dark-mode .text-slate-800 { color: var(--text-main) !important; }
html.dark-mode .text-slate-700, html.dark-mode .text-slate-600 { color: var(--text-secondary) !important; }
html.dark-mode .text-slate-500, html.dark-mode .text-slate-400 { color: var(--text-muted) !important; }
html.dark-mode .text-slate-300 { color: var(--text-muted) !important; }

/* Typography-plugin content has its own heading/link/code colors; inherited
   body text alone cannot theme it. Avoid overriding authored article styles. */
html.dark-mode .prose {
  --tw-prose-body: var(--text-main);
  --tw-prose-headings: var(--text-main);
  --tw-prose-lead: var(--text-muted);
  --tw-prose-links: var(--primary);
  --tw-prose-bold: var(--text-main);
  --tw-prose-counters: var(--text-muted);
  --tw-prose-bullets: var(--text-muted);
  --tw-prose-hr: var(--border-color);
  --tw-prose-quotes: var(--text-main);
  --tw-prose-quote-borders: var(--border-color);
  --tw-prose-captions: var(--text-muted);
  --tw-prose-kbd: var(--text-main);
  --tw-prose-kbd-shadows: 229 229 229;
  --tw-prose-code: var(--text-main);
  --tw-prose-pre-code: var(--text-main);
  --tw-prose-pre-bg: var(--card-bg);
  --tw-prose-th-borders: var(--border-color);
  --tw-prose-td-borders: var(--border-color);
}

html.dark-mode .border-slate-100, html.dark-mode .border-slate-200, html.dark-mode .border-slate-300 {
  border-color: var(--border-color) !important;
}
html.dark-mode .divide-slate-100 > :not([hidden]) ~ :not([hidden]) { border-color: var(--border-color) !important; }

/* Brand/selection uses blue; amber is reserved for premium content. */
html.dark-mode .bg-indigo-50, html.dark-mode .bg-indigo-100, html.dark-mode .bg-indigo-50\/50 {
  background-color: var(--primary-light) !important;
}
html.dark-mode .text-indigo-600, html.dark-mode .text-indigo-700, html.dark-mode .text-indigo-900 {
  color: var(--primary) !important;
}
html.dark-mode .hover\:bg-indigo-100:hover, html.dark-mode .hover\:bg-indigo-50:hover {
  background-color: var(--primary-light) !important;
}
html.dark-mode .bg-amber-50, html.dark-mode .bg-amber-100,
html.dark-mode .from-amber-100, html.dark-mode .to-amber-50 {
  --tw-gradient-from: var(--premium-bg) !important;
  --tw-gradient-to: var(--card-bg) !important;
  background-color: var(--premium-bg) !important;
}
html.dark-mode .text-amber-700 { color: var(--premium) !important; }

/* Landing page: swap its light sections, keep the already-dark hero as-is */
html.dark-mode .landing section.bg-slate-50, html.dark-mode .landing .bg-white {
  background-color: var(--bg-color) !important;
}

/* Floating toggle button — always visible, independent of current mode.
   Sits top-right, clear of the top nav bar (4rem tall on mobile) and clear
   of the side rail that the nav becomes at the 640px breakpoint. */
#dark-mode-toggle {
  position: fixed;
  top: 1rem;
  right: 4.7rem;
  bottom: auto;
  z-index: 9999;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  border: 1px solid #d4d4d8;
  background: #ffffff;
  color: #27272a;
  font-size: 1.05rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
@media (min-width: 640px) {
  #dark-mode-toggle { top: 9.5rem; right: 3.25rem; width: 3rem; height: 3rem; }
}
#dark-mode-toggle:hover { background: #f4f4f5; }
html.dark-mode #dark-mode-toggle {
  background: var(--card-bg);
  color: var(--text-muted);
  border-color: var(--border-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}
html.dark-mode #dark-mode-toggle:hover {
  background: var(--surface-hover);
  color: var(--primary);
  border-color: var(--accent-border);
}
