/* ============================================================
   AUDHDSPACE — Base styles: resets, tokens, RTL & accessibility
   ============================================================ */

:root {
  --color-bg:           #FDFBF7;
  --color-bg-elevated:  #FFFFFF;
  --color-text:         #2D2D2D;
  --color-text-muted:   #585858;
  --color-border:       #E3DFD6;
  --color-accent:       #2D6E63;
  --color-accent-hover: #1F4F46;
  --color-focus-ring:   #C0392B;
  --color-sidebar-bg:   #F4F1EA;
  --color-sidebar-text: #8A8578;

  --font-arabic: 'Tajawal', 'Noto Kufi Arabic', sans-serif;
  --line-height-body: 1.75;
  --max-prose-width: 70ch;
  --space-paragraph: 2.25em;
}

[data-theme="dark"] {
  --color-bg:           #1B1B1B;
  --color-bg-elevated:  #242424;
  --color-text:         #EAE6DD;
  --color-text-muted:   #A8A39A;
  --color-border:       #3A3A3A;
  --color-accent:       #6FB98C;
  --color-accent-hover: #8DCBA4;
  --color-focus-ring:   #FF6B5B;
  --color-sidebar-bg:   #161616;
  --color-sidebar-text: #79756C;
  --color-logo:         #6FB98C;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
img { max-width: 100%; height: auto; display: block; }

/* ── RTL + base typography ──────────────────────────────────
   No letter-spacing anywhere on Arabic text — breaks cursive joins.
   No text-align: justify — causes kashida stretching. Use start only. */
html, body {
  direction: rtl;
  overflow-x: hidden; /* kill the classic RTL horizontal-scroll bug */
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-arabic);
  line-height: var(--line-height-body);
  text-align: start;
  text-rendering: optimizeLegibility;
  font-feature-settings: "liga" 1, "rlig" 1;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

p {
  margin-block-end: var(--space-paragraph);
  word-spacing: 0.15em;
  text-align: start;
  letter-spacing: normal;
}

h1, h2, h3, h4 {
  line-height: 1.4;
  margin-block-end: 0.75em;
  text-align: start;
}

ul, ol { padding-inline-start: 1.5em; }

/* ── Focus & hover states — highly visible for ADHD tracking ── */
a, button, input, select, textarea, [tabindex] {
  transition: outline-color 0.15s ease, background-color 0.15s ease;
  font-family: inherit;
}
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}
a { color: var(--color-text); text-decoration: none; }
a:hover, button:hover {
  background-color: color-mix(in srgb, var(--color-accent) 12%, transparent);
}

button {
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-radius: 6px;
  padding: 0.5em 1em;
}

/* ── Google Material Icons: consistent icon glyphs instead of emoji ── */
.material-icons {
  font-size: 22px;
  line-height: 1;
  vertical-align: middle;
  color: inherit;
}

/* ── Site header / nav: muted vs. article body ──
   3-column grid (start / center / end) so the logo is always perfectly
   centered regardless of how much content sits in the side columns. */
.site-header {
  background: var(--color-sidebar-bg);
  border-block-end: 1px solid var(--color-border);
}
.site-header-inner {
  max-width: 1100px;
  margin-inline: auto;
  padding: 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.85rem 1.5rem;
}
.site-header-start { grid-column: 1; justify-self: start; }
.site-header-end   { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 0.5rem; }

.site-logo {
  grid-column: 2;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  color: var(--color-logo);
}
.site-logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.site-logo-wordmark {
  font-family: 'Poppins', 'Tajawal', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
}

.site-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.site-nav {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
}
.site-nav a { color: var(--color-sidebar-text); }
.site-nav a:hover { color: var(--color-text); }

.site-main { flex: 1; max-width: 1100px; margin-inline: auto; padding: 2rem 1.25rem; width: 100%; }

/* ── Mobile menu button + off-canvas drawer (right-side, RTL-correct) ──
   Hidden on desktop; becomes the nav trigger at the 768px breakpoint. */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: transparent;
  border: none;
  padding: 0;
}

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 40;
}
.nav-overlay.active { opacity: 1; pointer-events: auto; }

.site-nav-mobile-actions { display: none; }

/* ── Smart auto-hiding header (mobile only) ── */
@media (max-width: 768px) {
  .site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 45; /* above .nav-overlay (40) so the header/hamburger never gets dimmed */
    transition: transform 0.25s ease;
  }
  .site-header.header-hidden { transform: translateY(-100%); }

  .mobile-menu-btn { display: flex; }

  .site-header-actions { display: none; } /* desktop login/logout/theme group moves into drawer */

  .nav-overlay { display: block; } /* base rule has display:none for desktop; show it as a tap-to-close backdrop on mobile */

  .site-nav {
    display: flex;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;   /* inline-start = right edge in RTL */
    inset-inline-end: auto;
    width: 78%;
    max-width: 300px;
    flex-direction: column;
    flex-wrap: nowrap;        /* prevent items overflowing into a second column */
    align-items: stretch;
    background: var(--color-bg-elevated);
    padding: 4.5rem 1.5rem 2rem;
    gap: 0;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 50;
    overflow-y: auto;         /* scroll if content is taller than viewport */
    font-size: 1rem;
  }
  .site-nav.nav-open { transform: translateX(0); }
  .site-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    margin-block-end: 0.75rem;
    color: var(--color-text);
  }
  .site-nav-mobile-actions {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    margin-block-start: 0.75rem;
    padding-block-start: 0.75rem;
    border-block-start: 1px solid var(--color-border);
  }
  .site-nav-mobile-actions a,
  .site-nav-mobile-actions button {
    min-height: 44px;
    display: flex;
    align-items: center;
    margin-block-end: 0.75rem;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--color-text);
    width: 100%;
  }

  /* ── AuDHD-friendly touch targets: every UI control gets a real 48px hit area.
     Note: min-height has no effect on default-inline <a> — that's why every nav
     link, card, and button above is explicitly display:flex/block, not relying
     on this rule alone for inline prose links inside article text. ── */
  button { min-height: 48px; min-width: 48px; }
  .pillar-nav, .post-list { gap: 1rem; }
  .pillar-card, .post-list-item, .dashboard-card { margin-block-end: 0.25rem; min-height: 48px; }

  /* ── Fluid-but-controlled Arabic typography: legible body text, room for tashkeel ── */
  body, .post-body, .post-tldr {
    font-size: 1.125rem;
    line-height: 1.7;
  }

  /* ── Sidebars/widgets (if added later) always stack below main content on mobile ── */
  .site-main { display: flex; flex-direction: column; }
  .sidebar { order: 99; }

  /* ── The header already shows the logo on mobile — don't repeat it in the homepage hero ── */
  .home-logo { display: none; }

  /* ── Auth pages: full-bleed card, brand header visible ── */
  .auth-brand { display: flex; }
  .login-form {
    margin-block: 0;
    border-radius: 0;
    border-inline: none;
    border-block-start: none;
    box-shadow: none;
    padding-inline: 1.5rem;
    padding-block: 1.75rem 2.5rem;
    min-height: calc(100dvh - 60px);
  }
  .login-form h1 { font-size: 1.25rem; }
}

.site-footer {
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  border-block-start: 1px solid var(--color-border);
  font-size: 0.85rem;
}
.site-footer-inner { max-width: 1100px; margin-inline: auto; padding: 1.5rem 1.25rem; }
.home-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-block-start: 0.25rem;
}
.tiktok-btn, .alfa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6em 1.25em;
  font-weight: 600;
  border-radius: 6px;
  min-height: 48px;
}
.tiktok-btn {
  background: var(--color-accent);
  color: #fff;
}
.tiktok-btn:hover { background: var(--color-accent-hover); }
.alfa-btn {
  background: transparent;
  color: var(--color-accent);
  border: 2px solid var(--color-accent);
}
.alfa-btn:hover { background: var(--color-accent); color: #fff; }

/* ── Shared content components ── */
.home-hero {
  text-align: center;
  padding-block: 2.5rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.home-logo { width: 180px; height: auto; }
.home-tagline { color: var(--color-text-muted); }

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

.pillar-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-block: 2.5rem;
}
.pillar-card {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.5rem;
}
.pillar-card span { color: var(--color-text-muted); font-size: 0.9rem; }

.section-title { margin-block: 2.5rem 1.25rem; }

.post-list { display: flex; flex-direction: column; gap: 1.25rem; }
.post-list-item {
  display: block;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
}
.post-list-item h3 { margin-block: 0.4em 0.2em; }
.post-list-item p { color: var(--color-text-muted); margin-block-end: 0.4em; }
.post-list-item time { color: var(--color-text-muted); font-size: 0.8rem; }
.post-pillar-tag {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  padding: 0.15em 0.6em;
  border-radius: 4px;
}

.empty-state { color: var(--color-text-muted); padding: 2rem 0; }

.glossary-header { margin-block-end: 1.5rem; }
.glossary-header p { color: var(--color-text-muted); }
.glossary-list { display: flex; flex-direction: column; gap: 1.25rem; }
.glossary-item dt { font-weight: 700; font-size: 1.05rem; }
.glossary-item .term-en { color: var(--color-text-muted); font-weight: 400; font-size: 0.85rem; }
.glossary-item dd { color: var(--color-text); margin-block-start: 0.3em; }

.pillar-header { margin-block-end: 1.5rem; }
.pillar-header p { color: var(--color-text-muted); }

/* ── Shared form styling (login + simple admin forms) ── */
.auth-brand {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-block-end: 1.75rem;
}
.auth-brand img { width: 64px; height: 64px; }
.auth-brand-name {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--color-accent);
  letter-spacing: -0.01em;
}

.login-form {
  max-width: 440px;
  margin-inline: auto;
  margin-block: 2.5rem;
  padding: 2.5rem 2.25rem 2rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
}
.login-form h1 {
  font-size: 1.4rem;
  margin-block-end: 1.5rem;
  text-align: center;
}

.form-basic label { display: block; font-weight: 600; margin-block-end: 0.4em; }
.form-basic input[type="text"],
.form-basic input[type="email"],
.form-basic input[type="password"],
.form-basic textarea,
.form-basic select {
  width: 100%;
  padding: 0.7em 1em;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-elevated);
  color: var(--color-text);
  margin-block-end: 1.25em;
  font-family: var(--font-arabic);
  font-size: 1rem;
  min-height: 52px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-basic input:focus,
.form-basic textarea:focus,
.form-basic select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 20%, transparent);
}
.form-basic button[type="submit"] {
  width: 100%;
  font-size: 1.05rem;
  min-height: 52px;
  border-radius: 10px;
  margin-block-start: 0.25rem;
}
.message-box {
  padding: 0.75em 1em;
  border-radius: 6px;
  margin-block-end: 1.25em;
  font-size: 0.9rem;
}
.message-error { background: #F8D7DA; color: #721C24; border: 1px solid #F5C6CB; }
.message-success { background: #D4EDDA; color: #155724; border: 1px solid #C3E6CB; }

.form-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.editor-form label {
  display: block;
  font-weight: 600;
  margin-block-end: 0.4em;
}
.editor-form input[type="text"],
.editor-form input[type="email"],
.editor-form input[type="password"],
.editor-form textarea,
.editor-form select {
  width: 100%;
  padding: 0.6em 0.8em;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-elevated);
  color: var(--color-text);
  margin-block-end: 1.25em;
  font-family: var(--font-arabic);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 0.5em;
  font-weight: 400 !important;
  margin-block-end: 1.25em;
}
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }
.login-form-links { text-align: center; margin-block-start: 1rem; font-size: 0.9rem; color: var(--color-text-muted); }

/* ── Skip-to-content link (keyboard / screen reader) ── */
.skip-link {
  position: absolute;
  inset-block-start: -100%;
  inset-inline-start: 0;
  background: var(--color-accent);
  color: #fff;
  padding: 0.75rem 1.25rem;
  font-weight: 700;
  z-index: 999;
  border-radius: 0 0 8px 0;
  text-decoration: none;
}
.skip-link:focus { inset-block-start: 0; }

/* ── Reduced motion — stops all transitions/animations for users who prefer it ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Terms Modal ── */
dialog.terms-dialog:not([open]) { display: none; }
dialog.terms-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 86vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 8px 40px rgba(0,0,0,.28);
}
dialog.terms-dialog::backdrop {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}
.terms-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-block-end: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-bg-elevated);
  z-index: 1;
}
.terms-dialog-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.terms-dialog-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.terms-dialog-close:hover { background: var(--color-border); color: var(--color-text); }
.terms-dialog-body {
  overflow-y: auto;
  padding: 1.5rem;
  flex: 1;
}
.terms-dialog-body .post-page { padding: 0; }
.terms-dialog-body .post-title { font-size: 1.3rem; }
[data-theme="dark"] dialog.terms-dialog {
  box-shadow: 0 8px 40px rgba(0,0,0,.55);
}

@media (max-width: 768px) {
  dialog.terms-dialog {
    position: fixed;
    inset: auto 0 0 0;   /* pin to bottom edge */
    width: 100%;
    max-width: 100%;
    height: 92dvh;
    max-height: 92dvh;
    margin: 0;
    border-radius: 20px 20px 0 0;
  }
  .terms-dialog-body { padding: 1.25rem 1rem; }
}
