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

:root {
  --color-bg:           #FDFBF7;
  --color-bg-elevated:  #FFFFFF;
  --color-text:         #2D2D2D;
  --color-text-muted:   #6B6B6B;
  --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;
}

/* ── Site header / nav: muted vs. article body ── */
.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: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--color-logo);
  order: 1;
}
.site-logo-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.site-logo-wordmark {
  font-family: 'Poppins', 'Tajawal', sans-serif;
  letter-spacing: 0.5px;
}
.site-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  order: 2;
}
.site-nav {
  display: flex;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
  flex-basis: 100%;
  order: 3;
}
.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: 1.5rem 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;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 48px;
  height: 48px;
  background: transparent;
  border: none;
  padding: 0;
}
.mobile-menu-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-text);
  margin-inline: auto;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.mobile-menu-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mobile-menu-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.mobile-menu-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.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 — this is what actually anchors it on the right */
    inset-inline-end: auto;
    width: 78%;
    max-width: 300px;
    flex-direction: column;
    align-items: stretch;
    background: var(--color-bg-elevated);
    padding: 5rem 1.5rem 2rem;
    gap: 0;
    transform: translateX(100%); /* off-screen to the right side, matches RTL */
    transition: transform 0.25s ease;
    z-index: 50;
    overflow-y: auto;
    font-size: 1rem;
  }
  .site-nav.nav-open { transform: translateX(0); }
  .site-nav a {
    min-height: 48px;
    display: flex;
    align-items: center;
    margin-block-end: 1rem;
  }
  .site-nav-mobile-actions {
    display: flex;
    flex-direction: column;
    margin-block-start: 1rem;
    padding-block-start: 1rem;
    border-block-start: 1px solid var(--color-border);
  }
  .site-nav-mobile-actions a,
  .site-nav-mobile-actions button {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-block-end: 1rem;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--color-text);
    text-align: start;
  }

  /* ── 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; }
}

.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; }

/* ── Shared content components ── */
.home-hero { text-align: center; padding-block: 2rem; }
.home-logo { width: 180px; height: auto; margin-inline: auto; margin-block-end: 1rem; }
.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: 1rem;
  margin-block: 1.5rem;
}
.pillar-card {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
}
.pillar-card span { color: var(--color-text-muted); font-size: 0.9rem; }

.section-title { margin-block: 1.5rem 1rem; }

.post-list { display: flex; flex-direction: column; gap: 1rem; }
.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) ── */
.login-form { max-width: 420px; margin-inline: auto; padding-block: 2rem; }
.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.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);
}
.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; }
