/* ==========================================================================
   Components shared by every page:
   header, navigation, footer, cards, chips, tabs, forms, lattice,
   the QALY assistant and the cookie notice.
   ========================================================================== */

/* ---- Header ---- */
.site-header {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--fast) var(--ease);
}
.site-header.is-scrolled { border-bottom-color: var(--line); }
.site-header__bar { display: flex; align-items: center; gap: var(--s5); min-height: 84px; }
.brand { flex: none; display: block; }
.brand img { width: 150px; height: auto; }
@media (min-width: 1200px) { .brand img { width: 170px; } }

.nav { margin-inline-start: auto; }
.nav__list { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 0.2rem; }
.nav__list > li { position: relative; }
.nav__list a {
  display: block; padding: 0.55rem 0.7rem; border-radius: 999px;
  color: var(--ink); font-weight: 500; font-size: 0.975rem; text-decoration: none; white-space: nowrap;
}
.nav__list a:hover { background: var(--ice); }
.nav__list a[aria-current="page"] { background: var(--ice); font-weight: 700; }
.nav__menu {
  list-style: none; margin: 0; padding: var(--s2);
  position: absolute; top: calc(100% + 6px); inset-inline-start: 0; min-width: 230px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease), visibility var(--fast);
}
.nav__menu a { border-radius: var(--radius-s); }
.nav__has-menu:hover .nav__menu, .nav__has-menu:focus-within .nav__menu { opacity: 1; visibility: visible; transform: none; }

.site-header__tools { display: flex; align-items: center; gap: var(--s2); }
.lang-switch {
  display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; padding: 0 0.8rem;
  background: var(--white); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; color: var(--ink); font-weight: 700;
}
.lang-switch .icon { width: 20px; height: 20px; }
.lang-switch:hover { background: var(--ice); }
.btn--ask { min-height: 44px; padding-inline: 1rem; }
.btn--ask .icon { width: 20px; height: 20px; }
.menu-toggle { display: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--white); cursor: pointer; place-items: center; }

@media (max-width: 1199px) {
  .menu-toggle { display: grid; }
  .btn--ask span { display: none; }
  .nav {
    position: fixed; inset: 84px 0 auto 0; margin: 0;
    background: var(--white); border-bottom: 1px solid var(--line);
    padding: var(--s4) var(--gutter) var(--s6);
    max-height: calc(100vh - 84px); overflow-y: auto;
    display: none;
  }
  .nav.is-open { display: block; }
  .nav__list { flex-direction: column; align-items: stretch; gap: 0; }
  .nav__list a { padding: 0.85rem 0.5rem; border-radius: var(--radius-s); font-size: 1.05rem; }
  .nav__menu { position: static; opacity: 1; visibility: visible; transform: none; box-shadow: none; border: 0; padding: 0 0 0 var(--s4); min-width: 0; }
  .nav__menu a { font-size: 0.975rem; color: var(--slate-mid); }
  .site-header__tools { margin-inline-start: auto; }
}
@media (max-width: 420px) { .brand img { width: 140px; } .lang-switch .icon { display: none; } }

/* ---- Page intro (inner pages) ---- */
.page-hero { padding-block: var(--s8) var(--s7); background: linear-gradient(180deg, var(--ice), var(--white)); }
.page-hero .wrap { display: grid; gap: var(--s5); }
.page-hero__grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--s7); align-items: center; }
@media (max-width: 860px) { .page-hero__grid { grid-template-columns: 1fr; } }
.page-hero__logo { justify-self: end; width: min(calc(100% - 64px), 380px); }
@media (max-width: 860px) { .page-hero__logo { justify-self: start; width: min(calc(100% - 48px), 280px); } }
.crumbs { font-size: var(--fs-caption); color: var(--muted); }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.crumbs li + li::before { content: "/"; margin-inline-end: 0.4rem; color: var(--blue-light); }
.crumbs a { color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: var(--s6); height: 100%;
}
.section--ice .card { border-color: transparent; }
.card--link { text-decoration: none; color: inherit; transition: transform var(--fast) var(--ease), border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.card--link:hover { transform: translateY(-3px); border-color: var(--sky); box-shadow: var(--shadow); }
.card__more { margin-top: auto; display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; color: var(--ink); }
.card__more .icon { width: 18px; height: 18px; }
.card ul, .prose ul { margin: 0; padding-inline-start: 1.1rem; display: grid; gap: 0.35rem; }
.card li::marker, .prose li::marker { color: var(--sky); }

/* ---- Chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 42px; padding: 0.45rem 1rem; border-radius: 999px;
  background: var(--white); border: 1px solid var(--line); color: var(--ink);
  font-weight: 500; cursor: pointer; text-align: start;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.chip:hover { border-color: var(--sky); }
.chip[aria-checked="true"], .chip[aria-pressed="true"] { background: var(--sky); border-color: var(--sky); font-weight: 700; }

/* ---- Tabs ---- */
.tabs__list { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 6px; background: var(--ice); border-radius: 999px; width: fit-content; max-width: 100%; margin-bottom: var(--s6); }
.tabs__list [role="tab"] {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 46px; padding: 0 1.1rem;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink); font-weight: 500; cursor: pointer;
}
.tabs__list [role="tab"] .icon { width: 20px; height: 20px; }
.tabs__list [role="tab"][aria-selected="true"] { background: var(--white); font-weight: 700; box-shadow: 0 1px 6px rgba(75, 151, 200, 0.25); }
@media (max-width: 640px) { .tabs__list { border-radius: var(--radius); width: 100%; } .tabs__list [role="tab"] { flex: 1 1 100%; justify-content: flex-start; } }
.tabs__cta { margin-top: var(--s6); }

/* ---- Stats ---- */
.stat { border-top: 2px solid var(--sky); padding-top: var(--s4); display: grid; gap: var(--s2); }
.stat__num { font-size: clamp(2.6rem, 2rem + 2vw, 3.6rem); font-weight: 700; color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums; }
.std-cta { margin-top: var(--s7); }

/* ---- Steps (a real sequence, so it is numbered) ---- */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: var(--s3); }
.steps li { counter-increment: step; display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: var(--s3); align-items: baseline; padding: var(--s3) 0; border-top: 1px solid var(--line); }
.steps li::before {
  content: counter(step, decimal-leading-zero);
  font-weight: 700; color: var(--sky); font-variant-numeric: tabular-nums;
}
.steps li strong { display: block; }

/* ---- Forms ---- */
.form { display: grid; gap: var(--s5); }
.field { display: grid; gap: var(--s2); }
.field label, .field legend { font-weight: 700; color: var(--ink); font-size: var(--fs-small); }
.field .hint { font-size: var(--fs-caption); color: var(--muted); }
.field input[type="text"], .field input[type="email"], .field input[type="tel"], .field input[type="password"], .field select, .field textarea {
  width: 100%; min-height: 50px; padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--line); border-radius: var(--radius-s); background: var(--white); color: var(--text);
}
.field textarea { min-height: 150px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 4px var(--ice); }
.field--check { grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: var(--s3); }
.field--check input { width: 22px; height: 22px; accent-color: var(--ink); margin-top: 2px; }
.field--check label { font-weight: 400; color: var(--text); font-size: var(--fs-small); }
.field [aria-invalid="true"] { border-color: var(--ink); }
.field .error { color: var(--ink); font-size: var(--fs-caption); font-weight: 700; }
fieldset { border: 0; padding: 0; margin: 0; }
.radio-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row label { cursor: pointer; }
.radio-row input:checked + label { background: var(--sky); border-color: var(--sky); font-weight: 700; }
.radio-row input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- Copy row (addresses, phone, email) ---- */
.contact-card { display: grid; gap: var(--s3); align-content: start; }
.contact-card__value { font-size: 1.15rem; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.copy-btn { display: inline-flex; align-items: center; gap: 0.4rem; background: none; border: 0; padding: 0; color: var(--ink); font-weight: 700; font-size: var(--fs-small); cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; }
.copy-btn .icon { width: 18px; height: 18px; }
.nowrap { white-space: nowrap; }

/* ---- Accordion (FAQ) ---- */
.accordion { display: grid; gap: var(--s3); }
.accordion details { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.accordion summary {
  list-style: none; cursor: pointer; padding: var(--s4) var(--s5);
  display: flex; justify-content: space-between; gap: var(--s4); align-items: center;
  font-weight: 700; color: var(--ink); font-size: 1.075rem;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary .icon { transition: transform var(--fast) var(--ease); flex: none; }
.accordion details[open] summary .icon { transform: rotate(45deg); }
.accordion .accordion__body { padding: 0 var(--s5) var(--s5); display: grid; gap: var(--s3); }

/* ---- Prose (legal and long pages) ---- */
.prose { display: grid; gap: var(--s4); max-width: 760px; }
.prose h2 { font-size: 1.6rem; margin-top: var(--s6); }
.prose h3 { font-size: 1.2rem; margin-top: var(--s4); }
.prose p, .prose li { max-width: 70ch; }
.toc { position: sticky; top: 110px; align-self: start; display: grid; gap: var(--s2); font-size: var(--fs-small); }
.toc a { color: var(--ink); text-decoration: none; }
.toc a:hover { text-decoration: underline; }
.legal-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--s8); }
@media (max-width: 860px) { .legal-layout { grid-template-columns: 1fr; } .toc { position: static; } }
.meta-line { font-size: var(--fs-caption); color: var(--muted); }

/* ---- Heritage lattice band (drawn by lattice.js) ---- */
.lattice { width: 100%; height: 64px; display: block; position: relative; }
.lattice svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.lattice .tile { transition: opacity 500ms var(--ease), transform 500ms var(--ease); transform-box: fill-box; transform-origin: center; }
.js .lattice.is-waiting .tile.fill { opacity: 0; transform: scale(0.4); }
@media (prefers-reduced-motion: reduce) { .lattice .tile { transition: none; } .js .lattice.is-waiting .tile.fill { opacity: 1; transform: none; } }

/* ---- Footer ---- */
.site-footer { background: var(--surface); margin-top: 0; }
.site-footer .lattice { background: var(--white); }
.site-footer__grid { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); gap: var(--s7); padding-block: var(--s8) var(--s6); }
@media (max-width: 960px) { .site-footer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .site-footer__brand { grid-column: 1 / -1; } }
@media (max-width: 520px) { .site-footer__grid { grid-template-columns: 1fr; } }
.site-footer__brand img { width: 196px; }
.site-footer__tagline { font-size: 1.5rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.site-footer__col ul { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: var(--s2); }
.site-footer__col a, .linkish { color: var(--ink); text-decoration: none; font-size: var(--fs-small); }
.site-footer__col a:hover, .linkish:hover { text-decoration: underline; }
.linkish { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: var(--fs-small); }
.site-footer address { font-style: normal; margin-top: var(--s3); }
.site-footer address a { color: var(--ink); }
.social { list-style: none; margin: var(--s2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); }
.social a { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--white); border: 1px solid var(--line); }
.social a:hover { border-color: var(--sky); }
.social .icon { width: 20px; height: 20px; }
.site-footer__legal { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s4); padding-block: var(--s5) var(--s6); border-top: 1px solid var(--line); }
.legal-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.legal-links a { color: var(--ink); font-size: var(--fs-small); font-weight: 500; text-decoration: none; }
.legal-links a:hover { text-decoration: underline; }

/* ---- QALY: the AI guide ---- */
.ai-orb { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--orange); position: relative; }
.ai-orb::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid var(--sky); opacity: 0.8; }
@media (prefers-reduced-motion: no-preference) {
  .ai-orb::after { animation: orbit-pulse 3.2s var(--ease) infinite; }
  .ai-panel.is-thinking .ai-panel__avatar .ai-orb::after { animation-duration: 1.1s; }
}
@keyframes orbit-pulse { 0% { transform: scale(0.9); opacity: 0.9; } 70% { transform: scale(1.35); opacity: 0; } 100% { opacity: 0; } }

.ai-launcher {
  position: fixed; z-index: 60;
  inset-inline-end: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: inline-flex; align-items: center; gap: 0.7rem;
  min-height: 56px; padding: 0 1.2rem 0 0.8rem;
  background: var(--white); color: var(--ink); font-weight: 700;
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); cursor: pointer;
}
.ai-launcher:hover { border-color: var(--sky); }
.ai-launcher__avatar { width: 22px; height: 22px; margin: 6px; }
.ai-launcher[aria-expanded="true"] { display: none; }
@media (max-width: 520px) { .ai-launcher__text { display: none; } .ai-launcher { padding: 0 0.9rem; } }

.ai-panel {
  position: fixed; z-index: 70;
  inset-inline-end: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(420px, calc(100vw - 32px)); height: min(640px, calc(100vh - 120px));
  display: flex; flex-direction: column;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: 0 24px 64px rgba(2, 26, 145, 0.16);
  overflow: hidden;
}
.ai-panel__head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4); border-bottom: 1px solid var(--line); background: var(--ice); }
.ai-panel__avatar { width: 30px; height: 30px; margin: 6px; flex: none; }
.ai-panel__who { flex: 1; min-width: 0; }
.ai-panel__title { font-size: 1.05rem; line-height: 1.2; }
.ai-panel__status { font-size: var(--fs-caption); color: var(--muted); }
.ai-icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--white); display: grid; place-items: center; cursor: pointer; flex: none; }
.ai-icon-btn .icon { width: 20px; height: 20px; }
.ai-icon-btn[aria-pressed="true"] { background: var(--sky); border-color: var(--sky); }
.ai-panel__log { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); scroll-behavior: smooth; }
.msg { max-width: 88%; padding: 0.7rem 0.95rem; border-radius: 16px; font-size: 0.975rem; line-height: 1.55; overflow-wrap: anywhere; }
.msg p { max-width: none; }
.msg p + p { margin-top: 0.5rem; }
.msg--ai { align-self: flex-start; background: var(--ice); color: var(--text); border-end-start-radius: 4px; }
.msg--you { align-self: flex-end; background: var(--sky); color: var(--ink); font-weight: 500; border-end-end-radius: 4px; }
.msg__links { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.msg__links a { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.7rem; border-radius: 999px; background: var(--white); border: 1px solid var(--line); font-size: var(--fs-caption); font-weight: 700; color: var(--ink); text-decoration: none; }
.msg__links a:hover { border-color: var(--sky); }
.msg--thinking { display: inline-flex; gap: 5px; align-items: center; }
.msg--thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--sky); display: block; }
@media (prefers-reduced-motion: no-preference) {
  .msg--thinking i { animation: think 1.2s var(--ease) infinite; }
  .msg--thinking i:nth-child(2) { animation-delay: 0.15s; }
  .msg--thinking i:nth-child(3) { animation-delay: 0.3s; }
}
@keyframes think { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }
.ai-panel__chips { display: flex; gap: var(--s2); overflow-x: auto; padding: 0 var(--s4) var(--s3); scrollbar-width: thin; }
.ai-panel__chips .chip { flex: none; min-height: 36px; padding: 0.3rem 0.8rem; font-size: var(--fs-small); }
.ai-panel__form { display: flex; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--line); }
.ai-panel__form input { flex: 1; min-width: 0; min-height: 46px; padding: 0 0.9rem; border: 1.5px solid var(--line); border-radius: 999px; }
.ai-panel__form input:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 4px var(--ice); }
.ai-send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--sky); display: grid; place-items: center; cursor: pointer; flex: none; }
.ai-send .icon { width: 20px; height: 20px; }
[dir="rtl"] .ai-send .icon { transform: scaleX(-1); }
.ai-panel__note { padding: 0 var(--s4) var(--s3); }

/* ---- Cookie notice ---- */
.cookie {
  position: fixed; z-index: 65; inset-inline-start: max(16px, env(safe-area-inset-left, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(440px, calc(100vw - 32px));
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow);
  padding: var(--s5); display: grid; gap: var(--s4);
}
.cookie .btn { min-height: 42px; padding: 0.5rem 1rem; }
@media (max-width: 520px) { .cookie { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); } }

/* ---- Arabic notice for pages not yet translated ---- */
.i18n-note { background: var(--ice); border-bottom: 1px solid var(--line); padding: var(--s3) var(--gutter); text-align: center; font-size: var(--fs-small); color: var(--ink); }

/* ---- Tables and definition lists ---- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
.table th, .table td { text-align: start; padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--ink); font-weight: 700; }
.glossary dt, .glossary dd { margin: 0; }
.h3 { font-size: var(--fs-h3); line-height: 1.2; }
