/* =======================================================================
   Venomers — Certifications Page Styles (certifications-bilingual.css)
   Purpose: ONE stylesheet for BOTH English (LTR) and Arabic (RTL)
            Scope: Hero, section index, regulatory cards, QA/QC table,
            audit block, FAQ, and page-scoped utilities.
   Depends on: /en/css/global.css (tokens, base)
   Updated: 2025-10-07
   Notes:
   - Direction-aware: rely on logical properties + [dir] on <html>.
     Use <html lang="en" dir="ltr"> or <html lang="ar" dir="rtl">.
   - Self container-queries preserved for .card-grid and .methods-table.
   - Accessibility: focus-visible, reduced motion (scoped), forced-colors, print.
   - Cleaned/merged RTL overrides; removed left/right; text-align uses start.
   ======================================================================= */

@layer certifications-page {
  /* -------------------------------------------------------------------
     Local tokens & containers
     ------------------------------------------------------------------- */
  :where(.hero-certs, .section-index.on-this-page, .certs-section) {
    --gap: clamp(12px, 2.6vw, 24px);
    --pad: clamp(14px, 3vw, 26px);
    --pad-lg: clamp(18px, 4vw, 36px);
    --chip: 999px;
    --soft-border: 1px solid var(--border);
  }

  /* Self containers (keeps previous behavior) */
  :where(.card-grid, .methods-table) {
    container-type: inline-size;
  }

  /* -------------------------------------------------------------------
     Page hero
     ------------------------------------------------------------------- */
  .hero-certs {
    position: relative;
    display: grid; /* safe centering */
    justify-items: center;
    text-align: center;
    padding-block: clamp(48px, 10vw, 140px);
    padding-inline: clamp(12px, 3vw, 28px);
    border: var(--soft-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    background: radial-gradient(
        clamp(820px, 52vw, 1400px) clamp(420px, 34vw, 720px) at 50% -12%,
        color-mix(in oklab, var(--accent), transparent 84%),
        transparent 60%
      ),
      linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 40%),
      var(--surface-2);
  }
  .hero-certs h1 {
    margin-block-end: 0.4em;
    text-wrap: balance;
  }

  /* Center the lead paragraph with high specificity safety */
  .hero-certs > p.lead {
    inline-size: min(78ch, 100%);
    margin-inline: auto;
    display: block;
    text-align: center !important; /* outrank global .lead if any */
    color: var(--muted);
    text-wrap: pretty;
    line-height: 1.6;
  }

  /* -------------------------------------------------------------------
     Section index (chips) — NOT sticky
     ------------------------------------------------------------------- */
  .section-index.on-this-page {
    position: static;
    top: auto;
    z-index: auto; /* reset */
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.04),
        rgba(255, 255, 255, 0.02) 30%
      ),
      var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    backdrop-filter: blur(8px) saturate(1.05);
    -webkit-backdrop-filter: blur(8px) saturate(1.05);
    padding: 8px;
    margin-block: clamp(12px, 3vw, 20px);
  }
  .section-index.on-this-page ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    gap: clamp(6px, 2vw, 12px);
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable both-edges;
  }
  /* Natural tab order in RTL */
  :root[dir="rtl"] .section-index.on-this-page ul {
    direction: rtl;
  }

  .section-index.on-this-page a {
    display: inline-block;
    padding: 8px 12px;
    border-radius: var(--chip);
    border: 1px solid color-mix(in oklab, var(--glass-border), white 4%);
    background: transparent;
    color: var(--text);
    white-space: nowrap;
    text-decoration: none;
    transition: transform 0.16s ease, background 0.16s ease,
      border-color 0.16s ease, box-shadow 0.16s ease;
  }
  .section-index.on-this-page a:hover,
  .section-index.on-this-page a:focus-visible {
    background: var(--glass-hover);
    border-color: color-mix(in oklab, var(--accent), white 55%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    transform: translateY(-1px);
  }

  /* -------------------------------------------------------------------
     Sections (vertical structure preserved)
     ------------------------------------------------------------------- */
  .certs-section {
    display: grid;
    gap: var(--gap);
  }
  .certs-section > p,
  .certs-section > .sub,
  .certs-section > .note {
    max-width: 78ch;
    text-wrap: pretty;
  }
  .certs-section .sub,
  .certs-section .note {
    color: var(--muted);
    font-size: var(--fs-small);
  }
  .certs-section .sub {
    margin-block-start: -2px;
  }

  /* -------------------------------------------------------------------
     Regulatory cards grid — self container-query
     ------------------------------------------------------------------- */
  .card-grid {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: clamp(14px, 3vw, 24px);
    grid-template-columns: 1fr; /* default single column */
  }
  @container (min-width: 780px) {
    .card-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }
  @container (min-width: 1160px) {
    .card-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  .cert-card {
    background: var(--surface-2);
    border: var(--soft-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: var(--pad-lg);
    display: grid;
    gap: 12px;
    position: relative;
    transition: transform 0.18s ease, border-color 0.18s ease,
      box-shadow 0.18s ease;
  }
  .cert-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in oklab, var(--accent), white 60%);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  }
  .cert-card[data-type="regulatory"]::before {
    content: "";
    position: absolute;
    inset-inline: 0;
    inset-block-start: 0;
    block-size: 3px;
    border-radius: 3px 3px 0 0;
    background: linear-gradient(
      90deg,
      var(--accent),
      color-mix(in oklab, var(--accent), white 40%)
    );
    opacity: 0.9;
  }

  .cert-head {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
  }
  .cert-title {
    margin: 0;
    text-wrap: balance;
  }

  .status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--chip);
    font-size: 12px;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
  }
  .status.valid {
    background: color-mix(in oklab, #22c55e, black 8%);
    color: #d1fae5;
    border-color: color-mix(in oklab, #22c55e, black 20%);
  }
  .status.pending {
    background: color-mix(in oklab, #f59e0b, black 8%);
    color: #fff7ed;
    border-color: color-mix(in oklab, #f59e0b, black 22%);
  }
  .status.expired {
    background: color-mix(in oklab, #ef4444, black 8%);
    color: #fee2e2;
    border-color: color-mix(in oklab, #ef4444, black 22%);
  }

  /* Meta data list */
  .meta {
    display: grid;
    gap: 8px;
  }
  .meta > div {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 8px 10px;
    background: var(--surface);
    border: var(--soft-border);
    border-radius: var(--radius-sm);
  }
  @media (min-width: 720px) {
    .meta {
      grid-template-columns: 1fr;
    }
    .meta > div {
      grid-template-columns: minmax(140px, 0.6fr) 1fr;
      align-items: baseline;
    }
    .meta > div dt {
      grid-column: 1;
    }
    .meta > div dd {
      grid-column: 2;
    }
  }
  .meta dt {
    margin: 0;
    font-size: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .meta dd {
    margin: 0;
    color: var(--text);
    font-variant-numeric: tabular-nums;
  }
  .meta time {
    white-space: nowrap;
  }

  .actions {
    margin-top: 4px;
  }
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: transform 0.16s ease, border-color 0.16s ease,
      box-shadow 0.16s ease, background 0.16s ease;
  }
  .btn.outline {
    border: 1px solid var(--border);
    background: color-mix(in oklab, var(--surface), black 2%);
    color: var(--text);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  }
  .btn.outline:hover,
  .btn.outline:focus-visible {
    transform: translateY(-1px);
    border-color: color-mix(in oklab, var(--accent), white 60%);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.26);
  }

  /* -------------------------------------------------------------------
     QA/QC Methods table (self container)
     ------------------------------------------------------------------- */
  .table-wrap {
    border: var(--soft-border);
    border-radius: var(--radius);
    overflow: clip; /* clip overflow while allowing x-scroll below */
    background: var(--surface-2);
    box-shadow: var(--shadow-1);
  }
  .methods-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
  }
  .methods-table caption {
    caption-side: top;
    padding: 12px 14px;
    text-align: start; /* direction-aware */
    font-weight: 700;
    color: var(--text);
    background: color-mix(in oklab, var(--surface-2), black 4%);
    border-bottom: 1px solid var(--border);
  }
  .methods-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: color-mix(in oklab, var(--surface-2), black 4%);
    color: var(--text);
    text-align: start; /* direction-aware */
    font-weight: 700;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  .methods-table tbody th[scope="row"],
  .methods-table tbody td {
    padding: 12px 14px;
    vertical-align: top;
    border-bottom: 1px solid color-mix(in oklab, var(--border), black 6%);
  }
  .methods-table tbody tr:nth-child(odd) td,
  .methods-table tbody tr:nth-child(odd) th[scope="row"] {
    background: color-mix(in oklab, var(--surface), black 2%);
  }
  .methods-table code {
    padding: 2px 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: color-mix(in oklab, var(--surface), black 3%);
    font-size: 0.925em;
  }
  .methods-table .muted {
    color: var(--muted);
  }

  /* Horizontal scroll on small screens */
  .table-wrap {
    overflow-x: auto;
  }
  .table-wrap::-webkit-scrollbar {
    block-size: 10px;
  }
  .table-wrap::-webkit-scrollbar-thumb {
    background: color-mix(in oklab, var(--border), black 10%);
    border-radius: 10px;
  }

  /* -------------------------------------------------------------------
     Audit block
     ------------------------------------------------------------------- */
  #audit p {
    text-wrap: pretty;
  }

  /* -------------------------------------------------------------------
     FAQ (details/summary)
     ------------------------------------------------------------------- */
  #faq details {
    border: var(--soft-border);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 0;
    overflow: hidden;
  }
  #faq details + details {
    margin-top: 10px;
  }
  #faq summary {
    cursor: pointer;
    list-style: none;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    position: relative;
    text-wrap: balance;
  }
  #faq summary::-webkit-details-marker {
    display: none;
  }
  #faq summary::after {
    content: "▾";
    margin-inline-start: auto;
    transition: transform 0.2s ease;
  }
  #faq details[open] summary::after {
    transform: rotate(-180deg);
  }
  #faq details > p {
    margin: 0;
    padding: 0 14px 14px 14px;
    color: var(--text);
    text-wrap: pretty;
  }
  #faq summary:focus-visible {
    outline: var(--focus);
    outline-offset: 3px;
    border-radius: 8px;
  }

  @media (prefers-reduced-motion: reduce) {
    #faq summary::after {
      transition: none;
    }
  }

  /* -------------------------------------------------------------------
     Focus & accessibility
     ------------------------------------------------------------------- */
  main a:focus-visible {
    outline: var(--focus);
    outline-offset: 3px;
    border-radius: 8px;
  }

  /* -------------------------------------------------------------------
     RTL adjustments (minimal; rest handled by logical props)
     ------------------------------------------------------------------- */
  :root[dir="rtl"] .section-index.on-this-page a {
    text-align: center;
  }

  /* -------------------------------------------------------------------
     Reduced motion (page scoped)
     ------------------------------------------------------------------- */
  @media (prefers-reduced-motion: reduce) {
    /* Keep it scoped to this page to avoid global side-effects */
    :where(.hero-certs, .section-index.on-this-page, .certs-section) * {
      transition-duration: 0.001ms !important;
      animation-duration: 0.001ms !important;
    }
    .section-index.on-this-page a,
    .cert-card,
    .btn.outline {
      transition: none;
    }
  }

  /* -------------------------------------------------------------------
     High Contrast (Forced Colors)
     ------------------------------------------------------------------- */
  @media (forced-colors: active) {
    .section-index.on-this-page {
      background: Canvas;
      border-color: GrayText;
    }
    .section-index.on-this-page a {
      background: Canvas;
      border-color: GrayText;
    }
    .cert-card {
      background: Canvas;
      border-color: GrayText;
      box-shadow: none;
    }
    .status {
      border: 1px solid ButtonText;
      background: ButtonFace;
      color: ButtonText;
    }
    .btn.outline {
      background: ButtonFace;
      color: ButtonText;
      border: 1px solid ButtonText;
      box-shadow: none;
    }
    .table-wrap {
      border-color: GrayText;
    }
    .methods-table thead th {
      background: Canvas;
    }
    #faq details {
      background: Canvas;
      border-color: GrayText;
    }
  }

  /* -------------------------------------------------------------------
     Print
     ------------------------------------------------------------------- */
  @media print {
    .hero-certs {
      background: #fff;
      color: #000;
      border-color: #000;
    }
    .section-index.on-this-page {
      display: none;
    }
    .cert-card {
      break-inside: avoid;
    }
    .btn.outline {
      border: 1px solid #000;
      background: #fff;
      color: #000;
      box-shadow: none;
    }
    .methods-table thead th {
      position: static;
    }
  }
}

/* =======================================================================
   Page-confined link styles (kept separate for clarity)
   - No underline on hover/focus; gentle bold feedback.
   ======================================================================= */
@layer certifications-page {
  :where(.hero-certs, .section-index.on-this-page, .certs-section) a {
    text-decoration: none;
  }
  :where(.hero-certs, .section-index.on-this-page, .certs-section) a:hover,
  :where(.hero-certs, .section-index.on-this-page, .certs-section)
    a:focus-visible {
    text-decoration: none !important;
    font-weight: 600;
  }
  /* Optional consistency for links that appear elsewhere inside <main> on this page */
  main a:hover,
  main a:focus-visible {
    text-decoration: none !important;
    font-weight: 600;
  }
}
