/*
  Group Policy Search proof-of-concept styles.

  This file contains only presentation concerns. The HTML file owns the document
  structure, and gp-policy-search-poc.js owns all behavior and data loading.

  Organization:
  1. Design tokens and themes
  2. Base layout and typography
  3. Search/header controls
  4. Three-column application workspace
  5. Tree, result list, and policy detail components
  6. Utility states, responsive behavior, and footer
*/
/* Design tokens: shared colors, spacing, typography, and radius values. */
    :root {
      --bg: #f5f7fb;
      --surface: #ffffff;
      --surface-2: #edf4ff;
      --surface-3: #eef2f7;
      --text: #162033;
      --muted: #617089;
      --line: #d6deea;
      --brand: #2563eb;
      --brand-2: #0f6cbd;
      --ok: #107c10;
      --warn: #b45309;
      --danger: #b42318;
      --shadow: 0 20px 60px rgb(15 23 42 / 12%);
      --radius-xl: 28px;
      --radius-lg: 20px;
      --radius-md: 14px;
      --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
      --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    }

    /* System dark-mode defaults; explicit user choice below overrides these tokens. */
    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #0d1424;
        --surface: #121c2f;
        --surface-2: #102545;
        --surface-3: #1a2638;
        --text: #f3f7ff;
        --muted: #aab8ce;
        --line: #28384f;
        --brand: #78a9ff;
        --brand-2: #64b5f6;
        --ok: #7ee787;
        --warn: #f7c873;
        --danger: #ffb4ab;
        --shadow: 0 20px 60px rgb(0 0 0 / 38%);
      }
    }

    /* User-selected light theme persisted in localStorage. */
    html[data-theme="light"] {
      --bg: #f5f7fb;
      --surface: #ffffff;
      --surface-2: #edf4ff;
      --surface-3: #eef2f7;
      --text: #162033;
      --muted: #617089;
      --line: #d6deea;
      --brand: #2563eb;
      --brand-2: #0f6cbd;
      --ok: #107c10;
      --warn: #b45309;
      --danger: #b42318;
      --shadow: 0 20px 60px rgb(15 23 42 / 12%);
    }

    /* User-selected dark theme persisted in localStorage. */
    html[data-theme="dark"] {
      --bg: #0d1424;
      --surface: #121c2f;
      --surface-2: #102545;
      --surface-3: #1a2638;
      --text: #f3f7ff;
      --muted: #aab8ce;
      --line: #28384f;
      --brand: #78a9ff;
      --brand-2: #64b5f6;
      --ok: #7ee787;
      --warn: #f7c873;
      --danger: #ffb4ab;
      --shadow: 0 20px 60px rgb(0 0 0 / 38%);
    }

    /* Base element normalization. */
    * { box-sizing: border-box; }

    body {
      margin: 0;
      background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 34%), var(--bg);
      color: var(--text);
      font-family: var(--font);
      line-height: 1.45;
    }

    button,
    input,
    select { font: inherit; }

    button { cursor: pointer; }

    /* Main page container. */
    .app {
      inline-size: min(2200px, calc(100% - 32px));
      margin-inline: auto;
      padding-block: 28px 56px;
    }

    /* Header/search area at the top of the page. */
    .hero {
      display: grid;
      grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
      gap: 18px;
      margin-block-end: 18px;
    }

    .card,
    .panel {
      border: 1px solid var(--line);
      border-radius: var(--radius-xl);
      background: color-mix(in srgb, var(--surface) 94%, transparent);
      box-shadow: var(--shadow);
    }

    .card { padding: clamp(22px, 4vw, 38px); }

    .eyebrow {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      margin-block-end: 16px;
      color: var(--brand-2);
      font-size: 13px;
      font-weight: 800;
      letter-spacing: .08em;
      text-transform: uppercase;
    }

    h1,
    h2,
    h3,
    p { margin-block-start: 0; }

    h1 {
      max-inline-size: 880px;
      margin-block-end: 12px;
      font-size: clamp(34px, 5vw, 58px);
      line-height: 1.02;
      letter-spacing: -.055em;
    }

    h2 {
      margin-block-end: 10px;
      font-size: clamp(22px, 2.4vw, 32px);
      letter-spacing: -.035em;
    }

    h3 {
      margin-block-end: 8px;
      font-size: 17px;
      letter-spacing: -.018em;
    }

    .lead {
      max-inline-size: 790px;
      color: var(--muted);
      font-size: clamp(16px, 1.7vw, 19px);
    }

    /* Search form: keyword input, language picker, and submit button. */
    .query-grid {
      display: grid;
      grid-template-columns: minmax(220px, 1fr) 210px 160px;
      gap: 10px;
      margin-block-start: 24px;
      padding: 10px;
      border: 1px solid var(--line);
      border-radius: 22px;
      background: var(--surface);
    }

    .hero-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin-block-start: 12px;
    }

    .theme-toggle {
      border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
      background: color-mix(in srgb, var(--brand) 9%, var(--surface));
      color: var(--text);
    }

    .field {
      inline-size: 100%;
      min-block-size: 52px;
      border: 1px solid transparent;
      border-radius: 15px;
      padding-inline: 14px;
      background: var(--surface-3);
      color: var(--text);
      outline: none;
    }

    .field:focus {
      border-color: var(--brand);
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
    }

    .primary {
      min-block-size: 52px;
      border: 0;
      border-radius: 15px;
      padding-inline: 18px;
      background: var(--brand);
      color: white;
      font-weight: 800;
    }

    .primary[disabled] {
      cursor: progress;
      opacity: .76;
    }

    .primary.searching::before {
      content: "";
      display: inline-block;
      inline-size: 12px;
      block-size: 12px;
      margin-inline-end: 8px;
      border: 2px solid rgb(255 255 255 / 45%);
      border-block-start-color: #fff;
      border-radius: 999px;
      vertical-align: -2px;
      animation: spin .8s linear infinite;
    }

    .ghost {
      border: 1px solid var(--line);
      border-radius: 12px;
      padding-block: 8px;
      padding-inline: 11px;
      background: var(--surface);
      color: var(--text);
      font-size: 13px;
      font-weight: 750;
    }

    .ghost:hover,
    .primary:hover { filter: brightness(0.98); }

    .ghost.active {
      border-color: color-mix(in srgb, var(--brand) 65%, var(--line));
      background: var(--brand);
      color: white;
    }

    .status-card {
      display: grid;
      gap: 14px;
      padding: 24px;
    }

    .status-line {
      display: grid;
      grid-template-columns: 34px 1fr;
      gap: 12px;
      align-items: start;
    }

    .dot {
      display: grid;
      place-items: center;
      inline-size: 34px;
      block-size: 34px;
      border-radius: 12px;
      background: var(--surface-2);
      color: var(--brand-2);
      font-weight: 900;
    }

    .muted { color: var(--muted); }

    /* Main work area: category tree, result list, and policy detail pane. */
    .workspace {
      display: grid;
      grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1fr) minmax(560px, 1.45fr);
      gap: clamp(14px, 1.2vw, 24px);
      padding: 14px;
      border: 1px solid var(--line);
      border-radius: 30px;
      background: color-mix(in srgb, var(--surface-2) 66%, var(--surface));
      box-shadow: var(--shadow);
    }

    .panel {
      min-block-size: 730px;
      padding: 16px;
      border-radius: 22px;
      box-shadow: none;
      min-inline-size: 0;
      overflow: hidden;
    }

    .panel-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-block-end: 14px;
    }

    .label {
      color: var(--muted);
      font-size: 12px;
      font-weight: 850;
      letter-spacing: .07em;
      text-transform: uppercase;
    }

    .badge,
    .pill {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      border-radius: 999px;
      padding-block: 5px;
      padding-inline: 9px;
      background: var(--surface-3);
      color: var(--muted);
      font-size: 12px;
      font-weight: 750;
      white-space: nowrap;
    }

    .badge.ok { color: var(--ok); }
    .badge.warn { color: var(--warn); }
    .badge.danger { color: var(--danger); }

    .list {
      display: grid;
      gap: 10px;
      margin: 0;
      padding: 0;
      list-style: none;
    }

    /* Shared card styles for tree entries, result cards, and detail blocks. */
    .category,
    .result,
    /* Right-side detail cards. Cards with data-copy-detail are clickable copy targets. */
    .detail-card,
    .filter-card {
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      background: var(--surface);
    }

    .category,
    /* Policy result cards in the center pane. */
    .result {
      display: grid;
      inline-size: 100%;
      color: var(--text);
      text-align: start;
    }

    /* Category tree rows. */
    .category {
      grid-template-columns: 1fr auto;
      gap: 10px;
      align-items: center;
      padding: 12px;
    }

    .category:hover,
    .category.active,
    .result:hover,
    .result.active {
      border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
      background: var(--surface-2);
    }

    .category.selected {
      border-color: color-mix(in srgb, var(--brand) 72%, var(--line));
      background: color-mix(in srgb, var(--brand) 18%, var(--surface));
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
    }

    .result.selected {
      border-color: color-mix(in srgb, var(--brand) 72%, var(--line));
      background: color-mix(in srgb, var(--brand) 14%, var(--surface));
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
    }

    .category small {
      display: block;
      margin-block-start: 2px;
      color: var(--muted);
    }

    .chev {
      display: grid;
      place-items: center;
      inline-size: 28px;
      block-size: 28px;
      border-radius: 10px;
      background: var(--surface-3);
      color: var(--muted);
      font-weight: 900;
    }

    .toolbar {
      display: grid;
      gap: 10px;
      margin-block-end: 12px;
    }

    .row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
    }

    .result {
      gap: 9px;
      padding: 14px;
    }

    /* Compact metadata grid used by result cards and context panels. */
    .policy-meta {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
      gap: 8px;
      inline-size: 100%;
    }

    .policy-meta-item {
      min-inline-size: 0;
      border: 1px solid var(--line);
      border-radius: 12px;
      padding-block: 7px;
      padding-inline: 9px;
      background: var(--surface-3);
    }

    .policy-meta-label {
      display: block;
      margin-block-end: 2px;
      color: var(--muted);
      font-size: 10px;
      font-weight: 850;
      letter-spacing: .06em;
      text-transform: uppercase;
    }

    .policy-meta-value {
      display: block;
      overflow-wrap: anywhere;
      color: var(--text);
      font-size: 12px;
      font-weight: 750;
      line-height: 1.25;
    }

    .result p {
      margin: 0;
      color: var(--muted);
      font-size: 13px;
    }

    .empty,
    .loading {
      display: grid;
      gap: 10px;
      padding: 18px;
      border: 1px dashed var(--line);
      border-radius: var(--radius-lg);
      background: color-mix(in srgb, var(--surface-3) 70%, transparent);
      color: var(--muted);
    }

    .bar {
      block-size: 10px;
      border-radius: 999px;
      background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--brand) 24%, var(--line)), var(--line));
      animation: pulse 1.4s ease-in-out infinite;
    }

    @keyframes pulse {
      0%, 100% { opacity: .55; }
      50% { opacity: 1; }
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }

    mark.search-highlight {
      border-radius: 4px;
      padding-inline: 2px;
      background: #fff176;
      color: #111827;
    }

    /* Right-side policy detail header and HTML description area. */
    .detail-hero {
      display: grid;
      gap: 10px;
      padding: 18px;
      border: 1px solid color-mix(in srgb, var(--brand) 28%, var(--line));
      border-radius: var(--radius-lg);
      background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, var(--surface)), var(--surface));
      min-inline-size: 0;
      max-inline-size: 100%;
      overflow: hidden;
    }

    .policy-description {
      color: var(--muted);
      font-size: 14px;
      min-inline-size: 0;
      max-inline-size: 100%;
      overflow-wrap: anywhere;
      word-break: break-word;
    }

    .policy-description *,
    .policy-description p,
    .policy-description ul,
    .policy-description ol {
      max-inline-size: 100%;
      overflow-wrap: anywhere;
      word-break: break-word;
      margin-block: 0 10px;
    }

    .policy-description table {
      display: block;
      inline-size: 100%;
      max-inline-size: 100%;
      overflow-x: auto;
      border-collapse: collapse;
    }

    .policy-description pre,
    .policy-description code {
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }

    .policy-description img {
      max-inline-size: 100%;
      block-size: auto;
    }

    .policy-description a {
      color: var(--brand-2);
      overflow-wrap: anywhere;
    }

    .actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-block-start: 6px;
    }

    .detail-grid {
      display: grid;
      gap: 10px;
      margin-block-start: 12px;
      min-inline-size: 0;
    }

    @media (min-width: 1500px) {
      .detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .detail-card:nth-child(3) {
        grid-column: 1 / -1;
      }
    }

    @media (min-width: 1800px) {
      .workspace {
        grid-template-columns: minmax(320px, 0.75fr) minmax(460px, 0.95fr) minmax(780px, 1.65fr);
      }
    }

    .detail-card,
    .filter-card,
    .policy-context {
      padding: 13px;
      min-inline-size: 0;
      max-inline-size: 100%;
      overflow: hidden;
    }

    .detail-card[data-copy-detail] {
      cursor: copy;
      transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
      position: relative;
    }

    .detail-card[data-copy-detail]:hover {
      border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
      background: color-mix(in srgb, var(--brand) 8%, var(--surface));
    }

    .detail-card.copied {
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
    }

    .detail-card[data-copy-detail]::after {
      content: "Click to copy";
      color: var(--muted);
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .05em;
    }

    html[lang="de-DE"] .detail-card[data-copy-detail]::after {
      content: "Klicken zum Kopieren";
    }

    .wrap-value {
      display: block;
      max-inline-size: 100%;
      overflow-wrap: anywhere;
      word-break: break-word;
      white-space: normal;
    }

    .detail-card code {
      display: block;
      max-inline-size: 100%;
      overflow-wrap: anywhere;
      white-space: normal;
      line-height: 1.35;
    }

    .policy-context {
      display: grid;
      gap: 8px;
      border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--line));
      border-radius: var(--radius-lg);
      background: color-mix(in srgb, var(--brand) 9%, var(--surface));
    }

    .kv {
      display: grid;
      grid-template-columns: 128px 1fr;
      gap: 10px;
      align-items: start;
      font-size: 13px;
    }

    .filter-list {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
      gap: 8px;
      margin-block-start: 8px;
      max-block-size: 190px;
      overflow: auto;
    }

    .filter-option {
      display: flex;
      gap: 7px;
      align-items: center;
      color: var(--muted);
      font-size: 12px;
    }

    /* Monospace values such as registry keys and registry values. */
    code,
    pre {
      border: 1px solid var(--line);
      border-radius: 9px;
      background: var(--surface-3);
      color: var(--text);
      font-family: var(--mono);
      font-size: 12px;
    }

    code {
      padding-block: 3px;
      padding-inline: 6px;
    }

    pre {
      overflow: auto;
      max-block-size: 190px;
      margin: 0;
      padding: 12px;
      white-space: pre-wrap;
    }

    /* Small explanatory note below the category tree. */
    .footer-note {
      margin-block-start: 16px;
      padding: 14px;
      border: 1px solid var(--line);
      border-radius: var(--radius-md);
      background: var(--surface);
      color: var(--muted);
      font-size: 13px;
    }

    /* Footer links such as Impressum, privacy, downloads, and documentation. */
    .site-footer {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      justify-content: center;
      margin-block-start: 22px;
      color: var(--muted);
      font-size: 13px;
    }

    .site-footer a {
      color: var(--brand-2);
      text-decoration: none;
    }

    .site-footer a:hover {
      text-decoration: underline;
    }

    .footer-button {
      border: 0;
      padding: 0;
      background: transparent;
      color: var(--brand-2);
      font: inherit;
      cursor: pointer;
    }

    .footer-button:hover {
      text-decoration: underline;
    }

    /* Help & About panel: non-blocking slide-out that keeps the main UI context visible. */
    .about-backdrop {
      position: fixed;
      inset: 0;
      z-index: 40;
      background: rgb(15 23 42 / 28%);
      backdrop-filter: blur(2px);
    }

    .about-panel {
      position: fixed;
      inset-block: 0;
      inset-inline-end: 0;
      z-index: 50;
      display: grid;
      align-content: start;
      gap: 18px;
      inline-size: min(440px, 100%);
      padding: 24px;
      overflow: auto;
      border-inline-start: 1px solid var(--line);
      background: var(--surface);
      color: var(--text);
      box-shadow: -24px 0 70px rgb(15 23 42 / 24%);
      transform: translateX(100%);
      transition: transform .22s ease;
    }

    .about-panel.open {
      transform: translateX(0);
    }

    .about-header {
      display: flex;
      align-items: start;
      justify-content: space-between;
      gap: 16px;
    }

    .about-section {
      display: grid;
      gap: 8px;
      padding: 16px;
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      background: color-mix(in srgb, var(--surface-3) 58%, transparent);
    }

    .about-section h3,
    .about-section p {
      margin: 0;
    }

    .about-section ul {
      margin-block: 0;
      padding-inline-start: 20px;
    }

    .about-owner {
      border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
      background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, var(--surface)), var(--surface));
    }

    .owner-badge {
      inline-size: fit-content;
      border-radius: 999px;
      padding-block: 5px;
      padding-inline: 10px;
      background: color-mix(in srgb, var(--brand) 18%, var(--surface));
      color: var(--brand-2);
      font-size: 11px;
      font-weight: 850;
      letter-spacing: .06em;
      text-transform: uppercase;
    }

    .about-links {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
    }

    .about-links a,
    .about-legal a {
      color: var(--brand-2);
      text-decoration: none;
    }

    .about-links a:hover,
    .about-legal a:hover {
      text-decoration: underline;
    }

    .about-legal {
      color: var(--muted);
      font-size: 13px;
    }

    /* Autocomplete suggestion flyout below the search input. */
    .suggestions {
      position: absolute;
      z-index: 20;
      display: none;
      inline-size: min(620px, calc(100vw - 52px));
      margin-block-start: 4px;
      border: 1px solid var(--line);
      border-radius: 16px;
      background: var(--surface);
      box-shadow: var(--shadow);
      overflow: hidden;
    }

    .suggestions button {
      display: block;
      inline-size: 100%;
      border: 0;
      border-block-end: 1px solid var(--line);
      padding-block: 10px;
      padding-inline: 12px;
      background: transparent;
      color: var(--text);
      text-align: start;
    }

    .hidden { display: none !important; }

    /* Responsive layout: collapse the detail pane below the first two columns. */
    @media (max-width: 1220px) {
      .hero { grid-template-columns: 1fr; }
      .workspace { grid-template-columns: 300px 1fr; }
      .detail-panel { grid-column: 1 / -1; min-block-size: auto; }
    }

    /* Responsive layout: single-column mobile/tablet view. */
    @media (max-width: 820px) {
      .query-grid { grid-template-columns: 1fr; }
      .workspace { grid-template-columns: 1fr; }
      .panel { min-block-size: auto; }
      .kv { grid-template-columns: 1fr; }
    }
