:root {
  --navy: oklch(24% 0.045 255);
  --navy-dark: oklch(22% 0.03 255);
  --gold: oklch(72% 0.12 75);
  --page-bg: oklch(98% 0.006 90);
  --card-border: oklch(90% 0.008 90);
  --text-primary: oklch(20% 0.02 255);
  --text-heading: oklch(20% 0.03 255);
  --text-muted: oklch(50% 0.01 255);
  --text-muted-2: oklch(48% 0.01 255);
  --status-active-bg: oklch(93% 0.05 145);
  --status-active-text: oklch(36% 0.1 145);
  --status-other-bg: oklch(92% 0.006 90);
  --status-other-text: oklch(46% 0.01 255);
  --superseded-banner-bg: oklch(93% 0.03 75);
  --superseded-banner-text: oklch(38% 0.09 75);
  --shadow-card: 0 20px 60px rgba(0,0,0,.35);
  --shadow-search: 0 12px 30px rgba(0,0,0,.25);
  --motion-fast: 150ms;
  --motion-med: 250ms;
  --ease: cubic-bezier(.2,.7,.3,1);
}

* { box-sizing: border-box; }

/* Author rules that set `display` (e.g. .gate-screen { display: flex }) tie
   in specificity with the UA's [hidden] rule and can win the cascade, which
   would make an element ignore its `hidden` attribute/property. Force it. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text-primary);
  background: var(--page-bg);
}

html[dir="rtl"] body {
  font-family: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif;
}

button, input { font-family: inherit; }

.mono { font-family: 'IBM Plex Mono', monospace; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

.logo-mark {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold);
}
.logo-mark-sm { width: 34px; height: 34px; border-radius: 7px; }

/* ---------- Lead-capture gate screen ---------- */
.gate-screen {
  min-height: 100vh;
  background: var(--navy-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card-wrap { width: 100%; max-width: 400px; }
.gate-lang-toggle { display: flex; justify-content: center; margin: 0 auto 16px; width: fit-content; }

.brand-row { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 32px; }
.brand-word { color: white; font-weight: 600; font-size: 17px; letter-spacing: .2px; display: flex; gap: 6px; align-items: baseline; }
.brand-suffix { font-size: 12px; font-weight: 700; color: var(--gold); border: 1px solid oklch(72% 0.12 75 / 0.5); border-radius: 4px; padding: 1px 6px; }

.gate-card {
  background: white;
  border-radius: 12px;
  padding: 40px 36px;
  box-shadow: var(--shadow-card);
  animation: card-in var(--motion-med) var(--ease) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.gate-card-head { text-align: center; margin-bottom: 24px; }
.gate-card-head h1 { font-size: 20px; font-weight: 600; color: var(--text-heading); margin: 0 0 6px; }
.gate-card-head p { font-size: 13.5px; color: var(--text-muted-2); line-height: 1.5; margin: 0; }

.gate-error {
  background: oklch(93% 0.05 25); color: oklch(35% 0.12 25);
  font-size: 12.5px; padding: 10px 12px; border-radius: 7px; margin-bottom: 16px;
}

.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px; border-radius: 8px; border: 1px solid oklch(85% 0.01 255);
  background: white; font-size: 14.5px; font-weight: 500; color: oklch(25% 0.02 255);
  cursor: pointer; transition: background var(--motion-fast) var(--ease), transform var(--motion-fast) var(--ease);
}
.google-btn:hover { background: oklch(97% 0.005 90); }
.google-btn:active { transform: scale(0.98); }

.g-monogram {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid oklch(30% 0.02 255);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: oklch(30% 0.02 255);
}

.divider {
  display: flex; align-items: center; gap: 10px; margin: 20px 0;
  color: var(--text-muted); font-size: 12px;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: oklch(90% 0.006 90); }

.gate-form { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-muted-2); margin-top: 8px; }
.gate-form input {
  padding: 10px 12px; border-radius: 7px; border: 1px solid oklch(85% 0.01 90);
  font-size: 14px; outline: none; transition: border-color var(--motion-fast) var(--ease);
}
.gate-form input:focus { border-color: var(--navy); }

.gate-submit-btn {
  margin-top: 14px; background: var(--navy); color: white; border: none; border-radius: 8px;
  padding: 12px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform var(--motion-fast) var(--ease), opacity var(--motion-fast) var(--ease);
}
.gate-submit-btn:active { transform: scale(0.98); }
.gate-submit-btn:disabled { opacity: 0.6; cursor: default; }

.gate-footer-note {
  margin-top: 20px; padding-top: 20px; border-top: 1px solid oklch(93% 0.005 90);
  text-align: center; font-size: 11.5px; color: oklch(58% 0.01 255); line-height: 1.5;
}

/* ---------- Library screen ---------- */
.library-screen { min-height: 100vh; background: var(--page-bg); }

.site-header {
  background: white; border-bottom: 1px solid var(--card-border);
  padding: 14px 32px; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
}

.header-brand { display: flex; align-items: center; gap: 12px; }
.header-brand-name { font-weight: 600; font-size: 14.5px; color: var(--text-heading); line-height: 1.2; }
.header-tagline { font-size: 11.5px; color: var(--text-muted); line-height: 1.2; }

.header-actions { display: flex; align-items: center; gap: 14px; }

.download-index-link {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid oklch(88% 0.008 90); border-radius: 6px; padding: 6px 11px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted-2); text-decoration: none;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.download-index-link:hover { background: oklch(97% 0.005 90); border-color: oklch(80% 0.01 90); color: var(--navy); }

.lang-toggle { display: flex; border: 1px solid oklch(88% 0.008 90); border-radius: 7px; overflow: hidden; }
.lang-btn {
  border: none; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  background: white; color: oklch(30% 0.02 255); transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.lang-btn.active { background: var(--navy); color: white; }

.user-chip {
  display: flex; align-items: center; gap: 8px; background: none; border: none;
  cursor: pointer; padding: 4px 6px; border-radius: 8px;
  transition: background var(--motion-fast) var(--ease);
}
.user-chip:hover { background: oklch(97% 0.005 90); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: oklch(90% 0.03 255); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: oklch(35% 0.05 255);
}
.user-name { font-size: 13px; color: oklch(30% 0.01 255); }
.signout-btn {
  background: none; border: 1px solid oklch(88% 0.008 90); border-radius: 6px; padding: 5px 10px;
  font-size: 12px; color: var(--text-muted-2); cursor: pointer; transition: background var(--motion-fast) var(--ease);
}
.signout-btn:hover { background: oklch(97% 0.005 90); }

.hero { background: var(--navy); padding: 40px 32px 34px; display: flex; flex-direction: column; align-items: center; }
.hero-inner { width: 100%; max-width: 760px; text-align: center; }
.hero h1 { margin: 0 0 8px; font-size: clamp(24px,4vw,32px); font-weight: 600; color: white; letter-spacing: -.2px; }
.hero p { margin: 0 0 22px; font-size: 14.5px; color: oklch(80% 0.015 255); }

.reveal { opacity: 0; transform: translateY(10px); transition: opacity var(--motion-med) var(--ease), transform var(--motion-med) var(--ease); }
.reveal.is-visible { opacity: 1; transform: translateY(0); }

.search-bar {
  background: white; border-radius: 10px; padding: 4px; display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-search);
}
.search-icon { padding-inline-start: 14px; display: flex; color: oklch(50% 0.01 255); }
#search-input {
  flex: 1; border: none; outline: none; padding: 14px 4px; font-size: 15px;
  color: oklch(22% 0.02 255); background: transparent;
}
.search-btn {
  margin-inline-end: 4px; background: var(--gold); color: oklch(20% 0.03 255); border: none;
  border-radius: 7px; padding: 12px 20px; font-weight: 600; font-size: 13.5px; cursor: pointer;
  white-space: nowrap; transition: transform var(--motion-fast) var(--ease);
}
.search-btn:active { transform: scale(0.97); }

.filter-bar {
  background: white; border-bottom: 1px solid var(--card-border); padding: 18px 32px;
  display: flex; flex-direction: column; gap: 14px;
}
.filter-groups { display: flex; flex-wrap: wrap; gap: 28px; }
.filter-group-label {
  font-size: 11px; font-weight: 600; letter-spacing: .5px; color: oklch(52% 0.01 255);
  text-transform: uppercase; margin-bottom: 8px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border-radius: 16px; padding: 6px 13px; font-size: 12.5px; font-weight: 500; cursor: pointer;
  border: 1px solid oklch(85% 0.01 90); background: white; color: oklch(30% 0.02 255);
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.chip.active { background: var(--navy); color: white; border-color: var(--navy); }

.results-section { padding: 26px 32px 60px; max-width: 1400px; margin: 0 auto; }
.results-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.results-summary { font-size: 13.5px; color: var(--text-muted-2); }
.results-summary .count-num { font-variant-numeric: tabular-nums; }
.clear-filters-link { border: none; background: none; color: oklch(45% 0.09 255); font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: underline; }

.doc-group { margin-bottom: 38px; }
.doc-group-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 2px solid var(--navy);
}
.doc-group-head h2 { margin: 0; font-size: 19px; font-weight: 600; color: var(--text-heading); }
.doc-group-count { font-size: 12.5px; color: oklch(52% 0.01 255); }

.doc-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px;
}

.doc-card {
  position: relative;
  background: white; border: 1px solid var(--card-border); border-radius: 10px; padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: transform var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease), opacity var(--motion-med) var(--ease);
  opacity: 0; transform: translateY(8px);
}
.doc-card.is-visible { opacity: 1; transform: translateY(0); }
.doc-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.08); }
.doc-card.is-visible:hover { transform: translateY(-2px); }

.doc-card.superseded { background: oklch(96% 0.004 90); border-color: oklch(89% 0.006 90); opacity: 0.72; }
.doc-card.superseded:hover { opacity: 0.92; }

.doc-card.highlight { outline: 2px solid var(--gold); outline-offset: 2px; animation: highlight-pulse 1.1s var(--ease); }
@keyframes highlight-pulse {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 6px oklch(72% 0.12 75 / 0.25); }
}

.superseded-banner {
  background: var(--superseded-banner-bg); color: var(--superseded-banner-text);
  font-size: 11.5px; font-weight: 600; padding: 6px 10px; border-radius: 6px; margin: -4px -4px 0;
}

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; padding-inline-end: 34px; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 5px; }
.badge-lang { background: oklch(96% 0.005 90); color: oklch(42% 0.02 255); border: 1px solid oklch(88% 0.008 90); }
.badge-status-active { background: var(--status-active-bg); color: var(--status-active-text); }
.badge-status-other { background: var(--status-other-bg); color: var(--status-other-text); }

.doc-citation { font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 500; color: oklch(46% 0.01 255); margin-bottom: 4px; }
.doc-title { font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--text-heading); }
.doc-card.superseded .doc-title { color: var(--text-muted-2); }

.doc-extra {
  font-size: 12.5px; color: var(--text-muted); line-height: 1.6;
  margin-top: 2px; padding-top: 10px; border-top: 1px solid var(--card-border);
}
.doc-extra a { color: oklch(45% 0.09 255); text-decoration: none; }
.doc-extra a:hover { text-decoration: underline; }

.doc-alt-links { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.doc-alt-links a { color: oklch(45% 0.09 255); text-decoration: none; margin-inline-end: 8px; }
.doc-alt-links a:hover { text-decoration: underline; }

.doc-actions { display: flex; align-items: center; gap: 14px; margin-top: 2px; flex-wrap: wrap; }
.doc-open-btn {
  background: var(--navy); color: white; border: none; border-radius: 7px; padding: 9px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
  transition: transform var(--motion-fast) var(--ease);
}
.doc-open-btn:active { transform: scale(0.97); }
.doc-card.superseded .doc-open-btn { background: oklch(93% 0.006 90); color: oklch(42% 0.01 255); }
.doc-source-link { font-size: 12.5px; color: oklch(45% 0.09 255); text-decoration: none; font-weight: 500; }
.doc-source-link:hover { text-decoration: underline; }

.doc-share-corner {
  position: absolute; top: 14px; inset-inline-end: 14px;
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  background: white; border: 1px solid oklch(88% 0.008 90); border-radius: 6px;
  color: var(--text-muted-2); cursor: pointer;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.doc-share-corner:hover { background: oklch(97% 0.005 90); border-color: oklch(80% 0.01 90); color: var(--navy); }

.no-results { text-align: center; padding: 80px 20px; color: oklch(52% 0.01 255); }
.no-results h3 { font-size: 16px; font-weight: 600; color: oklch(30% 0.02 255); margin: 0 0 6px; }
.no-results p { font-size: 13.5px; margin: 0 0 18px; }
.no-results button { background: var(--navy); color: white; border: none; border-radius: 7px; padding: 10px 20px; font-size: 13.5px; font-weight: 600; cursor: pointer; }

/* ---------- Skeleton loading ---------- */
.skeleton-card {
  background: white; border: 1px solid var(--card-border); border-radius: 10px; padding: 18px;
  display: flex; flex-direction: column; gap: 12px; height: 168px;
}
.skeleton-line {
  height: 12px; border-radius: 4px;
  background: linear-gradient(90deg, oklch(94% 0.006 90) 25%, oklch(90% 0.006 90) 37%, oklch(94% 0.006 90) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-70 { width: 70%; }
.skeleton-line.w-90 { width: 90%; height: 18px; }
.skeleton-line.w-100 { width: 100%; margin-top: auto; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--navy); color: white; font-size: 13px; font-weight: 500;
  padding: 10px 18px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity var(--motion-med) var(--ease), transform var(--motion-med) var(--ease);
  z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Profile modal ---------- */
.profile-modal {
  position: fixed; inset: 0; background: rgba(20, 24, 34, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 200;
}
.profile-modal-card {
  position: relative; width: 100%; max-width: 380px; background: white; border-radius: 12px;
  padding: 32px 28px 28px; box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 6px;
  animation: card-in var(--motion-med) var(--ease) both;
}
.profile-modal-card h2 { font-size: 17px; font-weight: 600; color: var(--text-heading); margin: 0 0 14px; }
.profile-close-btn {
  position: absolute; top: 14px; inset-inline-end: 14px; width: 26px; height: 26px;
  border: none; background: none; font-size: 18px; line-height: 1; color: var(--text-muted);
  cursor: pointer; border-radius: 6px;
}
.profile-close-btn:hover { background: oklch(96% 0.005 90); }
.profile-modal-card input {
  padding: 10px 12px; border-radius: 7px; border: 1px solid oklch(85% 0.01 90);
  font-size: 14px; outline: none; transition: border-color var(--motion-fast) var(--ease);
}
.profile-modal-card input:focus { border-color: var(--navy); }
.profile-readonly-value { font-size: 13.5px; color: var(--text-muted-2); padding: 10px 0 4px; }
.profile-lang-toggle { margin: 4px 0 6px; }
.profile-saved-note { font-size: 12.5px; color: oklch(40% 0.09 145); margin-top: 4px; }

/* ---------- RTL adjustments ---------- */
html[dir="rtl"] .doc-citation,
html[dir="rtl"] .mono { direction: ltr; unicode-bidi: isolate; }

@media (max-width: 640px) {
  .site-header, .hero, .filter-bar, .results-section { padding-left: 16px; padding-right: 16px; }
  .filter-groups { gap: 18px; }
}
