/* ─────────────────────────────────────────────────────────────────
   references-viewer.css — schema-aware document viewer styles
   Used by Central / Academic / Teachers Hub references modal viewer.
   Source of truth: monorepo-root /shared-design/. Each hub copies this
   into its dist/ at build time (with a local-copy override for
   standalone deploys).
   Depends on the host page providing CSS variables: --accent,
   --accent-dk, --accent-2, --ink, --ink-2, --ink-3, --border, --paper,
   --white, --shadow-sm. All hubs already define these.
   ───────────────────────────────────────────────────────────────── */

/* Schema-aware document viewer — turns recognised JSON top-level keys
   (design_principles, regulatory_alignment, weights, scoring_scale,
   nonNegotiables, etc.) into prose-style cards instead of raw JSON.
   Anything unrecognised falls through to .json-render below.
   Together: 'document mode' for the human-readable bits, 'JSON mode'
   for the rest — both inside the same modal body. */
.doc-view { display: flex; flex-direction: column; gap: 18px; }

/* Header block: title, version/date, description */
.doc-view-header {
  padding: 16px 20px; border-radius: 12px;
  background: linear-gradient(135deg, #faf5ff 0%, #f0fdff 100%);
  border: 1px solid var(--accent-2);
}
.doc-view-header h2 {
  font-family: 'Lora', serif; font-size: 1.35rem; font-weight: 600;
  color: var(--ink); margin: 0 0 6px;
}
.doc-view-header .meta {
  font-size: 11.5px; color: var(--ink-3); display: flex;
  flex-wrap: wrap; gap: 14px; margin-bottom: 10px;
}
.doc-view-header .meta strong { color: var(--ink-2); font-weight: 600; }
.doc-view-header p { font-size: 13.5px; color: var(--ink-2); line-height: 1.6; margin: 6px 0 0; }

/* Section wrapper */
.doc-view-section { padding: 0 4px; }
.doc-view-section > h3 {
  font-family: 'Lora', serif; font-size: 1.05rem; font-weight: 600;
  color: var(--ink); margin: 0 0 12px;
  display: flex; align-items: baseline; gap: 8px;
}
.doc-view-section > h3 .count {
  font-family: 'DM Sans', sans-serif; font-size: 11px; font-weight: 600;
  color: var(--accent-dk); background: var(--accent-2);
  padding: 1px 8px; border-radius: 999px;
}

/* Bullet list (string arrays — design_principles, principles, ...) */
.doc-view-bullets { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.doc-view-bullets li {
  padding: 10px 14px 10px 32px; position: relative;
  background: #fafbfc; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; line-height: 1.55; color: var(--ink-2);
}
.doc-view-bullets li::before {
  content: ''; position: absolute; left: 14px; top: 16px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

/* Reference card (regulatory_alignment / framework_anchors entries) */
.doc-view-refs { display: flex; flex-direction: column; gap: 8px; }
.doc-view-ref {
  padding: 12px 14px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px;
  border-left: 3px solid var(--accent);
}
.doc-view-ref .code {
  display: inline-block; font-family: 'DM Mono', monospace;
  font-size: 11px; font-weight: 600; color: var(--accent-dk);
  background: var(--accent-2); padding: 2px 8px; border-radius: 4px;
  margin-bottom: 6px;
}
.doc-view-ref .title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.doc-view-ref .body { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }

/* Generic object array (e.g. scoring_scale) — auto-render 2-3 fields */
.doc-view-objects { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.doc-view-object {
  padding: 10px 12px; background: #fafbfc;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12.5px;
}
.doc-view-object .field { margin-bottom: 4px; }
.doc-view-object .field:last-child { margin-bottom: 0; }
.doc-view-object .field-label { font-size: 10.5px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.doc-view-object .field-value { color: var(--ink); }

/* Flat object → 2-column key/value table (weights, predicate_bands) */
.doc-view-kv {
  display: grid; grid-template-columns: max-content 1fr;
  gap: 6px 14px; font-size: 13px;
}
.doc-view-kv dt { color: var(--ink-3); font-weight: 600; font-family: 'DM Mono', monospace; font-size: 12px; }
.doc-view-kv dd { color: var(--ink); margin: 0; }
/* Compact summary chip used inside doc-view-kv when a value is itself
   a small nested object/array — avoids the entire row falling through
   to raw JSON just because one sub-key is non-primitive. */
.doc-view-kv-nested {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 6px; font-size: 11px;
  background: var(--accent-2); color: var(--accent-dk); font-weight: 600;
}

/* Document Metadata strip — chip-row of flat metadata fields
   (schema_version, version, edition, publisher, status, language,
   academic_year, etc.). Sits directly under the header so the reader
   can see version/effective-date/source at a glance instead of
   hunting for them inside Raw JSON. */
.doc-view-meta-strip {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 16px; border-radius: 10px;
  background: linear-gradient(135deg, #faf5ff 0%, #f0fdff 100%);
  border: 1px solid var(--accent-2);
  margin-top: -8px; /* hug the header */
}
.doc-view-meta-chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 10px; border-radius: 8px;
  background: var(--white); border: 1px solid var(--border);
  font-size: 11.5px; line-height: 1.4;
}
.doc-view-meta-chip .label {
  font-size: 9.5px; font-weight: 700; color: var(--ink-3);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.doc-view-meta-chip .value {
  font-size: 12px; color: var(--ink); font-weight: 500;
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-view-meta-chip a.value {
  color: var(--accent-dk); text-decoration: none;
}
.doc-view-meta-chip a.value:hover { text-decoration: underline; }

/* Provenance footer-strip — generation/build metadata. Sits at the
   very bottom (just before Raw JSON) in muted styling. */
.doc-view-provenance {
  padding: 10px 14px; border-radius: 8px;
  background: #fafbfc; border: 1px dashed var(--border);
  font-size: 11.5px; color: var(--ink-3);
  display: flex; flex-wrap: wrap; gap: 14px; align-items: baseline;
}
.doc-view-provenance::before {
  content: '◷'; color: var(--ink-3); font-size: 14px;
}
.doc-view-provenance b { color: var(--ink-2); font-weight: 600; }
.doc-view-provenance code {
  font-family: 'DM Mono', monospace; font-size: 11px;
  background: var(--white); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 3px; color: var(--ink-2);
}

/* Theory basis — primary statement plus citations underneath */
.doc-view-theory {
  padding: 14px 16px; border-radius: 10px;
  background: var(--white); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.doc-view-theory .primary {
  font-size: 13.5px; color: var(--ink); font-weight: 500; line-height: 1.55;
}
.doc-view-theory .refs {
  list-style: none; margin: 10px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.doc-view-theory .refs li {
  font-size: 12px; color: var(--ink-2); line-height: 1.5;
  padding-left: 14px; position: relative;
}
.doc-view-theory .refs li::before {
  content: '↳'; position: absolute; left: 0; top: 0;
  color: var(--ink-3); font-size: 11px;
}

/* Weights — percentage chip row */
.doc-view-weights {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px; border-radius: 10px;
  background: var(--white); border: 1px solid var(--border);
}
.doc-view-weights .w-chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 8px;
  background: var(--accent-2); color: var(--accent-dk);
  font-size: 12px; font-weight: 600;
}
.doc-view-weights .w-chip .w-key {
  font-family: 'DM Mono', monospace; font-size: 11px;
}
.doc-view-weights .w-chip .w-val {
  font-size: 13px; font-weight: 700;
}

/* Level Visibility — note + ordered chip flow */
.doc-view-levels-note {
  font-size: 12.5px; color: var(--ink-2); line-height: 1.55;
  margin-bottom: 10px;
}
.doc-view-levels-flow {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-family: 'DM Mono', monospace; font-size: 12px;
}
.doc-view-levels-flow .lvl {
  padding: 5px 12px; border-radius: 6px;
  background: var(--accent-2); color: var(--accent-dk); font-weight: 600;
}
.doc-view-levels-flow .arrow {
  color: var(--ink-3); font-size: 14px;
}

/* Frameworks/domains array — large card grid */
.doc-view-fw-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.doc-view-fw-card {
  background: var(--white); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
  border-left: 3px solid var(--accent);
  transition: box-shadow .15s, transform .15s;
}
.doc-view-fw-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.doc-view-fw-card-head {
  display: flex; align-items: center; gap: 10px;
}
.doc-view-fw-card-id {
  font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 5px;
  background: var(--accent-2); color: var(--accent-dk); flex-shrink: 0;
}
.doc-view-fw-card-title {
  font-size: 13.5px; font-weight: 600; color: var(--ink); line-height: 1.3;
}
.doc-view-fw-card-desc {
  font-size: 12.5px; color: var(--ink-2); line-height: 1.5;
}
.doc-view-fw-card-stats {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px;
}
.doc-view-fw-card-stat {
  font-size: 11px; padding: 3px 9px; border-radius: 5px;
  background: var(--paper); color: var(--ink-2); font-weight: 500;
  border: 1px solid var(--border);
}
.doc-view-fw-card-stat strong { color: var(--accent-dk); font-weight: 700; }

/* Raw JSON fallback section — collapsed by default, click to expand */
.doc-view-raw {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.doc-view-raw summary {
  padding: 10px 14px; cursor: pointer; user-select: none;
  font-size: 12px; color: var(--ink-3); font-weight: 600;
  background: #f8fafc; list-style: none;
}
.doc-view-raw summary::-webkit-details-marker { display: none; }
.doc-view-raw summary::before { content: '▸ '; color: var(--ink-3); display: inline-block; transition: transform .15s; }
.doc-view-raw[open] summary::before { transform: rotate(90deg); }
.doc-view-raw summary:hover { background: var(--accent-2); color: var(--accent-dk); }
.doc-view-raw .json-render { border-radius: 0; border: none; border-top: 1px solid var(--border); margin: 0; }

/* JSON pretty-render — light theme with syntax highlight.
   Replaces the previous terminal-style dark block; far easier to read
   alongside the rest of the page (which is already light). Tokens are
   wrapped in <span class="jh-*"> by formatJsonHtml() at runtime. */
.json-render {
  background: #fafbfc; color: #1f2937;
  padding: 18px 22px; border-radius: 10px;
  font-family: 'DM Mono', monospace; font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word;
  border: 1px solid #e5e7eb;
}
.json-render .jh-key  { color: #5b21b6; font-weight: 600; }   /* purple keys */
.json-render .jh-str  { color: #166534; }                      /* green strings */
.json-render .jh-num  { color: #b45309; font-weight: 500; }    /* amber numbers */
.json-render .jh-bool { color: #b91c1c; font-weight: 600; }    /* red bool/null */
.json-render .jh-null { color: #9ca3af; font-style: italic; }
.json-render .jh-punc { color: #9ca3af; }                      /* { } [ ] , : */
.json-render .jh-quote { color: #cbd5e1; }                     /* faded quotes */

/* Cross-ref chips inside JSON viewer — clickable inline tokens for
   CTS / SKL / PIGP refs. Light-theme variants. */
.json-render .task-chip.cts {
  display: inline-block; padding: 0 6px; margin: 0 1px; border-radius: 4px;
  background: #ede9fe; color: #5b21b6; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.json-render .task-chip.cts:hover { background: #ddd6fe; }
.json-render .hb-tag.skl, .json-render .hb-tag.pigp {
  display: inline-block; padding: 0 6px; margin: 0 1px; border-radius: 4px;
  cursor: pointer; font-weight: 600; transition: background 0.15s;
}
.json-render .hb-tag.skl  { background: #d1fae5; color: #065f46; }
.json-render .hb-tag.pigp { background: #fee2e2; color: #991b1b; }
.json-render .hb-tag.skl:hover  { background: #a7f3d0; }
.json-render .hb-tag.pigp:hover { background: #fecaca; }

/* Subsections (Eduversal Academic Standards: section-NN.json shape).
   A vertical stack of "madde" cards — each carries an id chip + title
   header and a body containing typed content blocks (text / list /
   process / table). Same visual language as framework cards but tuned
   for long-form policy prose. */
.doc-view-subsections {
  display: flex; flex-direction: column; gap: 14px;
}
.doc-view-subsection {
  border: 1px solid var(--border); border-radius: 10px; background: var(--white);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
/* Native <details>/<summary> accordion — first subsection opens by default;
   click any header to expand/collapse. Hides the browser's default disclosure
   triangle so the rotated chevron on the right is the single visual cue. */
.doc-view-subsection > summary { list-style: none; cursor: pointer; }
.doc-view-subsection > summary::-webkit-details-marker { display: none; }
.doc-view-subsection-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: linear-gradient(135deg, #faf5ff 0%, #f0fdff 100%);
  border-bottom: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.doc-view-subsection[open] > .doc-view-subsection-head {
  border-bottom-color: var(--accent-2);
}
.doc-view-subsection-head:hover {
  background: linear-gradient(135deg, #f3e8ff 0%, #ecfeff 100%);
}
.doc-view-subsection-id {
  font-family: 'DM Mono', monospace; font-size: 11.5px; font-weight: 600;
  color: var(--accent-dk); background: var(--white);
  padding: 2px 8px; border-radius: 4px; border: 1px solid var(--accent-2);
  flex-shrink: 0;
}
.doc-view-subsection-title {
  font-family: 'Lora', serif; font-size: 1rem; font-weight: 600;
  color: var(--ink); margin: 0; line-height: 1.3; flex: 1;
}
.doc-view-subsection-chevron {
  flex-shrink: 0; font-size: 14px; color: var(--ink-3);
  transition: transform 0.18s ease;
}
.doc-view-subsection[open] > .doc-view-subsection-head .doc-view-subsection-chevron {
  transform: rotate(90deg); color: var(--accent-dk);
}
.doc-view-subsection-body {
  padding: 14px 18px; display: flex; flex-direction: column; gap: 12px;
}

/* Content blocks inside a subsection. Each gets a typed style — text
   stays prose; list uses standard bullets; process gets numbered chips;
   table renders inline scrollable. */
.doc-view-block {}
.doc-view-block-title {
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
.doc-view-block-text p {
  margin: 0; font-size: 13.5px; line-height: 1.65; color: var(--ink-2);
}
.doc-view-block-list ul {
  margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 4px;
}
.doc-view-block-list li {
  font-size: 13.5px; line-height: 1.6; color: var(--ink-2);
}
.doc-view-block-list li::marker { color: var(--accent); }

/* Process: numbered list with circular chip per step */
.doc-view-process {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.doc-view-process > li {
  display: flex; gap: 12px; align-items: flex-start;
}
.doc-view-process .step-num {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--white);
  font-size: 11.5px; font-weight: 700; font-family: 'DM Sans', sans-serif;
}
.doc-view-process .step-body {
  font-size: 13.5px; line-height: 1.55; color: var(--ink-2); padding-top: 2px;
}

/* Table block */
.doc-view-table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; }
.doc-view-block-table table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.doc-view-block-table th,
.doc-view-block-table td {
  padding: 8px 12px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.doc-view-block-table th {
  background: #f8fafc; color: var(--ink); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
}
.doc-view-block-table tr:last-child td { border-bottom: none; }
.doc-view-block-table td { color: var(--ink-2); line-height: 1.5; }
