/* ==========================================================================
   Israeli Tax Guide - Main Stylesheet
   Fonts are loaded from base.html via <link> for non-blocking render.
   ========================================================================== */

/* ==========================================================================
   1. CSS Custom Properties
   ========================================================================== */

:root {
  --color-header-bg: #0b1638;
  --color-primary: #14224d;
  --color-secondary: #2c4a8a;
  --color-accent: #3d6bb5;
  --color-accent-warm: #c89b3c;
  --color-bg: #ffffff;
  --color-bg-alt: #f5f7fb;
  --color-bg-soft: #eaeff8;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-text: #15192a;            /* darker — better legibility */
  --color-text-light: #4a5161;      /* AA on white */
  --color-text-muted: #6a7385;      /* AA on white at 14px+ */
  --color-border: #e1e6ee;
  --color-border-subtle: #eef1f6;
  --color-border-strong: #c9d1de;
  --color-footer-bg: #0b1638;
  --color-success: #047857;
  --color-warning: #b45309;

  --color-link: #2a549a;
  --color-link-hover: #14224d;
  --color-card-shadow: rgba(11, 22, 56, 0.08);
  --color-overlay: rgba(11, 22, 56, 0.55);

  /* New semantic color tokens */
  --color-info: #1d4ed8;
  --color-info-bg: #eef4ff;
  --color-info-border: #93c5fd;
  --color-tip: #047857;
  --color-tip-bg: #ecfdf5;
  --color-tip-border: #6ee7b7;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fcd34d;
  --color-danger: #b91c1c;
  --color-danger-bg: #fef2f2;
  --color-danger-border: #fca5a5;
  --color-example-bg: #f0f4ff;
  --color-example-border: #818cf8;

  /* Editorial serif for headings; Rubik gives crisp Hebrew/Latin body. */
  --font-heading: "Frank Ruhl Libre", "Lora", Georgia, "Times New Roman", "Noto Serif Hebrew", serif;
  --font-body: "Rubik", "Inter", "Noto Sans Arabic", "Noto Sans Ethiopic",
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Fluid type scale — viewport-aware so mobile reads at ~17px and desktop at ~18px. */
  --text-xs: clamp(0.78rem, 0.76rem + 0.1vw, 0.8125rem);   /* ~12.5–13px */
  --text-sm: clamp(0.9rem, 0.86rem + 0.18vw, 0.9375rem);    /* ~14.4–15px */
  --text-base: clamp(1.0625rem, 1rem + 0.25vw, 1.125rem);   /* ~17–18px */
  --text-lg: clamp(1.15rem, 1.08rem + 0.32vw, 1.25rem);     /* ~18.4–20px */
  --text-xl: clamp(1.3rem, 1.2rem + 0.4vw, 1.5rem);         /* ~20.8–24px */
  --text-2xl: clamp(1.55rem, 1.4rem + 0.6vw, 1.875rem);     /* ~24.8–30px */
  --text-3xl: clamp(1.9rem, 1.65rem + 1vw, 2.375rem);       /* ~30.4–38px */
  --text-4xl: clamp(2.25rem, 1.9rem + 1.5vw, 3rem);         /* ~36–48px */
  --text-5xl: clamp(2.75rem, 2.2rem + 2vw, 3.75rem);        /* ~44–60px */

  --leading-tight: 1.25;
  --leading-snug: 1.4;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;
  --leading-loose: 1.9;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  --container-max: 1200px;
  --container-narrow: 760px;
  --sidebar-width: 280px;
  --header-height: 68px;
  --nav-height: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --shadow-xs: 0 1px 2px rgba(11, 22, 56, 0.04);
  --shadow-sm: 0 1px 3px rgba(11, 22, 56, 0.06), 0 1px 2px rgba(11, 22, 56, 0.04);
  --shadow-md: 0 4px 12px rgba(11, 22, 56, 0.07), 0 2px 4px rgba(11, 22, 56, 0.04);
  --shadow-lg: 0 12px 28px rgba(11, 22, 56, 0.1), 0 4px 12px rgba(11, 22, 56, 0.05);
  --shadow-xl: 0 24px 48px rgba(11, 22, 56, 0.14), 0 8px 16px rgba(11, 22, 56, 0.06);
  --shadow-card-hover: 0 16px 36px rgba(11, 22, 56, 0.14);

  /* Gradients */
  --gradient-hero: linear-gradient(135deg, #0b1638 0%, #14224d 50%, #2c4a8a 100%);
  --gradient-card-accent: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

/* ==========================================================================
   2. Reset & Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 100%; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  font-weight: 400;
  letter-spacing: 0.005em;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

/* Improve Hebrew + Arabic readability: looser leading, no Latin letter-spacing. */
[dir="rtl"] body {
  letter-spacing: 0;
  line-height: 1.85;
}

img { max-width: 100%; height: auto; display: block; }

/* Skip Navigation Link - Accessibility */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--color-primary);
  color: #fff;
  padding: 0.75rem 1.5rem;
  z-index: 10000;
  font-size: var(--text-base);
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Footer legal links */
.footer-legal {
  text-align: center;
  padding: 1rem 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 1rem;
}
.footer-legal .footer-heading {
  font-size: var(--text-sm);
  margin-bottom: 0.5rem;
}
.footer-legal-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
}
.footer-legal-links li { margin: 0; }
.footer-legal-links a {
  font-size: var(--text-sm);
  opacity: 0.85;
  transition: opacity var(--transition-fast);
}
.footer-legal-links a:hover { opacity: 1; }

a {
  color: var(--color-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover, a:focus { color: var(--color-link-hover); text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ==========================================================================
   3. Utility / Layout
   ========================================================================== */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 1.5rem);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   4. Typography
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--color-primary);
  margin-bottom: var(--space-md);
  letter-spacing: -0.015em;
  font-feature-settings: "kern" 1, "liga" 1, "ss01" 1;
}

[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3,
[dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6 {
  letter-spacing: 0;
  line-height: var(--leading-snug);
}

h1 { font-size: var(--text-4xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-3xl); margin-top: var(--space-2xl); letter-spacing: -0.02em; }
h3 { font-size: var(--text-2xl); margin-top: var(--space-xl); letter-spacing: -0.015em; }
h4 { font-size: var(--text-xl); margin-top: var(--space-lg); }
h5 { font-size: var(--text-lg); }
h6 {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--color-text-light);
}

p {
  margin-bottom: var(--space-md);
  line-height: var(--leading-relaxed);
  max-width: 75ch;
}

/* When inside containers that already constrain width, drop the prose limit */
.container > p, .home-section p, .home-feature p, .footer-description, td p, li p {
  max-width: none;
}

strong, b { font-weight: 700; color: var(--color-primary); }
em, i { font-style: italic; }

::selection {
  background: rgba(61, 107, 181, 0.25);
  color: var(--color-primary);
}

/* ==========================================================================
   5. Top Bar & Language Switcher
   ========================================================================== */

.top-bar {
  background-color: var(--color-header-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  min-height: 40px;
}

.lang-switcher {
  position: relative;
  flex-shrink: 0;
}

.lang-dropdown {
  position: relative;
}

.lang-current {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  font-size: var(--text-sm);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast);
}

.lang-current:hover { border-color: rgba(255, 255, 255, 0.6); }

.lang-arrow { font-size: 0.65em; opacity: 0.7; }

.lang-list {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 160px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  padding: var(--space-xs) 0;
  margin-top: var(--space-xs);
}

.lang-dropdown:hover .lang-list,
.lang-dropdown:focus-within .lang-list { display: block; }

.lang-list li a {
  display: block;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  transition: background-color var(--transition-fast);
}

.lang-list li a:hover,
.lang-list li a:focus { background-color: var(--color-bg-alt); text-decoration: none; }

.lang-list li a.lang-active {
  font-weight: 600;
  color: var(--color-primary);
  background-color: var(--color-bg-alt);
}

/* ==========================================================================
   6. Search Box
   ========================================================================== */

.search-box {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 6px var(--space-md);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast),
              box-shadow var(--transition-fast);
}

.search-input::placeholder { color: rgba(255, 255, 255, 0.5); }

.search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 0 3px rgba(61, 107, 181, 0.3);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-card-hover);
  z-index: 1200;
  margin-top: 2px;
  max-height: 70vh;
  overflow-y: auto;
}

.search-results-list { list-style: none; padding: 0; margin: 0; }

.search-results-list li a {
  display: block;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-bg-alt);
  transition: background-color var(--transition-fast);
}

.search-results-list li a:hover,
.search-results-list li a:focus {
  background-color: var(--color-bg-alt);
  text-decoration: none;
}

.search-result-title {
  display: block;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--color-primary);
  transition: color var(--transition-fast);
}

.search-results-list li a:hover .search-result-title {
  color: var(--color-accent);
}

.search-result-path {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-light);
  margin-top: 2px;
}

/* ==========================================================================
   7. Site Header & Logo (consolidated single-row)
   ========================================================================== */

.site-header-wrap {
  position: sticky;
  top: 0;
  z-index: 1000;
}

.site-header {
  background: linear-gradient(180deg, #0a142f 0%, var(--color-header-bg) 100%);
  color: #ffffff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  height: 64px;
}

.site-header-tools {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1 1 auto;
  justify-content: flex-end;
}

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: #ffffff;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}

.site-logo:hover { color: #ffffff; text-decoration: none; opacity: 0.85; }

.site-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-accent-warm) 0%, #b07f23 100%);
  color: #1a1410;
  box-shadow: 0 4px 12px rgba(200, 155, 60, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.site-name {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1;
  white-space: nowrap;
}

[dir="rtl"] .site-name { letter-spacing: 0; }

/* === Search inside the header === */
.site-header .search-box {
  position: relative;
  flex: 1 1 auto;
  max-width: 440px;
}

.site-header .search-icon {
  position: absolute;
  inset-inline-start: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
  display: inline-flex;
}

.site-header .search-input {
  width: 100%;
  height: 38px;
  padding-inline: 2.25rem 0.875rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast),
              box-shadow var(--transition-fast);
}

.site-header .search-input::placeholder { color: rgba(255, 255, 255, 0.5); }

.site-header .search-input:focus {
  outline: none;
  border-color: rgba(200, 155, 60, 0.6);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 3px rgba(200, 155, 60, 0.18);
}

/* === Language switcher button === */
.lang-current {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.lang-current:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}

.lang-globe { display: inline-flex; opacity: 0.8; }

.lang-current-label { line-height: 1; }

.lang-arrow {
  font-size: 0.6em;
  opacity: 0.7;
  margin-inline-start: 0.15rem;
}

@media (max-width: 640px) {
  .site-header-inner { height: 56px; gap: 0.5rem; }
  .site-name { font-size: var(--text-base); }
  .site-header .search-box { max-width: none; min-width: 0; }
  .lang-current-label { display: none; }
  .lang-current { padding: 0.45rem 0.55rem; }
}

@media (max-width: 420px) {
  .site-header .search-box {
    /* On the smallest phones the search and lang switcher compete for room.
       Hide the search here — the homepage hero already exposes a large search. */
    display: none;
  }
}

/* ==========================================================================
   8. Main Navigation
   ========================================================================== */

.main-nav {
  background-color: var(--color-primary);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-toggle-checkbox { display: none; }

.nav-toggle-label {
  display: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  position: relative;
  z-index: 1200;
}

.nav-toggle-label .hamburger,
.nav-toggle-label .hamburger::before,
.nav-toggle-label .hamburger::after {
  display: block;
  width: 24px;
  height: 2px;
  background-color: #ffffff;
  position: absolute;
  transition: transform var(--transition-base), opacity var(--transition-fast);
}

.nav-toggle-label .hamburger {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.nav-toggle-label .hamburger::before { content: ""; top: -7px; left: 0; }
.nav-toggle-label .hamburger::after { content: ""; top: 7px; left: 0; }

.nav-toggle-checkbox:checked + .nav-toggle-label .hamburger { background-color: transparent; }
.nav-toggle-checkbox:checked + .nav-toggle-label .hamburger::before { top: 0; transform: rotate(45deg); }
.nav-toggle-checkbox:checked + .nav-toggle-label .hamburger::after { top: 0; transform: rotate(-45deg); }

.nav-list {
  display: flex;
  align-items: stretch;
  min-height: var(--nav-height);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav-list::-webkit-scrollbar { display: none; }

.nav-item { position: relative; }

.nav-item > a {
  display: flex;
  align-items: center;
  height: 100%;
  min-height: 44px;
  padding-inline: 0.9rem;
  color: rgba(255, 255, 255, 0.88);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.nav-item > a:hover,
.nav-item > a:focus {
  background-color: var(--color-secondary);
  color: #ffffff;
  text-decoration: none;
}

.nav-item.has-dropdown > a::after {
  content: "\25BC";
  font-size: 0.55em;
  margin-inline-start: var(--space-xs);
  opacity: 0.7;
}

.nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  padding: var(--space-xs) 0;
}

[dir="rtl"] .nav-dropdown { left: auto; right: 0; }

.nav-item.has-dropdown:hover > .nav-dropdown,
.nav-item.has-dropdown:focus-within > .nav-dropdown,
.nav-item.has-dropdown.is-open > .nav-dropdown { display: block; }

/* On touch devices, suppress the hover-trigger entirely — the JS toggle is
   the only way the dropdown opens, and it stays open until the user taps
   somewhere else or selects an item. */
@media (hover: none) {
  .nav-item.has-dropdown:hover > .nav-dropdown,
  .nav-item.has-dropdown:focus-within > .nav-dropdown { display: none; }
  .nav-item.has-dropdown.is-open > .nav-dropdown { display: block; }
}

.nav-dropdown a {
  display: block;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  transition: background-color var(--transition-fast);
}

.nav-dropdown a:hover,
.nav-dropdown a:focus {
  background-color: var(--color-bg-alt);
  color: var(--color-primary);
  text-decoration: none;
}

/* ==========================================================================
   9. Breadcrumbs
   ========================================================================== */

nav.breadcrumbs {
  background: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-border);
}

nav.breadcrumbs ol {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.65rem 0;
  font-size: var(--text-xs);
  color: var(--color-text-light);
  overflow-x: auto;
  scrollbar-width: none;
}
nav.breadcrumbs ol::-webkit-scrollbar { display: none; }
nav.breadcrumbs li { white-space: nowrap; }

nav.breadcrumbs li {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

nav.breadcrumbs a { color: var(--color-text-light); }
nav.breadcrumbs a:hover { color: var(--color-accent); }

.breadcrumb-sep {
  color: var(--color-border);
  margin: 0 var(--space-xs);
}

/* ==========================================================================
   10. Homepage: Hero
   ========================================================================== */

.hero {
  background: var(--gradient-hero);
  color: #ffffff;
  padding: clamp(3rem, 5vw + 1rem, 5rem) 0 clamp(2.5rem, 4vw + 1rem, 4rem);
  text-align: center;
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-xl);
}

/* Subtle dot-grid overlay */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    radial-gradient(circle at 20% 30%, rgba(200, 155, 60, 0.08) 0, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(61, 107, 181, 0.18) 0, transparent 55%);
  background-size: 28px 28px, 100% 100%, 100% 100%;
  pointer-events: none;
  z-index: 0;
}

/* Curved bottom edge */
.hero::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: -5%;
  width: 110%;
  height: 3rem;
  background: var(--color-bg);
  border-radius: 50% 50% 0 0;
  z-index: 1;
}

.hero .container {
  position: relative;
  z-index: 2;
}

.hero-title {
  color: #ffffff;
  font-size: clamp(2rem, 3.5vw + 1rem, 3.25rem);
  margin-bottom: var(--space-md);
  line-height: 1.1;
  letter-spacing: -0.025em;
  font-weight: 700;
  text-wrap: balance;
}

[dir="rtl"] .hero-title { letter-spacing: 0; line-height: 1.2; }

.hero-tagline {
  font-size: clamp(1.0625rem, 1vw + 0.5rem, 1.25rem);
  color: rgba(255, 255, 255, 0.82);
  max-width: 640px;
  margin: 0 auto;
  line-height: 1.65;
  font-weight: 400;
  text-wrap: balance;
}

/* ==========================================================================
   10b. Hero Search Bar (NEW)
   ========================================================================== */

.hero-search {
  max-width: 560px;
  margin: var(--space-xl) auto 0;
  position: relative;
  z-index: 2;
}

.hero-search .hero-search-input {
  width: 100%;
  height: 56px;
  padding: 0 1.5rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #ffffff;
  font-size: var(--text-lg);
  font-family: inherit;
  transition: border-color var(--transition-fast), background var(--transition-fast),
              box-shadow var(--transition-fast);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.hero-search .hero-search-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.hero-search .hero-search-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12);
}

.hero-search .search-results {
  border-radius: var(--radius-lg);
  margin-top: var(--space-sm);
  box-shadow: var(--shadow-card-hover);
}

/* ==========================================================================
   11. Homepage: Category Grid & Cards
   ========================================================================== */

.section-heading {
  font-size: var(--text-2xl);
  text-align: center;
  margin: var(--space-2xl) 0 var(--space-lg);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-lg);
  padding-bottom: var(--space-xl);
}

.category-card {
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base),
              border-color var(--transition-base);
  position: relative;
  overflow: hidden;
}

.category-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(61, 107, 181, 0) 0%, rgba(20, 34, 77, 0.03) 100%);
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.category-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-4px);
  border-color: var(--color-border-strong);
  text-decoration: none;
  color: var(--color-text);
}

.category-card:hover::before { opacity: 1; }

.category-card-icon {
  width: 60px;
  height: 60px;
  background: var(--gradient-card-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
  font-size: var(--text-2xl);
  color: #ffffff;
  transition: transform var(--transition-base);
  box-shadow: 0 6px 16px rgba(20, 34, 77, 0.2);
}

.category-card:hover .category-card-icon {
  transform: scale(1.08) rotate(-3deg);
}

.category-card-title {
  font-size: var(--text-xl);
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
  letter-spacing: -0.01em;
}

[dir="rtl"] .category-card-title { letter-spacing: 0; }

.category-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  line-height: var(--leading-normal);
  flex-grow: 1;
}

.category-card-count {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ==========================================================================
   12. Homepage: Popular Articles
   ========================================================================== */

.popular-list {
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: var(--space-2xl);
  counter-reset: popular-counter;
}

.popular-list li {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  counter-increment: popular-counter;
  position: relative;
  padding-inline-start: calc(var(--space-md) + 36px);
}

.popular-list li::before {
  content: counter(popular-counter);
  position: absolute;
  inset-inline-start: var(--space-md);
  top: var(--space-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--gradient-card-accent);
  color: #ffffff;
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
}

.popular-list li a {
  font-weight: 600;
  color: var(--color-primary);
}

.popular-list li p {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

/* ==========================================================================
   13. Category Page: Subcategory Grid
   ========================================================================== */

.category-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 3px solid var(--color-bg-alt);
}

.category-description {
  font-size: var(--text-lg);
  color: var(--color-text-light);
  line-height: 1.8;
  max-width: 800px;
}

.subcategory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
  padding-bottom: var(--space-xl);
}

.subcategory-card {
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-decoration: none;
  color: var(--color-text);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
  position: relative;
  overflow: hidden;
}

/* Gradient top accent on hover */
.subcategory-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-card-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-base);
}

[dir="rtl"] .subcategory-card::before {
  transform-origin: right;
}

.subcategory-card:hover::before {
  transform: scaleX(1);
}

.subcategory-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-secondary);
  text-decoration: none;
  color: var(--color-text);
}

.subcategory-card-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
}

.subcategory-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  line-height: 1.6;
  flex-grow: 1;
}

.subcategory-card-count {
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-light);
}

/* ==========================================================================
   14. Subcategory Page: Article List
   ========================================================================== */

.subcategory-header { margin-bottom: var(--space-xl); }

.subcategory-description {
  font-size: var(--text-lg);
  color: var(--color-text-light);
  line-height: 1.8;
}

ol.article-list {
  list-style: none;
  counter-reset: article-counter;
  padding: 0;
}

.article-list-item {
  counter-increment: article-counter;
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.article-list-item:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--color-secondary);
}

.article-list-item::before {
  content: counter(article-counter);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-primary);
  color: #ffffff;
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 700;
  float: inline-start;
  margin-inline-end: var(--space-md);
  margin-top: 2px;
}

.article-list-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-xs);
  margin-top: 0;
}

.article-list-title a {
  color: var(--color-primary);
  text-decoration: none;
  position: relative;
}

.article-list-title a::after {
  content: "\2192";
  margin-inline-start: var(--space-sm);
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  display: inline-block;
}

[dir="rtl"] .article-list-title a::after {
  content: "\2190";
}

.article-list-title a:hover { color: var(--color-accent); }

.article-list-title a:hover::after {
  opacity: 1;
}

.article-list-desc {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  line-height: 1.6;
  margin-bottom: var(--space-xs);
}

.article-list-date {
  font-size: var(--text-xs);
  color: var(--color-text-light);
}

/* ==========================================================================
   15. Article Page: Layout
   ========================================================================== */

.article-layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-width);
  gap: var(--space-2xl);
  padding: var(--space-xl) 0;
}

.article-main { min-width: 0; }

.article-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--color-bg-alt);
}

.article-header h1 { margin-bottom: var(--space-sm); }

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-text-light);
  align-items: center;
}

.article-category a { color: var(--color-text-light); }
.article-category a:hover { color: var(--color-accent); }

.meta-sep { margin: 0 var(--space-xs); color: var(--color-border); }
.article-date { font-size: var(--text-xs); }

/* Reading Time Badge (NEW) */
.reading-time {
  font-size: var(--text-xs);
  color: var(--color-text-light);
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Article Content */
.article-content h2 {
  padding-top: var(--space-xl);
  border-bottom: 2px solid var(--color-border);
  padding-bottom: var(--space-sm);
  margin-top: var(--space-2xl);
}

.article-content h3 {
  color: var(--color-secondary);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-bg-alt);
}

.article-content ul,
.article-content ol {
  margin-bottom: var(--space-lg);
  padding-inline-start: var(--space-xl);
}

.article-content ul { list-style-type: disc; }
.article-content ol { list-style-type: decimal; }

.article-content li {
  margin-bottom: var(--space-sm);
  line-height: var(--leading-relaxed);
}
.article-content li::marker { color: var(--color-secondary); font-weight: 600; }

.article-content p {
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-md);
  font-size: var(--text-base);
  max-width: 70ch;
}

.article-content > p { max-width: 70ch; }

.article-content a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-color: rgba(61, 107, 181, 0.3);
  text-underline-offset: 2px;
}

.article-content a:hover { text-decoration-color: var(--color-accent); }

/* Responsive Tables */
.article-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
  margin-bottom: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: block;
  overflow-x: auto;
}

.article-content thead {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #ffffff;
}

.article-content th {
  padding: var(--space-sm) var(--space-md);
  text-align: start;
  font-weight: 600;
  white-space: nowrap;
}

.article-content td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.article-content tbody tr:nth-child(even) { background-color: var(--color-bg-alt); }
.article-content tbody tr:hover { background-color: rgba(44, 74, 138, 0.06); }

.article-content blockquote {
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  border-inline-start: 4px solid var(--color-secondary);
  background-color: var(--color-bg-alt);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

[dir="rtl"] .article-content blockquote {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.article-content blockquote p:last-child { margin-bottom: 0; }

/* Disclaimer blockquote - last blockquote in article */
.article-content blockquote:last-of-type {
  background-color: var(--color-warning-bg);
  border-inline-start-color: var(--color-warning-border);
  font-size: var(--text-sm);
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-bg-alt);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--color-primary);
}

.article-content pre {
  background: var(--color-header-bg);
  color: #e2e8f0;
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-lg);
  font-size: var(--text-sm);
}

.article-content pre code { background: transparent; padding: 0; color: inherit; }
.article-content hr { border: none; border-top: 1px solid var(--color-border); margin: var(--space-xl) 0; }

/* ==========================================================================
   15b. Example Box (NEW)
   ========================================================================== */

.example-box {
  position: relative;
  background-color: var(--color-example-bg);
  border: 1px solid var(--color-example-border);
  border-inline-start: 4px solid var(--color-example-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
}

.example-box::before {
  content: "\1F4CB";
  position: absolute;
  top: var(--space-sm);
  inset-inline-end: var(--space-sm);
  font-size: var(--text-xl);
  opacity: 0.25;
  pointer-events: none;
}

.example-box h3 {
  margin-top: 0;
  color: #4338ca;
  font-size: var(--text-lg);
  border-bottom: none;
  padding-bottom: 0;
}

.example-box p:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   15c. Callout Boxes (NEW)
   ========================================================================== */

.callout {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-lg) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  border-inline-start: 4px solid var(--color-border);
  background: var(--color-bg-alt);
}

.callout-icon {
  flex-shrink: 0;
  font-size: var(--text-xl);
  line-height: 1.6;
}

.callout-body {
  flex: 1;
  min-width: 0;
}

.callout-body p:last-child {
  margin-bottom: 0;
}

/* Info callout */
.callout-info {
  background: var(--color-info-bg);
  border-color: var(--color-info-border);
  border-inline-start-color: var(--color-info);
}

.callout-info .callout-icon { color: var(--color-info); }

/* Tip callout */
.callout-tip {
  background: var(--color-tip-bg);
  border-color: var(--color-tip-border);
  border-inline-start-color: var(--color-tip);
}

.callout-tip .callout-icon { color: var(--color-tip); }

/* Warning callout */
.callout-warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
  border-inline-start-color: var(--color-warning);
}

.callout-warning .callout-icon { color: var(--color-warning); }

/* Danger callout */
.callout-danger {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
  border-inline-start-color: var(--color-danger);
}

.callout-danger .callout-icon { color: var(--color-danger); }

/* ==========================================================================
   15d. In-Article Table of Contents (NEW)
   ========================================================================== */

.article-toc {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.article-toc-heading {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-light);
  margin-bottom: var(--space-md);
  margin-top: 0;
  font-family: var(--font-body);
  font-weight: 700;
}

.article-toc ol {
  list-style: decimal;
  padding-inline-start: var(--space-lg);
  margin: 0;
}

.article-toc ol li {
  margin-bottom: var(--space-xs);
  line-height: 1.5;
}

.article-toc ol li a {
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.article-toc ol li a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* ==========================================================================
   16. Article: Related Articles
   ========================================================================== */

.related-articles {
  margin-top: var(--space-2xl);
  padding-top: var(--space-xl);
  border-top: 2px solid var(--color-bg-alt);
}

.related-articles h2 { font-size: var(--text-xl); margin-top: 0; }

.related-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--space-md);
}

.related-list li {
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.related-list li:hover { border-color: var(--color-secondary); }
.related-list li a { font-weight: 600; color: var(--color-primary); }

.related-list li p {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

/* ==========================================================================
   17. Article: Prev / Next Pager
   ========================================================================== */

.article-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  margin-top: var(--space-2xl);
  padding-top: var(--space-xl);
  border-top: 2px solid var(--color-bg-alt);
}

.pager-prev,
.pager-next {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-primary);
  font-weight: 500;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

a.pager-prev:hover,
a.pager-next:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.pager-next { justify-content: flex-end; text-align: end; }
.pager-label { font-size: var(--text-lg); flex-shrink: 0; }
.pager-text { font-size: var(--text-sm); line-height: 1.4; }
.pager-disabled { visibility: hidden; }

/* ==========================================================================
   18. Article: Sidebar
   ========================================================================== */

.article-sidebar { font-size: var(--text-sm); }

.sidebar-sticky {
  position: sticky;
  top: calc(var(--header-height) + var(--space-xl));
  max-height: calc(100vh - var(--header-height) - var(--space-3xl));
  overflow-y: auto;
  padding: var(--space-lg);
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.sidebar-heading {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--color-secondary);
  margin-top: 0;
}

.sidebar-toc { list-style: none; counter-reset: sidebar-counter; padding: 0; }
.sidebar-toc li { counter-increment: sidebar-counter; }

.sidebar-toc li a {
  display: block;
  padding: var(--space-xs) var(--space-sm);
  color: var(--color-text-light);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  font-size: var(--text-sm);
}

.sidebar-toc li a:hover,
.sidebar-toc li a:focus {
  background-color: var(--color-bg);
  color: var(--color-primary);
  text-decoration: none;
}

.sidebar-toc li.toc-active a {
  color: var(--color-primary);
  font-weight: 600;
  background-color: var(--color-bg);
}

/* ==========================================================================
   19. Footer
   ========================================================================== */

footer[role="contentinfo"] {
  background: linear-gradient(180deg, var(--color-primary), var(--color-header-bg));
  color: rgba(255, 255, 255, 0.8);
  margin-top: auto;
  padding-top: var(--space-3xl);
  position: relative;
}

/* Gradient accent border at top of footer */
footer[role="contentinfo"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-secondary), var(--color-accent));
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2xl);
}

.footer-heading {
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 700;
  color: #ffffff;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--color-secondary);
}

.footer-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.footer-links a {
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--text-sm);
  transition: color var(--transition-fast);
}

.footer-links a:hover { color: #ffffff; text-decoration: none; }

.footer-description {
  font-size: var(--text-sm);
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.65);
}

.footer-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding: var(--space-lg);
  text-align: center;
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.5);
}

.copyright { margin-bottom: var(--space-sm); }

.disclaimer {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.4);
  line-height: 1.6;
}

/* ==========================================================================
   20. Back-to-Top Button (NEW)
   ========================================================================== */

.back-to-top {
  position: fixed;
  bottom: var(--space-xl);
  inset-inline-end: var(--space-xl);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: var(--text-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 900;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition-base), transform var(--transition-base),
              background-color var(--transition-fast);
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--color-secondary);
}

/* ==========================================================================
   21. Reading Progress Bar (NEW)
   ========================================================================== */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-secondary));
  z-index: 10001;
  transition: width 100ms linear;
}

/* ==========================================================================
   22. Responsive Design
   ========================================================================== */

@media (max-width: 1200px) {
  :root { --container-max: 960px; }
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
  .article-layout { grid-template-columns: 1fr; }
  .article-sidebar { order: -1; }
  .sidebar-sticky { position: static; max-height: none; }
  .subcategory-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* Activate the slide-in drawer on tablets too — hover-only desktop dropdowns
   are unreliable on touch, so anyone narrower than a small laptop gets the
   tap-friendly mobile drawer. */
@media (max-width: 1024px) {
  .nav-toggle-label { display: block; }

  /* Mobile Navigation - slide-in panel */
  .nav-list {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 86vw;
    height: 100vh;
    flex-direction: column;
    padding: calc(var(--header-height) + var(--space-md)) var(--space-sm) var(--space-sm);
    background-color: var(--color-primary);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    z-index: 1100;
    overflow-y: auto;
    display: flex;
  }

  [dir="rtl"] .nav-list {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }

  .nav-toggle-checkbox:checked ~ .nav-list {
    transform: translateX(0);
  }

  .nav-item > a {
    padding: var(--space-sm) var(--space-md);
    height: auto;
    border-radius: var(--radius-sm);
    min-height: 44px;
  }

  /* In the mobile drawer, ALWAYS show the dropdown expanded.
     Hover/focus-based reveal is unreliable on touch — taps on the parent
     link were dismissing the submenu before users could pick an item. */
  .nav-item.has-dropdown > .nav-dropdown,
  .nav-item.has-dropdown:hover > .nav-dropdown,
  .nav-item.has-dropdown:focus-within > .nav-dropdown {
    display: block;
    position: static;
    box-shadow: none;
    border: none;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    min-width: 0;
    margin: 0 0 0.4rem;
    padding: 0.25rem 0;
  }

  .nav-dropdown a {
    color: rgba(255, 255, 255, 0.78);
    padding-inline-start: 1.85rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: var(--text-sm);
  }

  .nav-dropdown a:hover,
  .nav-dropdown a:active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
  }

  /* Parent link reads as a section header (already-expanded section). */
  .nav-item.has-dropdown > a {
    font-weight: 600;
    color: #ffffff;
    margin-top: 0.35rem;
  }
  /* The chevron implies "tap to expand" but on mobile sections are already
     expanded — hide it to avoid confusion. */
  .nav-item.has-dropdown > a::after { display: none; }

  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }

  .article-pager { grid-template-columns: 1fr; }
  .pager-next { justify-content: flex-start; text-align: start; }

  .footer-grid { grid-template-columns: 1fr; gap: var(--space-xl); }
  .category-grid { grid-template-columns: 1fr; }
  .subcategory-grid { grid-template-columns: 1fr; }
  .related-list { grid-template-columns: 1fr; }

  .container { padding-inline: var(--space-md); }

  .hero { padding: var(--space-xl) 0; padding-bottom: calc(var(--space-xl) + 2rem); }
  .hero-title { font-size: var(--text-2xl); }

  /* Mobile Search - full-width with larger touch targets */
  .search-box { max-width: none; }
  .search-input { min-height: 44px; }
  .search-results {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    max-height: 60vh;
    border-radius: 0;
    z-index: 1300;
  }

  .top-bar-inner { flex-wrap: wrap; gap: var(--space-sm); padding: var(--space-sm) 0; }

  /* Mobile touch targets (44px minimum) */
  nav.breadcrumbs a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .footer-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .sidebar-toc li a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

@media (max-width: 480px) {
  .top-bar-inner { flex-direction: column; align-items: stretch; }
  .lang-switcher { align-self: flex-end; }
}

/* ==========================================================================
   23. Accessibility
   ========================================================================== */

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  background: var(--color-primary);
  color: #ffffff;
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  z-index: 10000;
  font-size: var(--text-sm);
  font-weight: 600;
}

.skip-link:focus { top: 0; color: #ffffff; text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
::selection { background-color: rgba(44, 74, 138, 0.2); color: var(--color-text); }

/* ==========================================================================
   24. Theme toggle button (in header)
   ========================================================================== */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.32); }
.theme-toggle .theme-sun { display: none; }
.theme-toggle .theme-moon { display: inline-flex; }
[data-theme="dark"] .theme-toggle .theme-sun { display: inline-flex; }
[data-theme="dark"] .theme-toggle .theme-moon { display: none; }

/* ==========================================================================
   25. Table scroll wrapper (mobile)
   ========================================================================== */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--space-md) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-subtle);
}
.table-scroll table { margin: 0; min-width: 100%; }
.table-scroll table thead th { white-space: nowrap; }

/* ==========================================================================
   26. Mobile article TOC drawer (uses native <details>)
   ========================================================================== */
.article-toc-mobile {
  display: none;
  margin: 0 0 var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-alt);
  overflow: hidden;
}
.article-toc-mobile > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1rem;
  font-weight: 600;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 44px;
}
.article-toc-mobile > summary::-webkit-details-marker { display: none; }
.article-toc-mobile > summary::after {
  content: "▾";
  font-size: 0.8em;
  opacity: 0.7;
  transition: transform var(--transition-fast);
}
.article-toc-mobile[open] > summary::after { transform: rotate(180deg); }
.article-toc-mobile .article-toc-list {
  margin: 0;
  padding: 0 1rem 0.85rem;
  list-style: none;
  counter-reset: toc;
}
.article-toc-mobile .article-toc-list li {
  counter-increment: toc;
  padding: 0.45rem 0;
  border-top: 1px solid var(--color-border-subtle);
}
.article-toc-mobile .article-toc-list li:first-child { border-top: 0; }
.article-toc-mobile .article-toc-list a {
  display: block;
  font-size: var(--text-sm);
}
.article-toc-mobile .article-toc-list a::before {
  content: counter(toc) ". ";
  color: var(--color-text-muted);
}

@media (max-width: 1024px) {
  .article-toc-mobile { display: block; }
  .article-sidebar .sidebar-sticky { display: none; }
}

/* Anchor-link on hover for article h2/h3 */
.article-content h2, .article-content h3 { scroll-margin-top: 92px; }
.article-content h2:hover .anchor-link,
.article-content h3:hover .anchor-link { opacity: 1; }

/* ==========================================================================
   27. Footer redesign
   ========================================================================== */
.site-footer {
  background: linear-gradient(180deg, var(--color-footer-bg) 0%, #060b1f 100%);
  color: rgba(255, 255, 255, 0.78);
  margin-top: var(--space-2xl);
}
.site-footer .container { padding-block: var(--space-2xl) var(--space-xl); }
.footer-top {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--space-2xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.footer-brand { max-width: 360px; }
.footer-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #ffffff;
  text-decoration: none;
  margin-bottom: 0.75rem;
}
.footer-logo:hover { color: #ffffff; opacity: 0.85; text-decoration: none; }
.footer-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--color-accent-warm) 0%, #b07f23 100%);
  color: #1a1410;
}
.footer-logo-text {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
}
[dir="rtl"] .footer-logo-text { letter-spacing: 0; }

.footer-description {
  font-size: var(--text-sm);
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.62);
  margin: 0 0 1rem;
}
.footer-stamp {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent-warm);
  background: rgba(200, 155, 60, 0.1);
  border: 1px solid rgba(200, 155, 60, 0.35);
  border-radius: 999px;
}
.footer-heading {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  margin: 0 0 1rem;
}
.footer-links { list-style: none; padding: 0; margin: 0; }
.footer-links li { margin-bottom: 0.55rem; }
.footer-links a {
  color: rgba(255, 255, 255, 0.78);
  font-size: var(--text-sm);
  transition: color var(--transition-fast);
}
.footer-links a:hover { color: #ffffff; text-decoration: none; }

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: var(--space-md);
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.45);
}
.footer-bottom .copyright { margin: 0; font-weight: 500; color: rgba(255, 255, 255, 0.6); }
.footer-bottom .disclaimer { margin: 0; max-width: 60%; line-height: 1.6; }

@media (max-width: 900px) {
  .footer-top { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; max-width: none; }
}
@media (max-width: 520px) {
  .footer-top { grid-template-columns: 1fr; gap: var(--space-xl); }
  .footer-bottom { flex-direction: column; align-items: flex-start; }
  .footer-bottom .disclaimer { max-width: none; }
}

/* ==========================================================================
   28. Dark mode (data-theme="dark")
   ========================================================================== */
[data-theme="dark"] {
  --color-bg: #0e1322;
  --color-bg-alt: #141a2c;
  --color-bg-soft: #1c2438;
  --color-surface: #141a2c;
  --color-surface-elevated: #1c2438;
  --color-text: #e7ebf3;
  --color-text-light: #b3bbcc;
  --color-text-muted: #8b94a9;
  --color-border: #232c45;
  --color-border-subtle: #1c2438;
  --color-border-strong: #2e3a58;
  --color-primary: #e7ebf3;
  --color-link: #91b3f3;
  --color-link-hover: #c5d6f8;
  --color-info-bg: rgba(29, 78, 216, 0.18);
  --color-info-border: rgba(147, 197, 253, 0.35);
  --color-tip-bg: rgba(4, 120, 87, 0.18);
  --color-tip-border: rgba(110, 231, 183, 0.35);
  --color-warning-bg: rgba(180, 83, 9, 0.18);
  --color-warning-border: rgba(252, 211, 77, 0.35);
  --color-danger-bg: rgba(185, 28, 28, 0.18);
  --color-danger-border: rgba(252, 165, 165, 0.35);
  --color-example-bg: rgba(67, 56, 202, 0.18);
  --color-example-border: rgba(129, 140, 248, 0.35);
  --gradient-card-accent: linear-gradient(135deg, #1f2c54, #2c4a8a);
  color-scheme: dark;
}
[data-theme="dark"] body { background-color: var(--color-bg); color: var(--color-text); }
[data-theme="dark"] .category-card {
  background: var(--color-surface);
  border-color: var(--color-border);
}
[data-theme="dark"] .category-card:hover { border-color: var(--color-border-strong); }
[data-theme="dark"] strong, [data-theme="dark"] b { color: #ffffff; }
[data-theme="dark"] .article-content blockquote { background: var(--color-bg-alt); }
[data-theme="dark"] .article-content table th { background: var(--color-bg-soft); }
[data-theme="dark"] .article-content table td { border-color: var(--color-border); }
[data-theme="dark"] nav.breadcrumbs { background: var(--color-bg-alt); border-color: var(--color-border); }
[data-theme="dark"] nav.breadcrumbs a,
[data-theme="dark"] nav.breadcrumbs ol { color: var(--color-text-light); }
[data-theme="dark"] .article-toc-mobile { background: var(--color-bg-alt); border-color: var(--color-border); }
[data-theme="dark"] .sidebar-sticky { background: var(--color-bg-alt); border-color: var(--color-border); }
[data-theme="dark"] .related-articles { background: var(--color-bg-alt); border-color: var(--color-border); }
[data-theme="dark"] .article-pager > a { background: var(--color-bg-alt); border-color: var(--color-border); }
