/* Match /admin/dashboard/ chrome: 52px primary + compact secondary, no blank band.
     Legacy pages used header{position:fixed} + body{padding-top:70px} — kill that.
     portal.css still styles bare `header`/`nav a`/`section` — beat those here. */
  html body { padding-top: 0 !important; margin-top: 0 !important; }
  /* !important guards: legacy per-page CSS styles bare `header` elements */
  header.pqa-header,
  header.header,
  .pqa-header {
    background: #fff !important;
    color: #0f172a !important;
    border-bottom: 1px solid #e2e8f0 !important;
    box-shadow: 0 1px 3px rgba(15,23,42,.06) !important;
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    right: auto !important;
    z-index: 100 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 0 -1px 0 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }
  header.pqa-header { position: sticky !important; top: 0 !important; }
  .pqa-header * { box-sizing: border-box; }
  /* Admin dashboard parity: 52px bar, 16px side padding, tight gaps */
  .pqa-bar,
  header.header > .header-content,
  .header .header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px !important;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    height: 52px !important;
    min-height: 52px !important;
    max-height: 52px !important;
    box-sizing: border-box !important;
  }
  .pqa-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #0f172a; flex: 0 0 auto; }
  .pqa-mark {
    width: 32px; height: 32px; background: #0a66c2; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 16px;
  }
  .pqa-word { line-height: 1; }
  .pqa-word b { display: block; font-size: 16px; font-weight: 700; }
  .pqa-word span { display: block; font-size: 11px; color: #0a66c2; font-weight: 600; letter-spacing: .5px; }
  .pqa-ver { font-size: 11px; color: #64748b; font-weight: 500; white-space: nowrap; flex: 0 0 auto; }
  .pqa-country { position: relative; flex: 0 0 auto; }
  .pqa-country-btn {
    display: flex; align-items: center; gap: 6px; background: #fff;
    border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px 8px;
    font-size: 12px; font-weight: 600; color: #334155; cursor: pointer; font-family: inherit;
  }
  .pqa-country-dd {
    position: absolute; top: 110%; left: 0; background: #fff; border: 1px solid #e2e8f0;
    border-radius: 8px; box-shadow: 0 4px 12px rgba(15,23,42,.1); min-width: 170px; display: none; z-index: 1000;
  }
  .pqa-country-dd.active { display: block; }
  .pqa-country-dd .pqa-copt { display: flex; gap: 8px; padding: 9px 12px; font-size: 12px; color: #334155; cursor: pointer; }
  .pqa-country-dd .pqa-copt:hover { background: #f1f5f9; }
  /* Nav tight like admin — never space-between across full width */
  .pqa-nav {
    display: inline-flex !important;
    align-items: center;
    gap: 0 !important;
    flex: 0 0 auto !important;
    flex-wrap: nowrap;
    margin: 0;
    padding: 0;
    justify-content: flex-start !important;
  }
  .pqa-nav a {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
    padding: 5px 7px;
    text-decoration: none;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    white-space: nowrap;
    transition: background .15s, color .15s;
  }
  .pqa-nav a:hover { background: #f1f5f9; color: #0a66c2; }
  .pqa-nav a.is-active, .pqa-nav a.active { color: #0a66c2; background: #eff6ff; }
  .pqa-auth {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    margin-left: auto;
    flex: 0 0 auto;
  }
  .pqa-signin { padding: 8px 16px; background: #0a66c2; color: #fff !important; border-radius: 6px; font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; }
  .pqa-signin:hover { background: #0052a3; }
  .pqa-register { padding: 8px 16px; background: transparent; color: #0a66c2 !important; border: 1px solid #0a66c2; border-radius: 6px; font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; }
  .pqa-register:hover { background: #eff6ff; }
  #auth-buttons { display: none; align-items: center; gap: 8px; }
  html.pqa-is-guest #auth-buttons { display: flex; }
  html.pqa-auth-in #auth-buttons,
  html.pqa-is-signed-in #auth-buttons,
  html:not(.pqa-is-guest) #auth-buttons { display: none !important; }
  #user-info { display: none; align-items: center; gap: 8px; position: relative; }
  #user-info.is-on,
  html.pqa-auth-in #user-info,
  html.pqa-is-signed-in #user-info { display: flex; }
  .pqa-user-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 999px;
    padding: 3px 10px 3px 3px; cursor: pointer; font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
  }
  .pqa-user-btn:hover, .pqa-user-btn[aria-expanded="true"] {
    border-color: #0a66c2; box-shadow: 0 0 0 3px rgba(10,102,194,.12);
  }
  .pqa-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, #0a66c2, #004182);
    color: #fff; display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; flex-shrink: 0; text-transform: uppercase;
  }
  .pqa-role-badge {
    font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: #0a66c2; background: #eff6ff; border-radius: 999px; padding: 3px 8px; white-space: nowrap;
  }
  .pqa-role-badge.role-admin { background: #fef2f2; color: #dc2626; }
  .pqa-role-badge.role-manager { background: #fffbeb; color: #d97706; }
  .pqa-role-badge.role-viewer { background: #f1f5f9; color: #475569; }
  .pqa-user-caret { font-size: 9px; color: #64748b; margin-right: 2px; }
  .pqa-user-dd {
    display: none; position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 220px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15,23,42,.12); z-index: 1100; overflow: hidden;
  }
  .pqa-user-dd.open { display: block; }
  .pqa-user-meta { padding: 12px 14px; border-bottom: 1px solid #e2e8f0; }
  .pqa-user-meta #user-name { font-weight: 700; font-size: 13px; color: #0f172a; }
  .pqa-user-meta #user-email { font-size: 11px; color: #64748b; margin-top: 2px; word-break: break-all; }
  .pqa-user-dd a, .pqa-user-dd button.pqa-dd-item {
    display: block; width: 100%; text-align: left; padding: 10px 14px;
    font: inherit; font-size: 13px; font-weight: 500; color: #334155;
    text-decoration: none; background: none; border: none; cursor: pointer;
  }
  .pqa-user-dd a:hover, .pqa-user-dd button.pqa-dd-item:hover { background: #f1f5f9; color: #0a66c2; }
  .pqa-user-dd .pqa-dd-divider { height: 1px; background: #e2e8f0; margin: 4px 0; }
  /* Admin shortcut — visible only when signed in as admin/manager */
  .pqa-admin-icon {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    text-decoration: none;
    flex-shrink: 0;
    transition: background .15s, box-shadow .15s, transform .15s;
  }
  .pqa-admin-icon.is-on { display: inline-flex; }
  .pqa-admin-icon:hover {
    background: #fee2e2;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
    transform: translateY(-1px);
  }
  .pqa-admin-icon:focus-visible {
    outline: 2px solid #dc2626;
    outline-offset: 2px;
  }
  .pqa-admin-icon svg { width: 18px; height: 18px; display: block; }
  /* Demo mode toggle next to admin icon */
  .pqa-demo-toggle {
    display: none;
    align-items: center;
    gap: 0;
    height: 36px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #64748b;
    font: inherit;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  }
  .pqa-demo-toggle.is-on { display: inline-flex; }
  .pqa-demo-toggle[aria-pressed="true"] {
    background: #fef3c7;
    border-color: #fbbf24;
    color: #b45309;
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.2);
  }
  .pqa-demo-toggle:hover { border-color: #0a66c2; color: #0a66c2; }
  .pqa-demo-toggle[aria-pressed="true"]:hover { border-color: #d97706; color: #92400e; }
  body.pqa-demo-mode::after {
    content: "DEMO · max 5 results";
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 9999;
    background: #f59e0b;
    color: #fff;
    font: 700 11px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0.04em;
    padding: 8px 12px;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
    pointer-events: none;
  }
  /* Admin view-as exit bar (always available while previewing) */
  .pqa-viewas-bar {
    display: none;
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 10000;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #0f172a;
    color: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(15,23,42,.35);
    font: 600 12px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    max-width: min(420px, calc(100vw - 24px));
  }
  .pqa-viewas-bar.is-on { display: flex; flex-wrap: wrap; }
  .pqa-viewas-bar strong { color: #fbbf24; }
  .pqa-viewas-bar button {
    border: none; border-radius: 8px; padding: 7px 10px; cursor: pointer;
    font: inherit; font-weight: 700; font-size: 11px; letter-spacing: .03em;
    background: #fbbf24; color: #0f172a;
  }
  .pqa-viewas-bar button:hover { background: #f59e0b; }
  .pqa-viewas-bar a {
    color: #93c5fd; font-weight: 700; text-decoration: none; font-size: 11px;
  }
  .pqa-viewas-bar a:hover { text-decoration: underline; }
  .pqa-user-dd .pqa-viewas-label {
    padding: 8px 14px 4px; font-size: 10px; font-weight: 700;
    letter-spacing: .06em; text-transform: uppercase; color: #94a3b8;
  }
  .pqa-user-dd button.pqa-dd-item.is-active {
    background: #eff6ff; color: #0a66c2; font-weight: 700;
  }
  .pqa-menu-toggle {
    display: none; background: none; border: 1px solid #cbd5e1; border-radius: 6px;
    padding: 7px 10px; cursor: pointer; font-size: 17px; line-height: 1; color: #334155;
  }
  @media (max-width: 900px) {
    .pqa-bar,
    header.header > .header-content,
    .header .header-content {
      flex-wrap: wrap;
      height: auto !important;
      max-height: none !important;
      min-height: 52px !important;
      padding: 8px 16px !important;
    }
    .pqa-menu-toggle { display: inline-flex; margin-left: auto; }
    .pqa-nav {
      display: none !important;
      width: 100%;
      flex-direction: column;
      align-items: stretch;
      margin-left: 0;
      flex-wrap: wrap;
    }
    .pqa-nav.open { display: flex !important; }
    .pqa-nav a { padding: 11px 12px; }
    .pqa-auth { margin-left: 0; }
  }
  /* Owner bar only on /admin/ — never on the public homepage or role desks */
  body:not(.pqa-owner-bar) .pqa-subnav-wrap { display: none !important; }
  .pqa-subnav-wrap { top: 52px !important; }
  .pqa-ternav-wrap { top: 52px !important; }
  body.pqa-owner-bar .pqa-ternav-wrap { top: 84px !important; }
  .phase-filter-sticky { top: 52px !important; }
  body.pqa-owner-bar .phase-filter-sticky { top: 84px !important; }
  body.pqa-owner-bar.pqa-on-tenders .phase-filter-sticky,
  body.pqa-owner-bar.pqa-on-grants .phase-filter-sticky,
  body.pqa-owner-bar.pqa-on-panels .phase-filter-sticky { top: 116px !important; }

  /* Content hugs the sticky chrome — same 8px as /admin/dashboard/ main */
  html body > main,
  html body > #main-content,
  html body > .tenders-container,
  html body > .buyers-wrap,
  html body > .suppliers-main,
  html body > .pipeline-main,
  html body > .services-container,
  html body > .legal-wrap,
  html body > .rdash,
  html body > .dash,
  .pqa-subnav-wrap + main,
  .pqa-subnav-wrap + #main-content,
  .pqa-subnav-wrap + .tenders-container,
  .pqa-subnav-wrap + .buyers-wrap,
  .pqa-subnav-wrap + .suppliers-main,
  .pqa-subnav-wrap + .services-container,
  .pqa-subnav-wrap + .legal-wrap,
  .pqa-ternav-wrap + main,
  .pqa-ternav-wrap + #main-content,
  .pqa-ternav-wrap + .tenders-container,
  header.header + main,
  .pqa-header + main,
  .pqa-header + #main-content {
    padding-top: 8px !important;
    margin-top: 0 !important;
  }
