/*
  Design tokens transcribed from the Stitch output
  (stitch_steps_2026_health_portal/institutional_health/DESIGN.md).
  Every hand-built page should pull colors/type/spacing from here rather
  than hardcoding values, so the 13 pages stay visually consistent.
*/

:root {
  /* Color */
  --color-surface: #f8fafa;
  --color-surface-dim: #d8dada;
  --color-surface-bright: #f8fafa;
  --color-surface-container-lowest: #ffffff;
  --color-surface-container-low: #f2f4f4;
  --color-surface-container: #eceeee;
  --color-surface-container-high: #e6e8e9;
  --color-surface-container-highest: #e1e3e3;
  --color-on-surface: #191c1d;
  --color-on-surface-variant: #3f4945;
  --color-inverse-surface: #2e3131;
  --color-inverse-on-surface: #eff1f1;
  --color-outline: #6f7975;
  --color-outline-variant: #bec9c4;

  --color-primary: #005446;
  --color-on-primary: #ffffff;
  --color-primary-container: #0f6e5d;
  --color-on-primary-container: #9bedd7;

  --color-secondary: #795900;
  --color-on-secondary: #ffffff;
  --color-secondary-container: #ffbf00;
  --color-on-secondary-container: #6d5000;

  --color-tertiary: #3a4b5d;
  --color-on-tertiary: #ffffff;
  --color-tertiary-container: #526376;
  --color-on-tertiary-container: #cddff6;

  --color-error: #ba1a1a;
  --color-on-error: #ffffff;
  --color-error-container: #ffdad6;
  --color-on-error-container: #93000a;

  --color-background: #f8fafa;
  --color-on-background: #191c1d;

  /* Type — Vazirmatn, per the RTL/Persian spec in DESIGN.md */
  --font-family: "Vazirmatn", sans-serif;

  --font-headline-lg-size: 32px;   --font-headline-lg-line: 48px;   --font-headline-lg-weight: 700;
  --font-headline-md-size: 24px;   --font-headline-md-line: 36px;   --font-headline-md-weight: 700;
  --font-headline-sm-size: 20px;   --font-headline-sm-line: 30px;   --font-headline-sm-weight: 600;
  --font-body-lg-size: 18px;       --font-body-lg-line: 32px;       --font-body-lg-weight: 400;
  --font-body-md-size: 16px;       --font-body-md-line: 28px;       --font-body-md-weight: 400;
  --font-label-lg-size: 14px;      --font-label-lg-line: 20px;      --font-label-lg-weight: 600;
  --font-label-sm-size: 12px;      --font-label-sm-line: 18px;      --font-label-sm-weight: 500;
  --font-headline-lg-mobile-size: 26px; --font-headline-lg-mobile-line: 40px;

  /* Shape */
  --radius-sm: 0.125rem;
  --radius-default: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-full: 9999px;

  /* Spacing (8px base scale) */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  --space-8: 64px;
  --gutter: 24px;
  --margin-mobile: 16px;
  --margin-desktop: 64px;
  --max-width: 1280px;

  /* Elevation (per DESIGN.md — tonal layers, not heavy shadows) */
  --elevation-1-border: 1px solid #cfd8dc;
  --elevation-2-shadow: 0px 4px 12px rgba(26, 43, 60, 0.05);
}

* { box-sizing: border-box; }

html {
  direction: rtl;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  background: var(--color-background);
  color: var(--color-on-background);
  text-align: right;
}

/* Sticky footer: on short pages (few gallery items, empty states, etc.)
   this pushes #site-footer to the bottom of the viewport instead of
   leaving the body's own background exposed below it — no page-specific
   markup changes needed, works for every page that includes the footer. */
#site-footer {
  margin-top: auto;
}

.container {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--margin-desktop);
}

@media (max-width: 768px) {
  .container {
    padding-inline: var(--margin-mobile);
  }
}

h1, h2, h3 { font-weight: 700; margin: 0; }

h1 { font-size: var(--font-headline-lg-size); line-height: var(--font-headline-lg-line); }
h2 { font-size: var(--font-headline-md-size); line-height: var(--font-headline-md-line); }
h3 { font-size: var(--font-headline-sm-size); line-height: var(--font-headline-sm-line); font-weight: 600; }

@media (max-width: 768px) {
  h1 { font-size: var(--font-headline-lg-mobile-size); line-height: var(--font-headline-lg-mobile-line); }
}

p, li {
  font-size: var(--font-body-md-size);
  line-height: var(--font-body-md-line);
  text-align: justify;
  text-align-last: right; /* the final (usually short) line stays right-aligned instead of stretching */
}

/* Per-element direction override for mixed-language content (e.g. English
   publication abstracts/body inside an otherwise RTL page) — see detectDir()
   in layout.js. Uses :dir() rather than [dir="ltr"] because content like the
   publication body is a block of wpautop-generated <p> tags nested under one
   ancestor carrying dir="ltr" — [dir="ltr"] only matches that ancestor, not
   the inherited-direction paragraphs inside it, which the `p, li` rule above
   would otherwise still right-justify. :dir() tracks resolved (inherited)
   direction, so it correctly matches those descendants too. */
:dir(ltr) {
  text-align: left;
  text-align-last: left;
}

/* WordPress/Gutenberg content utility classes -- the block editor writes
   these classes directly into post_content (font size + alignment controls
   in the toolbar), but a headless frontend never loads wp-block-library's
   CSS, so without these rules the classes are present in the HTML and do
   nothing: an admin's "make this smaller" edit silently has zero effect. */
.has-small-font-size { font-size: 13px; }
.has-normal-font-size, .has-regular-font-size { font-size: 16px; }
.has-medium-font-size { font-size: 20px; }
.has-large-font-size { font-size: 36px; }
.has-huge-font-size, .has-x-large-font-size { font-size: 42px; }
.has-text-align-left { text-align: left; }
.has-text-align-right { text-align: right; }
.has-text-align-center { text-align: center; }

/* Admin-configurable publication title size (ACF `title_size` field). */
.pub-title-small { font-size: 18px !important; }
.pub-title-normal { font-size: var(--font-headline-sm-size) !important; }
.pub-title-large { font-size: var(--font-headline-md-size) !important; }
.pub-title-x-large { font-size: var(--font-headline-lg-size) !important; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-default);
  padding: 12px 20px;
  font-size: var(--font-label-lg-size);
  font-weight: var(--font-label-lg-weight);
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--color-primary-container); color: var(--color-on-primary); }
.btn-outline { background: transparent; color: var(--color-primary); border: 1px solid var(--color-primary); }
.btn-cta     { background: var(--color-secondary-container); color: var(--color-on-secondary-container); }

.card {
  background: var(--color-surface-container-lowest);
  border: var(--elevation-1-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}

.chip {
  display: inline-block;
  border-radius: var(--radius-full);
  padding: 2px 10px;
  font-size: var(--font-label-sm-size);
  font-weight: var(--font-label-sm-weight);
}

/* ---------------------------------------------------------------------
 * Shared header (assets/js/layout.js renders these classes)
 * ------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-surface-container-lowest);
  border-bottom: 1px solid var(--color-outline-variant);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 14px;
}

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-primary-container);
  font-weight: 700;
  font-size: 20px;
  flex-shrink: 0;
}

.site-logo-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-on-surface);
  border-radius: var(--radius-full);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 900px) {
  .nav-toggle { display: flex; }

  .site-header-inner { flex-wrap: wrap; }

  .site-nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 3;
    gap: 0;
    border-top: 1px solid var(--color-outline-variant);
    margin-top: 14px;
    padding-top: 8px;
  }

  .site-nav.open { display: flex; }

  .nav-link { padding: 12px 8px; }
  .nav-link::after { display: none; }
  .nav-link.active { background: var(--color-surface-container-low); border-radius: var(--radius-default); }

  .site-logo span { font-size: 16px; }
  .nav-user { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
}

@media (max-width: 420px) {
  .nav-user { display: none; } /* keep just the خروج button when space is very tight */
}

/* Font-weight never changes between default/active/hover states — only
   color and the underline do. That's what keeps the nav a single
   fixed-width row instead of reflowing (and wrapping) when a link becomes
   "active". */
.nav-link {
  position: relative;
  text-decoration: none;
  color: var(--color-on-surface);
  font-size: var(--font-label-lg-size);
  font-weight: 600;
  white-space: nowrap;
  padding: 6px 12px;
  transition: color 0.15s ease;
}

.nav-link::after {
  content: "";
  position: absolute;
  right: 12px;
  left: 12px;
  bottom: -2px;
  height: 2px;
  background: var(--color-primary-container);
  border-radius: var(--radius-full);
  transform: scaleX(0);
  transition: transform 0.2s ease;
}

.nav-link:hover { color: var(--color-primary-container); }
.nav-link:hover::after { transform: scaleX(0.6); }

.nav-link.active { color: var(--color-primary-container); }
.nav-link.active::after { transform: scaleX(1); }

.nav-user {
  font-size: var(--font-label-lg-size);
  margin-inline-end: 12px;
}

.site-header-auth { display: flex; align-items: center; flex-shrink: 0; }

/* ---------------------------------------------------------------------
 * Shared footer
 * ------------------------------------------------------------------- */

.site-footer {
  background: var(--color-inverse-surface);
  color: var(--color-inverse-on-surface);
  margin-top: 64px;
}

.site-footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  padding-block: 48px;
}

.site-footer-grid h3 { color: var(--color-secondary-container); }
.site-footer-grid h3.footer-brand { color: inherit; }
.site-footer-grid a { color: inherit; transition: color 0.15s ease; }
.site-footer-grid a:hover { color: var(--color-secondary-container); }

.site-footer-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  text-align: center;
  padding: 16px;
  font-size: var(--font-label-sm-size);
}

@media (max-width: 768px) {
  .site-footer-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .site-footer-grid { grid-template-columns: 1fr; gap: 32px; }
}

/* ---------------------------------------------------------------------
 * Motion — subtle, institutional. Respects reduced-motion preference.
 * ------------------------------------------------------------------- */

html { scroll-behavior: smooth; }

body { animation: page-fade-in 0.35s ease; }

@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: content-fade-in 0.25s ease; }

@keyframes content-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn {
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--elevation-2-shadow); filter: brightness(1.04); }
.btn:active { transform: translateY(0); }

/* Clickable cards (news rows, publication/team cards, gallery tiles, etc.)
   lift on hover; plain info cards (profile, document metadata) don't need
   the affordance since they aren't clickable. */
a.card:hover,
.team-card:hover,
.pub-card:hover,
.news-row:hover,
.video-card:hover,
.image-grid figure:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px rgba(26, 43, 60, 0.08);
}

a.card, .team-card, .pub-card, .news-row, .video-card, .image-grid figure {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.image-grid figure img { transition: transform 0.3s ease; }
.image-grid figure:hover img { transform: scale(1.04); }

.doc-table tbody tr { transition: background-color 0.15s ease; }
.doc-table tbody tr:hover { background-color: var(--color-surface-container-low); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  body, .fade-in, .btn, a.card, .team-card, .pub-card, .news-row, .video-card, .image-grid figure, .image-grid figure img {
    animation: none !important;
    transition: none !important;
  }
}
