/* ==========================================================================
   Dexamed Radiology Gallery — dark glassmorphism, RTL/logical, zero runtime deps
   Font: Vazirmatn variable (self-hosted, fonts/Vazirmatn-var.woff2 · 108.5 KB)
   ========================================================================== */

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-var.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

/* ==========================================================================
   Design Tokens (3-layer: Primitive -> Semantic -> Component)
   Direction-agnostic via CSS logical properties throughout.
   ========================================================================== */
:root {
  /* Primitive Palette */
  --bg: #070d12;
  --bg-2: #0a1520;
  --bg-card: rgba(10, 21, 32, 0.72);
  --ink: #e8f1f5;
  --ink-dim: #93a7b4;
  --ink-faint: #64798a;
  --teal: #3fbfad;
  --teal-deep: #0e7c7b;
  --violet: #7c8cf8;
  --amber: #f0b64a;
  --rose: #f2748c;

  /* Glass & Edges */
  --glass: rgba(255, 255, 255, .045);
  --glass-2: rgba(255, 255, 255, .075);
  --glass-drawer: rgba(7, 13, 18, .92);
  --edge: rgba(255, 255, 255, .10);
  --edge-subtle: rgba(255, 255, 255, .06);
  --edge-lit: rgba(63, 191, 173, .45);

  /* Radii */
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 9px;
  --r-full: 999px;

  /* Shadows */
  --shadow: 0 18px 48px -22px rgba(0, 0, 0, .85);
  --shadow-lg: 0 24px 64px -18px rgba(0, 0, 0, .92);
  --shadow-card: 0 12px 32px -16px rgba(0, 0, 0, .75);

  /* Typography Stacks (Phase 2 seam: swap --font-sans for Inter/Geist on LTR) */
  --sys-fa: "Vazirmatn", "IRANSans", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  --font-sans: var(--sys-fa);
  --font-mono: var(--mono);

  /* Semantic Badge Colors (Audited for WCAG AA: text contrast >= 8:1) */
  --badge-normal-bg: rgba(63, 191, 173, .14);
  --badge-normal-border: rgba(63, 191, 173, .38);
  --badge-normal-ink: #9fe8dc;        /* 14.0:1 over --bg, 13.2:1 over --bg-2 */

  --badge-pathology-bg: rgba(240, 182, 74, .14);
  --badge-pathology-border: rgba(240, 182, 74, .42);
  --badge-pathology-ink: #f0b64a;     /* 10.7:1 over --bg, 10.1:1 over --bg-2 */

  /* Motion Curves & Timing (apply-easing-and-timing + cinematic-motion) */
  --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);    /* Power3.out */
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);         /* Expo.out */
  --dur-micro: 90ms;      /* hover, click states */
  --dur-std: 200ms;       /* open/close, focus, opacity */
  --dur-complex: 320ms;   /* drawer slide, lightbox */
  --dur-page: 450ms;      /* grid refresh */
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.75 var(--font-sans);
  font-variation-settings: "wght" 400;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.drawer-open {
  overflow: hidden;
}

/* --- ambient background ------------------------------------------------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aurora span {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .30;
  animation: drift 26s ease-in-out infinite alternate;
}
.aurora span:nth-child(1) {
  width: 46vw; height: 46vw; top: -12vw; inset-inline-end: -6vw;
  background: radial-gradient(circle, var(--teal-deep), transparent 68%);
}
.aurora span:nth-child(2) {
  width: 38vw; height: 38vw; top: 34vh; inset-inline-start: -10vw;
  background: radial-gradient(circle, #3b3f9e, transparent 68%);
  animation-delay: -9s;
}
.aurora span:nth-child(3) {
  width: 30vw; height: 30vw; bottom: -8vw; inset-inline-end: 22vw;
  background: radial-gradient(circle, #0b5f6b, transparent 70%);
  animation-delay: -16s;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-4vw, 5vh, 0) scale(1.14); }
}

/* --- glass primitive ---------------------------------------------------- */
.glass {
  background: linear-gradient(155deg, var(--glass-2), var(--glass));
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: var(--shadow);
}

/* --- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px clamp(14px, 3vw, 34px);
  background: linear-gradient(180deg, rgba(7, 13, 18, .94), rgba(7, 13, 18, .72));
  border-bottom: 1px solid var(--edge);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; }
.mark { width: 38px; height: 38px; flex: 0 0 auto; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.35; }
.brand-txt strong { font-variation-settings: "wght" 700; font-size: 15px; letter-spacing: -.2px; }
.brand-txt span { color: var(--ink-faint); font-size: 11.5px; }

.topbar-actions {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
}

/* --- icon button primitive --------------------------------------------- */
.iconbtn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  color: var(--ink);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out),
              background var(--dur-std) var(--ease-out),
              border-color var(--dur-std) var(--ease-out);
}
.iconbtn svg { width: 18px; height: 18px; stroke: currentColor; }
.iconbtn:hover {
  background: rgba(255, 255, 255, .09);
  border-color: var(--edge-lit);
  transform: translateY(-1px);
}
.iconbtn:active { transform: translateY(0); }
.iconbtn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.iconbtn[aria-expanded="true"] {
  background: rgba(63, 191, 173, .16);
  border-color: var(--edge-lit);
  color: var(--teal);
}
.iconbtn-dot {
  position: absolute;
  top: 7px; inset-inline-end: 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 2px var(--bg);
}

/* --- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  color: var(--ink); font: inherit; font-size: 13px;
  font-variation-settings: "wght" 550;
  background: linear-gradient(140deg, rgba(63, 191, 173, .22), rgba(124, 140, 248, .16));
  border: 1px solid var(--edge-lit);
  border-radius: var(--r-full);
  cursor: pointer; text-decoration: none;
  transition: transform var(--dur-micro) var(--ease-out),
              box-shadow var(--dur-std) var(--ease-out),
              border-color var(--dur-std) var(--ease-out),
              background var(--dur-std) var(--ease-out);
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -10px rgba(63, 191, 173, .6);
}
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn.ghost { background: rgba(255, 255, 255, .05); border-color: var(--edge); }
.btn.ghost:hover { background: rgba(255, 255, 255, .09); border-color: var(--edge-lit); }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn-ico { width: 15px; height: 15px; flex: 0 0 auto; }

/* --- Directive 6: Compact Expandable Search Panel ---------------------- */
.search-panel {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: clamp(14px, 3vw, 34px);
  width: min(520px, calc(100vw - 28px));
  z-index: 45;
  background: var(--bg-2);
  border: 1px solid var(--edge-lit);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity var(--dur-std) var(--ease-out),
              transform var(--dur-std) var(--ease-out);
}
.search-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.search-wrap {
  position: relative;
  display: flex; align-items: center;
  width: 100%;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.search-wrap .search-icon {
  position: absolute; inset-inline-start: 12px;
  width: 17px; height: 17px;
  color: var(--ink-faint);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding-block: 10px;
  padding-inline-start: 38px;
  padding-inline-end: 70px;
  color: var(--ink); font: inherit; font-size: 13.5px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  outline: none;
  transition: border-color var(--dur-std) var(--ease-out),
              background var(--dur-std) var(--ease-out),
              box-shadow var(--dur-std) var(--ease-out);
}
.search-wrap input::placeholder { color: var(--ink-faint); }
.search-wrap input:focus-visible {
  border-color: var(--edge-lit);
  background: rgba(255, 255, 255, .08);
  box-shadow: 0 0 0 3px rgba(63, 191, 173, .14);
}
.search-wrap kbd {
  position: absolute;
  inset-inline-end: 38px;
  padding: 1px 7px;
  font: 600 11px var(--font-mono);
  color: var(--ink-faint);
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--edge);
  border-radius: 6px;
  pointer-events: none;
}
.search-close {
  position: absolute;
  inset-inline-end: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  color: var(--ink-dim);
  background: transparent;
  border: none;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
}
.search-close:hover { color: var(--ink); background: rgba(255, 255, 255, .08); }

/* --- layout ------------------------------------------------------------- */
main {
  width: min(1420px, 100%);
  margin-inline: auto;
  padding-block: 24px 80px;
  padding-inline: clamp(14px, 3vw, 34px);
  display: flex; flex-direction: column; gap: 18px;
}

/* --- hero --------------------------------------------------------------- */
.hero { padding: 22px clamp(18px, 3vw, 30px); }
.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(18px, 2.3vw, 24px);
  font-variation-settings: "wght" 750;
  letter-spacing: -.3px;
  background: linear-gradient(100deg, #fff 10%, var(--teal) 60%, var(--violet));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.hero p { margin: 0; max-width: 76ch; color: var(--ink-dim); font-size: 13.5px; line-height: 1.7; }
.hero p b { color: var(--ink); font-variation-settings: "wght" 650; }

/* --- Category Showcase Section (ECG Paradigm) --------------------------- */
.showcase-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 0;
}
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-variation-settings: "wght" 700;
  color: var(--ink);
}
.section-title-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: rgba(63, 191, 173, 0.14);
  color: var(--teal);
  border: 1px solid rgba(63, 191, 173, 0.35);
}
.section-subtitle {
  font-size: 12.5px;
  color: var(--ink-faint);
  margin-top: 3px;
}

.showcase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
@media (max-width: 768px) {
  .topbar {
    position: relative !important;
    top: auto !important;
  }
  .showcase-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.showcase-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform var(--dur-std) var(--ease-out),
              border-color var(--dur-std) var(--ease-out),
              box-shadow var(--dur-std) var(--ease-out),
              background var(--dur-std) var(--ease-out);
  user-select: none;
}
.showcase-card:hover {
  transform: translateY(-3px);
  border-color: var(--edge-lit);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 16px rgba(63, 191, 173, 0.15);
}
.showcase-card:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
.showcase-card.is-active {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px var(--teal), 0 14px 36px rgba(0, 0, 0, 0.7), 0 0 24px rgba(63, 191, 173, 0.3);
  background: rgba(14, 28, 40, 0.95);
}

.showcase-header {
  padding: 14px 16px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.showcase-title-wrap h3 {
  margin: 0;
  font-size: 15px;
  font-variation-settings: "wght" 700;
  color: #fff;
}
.showcase-en-title {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  direction: ltr;
  text-align: right;
}
.showcase-badge {
  flex: none;
  font-size: 10.5px;
  font-variation-settings: "wght" 600;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  color: var(--ink-dim);
}
.showcase-card.is-active .showcase-badge {
  background: rgba(63, 191, 173, 0.18);
  border-color: rgba(63, 191, 173, 0.45);
  color: #5eead4;
}

.showcase-visual-container {
  position: relative;
  width: 100%;
  padding: 4px 14px;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: var(--r-md);
}
.showcase-img {
  width: 100%;
  height: 200px;
  object-fit: contain !important;
  border-radius: 8px;
  display: block;
  background: #050911;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}
.showcase-card:hover .showcase-img,
.showcase-card.is-active .showcase-img {
  transform: scale(1.02);
  border-color: rgba(63, 191, 173, 0.45);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 12px rgba(63, 191, 173, 0.15);
}

.showcase-footer {
  padding: 12px 16px;
  background: rgba(4, 9, 14, 0.6);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  justify-content: space-between;
}
.showcase-subchips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.showcase-subchips .subchip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--edge-subtle);
  border-radius: var(--r-full);
  padding: 2px 8px;
  font-size: 10.5px;
  color: var(--ink-dim);
}
.showcase-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 11.5px;
  color: var(--ink-faint);
}
.showcase-card:hover .showcase-actions,
.showcase-card.is-active .showcase-actions {
  color: var(--teal);
}
.showcase-arrow {
  font-size: 13px;
  transition: transform var(--dur-micro) var(--ease-out);
}
.showcase-card:hover .showcase-arrow {
  transform: translateX(-4px);
}

/* --- Unified Horizontal Category Filter Bar Law -------------------------- */
.anatomy-filter-bar {
  display: flex;
  align-items: center;
  padding: 8px 0 4px;
  width: 100%;
}
.anatomy-filter-bar .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  width: 100%;
}
.anatomy-filter-bar .chip {
  padding: 6px 14px;
  font-size: 12.5px;
  font-variation-settings: "wght" 550;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  color: var(--ink-dim);
  cursor: pointer;
  transition: all var(--dur-micro) var(--ease-out);
}
.anatomy-filter-bar .chip:hover {
  color: var(--ink);
  border-color: var(--edge-lit);
  background: rgba(255, 255, 255, 0.08);
}
.anatomy-filter-bar .chip.active,
.anatomy-filter-bar .chip[aria-pressed="true"] {
  color: #04120f;
  background: linear-gradient(120deg, var(--teal), #74d9c9);
  border-color: transparent;
  font-variation-settings: "wght" 650;
  box-shadow: 0 0 14px rgba(63, 191, 173, 0.4);
}

/* --- Result status bar & controls --------------------------------------- */
.resultbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px;
  width: 100%;
  flex-wrap: wrap;
}
.resultbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.limit-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-dim);
}
.limit-wrap label {
  font-size: 12px;
  color: var(--ink-faint);
}
.select-sm {
  background: rgba(10, 14, 23, 0.85);
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.select-sm:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(63, 191, 173, 0.2);
}
.count { font-size: 12.5px; color: var(--ink-dim); font-family: var(--font-mono); }

/* --- Directive 7: Sliding Filter Drawer --------------------------------- */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(3, 6, 9, .70);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--dur-complex) var(--ease-out);
}
.drawer-scrim.is-open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0; bottom: 0;
  inset-inline-end: 0;
  width: min(440px, 92vw);
  z-index: 70;
  background: var(--glass-drawer);
  border-inline-start: 1px solid var(--edge-lit);
  border-radius: 0;
  display: flex; flex-direction: column;
  box-shadow: -12px 0 48px rgba(0, 0, 0, .85);
  transform: translateX(100%);
  transition: transform var(--dur-complex) var(--ease-expo);
}
/* In RTL, drawer slides from the inline-end (the left side of screen).
   CSS transform using translateX: in RTL 100% moves right or left depending
   on user-agent, but with inset-inline-end + translateX(100% * direction): */
[dir="rtl"] .drawer {
  transform: translateX(-100%);
}
[dir="rtl"] .drawer.is-open {
  transform: translateX(0);
}
[dir="ltr"] .drawer {
  transform: translateX(100%);
}
[dir="ltr"] .drawer.is-open {
  transform: translateX(0);
}

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--edge);
}
.drawer-head h2 {
  margin: 0; font-size: 16px; font-variation-settings: "wght" 700; color: var(--ink);
}
.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 20px;
}
.drawer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--edge);
  background: rgba(7, 13, 18, .6);
}
.flabel { font-size: 12px; color: var(--ink-faint); font-variation-settings: "wght" 600; }
.frow { display: flex; flex-direction: column; gap: 9px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 12px;
  color: var(--ink-dim); font: inherit; font-size: 12px;
  background: rgba(255, 255, 255, .035);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: color var(--dur-micro) var(--ease-out),
              border-color var(--dur-micro) var(--ease-out),
              background var(--dur-micro) var(--ease-out),
              transform var(--dur-micro) var(--ease-out);
}
.chip:hover {
  color: var(--ink);
  border-color: var(--edge-lit);
  transform: translateY(-1px);
}
.chip:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.chip[aria-pressed="true"] {
  color: #04120f;
  background: linear-gradient(120deg, var(--teal), #74d9c9);
  border-color: transparent;
  font-variation-settings: "wght" 650;
}

/* --- grid --------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-items: stretch;
  gap: 18px;
}

/* --- Directive 9: Redesigned Card --------------------------------------- */
/* Card fills the grid cell. Whole card body is a single link to SLP.
   Image takes 75-80% of card height; footer takes 15-20%. */
.card {
  position: relative;
  display: flex; flex-direction: column;
  height: 100%;
  background: var(--bg-card);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--dur-std) var(--ease-out),
              border-color var(--dur-std) var(--ease-out),
              box-shadow var(--dur-std) var(--ease-out);
}
.card:hover {
  border-color: var(--edge-lit);
  transform: translateY(-3px);
  box-shadow: 0 16px 36px -12px rgba(63, 191, 173, .22), var(--shadow);
}

.card-link {
  display: flex; flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.card-link:focus-visible {
  outline: 2px solid var(--teal); outline-offset: 2px;
}
.card-link.is-unlinked {
  cursor: default;
}

/* 🔴 Sized radiograph container. The 75–80% image / 15–20% footer split is
   achieved by SIZING A CONTAINER and keeping `object-fit: contain` on the
   radiograph — never by cropping.

   Why 5 / 4 (=1.25): measured over a 900-image random sample of the real
   thumbs/, aspect ratios span 0.624–1.221 with a median of 1.000. A 1.25
   container paints 78.8% of the box area on average (vs 73.9% at the old
   4:3, and 88.1% only at 1:1 which would leave the wide cards letterboxed).
   1.25 is the widest container that keeps the mean painted area high without
   discarding the apex or the costophrenic angles on the tall (320×390) films.

   Height maths at the 4-up column width the tests use (324.5px):
     media = 324.5 / 1.25 = 259.6px
     foot  = 20 (padding) + 21.4 (badge row) + 6 (gap) + 18 (tag) = 65.4px
     card  = 325px  ⇒  image 79.4%, footer 20.0%.  Inside both bands.
   The footer height is deterministic because .card-tag is clamped to one
   line, so no card in a row ever grows taller than its neighbours. */
.card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 4;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-media img {
  width: 100%; height: 100%;
  object-fit: contain;          /* 🔴 NEVER cover or distort a radiograph */
  background: #000;
  transition: opacity var(--dur-std) var(--ease-out);
}
.card-media img.loading { opacity: 0; }
.card-media .ph {
  display: grid; place-items: center;
  width: 100%; height: 100%;
  color: var(--ink-faint); font-size: 12px; background: #05090c;
}

/* Dedicated zoom button overlaid on card media */
.card-zoom {
  position: absolute;
  top: 10px; inset-inline-end: 10px;
  z-index: 5;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  color: var(--ink);
  background: rgba(7, 13, 18, .68);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  cursor: zoom-in;
  opacity: 0.85;
  transition: opacity var(--dur-micro) var(--ease-out),
              background var(--dur-micro) var(--ease-out),
              transform var(--dur-micro) var(--ease-out);
}
.card-zoom svg { width: 15px; height: 15px; stroke: currentColor; }
.card-zoom:hover {
  opacity: 1;
  background: rgba(63, 191, 173, .30);
  border-color: var(--teal);
  transform: scale(1.08);
}
.card-zoom:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* Card footer (15-20% height): status badge + case id + pathology tag.
   min-height is explicit so a card with an empty/delayed tag stays the exact
   same height as its neighbours in the grid row. */
.card-foot {
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  padding: 10px 14px 12px;
  min-height: 66px;
  background: linear-gradient(180deg, rgba(10, 21, 32, .92), rgba(7, 13, 18, .98));
  border-top: 1px solid var(--edge-subtle);
  flex: 0 0 auto;
}
.card-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 22px;
}
.cid { font: 600 11.5px var(--font-mono); color: var(--ink-faint); letter-spacing: .3px; }
.card-tag {
  font-size: 12px; color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: baseline; gap: 6px;
  min-height: 18px; line-height: 1.5;
}
.card-tag .sub {
  font-style: normal; font-size: 9.5px;
  padding: 1px 6px; border-radius: var(--r-full);
  background: rgba(240, 182, 74, .18);
  border: 1px solid rgba(240, 182, 74, .32);
  color: var(--amber);
}

/* Status Badges: green = normal, amber = pathology (WCAG 1.4.1 compliant) */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 9px; font-size: 11px;
  font-variation-settings: "wght" 600;
  border-radius: var(--r-full);
  line-height: 1.4;
}
.badge-ok {
  background: var(--badge-normal-bg);
  border: 1px solid var(--badge-normal-border);
  color: var(--badge-normal-ink);
}
.badge-pathology {
  background: var(--badge-pathology-bg);
  border: 1px solid var(--badge-pathology-border);
  color: var(--badge-pathology-ink);
}

/* --- Directive 8: Pagination Component ---------------------------------- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 24px;
  padding: 14px;
}
.pager-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 38px; height: 38px;
  padding-inline: 10px;
  color: var(--ink-dim);
  font: 500 13px var(--font-mono);
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--dur-micro) var(--ease-out),
              background var(--dur-micro) var(--ease-out),
              border-color var(--dur-micro) var(--ease-out),
              transform var(--dur-micro) var(--ease-out);
}
.pager-btn:hover:not(:disabled) {
  color: var(--ink);
  background: rgba(255, 255, 255, .08);
  border-color: var(--edge-lit);
  transform: translateY(-1px);
}
.pager-btn:active:not(:disabled) { transform: translateY(0); }
.pager-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.pager-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}
.pager-btn.is-active {
  color: #04120f;
  background: linear-gradient(120deg, var(--teal), #74d9c9);
  border-color: transparent;
  font-weight: 700;
}
.pager-ellipsis {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 38px;
  color: var(--ink-faint); font-size: 14px;
}
.pager-arrow { width: 14px; height: 14px; }
/* Arrow direction in RTL vs LTR:
   In RTL, Next (بعدی) advances toward inline-end (the left), so arrow points left.
   Prev (قبلی) goes backward toward inline-start (the right), so arrow points right. */
[dir="rtl"] .pager-prev .pager-arrow { transform: rotate(0deg); }
[dir="rtl"] .pager-next .pager-arrow { transform: rotate(180deg); }
[dir="ltr"] .pager-prev .pager-arrow { transform: rotate(180deg); }
[dir="ltr"] .pager-next .pager-arrow { transform: rotate(0deg); }

.empty { text-align: center; color: var(--ink-faint); padding: 40px 0; }

/* --- Clinical Empty State (Task 2) --------------------------------------- */
.empty-state-clinical {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  margin: 12px 0 24px;
  background: var(--bg-card, rgba(14, 22, 34, 0.65));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--edge, rgba(255, 255, 255, 0.08));
  border-radius: var(--r-md, 12px);
  color: var(--ink-dim, #94a3b8);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}
.empty-state-clinical .empty-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 12px rgba(63, 191, 173, 0.25));
}
.empty-state-clinical h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-variation-settings: "wght" 650;
  color: var(--ink, #e2e8f0);
}
.empty-state-clinical p {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-faint, #64748b);
  max-width: 480px;
  line-height: 1.6;
}
.site-foot {
  text-align: center;
  padding-block: 20px 10px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* --- Directive 5: Full-size Lightbox Viewer ----------------------------- */
.viewer {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 3vh 3vw 2vh;
  background: rgba(3, 6, 9, .94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.viewer[hidden] { display: none; }
.viewer-stage {
  flex: 1 1 auto;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  overflow: hidden;
}
.viewer-stage img {
  max-width: 90vw; max-height: 80vh;
  object-fit: contain;
  border-radius: var(--r-md);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-lg);
}
.viewer-stage .ph-viewer {
  min-width: 280px; min-height: 200px;
  padding: 30px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  border: 1px dashed var(--edge);
  color: var(--ink-faint); font-size: 13px;
}
.viewer-foot {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding-top: 10px;
}
.viewer-cap {
  text-align: center; font-size: 13px; color: var(--ink-dim);
  font-family: var(--font-mono); direction: ltr;
}
.viewer-cap b { font-weight: 600; color: var(--ink); }

/* Directive 5: attribution slot in viewer modal footer */
.viewer-attr {
  font-size: 11.5px; color: var(--ink-faint);
  text-align: center;
}
.attr-line { margin: 0; }
.attr-link {
  color: var(--teal); text-decoration: none;
  border-bottom: 1px dashed rgba(63, 191, 173, .45);
}
.attr-link:hover { color: #74d9c9; }

.viewer-close {
  position: absolute; top: 18px; inset-inline-end: 18px;
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--ink); font-size: 17px; cursor: pointer;
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--edge);
  transition: background var(--dur-micro) var(--ease-out);
}
.viewer-close:hover { background: rgba(255, 255, 255, .15); }

.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 54px; height: 80px; border-radius: var(--r-md);
  color: var(--ink); font-size: 28px; line-height: 1;
  cursor: pointer; user-select: none;
  background: rgba(255, 255, 255, .10);
  border: 1px solid var(--edge);
  transition: background var(--dur-micro) var(--ease-out);
  z-index: 2;
}
.viewer-nav:hover:not(:disabled) { background: rgba(63, 191, 173, .35); }
.viewer-nav:disabled { opacity: .25; cursor: not-allowed; }
.viewer-nav.prev { inset-inline-start: 20px; }
.viewer-nav.next { inset-inline-end: 20px; }
.viewer-nav[hidden] { display: none; }

/* Responsive adjustments */
@media (max-width: 820px) {
  .topbar { padding: 10px 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
  .viewer-nav { width: 40px; height: 56px; font-size: 22px; }
  .viewer-nav.prev { inset-inline-start: 8px; }
  .viewer-nav.next { inset-inline-end: 8px; }
  .search-panel { inset-inline: 14px; width: auto; }
}

/* ==========================================================================
   SLP pages (/radiology/cases/<slug>/) — shared tokens, re-modernized.
   The new generator emits self-contained pages with an inline <style> block,
   but setupSlpViewer() in app.js builds the lightbox with these classes and
   any SLP that still links app.css must keep working. Kept as a superset with
   logical properties (was physical in the pre-redesign file).
   Classes: meta-card, findings, finding, num, mesh, images, crumb-cat, fa,
   slp-link. The viewer classes above (.viewer, .viewer-stage, .viewer-cap,
   .viewer-nav, .viewer-close, .viewer-attr) are shared and already defined.
   ========================================================================== */
main > header nav { color: var(--ink-faint); font-size: 13px; }
.crumb-cat { color: var(--ink-faint); }

.meta-card {
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  padding: 14px 18px;
}
.meta-card dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; margin: 0; }
.meta-card dt { color: var(--ink-dim); font-size: 13px; }
.meta-card dd { margin: 0; font-size: 14px; }

.findings { display: flex; flex-wrap: wrap; gap: 8px; }
.finding a {
  display: inline-block;
  background: var(--glass-2);
  border: 1px solid var(--edge);
  border-radius: var(--r-full);
  padding: 6px 14px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  transition: border-color var(--dur-micro) var(--ease-out);
}
.finding a:hover { border-color: var(--edge-lit); }
.finding .num { color: var(--teal); }
.finding .mesh { color: var(--ink-faint); font-size: 12px; }
.finding .fa { font-variation-settings: "wght" 600; }

.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.images figure {
  margin: 0; background: var(--glass);
  border: 1px solid var(--edge); border-radius: var(--r-md); padding: 8px;
}
.images img {
  display: block; width: 100%; height: auto;
  border-radius: var(--r-sm); cursor: zoom-in;
}
.images figcaption { color: var(--ink-faint); font-size: 11px; margin-top: 6px; text-align: center; }

/* gallery card deep link into case pages (legacy; new cards use .card-link) */
.slp-link { color: var(--teal); text-decoration: none; font-size: 12px; }
.slp-link:hover { text-decoration: underline; }

/* ==========================================================================
   Reduced Motion: Fold all animations & transitions into OS preference
   (apply-reduced-motion skill & Section 5 luxury polish constraint)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  .aurora span { animation: none !important; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .card:hover {
    transform: none !important;
  }
  .drawer {
    transition: none !important;
  }
  .drawer-scrim {
    transition: none !important;
  }
  .search-panel {
    transition: none !important;
    transform: none !important;
  }
}
