:root {
    color-scheme: light;
    --navy: #0B2545;
    --navy-deep: #0F3060;
    --ink: #1C2E4A;
    --ink-soft: #5A6A7E;
    --paper: #F8F6F0;
    --paper-raised: #FFFFFF;
    --line: #E2DDD4;
    --brass: #C49A2A;
    --brass-deep: #9C7C1F;
    --teal: #0F6E56;
    --safety: #C1501F;
    --good: #2F6B4F;
    --good-bg: #E7F0EA;
    --bad: #9C3A34;
    --bad-bg: #F5E7E4;
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  * { box-sizing: border-box; }
  html { scroll-padding-top: env(safe-area-inset-top, 0px); }
  html, body { height: 100%; }
  body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
  }

  .masthead {
    background: var(--navy-deep);
    padding: 3.2rem 1.5rem 2.6rem;
    flex-shrink: 0;
  }
  .masthead-inner {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
  }
  .kicker {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--brass);
    margin: 0 0 0.6rem;
  }
  .masthead h1 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.8rem, 4.5vw, 2.6rem);
    line-height: 1.15;
    margin: 0 0 0.55rem;
    letter-spacing: -0.01em;
    color: #FFFFFF;
  }
  .masthead .sub {
    color: #C7CEDB;
    font-size: 0.98rem;
    line-height: 1.55;
    margin: 0;
    max-width: 46ch;
    margin-inline: auto;
  }

  main {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 2.2rem 1.5rem 4rem;
    flex-shrink: 0;
  }

  .search-wrap { position: relative; }
  .search-box {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--paper-raised);
    border: 1.5px solid var(--line);
    border-radius: 3px;
    padding: 0.2rem 0.2rem 0.2rem 1rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .search-box:focus-within {
    border-color: var(--brass);
    box-shadow: 0 0 0 3px rgba(181, 132, 42, 0.14);
  }
  .search-box svg { flex: none; color: var(--ink-soft); }
  #q {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: 1.05rem;
    padding: 0.85rem 0;
    color: var(--ink);
    min-width: 0;
  }
  #q::placeholder { color: #93897a; }
  #clear {
    display: none;
    border: none;
    background: var(--line);
    color: var(--ink);
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 0.95rem;
    cursor: pointer;
    flex: none;
  }
  #clear.show { display: block; }
  #searchBtn {
    flex: none;
    border: none;
    background: var(--ink);
    color: var(--paper-raised);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.72rem 1.3rem;
    border-radius: 2px;
    cursor: pointer;
  }
  #searchBtn:hover { background: var(--brass-deep); }

  .hint-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: var(--ink-soft);
  }
  .hint-row span:last-child { font-family: var(--font-mono); }

  .status-line {
    margin: 2.2rem 0 0.9rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    min-height: 1.2em;
  }

  .results { list-style: none; margin: 0; padding: 0; }
  .result-card {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 1.05rem 1.2rem;
    margin-bottom: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }
  .result-main { min-width: 0; }
  .result-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.12rem;
    margin: 0 0 0.3rem;
    color: var(--ink);
  }
  .result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.7rem;
    align-items: center;
    font-size: 0.82rem;
    color: var(--ink-soft);
  }
  .aff-num {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    color: var(--ink);
  }
  .category-tag {
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    color: var(--brass-deep);
  }
  .badge {
    flex: none;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    white-space: nowrap;
  }
  .badge.active { color: var(--good); background: var(--good-bg); }
  .badge.deleted { color: var(--bad); background: var(--bad-bg); }

  mark {
    background: rgba(181, 132, 42, 0.28);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
  }

  .empty-state, .idle-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--ink-soft);
  }
  .empty-state h3, .idle-state h3 {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--ink);
    font-size: 1.2rem;
    margin: 0 0 0.5rem;
  }
  .empty-state p, .idle-state p { margin: 0; font-size: 0.92rem; line-height: 1.5; max-width: 38ch; margin-inline: auto; }
  .idle-icon, .empty-icon {
    width: 44px; height: 44px;
    margin: 0 auto 1rem;
    color: var(--line);
  }

  /* ---------- Top navigation ---------- */
  .topnav {
    background: var(--navy);
    padding: 0.6rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.6rem;
  }
  .topnav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #FFFFFF;
    text-decoration: none;
    flex: none;
  }
  .topnav-brand svg { flex: none; }
  .nav-logo-img { width: var(--nav-logo-desktop, 120px); height: auto; display: block; }
  @media (max-width: 640px) {
    .nav-logo-img { width: var(--nav-logo-mobile, 160px); }
  }
  .topnav-brand span {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.02rem;
    color: #FFFFFF;
  }
  .topnav-links {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    flex-wrap: wrap;
    padding: 0.8rem 0;
  }
  .topnav-links > a, .topnav-links > .nav-dropdown > button {
    font-size: 0.86rem;
    font-weight: 500;
    color: #FFFFFF;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0 0 3px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .topnav-links > a.active, .topnav-links > .nav-dropdown > button.active {
    color: var(--brass);
    border-bottom-color: var(--brass);
  }
  .nav-dropdown { position: relative; }
  .nav-dropdown-panel {
    display: none;
    position: absolute;
    top: 30px;
    left: -16px;
    background: #FFFFFF;
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 10px 28px rgba(11,38,68,0.22);
    min-width: 260px;
    padding: 6px;
    z-index: 40;
  }
  .nav-dropdown.open .nav-dropdown-panel { display: block; }
  .nav-dropdown-panel a {
    display: block;
    padding: 9px 14px;
    font-size: 0.82rem;
    color: var(--ink);
    text-decoration: none;
    border-radius: 3px;
  }
  .nav-dropdown-panel a:hover { background: var(--paper); }
  .nav-dropdown-panel a.active { color: var(--brass-deep); font-weight: 600; }
  .nav-dropdown-divider { height: 1px; background: #EEE9DA; margin: 5px 8px; }

  /* ---------- Page header (interior pages) ---------- */
  .page-header {
    background: var(--navy-deep);
    padding: 2.2rem 1.5rem;
    flex-shrink: 0;
  }
  .page-header-inner { max-width: 900px; margin: 0 auto; }
  .breadcrumb {
    font-size: 0.72rem;
    color: #E8C96A;
    margin: 0 0 0.5rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }
  .page-header h1 {
    color: #FFFFFF;
    margin: 0;
    font-size: clamp(1.6rem, 4vw, 2.1rem);
  }

  /* ---------- Content pages ---------- */
  .content-main { width: 100%; max-width: 900px; margin: 0 auto; padding: 2.8rem 1.5rem 5rem; flex-shrink: 0; }

  @media (max-width: 640px) {
    main, .masthead-inner, .content-main, .page-header-inner {
      width: 95%;
      max-width: 95%;
      margin-left: auto;
      margin-right: auto;
      padding-left: 0;
      padding-right: 0;
    }
  }
  .content-card {
    background: var(--paper-raised);
    border-left: 4px solid var(--brass);
    border-radius: 3px;
    padding: 1.3rem 1.5rem;
    margin-bottom: 1rem;
  }
  .content-card p { font-size: 0.95rem; line-height: 1.7; margin: 0; color: var(--ink); }
  .content-main > p { font-size: 0.95rem; line-height: 1.75; margin: 0 0 1.1rem; }
  .content-main h2 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.2rem;
    margin: 1.8rem 0 0.6rem;
    color: var(--navy-deep);
  }
  .dark-box {
    background: var(--navy);
    border-radius: 3px;
    padding: 1.4rem 1.6rem;
    margin: 1.2rem 0;
  }
  .dark-box p { color: #C7CEDB; font-size: 0.9rem; margin: 0 0 0.3rem; }
  .dark-box a { color: var(--brass); }
  .dark-box strong { color: #FFFFFF; }
  .motto-box {
    background: var(--navy);
    border-radius: 3px;
    padding: 1.6rem;
    text-align: center;
    margin-top: 1rem;
  }
  .motto-box p {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 600;
    font-size: 1.15rem;
    color: var(--brass);
    margin: 0;
  }
  .download-row {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-left: 4px solid var(--brass);
    border-radius: 4px;
    padding: 0.9rem 1.1rem;
    margin-bottom: 0.7rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
  }
  .download-row .block-button-link { flex: none; }
  .download-row .dl-title { font-weight: 600; font-size: 0.92rem; }
  .download-row .dl-note { font-size: 0.78rem; color: var(--ink-soft); margin-top: 3px; }
  .download-btn {
    background: var(--navy);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.76rem;
    letter-spacing: 0.03em;
    padding: 0.55rem 1rem;
    border-radius: 3px;
    text-decoration: none;
    white-space: nowrap;
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.15s ease, transform 0.1s ease;
  }
  .download-btn:hover, .download-btn:focus-visible { background: var(--brass-deep); }
  .download-btn:active { transform: translateY(1px); }

  /* ---------- Button block (Pages editor) ---------- */
  .block-button-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--navy);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.7rem 1.3rem;
    border-radius: 3px;
    text-decoration: none;
    transition: background-color 0.15s ease, transform 0.1s ease;
  }
  .block-button-link:hover, .block-button-link:focus-visible { background: var(--brass-deep); }
  .block-button-link:active { transform: translateY(1px); }

  /* ---------- Inline links within block text ---------- */
  .block-inline-link {
    color: var(--brass-deep);
    text-decoration: underline;
    text-decoration-color: rgba(156,124,31,0.35);
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
  }
  .block-inline-link:hover, .block-inline-link:focus-visible {
    color: var(--navy-deep);
    text-decoration-color: currentColor;
  }
  /* Document/resource links (PDFs, external pages) use teal, matching the
     real site's distinct color for these vs. plain contact links. */
  .block-inline-link-doc {
    color: var(--teal);
    text-decoration: underline;
    text-decoration-color: rgba(15,110,86,0.35);
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
  }
  .block-inline-link-doc:hover, .block-inline-link-doc:focus-visible {
    color: var(--brass-deep);
    text-decoration-color: currentColor;
  }
  .pending-note { font-size: 0.78rem; color: #8A8272; font-style: italic; white-space: nowrap; }

  /* ---------- Certification cards ---------- */
  .cert-group { margin-bottom: 1.8rem; }
  .cert-group-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--brass-deep);
  }
  .cert-group-rule { width: 32px; height: 2px; background: var(--brass); margin: 0.4rem 0 0.9rem; }
  .cert-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0.8rem; }
  .cert-card { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 3px; padding: 1rem 1.1rem; }
  .cert-code {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    color: #FFFFFF;
    background: var(--navy);
    padding: 3px 8px;
    border-radius: 2px;
    margin-bottom: 0.5rem;
  }
  .cert-card h3 { font-family: var(--font-display); font-weight: 600; font-size: 0.98rem; margin: 0 0 0.4rem; }
  .cert-card p { font-size: 0.82rem; line-height: 1.55; color: var(--ink-soft); margin: 0; }
  .cert-summary-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.7rem 1.1rem; border-bottom: 1px solid var(--line);
    background: var(--paper-raised); font-size: 0.88rem;
  }
  .cert-summary-row:last-child { border-bottom: none; }
  .cert-summary-row .cert-code { margin: 0; }

  /* ---------- Directory (Training Centers / National Offices) ---------- */
  .directory-toolbar { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
  .directory-toolbar input, .directory-toolbar select {
    font-family: var(--font-body);
    font-size: 0.86rem;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid var(--line);
    border-radius: 3px;
    background: var(--paper-raised);
    color: var(--ink);
  }
  .directory-toolbar input { flex: 1; min-width: 200px; }
  .directory-count { font-size: 0.78rem; color: var(--ink-soft); margin: 0.6rem 0 1.2rem; }
  .directory-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1.1rem; }
  .directory-card {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-top: 3px solid var(--brass);
    border-radius: 4px;
    padding: 1.1rem 1.2rem;
  }
  .directory-tag {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--brass-deep);
  }
  .directory-logo {
    width: 100%; height: 70px;
    border-radius: 3px;
    background: var(--navy);
    display: flex; align-items: center; justify-content: center;
    margin: 0.6rem 0;
    overflow: hidden;
  }
  .directory-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
  .directory-logo span { color: var(--brass); font-family: var(--font-display); font-weight: 700; font-size: 0.85rem; }
  .directory-card h3 { font-family: var(--font-display); font-weight: 600; font-size: 1rem; margin: 0 0 0.4rem; }
  .directory-meta { font-size: 0.78rem; color: var(--ink-soft); line-height: 1.6; }
  .directory-meta a { color: var(--brass-deep); }
  /* Training Centers: larger logos and the card styling used on worldsafety.org */
  .directory-grid.tc-grid { grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 1.25rem; }
  .tc-card { padding: 1.4rem 1.2rem 1.5rem; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,0.07); }
  .tc-card .tc-tag {
    display: block;
    font-family: var(--font-body);
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--brass);
  }
  .tc-card .tc-rule { width: 40px; height: 2px; background: var(--brass); margin: 0.6rem 0 1.1rem; }
  .tc-card .tc-logo { display: block; width: 100%; height: auto; max-height: 260px; object-fit: contain; border-radius: 6px; margin: 0 0 1rem; }
  .tc-card h3 {
    font-family: var(--font-body); font-weight: 600; font-size: 1rem;
    letter-spacing: 0.1em; text-transform: uppercase; line-height: 1.6;
    color: var(--brass); margin: 0 0 0.5rem;
  }
  .tc-card .tc-contact { font-weight: 600; font-size: 1rem; color: var(--ink); margin: 0 0 0.5rem; }
  .tc-card .tc-line { font-size: 0.85rem; color: var(--ink-soft); margin: 0 0 0.55rem; overflow-wrap: anywhere; }
  .tc-card .tc-line a { color: var(--teal); text-decoration: underline; }
  .tc-card .tc-line a.tc-phone { color: var(--ink-soft); }
  .tc-card .tc-line a:hover { color: var(--brass-deep); }
  /* Fact sheet illustration: the whole card opens the PDF */
  .fs-pdf-link, .fs-pdf-link:hover { display: block; color: inherit; text-decoration: none; border-radius: 3px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12); transition: box-shadow 0.3s ease; }
  .fs-pdf-link:hover, .fs-pdf-link:focus-visible { box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
  .fs-pdf-link:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }
  .fs-pdf-caption { text-align: center; color: var(--ink-soft); font-size: 0.85rem; font-style: italic; margin: 12px 0 0; }

  .directory-empty { text-align: center; padding: 3rem 1.5rem; color: var(--ink-soft); grid-column: 1 / -1; }

  @media (max-width: 900px) {
    .directory-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .cert-grid { grid-template-columns: 1fr; }
  }
  @media (max-width: 640px) {
    .directory-grid { grid-template-columns: 1fr; }
    .topnav { height: auto; padding: 0.8rem 1.2rem; }
  }

  /* ---------- Page blocks (admin-editable content) ---------- */
  .block-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin: 1.2rem 0;
  }
  .block-item { grid-column: span var(--dcols, 1); }
  @media (max-width: 640px) {
    .block-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .block-item { grid-column: span var(--mcols, 1); }
  }
  .block-image-link { display: block; }

  /* ---------- Lightbox ---------- */
  .lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 38, 68, 0.9);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 2rem;
  }
  .lightbox-overlay.open { display: flex; }
  .lightbox-overlay img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 4px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  }
  .lightbox-close {
    position: absolute;
    top: 1.2rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #FFFFFF;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
  }

  /* ---------- Bottom mobile nav ---------- */
  .mobile-bottom-nav {
    display: none;
  }
  @media (max-width: 640px) {
    .mobile-bottom-nav {
      display: flex;
      position: fixed;
      bottom: 0; left: 0; right: 0;
      height: 64px;
      background: #FFFFFF;
      border-top: 1px solid var(--line);
      align-items: center;
      justify-content: space-between;
      padding: 0 2px calc(6px + env(safe-area-inset-bottom, 0px));
      z-index: 100;
    }
    .mobile-bottom-nav a {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      text-decoration: none;
      color: #8A9099;
      font-size: 9px;
      font-weight: 500;
      padding-top: 8px;
    }
    .mobile-bottom-nav a.active { color: var(--brass); font-weight: 600; }
    .mobile-bottom-nav .icon { display: flex; }
    .mobile-bottom-nav .icon svg { width: 19px; height: 19px; }
    /* leave room so the fixed bar never covers page content */
    body { padding-bottom: 64px; }
  }

  @media (max-width: 640px) {
    .topnav-links { display: none; }
  }

  footer:not(.site-footer) {
    border-top: 1px solid var(--line);
    padding: 1.6rem 1.5rem 2.4rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--ink-soft);
    flex-shrink: 0;
  }
  footer:not(.site-footer) strong { color: var(--ink); font-weight: 600; }

  /* ---------- Menu list (Membership/Certification mobile menu pages) ---------- */
  .menu-group-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--brass-deep);
    margin: 0 0 0.5rem;
  }
  .menu-list { margin: 0 0 1.8rem; }
  .menu-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
    font-size: 0.95rem;
  }
  .menu-list a:last-child { border-bottom: none; }
  .menu-list a .chevron { color: #B7AF9C; }

  .footer-logo-img { width: var(--footer-logo-desktop, 260px); height: auto; display: block; }
  @media (max-width: 640px) {
    .footer-logo-img { width: var(--footer-logo-mobile, 160px); }
  }

  .site-footer { width: 100%; margin-top: auto; flex-shrink: 0; }

  @media (max-width: 480px) {
    .result-card { flex-direction: column; align-items: flex-start; }
    .badge { align-self: flex-start; }
  }
