/*
 * Knowledge layers, the document reader and the upload form. Every class starts with kn-.
 * A layer's colour arrives as --tone (set inline or by the .kn-*--<tone> classes below) and
 * is mixed with color-mix so translucent surfaces stay on-brand.
 */

.kn-card--violet, .kn-result--violet, .kn-layer--violet { --tone: #6a6dff; }
.kn-card--blue, .kn-result--blue, .kn-layer--blue { --tone: #3d7bfd; }
.kn-card--cyan, .kn-result--cyan, .kn-layer--cyan { --tone: #43b7fd; }
.kn-card--sky, .kn-result--sky, .kn-layer--sky { --tone: #c1e9fc; }
.kn-card--green, .kn-result--green, .kn-layer--green { --tone: #3ee6a8; }
.kn-card--slate, .kn-result--slate, .kn-layer--slate { --tone: #9db3e0; }

.knowledge-area mark {
  background: rgba(67, 183, 253, 0.24); color: var(--white); border-radius: 3px; padding: 0 2px;
  box-shadow: 0 0 0 1px rgba(67, 183, 253, 0.4), 0 0 12px rgba(67, 183, 253, 0.25);
}

.kn-version {
  display: inline-flex; align-items: center; font-size: 11.5px; padding: 1px 7px; border-radius: 6px; flex: none;
  color: var(--sky); background: rgba(1, 9, 45, 0.55); border: 1px solid var(--border-strong);
}
.kn-version--next { color: var(--navy-950); background: var(--ribbon); border-color: transparent; font-weight: 600; }
.kn-visibility { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.kn-visibility svg { width: 12px; height: 12px; }
.kn-status { gap: 6px; }
.kn-status .dot { width: 6px; height: 6px; }

/* ---------- Hero: the layer stack ---------- */

.kn-hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 8px 26px; align-items: center;
  padding: 18px 24px; margin-bottom: 18px; overflow: hidden;
  background:
    radial-gradient(520px 260px at 22% 60%, rgba(68, 73, 253, 0.2), transparent 70%),
    radial-gradient(420px 200px at 90% 0%, rgba(67, 183, 253, 0.12), transparent 70%),
    var(--surface);
}
.kn-hero-stack { position: relative; }
.kn-hero-stack::after {
  content: ""; position: absolute; left: 0; right: 30%; height: 2px; top: 10%; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(67, 183, 253, 0.75), transparent);
  box-shadow: 0 0 14px rgba(67, 183, 253, 0.6); opacity: 0.55;
  animation: kn-sweep 6s ease-in-out infinite;
}
@keyframes kn-sweep { 0%, 100% { top: 12%; opacity: 0; } 15% { opacity: 0.55; } 50% { top: 82%; opacity: 0.4; } 70% { opacity: 0; } }

.kn-stack { display: block; width: 100%; height: auto; max-height: 360px; overflow: visible; }
.kn-slab { cursor: pointer; transition: transform 0.25s ease, opacity 0.25s ease; transform-box: fill-box; }
.kn-slab:hover { transform: translateY(-6px); }
.kn-slab:focus-visible { outline: none; }
.kn-slab:focus-visible .kn-slab-top { stroke-width: 2.4; }
.kn-slab-top { stroke: var(--slab); stroke-width: 1.2; stroke-opacity: 0.9; stroke-linejoin: round; }
.kn-slab-side { fill: var(--slab); fill-opacity: 0.22; stroke: var(--slab); stroke-opacity: 0.55; stroke-width: 1; stroke-linejoin: round; }
.kn-slab-side--right { fill-opacity: 0.1; }
.kn-slab--empty .kn-slab-top { stroke-dasharray: 4 5; stroke-opacity: 0.35; }
.kn-slab--empty .kn-slab-side { fill-opacity: 0.03; stroke-opacity: 0.18; }
.kn-slab--empty .kn-slab-name { fill: var(--text-faint); }
.kn-slab--active .kn-slab-top { stroke-width: 2.2; filter: drop-shadow(0 0 10px var(--slab)); }
.kn-slab--dim { opacity: 0.32; }
.kn-slab--dim:hover { opacity: 0.75; }
.kn-led { fill: var(--slab); }
.kn-leader { stroke: var(--slab); stroke-opacity: 0.5; stroke-dasharray: 2 4; }
.kn-slab-name { fill: var(--white); font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.kn-slab-count { fill: var(--text-muted); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; }

.kn-hero-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.kn-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 12px; background: rgba(1, 9, 45, 0.4); }
.kn-stat { display: flex; flex-direction: column; padding: 12px 14px; border-left: 1px solid var(--border); }
.kn-stat:first-child { border-left: 0; }
.kn-stat .stat-value { font-size: 26px; }
.kn-stat .stat-value .faint { font-size: 18px; }
.kn-stat .stat-label { font-size: 10px; }

.kn-search {
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: rgba(1, 9, 45, 0.65);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.kn-search:focus-within { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(67, 183, 253, 0.16), 0 0 26px rgba(67, 183, 253, 0.18); }
.kn-search > svg { width: 18px; height: 18px; color: var(--cyan); flex: none; }
.kn-search input[type=search] { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font: 14.5px/1.4 var(--font-body); padding: 6px 0; }
.kn-search input[type=search]::placeholder { color: var(--text-faint); }

.kn-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.kn-filter { transition: border-color 0.15s, background 0.15s, color 0.15s; }
.kn-filter:hover { color: var(--white); border-color: var(--border-strong); background: var(--surface-hover); }
.kn-filter--active { color: var(--white); background: var(--ribbon-soft); border-color: var(--cyan); box-shadow: 0 0 14px rgba(67, 183, 253, 0.22); }
.kn-filter--empty { opacity: 0.55; }
.kn-filter-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); box-shadow: 0 0 8px var(--tone); }

.kn-restricted { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: 13px; }
.kn-restricted svg { width: 15px; height: 15px; flex: none; margin-top: 2px; }

/* ---------- Search results ---------- */

.kn-results { margin-bottom: 22px; }
.kn-results .panel-header > svg { width: 17px; height: 17px; color: var(--cyan); }
.kn-results .panel-header .faint { font-size: 12.5px; }
.kn-result-list { list-style: none; margin: 0; padding: 0; }
.kn-result { border-bottom: 1px solid rgba(67, 183, 253, 0.08); box-shadow: inset 3px 0 0 var(--tone); }
.kn-result:last-child { border-bottom: 0; }
.kn-result-link { display: block; padding: 14px 18px 14px 20px; color: var(--text); transition: background 0.15s; }
.kn-result-link:hover { background: rgba(23, 66, 149, 0.25); color: var(--text); }
.kn-result-cite { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.kn-result-section { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--white); }
.kn-result-excerpt { margin: 6px 0 0; color: var(--text-muted); line-height: 1.6; max-width: 90ch; }

/* ---------- Layers of document cards ---------- */

.kn-layers { display: flex; flex-direction: column; gap: 16px; }
/* Each layer is a translucent band in its colour: header on the left, its documents on the right. */
.kn-layer {
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px 22px; padding: 18px 20px;
  border-radius: 16px; border: 1px solid color-mix(in srgb, var(--tone) 22%, transparent);
  background: linear-gradient(100deg, color-mix(in srgb, var(--tone) 12%, transparent) 0%, rgba(3, 16, 77, 0.28) 42%, rgba(3, 16, 77, 0.12) 100%);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--tone) 18%, transparent);
}
.kn-layer-header { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.kn-layer-header .row { flex-wrap: nowrap; gap: 12px; }
.kn-layer-eyebrow { color: var(--tone); font-size: 10px; }
.kn-layer-header h2 { font-size: 18px; display: flex; align-items: baseline; gap: 8px; }
.kn-layer-header h2 .num { font-size: 13px; }
.kn-layer-header p { margin: 0; font-size: 13px; line-height: 1.5; }
.kn-layer-header .btn { margin-left: -10px; }
.knowledge-area .btn svg { width: 15px; height: 15px; flex: none; }
.kn-layer-glyph {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 11px; color: var(--tone);
  background: color-mix(in srgb, var(--tone) 16%, transparent); border: 1px solid color-mix(in srgb, var(--tone) 45%, transparent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--tone) 28%, transparent);
}
.kn-layer-glyph svg { width: 19px; height: 19px; }

.kn-card-grid { display: grid; gap: 16px 18px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); padding: 0 10px 10px 0; }
.kn-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 16px 18px 15px 20px; min-height: 168px;
  color: var(--text); border-radius: var(--radius); overflow: hidden;
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--tone) 15%, rgba(14, 32, 106, 0.55)) 0%, rgba(3, 16, 77, 0.5) 70%);
  border: 1px solid color-mix(in srgb, var(--tone) 32%, transparent);
  /* Translucent sheets behind the card: a document is a stack of its versions. */
  box-shadow:
    5px 5px 0 -1px color-mix(in srgb, var(--tone) 14%, rgba(1, 9, 45, 0.9)),
    10px 10px 0 -2px color-mix(in srgb, var(--tone) 7%, rgba(1, 9, 45, 0.7)),
    0 14px 34px rgba(1, 9, 45, 0.5);
  backdrop-filter: blur(10px);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.kn-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--tone); box-shadow: 0 0 14px var(--tone); }
.kn-card:hover {
  color: var(--text); transform: translate(-2px, -3px); border-color: color-mix(in srgb, var(--tone) 60%, transparent);
  box-shadow:
    7px 7px 0 -1px color-mix(in srgb, var(--tone) 16%, rgba(1, 9, 45, 0.9)),
    13px 13px 0 -2px color-mix(in srgb, var(--tone) 8%, rgba(1, 9, 45, 0.7)),
    0 0 30px color-mix(in srgb, var(--tone) 22%, transparent);
}
.kn-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.kn-card-title { font-size: 15.5px; line-height: 1.3; color: var(--white); }
.kn-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12.5px; }
.kn-card-stats { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 11.5px; color: var(--text-muted); }
.kn-card-stats strong { color: var(--white); font-weight: 600; }
.kn-card-foot { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.kn-card-error { font-size: 12.5px; color: #ffd0d8; background: rgba(255, 93, 122, 0.08); border: 1px solid rgba(255, 93, 122, 0.3); border-radius: 8px; padding: 6px 9px; }

/* ---------- Document reader ---------- */

.kn-citation-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: -6px 0 16px; padding: 10px 16px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: inset 3px 0 0 var(--tone);
}
.kn-citation { color: var(--sky); font-size: 13px; }
.kn-icon-flip { transform: rotate(180deg); }
.kn-banner { margin-bottom: 16px; }
.kn-banner a { margin-left: 4px; }
.kn-banner-actions { margin-top: 10px; }

.kn-scanning { position: relative; overflow: hidden; margin-bottom: 16px; }
.kn-scanline { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent, rgba(67, 183, 253, 0.16), transparent); animation: kn-scan 1.6s linear infinite; }
@keyframes kn-scan { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.kn-reader { display: grid; grid-template-columns: 250px minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.kn-toc { position: sticky; top: 74px; max-height: calc(100vh - 96px); overflow-y: auto; }
.kn-toc ol { list-style: none; margin: 0; padding: 8px; counter-reset: toc; }
.kn-toc li a {
  display: block; padding: 6px 10px; border-radius: 8px; border-left: 2px solid transparent;
  color: var(--text-muted); font-size: 13px; line-height: 1.35;
}
.kn-toc li a:hover { color: var(--white); background: var(--surface-hover); border-left-color: var(--cyan); }
.kn-toc-empty { padding: 12px 16px; margin: 0; font-size: 13px; }

.kn-text { padding: 6px 30px 24px; }
.kn-section { padding: 18px 0 16px; border-bottom: 1px solid rgba(67, 183, 253, 0.08); scroll-margin-top: 84px; }
.kn-section:last-child { border-bottom: 0; }
.kn-section--cont { padding-top: 4px; }
.kn-section:target, .kn-section--match {
  margin: 0 -30px; padding-left: 30px; padding-right: 30px;
  background: linear-gradient(90deg, rgba(67, 183, 253, 0.09), transparent 65%); box-shadow: inset 3px 0 0 var(--cyan);
}
.kn-section-head { display: flex; align-items: baseline; gap: 10px; }
.kn-section-label { font-size: 16.5px; color: var(--white); }
.kn-chunk-tag { font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.04em; white-space: nowrap; opacity: 0.75; }
.kn-section-body p { margin: 8px 0 0; line-height: 1.72; font-size: 15px; max-width: 74ch; }
.kn-section-body ul { margin: 8px 0 0; padding-left: 20px; line-height: 1.72; font-size: 15px; max-width: 74ch; }
.kn-section-body li { margin-bottom: 4px; }

.kn-side .kv { grid-template-columns: max-content minmax(0, 1fr); font-size: 13.5px; }
.kn-filename { font-family: var(--font-mono); font-size: 12px; word-break: break-all; }
.kn-versions { list-style: none; margin: 0; padding: 6px 16px 10px; }
.kn-version-row { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid rgba(67, 183, 253, 0.08); font-size: 13.5px; }
.kn-version-row:last-child { border-bottom: 0; }
.kn-version-row .badge { margin-left: 6px; font-size: 11px; }
.kn-version-row .faint { font-size: 12.5px; margin-top: 2px; }
.kn-version-row--here > div > a { color: var(--white); font-weight: 600; }
.kn-version-dot { width: 10px; height: 10px; flex: none; margin-top: 5px; border-radius: 50%; border: 2px solid var(--text-faint); }
.kn-version-dot--current { background: var(--ok); border-color: var(--ok); box-shadow: 0 0 10px var(--ok); }
.kn-immutable { font-size: 13px; line-height: 1.55; }
.kn-immutable svg { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- Upload form ---------- */

/* .field sets display: flex, which would beat the hidden attribute. */
.kn-form [hidden] { display: none; }
.kn-fixed { padding: 9px 0; }
.kn-supersedes {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; padding: 10px 12px;
  border-radius: 10px; background: rgba(1, 9, 45, 0.45); border: 1px dashed var(--border-strong); font-size: 13px;
}
.kn-supersedes-arrow { color: var(--cyan); font-size: 16px; }

.kn-source { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: rgba(1, 9, 45, 0.35); }
.kn-source-tabs { display: flex; border-bottom: 1px solid var(--border); }
.kn-source-tab {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 11px 14px; cursor: pointer;
  color: var(--text-muted); font-weight: 600; font-size: 13.5px; transition: background 0.15s, color 0.15s;
}
.kn-source-tab + .kn-source-tab { border-left: 1px solid var(--border); }
.kn-source-tab svg { width: 16px; height: 16px; }
.kn-source-tab input { accent-color: var(--cyan); }
.kn-source-tab:has(input:checked) { color: var(--white); background: var(--ribbon-soft); box-shadow: inset 0 -2px 0 var(--cyan); }
.kn-source-pane { padding: 16px; }
.kn-source-pane[hidden] { display: none; }

.kn-dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 30px 16px;
  border: 1.5px dashed var(--border-strong); border-radius: 12px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.kn-dropzone > svg { width: 30px; height: 30px; color: var(--cyan); filter: drop-shadow(0 0 10px rgba(67, 183, 253, 0.5)); }
.kn-dropzone:hover, .kn-dropzone--over { border-color: var(--cyan); background: rgba(67, 183, 253, 0.06); box-shadow: inset 0 0 34px rgba(67, 183, 253, 0.1); }
.kn-dropzone--chosen { border-style: solid; border-color: rgba(62, 230, 168, 0.6); background: rgba(62, 230, 168, 0.05); }
.kn-dropzone-title { font-weight: 600; color: var(--white); }
.kn-file-input { margin-top: 8px; color: var(--text-muted); max-width: 100%; }
/* With the form controller connected, the whole drop zone is the picker. */
[data-controller~="knowledge-form"] .kn-file-input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.kn-client-error { margin: 10px 0 0; }

.kn-steps ol { list-style: none; margin: 0; padding: 16px 18px; }
.kn-steps li { display: flex; gap: 12px; margin-bottom: 14px; font-size: 13.5px; line-height: 1.5; }
.kn-steps li:last-child { margin-bottom: 0; }
.kn-step-num { color: var(--cyan); font-size: 12px; padding-top: 2px; }

/* ---------- Narrow screens ---------- */

@media (max-width: 1240px) {
  .kn-reader { grid-template-columns: 220px minmax(0, 1fr); }
  .kn-side { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}
@media (max-width: 980px) {
  .kn-hero { grid-template-columns: 1fr; }
  .kn-layer { grid-template-columns: 1fr; }
  .kn-reader { grid-template-columns: 1fr; }
  .kn-toc { position: static; max-height: none; }
}
@media (max-width: 760px) {
  .kn-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kn-stat:nth-child(3) { border-left: 0; }
  .kn-stat:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kn-text { padding: 4px 18px 20px; }
  .kn-section:target, .kn-section--match { margin: 0 -18px; padding-left: 18px; padding-right: 18px; }
}

/* ---------- Bulk upload: one card per file (people-fix, finding E2E-6) ---------- */

/* The check table is laid out as a card per file, so who each file opens to is on screen at any
   width (a six-column table cut "Open to" off at 1280 pixels and squeezed titles to two letters).
   A card reads: the file, who it opens to, then its title, layer and date, wrapping as needed.
   The header row is kept for screen readers; each field carries its own label. */
.kn-bulk-table, .kn-bulk-table tbody { display: block; width: 100%; }
.kn-bulk-table tr.kn-bulk-row {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px;
  padding: 14px 0; border-bottom: 1px solid rgba(67, 183, 253, 0.12);
}
.kn-bulk-table tr.kn-bulk-row:last-child { border-bottom: 0; }
.kn-bulk-table tbody tr.kn-bulk-row:hover td { background: none; }
.kn-bulk-table td { display: block; padding: 0; border: 0; min-width: 0; }
.kn-bulk-include { flex: 0 0 auto; align-self: center; }
.kn-bulk-include input { accent-color: var(--cyan); width: 16px; height: 16px; }
.kn-bulk-file { flex: 1 1 0; align-self: center; overflow-wrap: anywhere; }
.kn-bulk-file label { cursor: pointer; color: var(--white); }
.kn-bulk-open { flex: 1 1 100%; }
.kn-bulk-title { flex: 3 1 16rem; }
.kn-bulk-layer { flex: 1 1 8rem; }
.kn-bulk-date { flex: 1 1 10rem; }
.kn-bulk-label {
  display: block; margin-bottom: 4px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-faint);
}
.kn-bulk-open-fields { display: flex; flex-wrap: wrap; gap: 8px; }
.kn-bulk-table .input, .kn-bulk-table .select { width: 100%; }
.kn-bulk-open-fields .select { flex: 1 1 12rem; min-width: 0; }
.kn-bulk-ask { margin: 6px 0 0; color: var(--warn); }
.kn-bulk-ask svg { width: 13px; height: 13px; vertical-align: -2px; }
.kn-bulk-row--ask .kn-bulk-open-fields .select:first-child { border-color: rgba(255, 200, 87, 0.55); }
.kn-bulk-row--refused .kn-bulk-file label { color: var(--text-muted); }
/* Title, layer and date line up by their labels; the date's note (where it came from) hangs below. */
.kn-bulk-title, .kn-bulk-layer, .kn-bulk-date { align-self: flex-start; }
.kn-bulk-date-note { margin: 6px 0 0; }
.kn-bulk-row--date-guessed .kn-bulk-date-note { color: var(--warn); }
.kn-bulk-row--date-guessed .kn-bulk-date-note svg { width: 13px; height: 13px; vertical-align: -2px; }
.kn-bulk-row--date-guessed .kn-bulk-date .input { border-color: rgba(255, 200, 87, 0.55); }
