/* Product accent: a saturated royal blue in light mode and a brighter,
   softer blue in dark mode. Both keep strong contrast for controls, focus
   rings, citation hover states, and the answer rail. */
:root {
  --primary: 221 83% 53% !important;
  --primary-foreground: 210 40% 98% !important;
  --ring: 221 83% 53% !important;
}

:root.dark {
  --primary: 213 94% 68% !important;
  --primary-foreground: 222 47% 11% !important;
  --ring: 213 94% 68% !important;
}

/* The auth screen is a calm entry point, even when the app is in dark mode.
   Keep it lighter than the chat canvas so the form does not disappear into a
   black slab, and give the controls enough separation to scan immediately. */
:root.dark body:has(#email) {
  background: #243746;
}

:root.dark body:has(#email) .grid.min-h-svh > div:first-child {
  background: #243746;
  color: #edf7f4;
}

:root.dark body:has(#email) .grid.min-h-svh > div:first-child input {
  border-color: #527181;
  background: #304a5b;
}

.km-language-switcher {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.km-language-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.km-language-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 40;
  min-width: 9rem;
  padding: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  background: hsl(var(--card));
  box-shadow: 0 8px 24px hsl(var(--foreground) / 0.08);
}

.km-language-menu button {
  display: block;
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: hsl(var(--foreground));
  text-align: left;
}

.km-language-menu button[aria-selected="true"] {
  background: hsl(var(--primary) / 0.12);
  color: hsl(var(--primary));
}

:root.dark body:has(#email) .grid.min-h-svh > div:first-child input {
  color: #f3fbf8;
}

:root.dark body:has(#email) .grid.min-h-svh > div:first-child input::placeholder {
  color: #b8cbd0;
}

:root.dark body:has(#email) .grid.min-h-svh > div:first-child input:focus {
  border-color: #8de4d5;
  box-shadow: 0 0 0 3px hsl(173 58% 56% / 0.24);
}

/* Citation markers ([1], [2], ...) in the answer text.

   Chainlit only renders its own chip for a link whose text names a message
   element, and every such element is shown in the side panel — which is the
   PDF viewer's alone. So the markers are plain markdown links (see
   `citation_marker()` in km_v6_ui/card.py) restyled here to match
   `ElementRef`'s chip, and AnswerCard.jsx handles the click. */
.message-content a[href^="#km-cite:"] {
  display: inline-flex;
  align-items: center;
  transform: translateY(-1px);
  border-radius: 0.75rem;
  padding: 0 0.375rem;
  background-color: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  font-size: 0.7rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.message-content a[href^="#km-cite:"]:hover {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  text-decoration: none;
}

/* A marker whose citation is one side of a contradiction, so the disagreement
   reads in the prose itself and not only in the evidence list below. The
   padding drops by the 1px the border adds, keeping the chip its own size. */
.message-content a[href^="#km-cite:"].km-cite-conflict {
  padding: 0 0.3rem;
  border: 1px solid hsl(var(--destructive));
  background-color: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
}

.message-content a[href^="#km-cite:"].km-cite-conflict:hover {
  background-color: hsl(var(--destructive));
  color: hsl(var(--primary-foreground));
}

/* A page the model named that nothing confirmed. Deliberately NOT a number:
   it is not one more footnote, and it opens the page with nothing highlighted.
   The dashed outline is what carries "provisional" at 0.7rem -- fill vs
   outline alone did not, because --border and --muted resolve to the same
   colour in the dark theme. The title says where to look and what to look
   for. */
.message-content a[href^="#km-page:"] {
  display: inline-flex;
  align-items: center;
  transform: translateY(-1px);
  border: 1px dashed hsl(var(--muted-foreground) / 0.7);
  border-radius: 0.75rem;
  padding: 0 0.4rem;
  background-color: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 0.7rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.message-content a[href^="#km-page:"]:hover {
  border-style: solid;
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
  text-decoration: none;
}

/* A figure the answer points at: shown inline, centred, clickable through to
   its page. Not a citation, so no gold and no number. The file and page live in
   the link title, so a chart is not followed by a caption repeating what the
   sentence above it already said. */
.message-content.km-answer-message a[href^="#km-visual:"] {
  display: block;
  margin: 0.6rem 0 0.2rem;
  text-align: center;
  text-decoration: none;
  cursor: zoom-in;
}

/* Chainlit wraps a markdown image in its own div capped at 28rem, which is
   narrower than this column and was clamping every figure to 448px. */
.message-content.km-answer-message a[href^="#km-visual:"] :is(div, p) {
  max-width: none;
  width: 100%;
}

.message-content.km-answer-message a[href^="#km-visual:"] img {
  display: block;
  /* auto, not 100%: a small crop stays its own size and centres rather than
     being upscaled into blur; a large one fills the column. */
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 34rem;
  margin-inline: auto;
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: 0.35rem;
  object-fit: contain;
}

/* One quiet progress surface, kept visually secondary to the answer. */
.km-progress-card {
  width: min(100%, 46rem);
  margin: 0.25rem 0 0.5rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.8rem;
  background: hsl(var(--muted) / 0.42);
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  line-height: 1.4;
}

.km-progress-card.is-complete {
  margin: 0 0 0.3rem;
  padding: 0.25rem 0.1rem;
  border-color: transparent;
  border-radius: 0;
  background: transparent;
  font-size: 0.78rem;
}

.km-progress-head {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  list-style: none;
  cursor: pointer;
}

.km-progress-head::-webkit-details-marker {
  display: none;
}

.km-progress-head::after {
  width: 0.42rem;
  height: 0.42rem;
  margin: 0.32rem 0.18rem 0 auto;
  flex: 0 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  opacity: 0.6;
  transform: rotate(45deg);
  transition: transform 160ms ease;
}

.km-progress-disclosure[open] > .km-progress-head::after {
  transform: translateY(0.15rem) rotate(225deg);
}

.km-progress-indicator {
  display: grid;
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.08rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1.5px solid hsl(var(--primary) / 0.28);
  border-radius: 999px;
  color: hsl(var(--primary));
  font-size: 0.68rem;
  font-weight: 700;
}

.km-progress-indicator.is-working {
  border-top-color: hsl(var(--primary));
  animation: km-spin 0.9s linear infinite;
}

.km-progress-copy {
  display: grid;
  min-width: 0;
  gap: 0.1rem;
}

.km-progress-copy strong {
  color: hsl(var(--foreground) / 0.82);
  font-size: 0.84rem;
  font-weight: 600;
}

.km-progress-copy span {
  overflow-wrap: anywhere;
}

.km-progress-card.is-complete .km-progress-copy {
  display: flex;
  flex: 1 1 auto;
  align-items: baseline;
  gap: 0.45rem;
}

.km-progress-card.is-complete .km-progress-copy > span {
  overflow: hidden;
  color: hsl(var(--muted-foreground) / 0.82);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-upload-progress-card .km-progress-head {
  order: 1;
  cursor: default;
}

/* A finished upload wraps its head in a <details>, which then owns the slot. */
.km-upload-progress-card > .km-progress-disclosure {
  order: 1;
}

.km-upload-progress-card summary.km-progress-head {
  cursor: pointer;
}

.km-upload-progress-card summary.km-progress-head::after {
  display: block;
}

.km-upload-progress-card {
  display: grid !important;
  width: min(100%, 38rem);
  min-height: 0 !important;
  align-content: start !important;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
}

.km-upload-progress-card .km-progress-head::after {
  display: none;
}

.km-upload-progress-card .km-progress-copy strong {
  display: block;
  overflow: hidden;
  max-width: 32rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-upload-progress-card.is-failed .km-progress-indicator {
  border-color: hsl(var(--destructive) / 0.45);
  color: hsl(var(--destructive));
}

.km-upload-progress-track,
.km-upload-transfer-track {
  display: block;
  height: 0.24rem;
  overflow: hidden;
  border-radius: 999px;
  background: hsl(var(--border));
}

.km-upload-progress-track {
  order: 2;
  margin: 0 0 0 1.8rem;
}

.km-upload-progress-track > span,
.km-upload-transfer-track > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: hsl(var(--primary));
  transition: width 160ms ease-out;
}

.km-upload-transfer {
  display: grid;
  gap: 0.3rem;
  width: min(100%, 30rem);
  margin: 0.35rem 0 0.2rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.76rem;
}

.km-upload-transfer.is-failed {
  color: hsl(var(--destructive));
}

.km-upload-transfer-track {
  width: 100%;
}

/* Inside a card the log lines up with the copy; the bare stub stays flush. */
.km-progress-disclosure > .km-phase-log {
  margin-left: 1.8rem;
}

.km-phase-log {
  width: min(100%, 34rem);
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.6rem;
  background: hsl(var(--muted) / 0.42);
  font-size: 0.74rem;
  line-height: 1.5;
}

.km-phase-log ol {
  display: grid;
  margin: 0;
  padding: 0;
  gap: 0.15rem;
  list-style: none;
}

.km-phase-log li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.km-phase-log li > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.km-phase-log li > em {
  margin-left: auto;
  flex: 0 0 auto;
  color: hsl(var(--muted-foreground) / 0.75);
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.km-phase-ref {
  margin: 0.45rem 0 0;
  padding-top: 0.4rem;
  border-top: 1px solid hsl(var(--border) / 0.7);
  color: hsl(var(--muted-foreground) / 0.6);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
}

.km-phase-ref a {
  color: hsl(var(--primary));
  text-decoration: none;
}

.km-phase-ref a:hover {
  text-decoration: underline;
}

.km-progress-sources {
  display: grid;
  gap: 0.35rem;
  margin: 0.7rem 0 0 1.8rem;
}

.km-progress-source {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.km-source-file,
.km-page-chips button,
.km-source-link,
.km-evidence-image,
.km-answer-actions button,
.km-followup-chip {
  appearance: none;
  border: 0;
  font: inherit;
}

.km-source-file {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 0.4rem;
  padding: 0;
  background: transparent;
  color: hsl(var(--foreground) / 0.76);
  text-align: left;
}

.km-source-file svg {
  width: 0.95rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.35;
}

.km-source-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-source-file:not(:disabled),
.km-page-chips button:not(:disabled) {
  cursor: pointer;
}

.km-source-file:not(:disabled):hover {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 0.18rem;
}

.km-page-chips {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.km-page-chips button,
.km-page-pill {
  border-radius: 999px;
  padding: 0.1rem 0.42rem;
  background: hsl(var(--background));
  color: hsl(var(--muted-foreground));
  font-size: 0.7rem;
  font-weight: 600;
}

.km-page-chips button:not(:disabled):hover {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.km-source-file:disabled,
.km-page-chips button:disabled {
  opacity: 0.62;
}

/* The progress element shares the durable answer message, but visually leads
   it so search context is established before the answer label and prose. */
.message-content.km-answer-message
  > div:has([data-km-progress-card]),
.message-content.km-answer-message
  > div:has([data-km-progress-card])
  > div:has([data-km-progress-card]) {
  display: contents;
}

.message-content.km-answer-message
  .inline-custom:has([data-km-progress-card]) {
  order: -1;
}

/* The native markdown is the sole answer surface; the custom elements add
   progress, evidence, and controls without repeating the answer. */
.message-content.km-answer-message {
  max-width: 74ch;
  margin-top: 0.35rem;
  padding: 1rem 1.15rem 0.8rem;
  border-left: 3px solid hsl(var(--primary));
  border-radius: 0 0.75rem 0.75rem 0;
  background: hsl(var(--card) / 0.58);
  color: hsl(var(--foreground));
  font-size: 1.02rem;
  line-height: 1.72;
}

.message-content.km-answer-message::before {
  display: block;
  margin-bottom: 0.55rem;
  color: hsl(var(--primary));
  content: attr(data-km-answer-label);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.message-content.km-answer-message p {
  margin-block: 0 0.8rem;
}

.message-content.km-answer-message :is(h1, h2, h3) {
  margin-block: 1.25em 0.45em;
  line-height: 1.25;
}

.message-content.km-answer-message :is(ul, ol) {
  margin-block: 0.45rem 0.9rem;
}

.km-answer-card {
  margin-top: 0.65rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  line-height: 1.5;
}

.km-answer-banner {
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.7rem;
  border-left: 2px solid hsl(var(--primary));
  background: hsl(var(--muted) / 0.55);
  color: hsl(var(--foreground));
}

.km-disclosure {
  border-top: 1px solid hsl(var(--border));
}

.km-disclosure > summary {
  display: flex;
  min-height: 2.55rem;
  align-items: center;
  gap: 0.45rem;
  color: hsl(var(--foreground) / 0.8);
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}

.km-disclosure > summary::-webkit-details-marker {
  display: none;
}

.km-disclosure-count {
  margin-right: auto;
  color: hsl(var(--muted-foreground));
  font-size: 0.74rem;
  font-weight: 500;
}

.km-disclosure summary svg {
  width: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
  transition: transform 160ms ease;
}

.km-disclosure[open] summary svg {
  transform: rotate(180deg);
}

.km-evidence-list,
.km-location-list,
.km-conflict-list {
  display: grid;
  gap: 0.65rem;
  padding: 0.2rem 0 0.85rem;
}

.km-evidence-row {
  display: grid;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.65rem;
  background: hsl(var(--background) / 0.72);
}

/* A citation that is one side of a contradiction. Under the conversation
   strategy there is no prose, so the separate conflicts block never renders
   and this inline mark is the only signal the reader gets. */
.km-evidence-row.is-conflict {
  border-color: hsl(var(--destructive) / 0.45);
  border-left: 3px solid hsl(var(--destructive));
  background: hsl(var(--destructive) / 0.07);
}

.km-evidence-row.is-conflict .km-citation-number {
  color: hsl(var(--destructive));
}

.km-evidence-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.5rem;
}

.km-citation-number {
  color: hsl(var(--primary));
  font-weight: 700;
}

.km-source-link {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 0.45rem;
  padding: 0;
  background: transparent;
  color: hsl(var(--foreground) / 0.82);
  cursor: pointer;
  text-align: left;
}

.km-source-link > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-source-link:hover > span:first-child {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 0.18rem;
}

.km-evidence-image {
  position: relative;
  display: grid;
  overflow: hidden;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.4rem;
  place-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: 0.45rem;
  background: hsl(var(--muted) / 0.38);
  box-shadow: inset 0 0 0 1px hsl(var(--background) / 0.65);
  cursor: zoom-in;
}

.km-evidence-image img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 12rem;
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: 0.25rem;
  object-fit: contain;
}

.km-evidence-image:hover {
  border-color: hsl(var(--primary) / 0.55);
}

.km-evidence-quote {
  position: absolute;
  right: 0.7rem;
  bottom: 0.7rem;
  left: 0.7rem;
  z-index: 1;
  max-height: calc(100% - 1.4rem);
  overflow: auto;
  padding: 0.55rem 0.65rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.4rem;
  background: hsl(var(--popover) / 0.97);
  box-shadow: 0 0.45rem 1.4rem hsl(222 47% 11% / 0.2);
  color: hsl(var(--popover-foreground));
  font-size: 0.76rem;
  line-height: 1.45;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.3rem);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.km-evidence-image:is(:hover, :focus-visible) .km-evidence-quote {
  opacity: 1;
  transform: translateY(0);
}

.km-evidence-row blockquote {
  margin: 0;
  padding-left: 0.7rem;
  border-left: 2px solid hsl(var(--border));
  color: hsl(var(--foreground) / 0.72);
  font-size: 0.84rem;
  line-height: 1.55;
}

.km-preview-unavailable,
.km-conflict-list p {
  margin: 0;
}

.km-location-row {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  border-radius: 0.55rem;
  background: hsl(var(--muted) / 0.45);
}

.km-location-label {
  flex: 0 0 auto;
  color: hsl(var(--muted-foreground));
  font-size: 0.72rem;
}

/* A conflict is a claim the model is confident enough to state, not a
   citation it's unsure of -- so this is a warning accent, not the fuzzy/
   unverified treatment. It has to read before the section is even expanded,
   so the color lives on the summary too, not just the opened list. */
.km-disclosure.km-conflicts > summary {
  color: hsl(var(--destructive));
}

.km-disclosure.km-conflicts .km-disclosure-count {
  color: hsl(var(--destructive) / 0.85);
}

.km-conflict-list article {
  padding: 0.65rem 0.75rem;
  border: 1px solid hsl(var(--destructive) / 0.45);
  border-left: 3px solid hsl(var(--destructive));
  border-radius: 0.55rem;
  background: hsl(var(--destructive) / 0.07);
}

.km-answer-actions {
  margin-top: 0.7rem;
}

.km-answer-actions button {
  padding: 0.4rem 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}

.km-answer-actions button:hover {
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
}

.km-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.7rem 0 0.15rem;
}

.km-followup-chip {
  max-width: 100%;
  padding: 0.35rem 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: left;
  overflow-wrap: anywhere;
}

.km-followup-chip:hover:not(:disabled) {
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
}

.km-followup-chip:disabled {
  cursor: default;
  opacity: 0.62;
}

.km-answer-receipt {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin-top: 0.65rem;
  color: hsl(var(--muted-foreground) / 0.72);
  font-size: 0.68rem;
}

.km-answer-receipt span + span::before {
  margin-right: 0.85rem;
  content: "·";
}

.km-answer-receipt-log > summary {
  cursor: pointer;
  list-style: none;
}

.km-answer-receipt-log > summary::-webkit-details-marker {
  display: none;
}

.km-answer-receipt-log > summary:hover {
  color: hsl(var(--muted-foreground));
}

.km-answer-receipt-log > summary svg {
  width: 0.8rem;
  margin-left: auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  transition: transform 160ms ease;
}

.km-answer-receipt-log[open] > summary svg {
  transform: rotate(180deg);
}

.km-answer-receipt-log > .km-phase-log {
  margin-top: 0.5rem;
}

.km-empty-collection {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 1.1rem;
  width: min(100%, 38rem);
  margin: 0.35rem 0 0.75rem;
  padding: 1.2rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.85rem;
  background: hsl(var(--muted) / 0.3);
}

.km-empty-document {
  display: grid;
  place-items: center;
  width: 4.5rem;
  height: 5.25rem;
  border: 1px solid hsl(var(--primary) / 0.35);
  border-radius: 0.45rem 0.9rem 0.45rem 0.45rem;
  background: hsl(var(--background));
  color: hsl(var(--primary));
  box-shadow: 0 0.5rem 1.4rem hsl(var(--foreground) / 0.07);
}

.km-empty-document svg {
  width: 2rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.km-empty-eyebrow {
  margin: 0 0 0.2rem;
  color: hsl(var(--primary));
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.km-empty-collection h2 {
  margin: 0;
  color: hsl(var(--foreground));
  font-size: 1.05rem;
  font-weight: 650;
}

.km-empty-collection p:not(.km-empty-eyebrow) {
  max-width: 30rem;
  margin: 0.35rem 0 0.8rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.84rem;
  line-height: 1.5;
}

.km-empty-collection button {
  padding: 0.5rem 0.8rem;
  border: 0;
  border-radius: 0.55rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 650;
}

.km-empty-collection button:hover {
  filter: brightness(1.05);
}

.km-source-file:focus-visible,
.km-page-chips button:focus-visible,
.km-source-link:focus-visible,
.km-evidence-image:focus-visible,
.km-answer-actions button:focus-visible,
.km-followup-chip:focus-visible,
.km-empty-collection button:focus-visible,
.km-disclosure > summary:focus-visible,
.km-answer-receipt-log > summary:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

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

@media (max-width: 640px) {
  .km-empty-collection {
    grid-template-columns: 3.25rem minmax(0, 1fr);
    padding: 1rem;
  }

  .km-empty-document {
    width: 3.25rem;
    height: 4rem;
  }

  .message-content.km-answer-message {
    padding: 0.85rem 0.85rem 0.7rem;
    font-size: 1rem;
  }

  .km-progress-source,
  .km-location-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .km-page-chips {
    justify-content: flex-start;
    margin-left: 1.35rem;
  }

  .km-evidence-image img {
    max-height: 10rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .km-progress-indicator.is-working {
    animation: none;
    border-color: hsl(var(--primary));
  }

  .km-disclosure summary svg,
  .km-evidence-quote,
  .km-upload-progress-track > span,
  .km-upload-transfer-track > span {
    transition: none;
  }
}

#side-view-title:has([data-km-side-title]) {
  min-width: 0;
  min-height: 3rem;
  column-gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #cbd5dc;
  background: #eef2f5;
  color: #17242c;
  box-shadow: 0 1px 0 rgb(23 36 44 / 0.06);
}

:root.dark #side-view-title:has([data-km-side-title]) {
  border-bottom-color: #52616b;
  background: #2c3941;
  color: #f1f5f7;
}

#side-view-title:has([data-km-side-title]) button {
  flex: 0 0 auto;
  border: 1px solid #bbc7ce;
  background: #ffffff;
  color: inherit;
}

:root.dark #side-view-title:has([data-km-side-title]) button {
  border-color: #64737d;
  background: #3d4b54;
}

#side-view-title [data-km-open-history] {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

#side-view-title [data-km-side-title] {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 768px) {
  [data-panel-group-direction="horizontal"]:has(#side-view-content)
    > [data-panel] {
    flex: 1 1 0%;
    min-width: 0;
  }
}

@media (max-width: 767px) {
  #side-view-title [data-km-open-history] {
    display: inline-flex;
  }

  [role="dialog"]:has(#side-view-content) {
    inset: 0 !important;
    width: 100vw !important;
    max-width: none !important;
    height: 100dvh !important;
  }
}

/* Catalog mode is a separate interface: hide chat chrome, strip the assistant
   message wrapper around the hub, and widen only the catalog column. The
   default Chainlit layout stays 48rem for ordinary answers.
   `[data-km-view=chat]` wins over a leftover hub node so opening a collection
   can never keep the composer hidden. */
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  .flex.flex-col.mx-auto.w-full.p-4.pt-0:has(#message-composer),
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  :has(> #message-composer),
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  #message-composer,
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  .watermark,
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  #new-chat-button,
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  #chat-settings-open-modal,
:is(
    html[data-km-view="collections"],
    html:not([data-km-view="chat"]):has([data-km-collection-hub])
  )
  .absolute.bottom-4.left-0.right-0.flex.justify-center {
  display: none !important;
}

[data-km-catalog-shell] {
  max-width: min(75rem, 100%) !important;
  width: 100%;
}

.step:has([data-km-collection-hub]) {
  padding-block: 0;
}

.ai-message:has([data-km-collection-hub]) {
  gap: 0;
}

.ai-message:has([data-km-collection-hub]) > :first-child {
  display: none;
}

/* Collections read like a compact source catalogue: filenames form the visual
   spine, while actions stay quiet until the user reaches the card footer. */
.message-content:has([data-km-collection-hub]) {
  width: 100%;
  max-width: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.km-collection-hub {
  display: grid;
  gap: 1.4rem;
  width: 100%;
  margin: 0.25rem 0 1rem;
  color: hsl(var(--foreground));
  container-type: inline-size;
  container-name: km-catalog;
}

.km-collection-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid hsl(var(--border));
}

.km-collection-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.km-collection-search input {
  width: min(22rem, 100%);
  padding: 0.55rem 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.55rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 0.82rem;
}

.km-collection-search input:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.km-collection-notice {
  margin: 0;
  padding: 0.7rem 0.85rem;
  border: 1px solid hsl(var(--border));
  border-left: 3px solid hsl(var(--primary));
  border-radius: 0.6rem;
  background: hsl(var(--muted) / 0.45);
  color: hsl(var(--foreground));
  font-size: 0.88rem;
}

.km-collection-empty-filter {
  display: grid;
  justify-items: start;
  gap: 0.7rem;
  padding: 1.1rem 0.2rem;
  color: hsl(var(--muted-foreground));
}

.km-collection-dialog {
  width: min(100%, 32rem);
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: 0.85rem;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: 0 1rem 2.5rem hsl(var(--foreground) / 0.12);
}

.km-collection-dialog::backdrop {
  background: rgb(0 0 0 / 0.48);
}

.km-collection-dialog .km-collection-form {
  grid-template-columns: 1fr;
  margin: 0;
}

.km-collection-dialog h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.km-collection-kicker {
  margin: 0 0 0.25rem;
  color: hsl(var(--primary));
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.km-collection-hero h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 720;
  letter-spacing: -0.035em;
  line-height: 1;
}

.km-collection-hero p:not(.km-collection-kicker) {
  max-width: 38rem;
  margin: 0.65rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.9rem;
}

.km-collection-hub button,
.km-collection-panel button,
.km-collection-start-card button,
.km-collection-form button {
  appearance: none;
  padding: 0.52rem 0.78rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.55rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
}

.km-collection-hub button.is-primary,
.km-collection-panel button.is-primary,
.km-collection-start-card button.is-primary,
.km-collection-form button.is-primary {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.km-collection-hub button:hover,
.km-collection-panel button:hover,
.km-collection-start-card button:hover,
.km-collection-form button:hover {
  border-color: hsl(var(--primary) / 0.62);
}

.km-collection-hub button:focus-visible,
.km-collection-panel button:focus-visible,
.km-collection-start-card button:focus-visible,
.km-collection-form :is(button, input, textarea):focus-visible,
.km-collection-search input:focus-visible,
.km-collection-dialog :is(button, input, textarea):focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.km-collection-section {
  display: grid;
  gap: 0.75rem;
}

.km-collection-section-title,
.km-document-heading {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.km-collection-section-title h2,
.km-document-heading h3 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.km-collection-section-title span,
.km-document-heading > span {
  display: grid;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  place-items: center;
  border-radius: 999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  font-size: 0.68rem;
  font-weight: 700;
}

.km-collection-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
}

@container km-catalog (min-width: 36rem) {
  .km-collection-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container km-catalog (min-width: 56rem) {
  .km-collection-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.km-collection-card {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 0.7rem;
  padding: 0.85rem 0.9rem 0.9rem;
  border: 1px solid hsl(var(--border));
  border-left: 3px solid hsl(var(--primary) / 0.72);
  border-radius: 0.8rem;
  background: hsl(var(--card) / 0.68);
  transition: border-color 140ms ease, transform 140ms ease;
}

.km-collection-card[data-state="archived"] {
  border-left-color: hsl(var(--muted-foreground) / 0.55);
  opacity: 0.84;
}

.km-collection-card:hover {
  border-color: hsl(var(--primary) / 0.45);
  transform: translateY(-1px);
}

.km-collection-card h3,
.km-collection-panel h2 {
  margin: 0.45rem 0 0;
  overflow-wrap: anywhere;
  color: hsl(var(--foreground));
  font-size: 1.08rem;
  font-weight: 690;
  letter-spacing: -0.012em;
}

.km-collection-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.km-collection-labels > :is(span, strong) {
  padding: 0.18rem 0.43rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  color: hsl(var(--muted-foreground));
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.2;
}

.km-collection-labels > span[data-visibility="public"] {
  border-color: hsl(var(--primary) / 0.34);
  color: hsl(var(--primary));
}

.km-collection-labels > strong {
  margin-left: auto;
  border-color: transparent;
  background: hsl(var(--muted));
}

.km-owner-label,
.km-collection-description,
.km-collection-panel > header > p,
.km-panel-limit {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.78rem;
  line-height: 1.5;
}

.km-collection-description {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.km-collection-description.is-expanded {
  -webkit-line-clamp: 6;
}

.km-owner-label {
  margin-top: 0.25rem;
  overflow-wrap: anywhere;
  font-size: 0.7rem;
}

.km-collection-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.74rem;
}

.km-collection-stats strong {
  color: hsl(var(--foreground));
  font-variant-numeric: tabular-nums;
}

.km-collection-files {
  display: grid;
  align-content: start;
  gap: 0.32rem;
  min-width: 0;
  margin: 0;
  padding: 0.7rem 0 0 0.15rem;
  border-top: 1px solid hsl(var(--border));
  list-style: none;
}

.km-collection-files li {
  display: grid;
  min-width: 0;
  grid-template-columns: 1rem minmax(0, 1fr);
  gap: 0.25rem;
  color: hsl(var(--foreground) / 0.78);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
}

.km-collection-files li span:first-child {
  color: hsl(var(--primary));
}

.km-collection-files li span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-collection-more {
  color: hsl(var(--muted-foreground));
  font-family: inherit;
}

.km-collection-empty {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.78rem;
}

.km-collection-card > footer,
.km-collection-form > footer,
.km-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.km-collection-card > footer {
  margin-top: auto;
}

.km-collection-form {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 0.8rem;
  padding: 1rem;
  border: 1px solid hsl(var(--primary) / 0.32);
  border-radius: 0.75rem;
  background: hsl(var(--muted) / 0.3);
}

.km-collection-form > div,
.km-collection-form.is-panel {
  display: grid;
  gap: 0.35rem;
}

.km-collection-form label {
  color: hsl(var(--foreground) / 0.8);
  font-size: 0.72rem;
  font-weight: 700;
}

.km-collection-form label span {
  color: hsl(var(--muted-foreground));
  font-weight: 500;
}

.km-collection-form-error {
  margin: 0;
  color: hsl(var(--destructive));
  font-size: 0.76rem;
  line-height: 1.45;
}

.km-collection-form :is(input, textarea) {
  width: 100%;
  padding: 0.58rem 0.65rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 0.82rem;
}

.km-collection-form textarea {
  resize: vertical;
}

.km-collection-form > footer {
  grid-column: 1 / -1;
}

.km-collection-panel {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  color: hsl(var(--foreground));
}

.km-collection-start-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.85rem 1.25rem;
  width: min(100%, 42rem);
  margin: 0.35rem 0 0.8rem;
  padding: 1rem 1.05rem;
  border: 1px solid hsl(var(--border));
  border-left: 3px solid hsl(var(--primary));
  border-radius: 0.8rem;
  background: hsl(var(--card) / 0.68);
}

.km-collection-start-main {
  display: grid;
  min-width: 0;
  gap: 0.52rem;
}

.km-collection-start-card h2 {
  margin: 0;
  overflow-wrap: anywhere;
  color: hsl(var(--foreground));
  font-size: 1.16rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.km-collection-start-card p {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.8rem;
  line-height: 1.5;
}

.km-collection-start-files {
  display: grid;
  align-content: center;
  gap: 0.28rem;
  min-width: 9rem;
  max-width: 14rem;
  margin: 0;
  padding: 0.1rem 0 0.1rem 0.85rem;
  border-left: 1px solid hsl(var(--border));
  color: hsl(var(--foreground) / 0.78);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.69rem;
  list-style: none;
}

.km-collection-start-files li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-collection-start-files li::before {
  margin-right: 0.3rem;
  color: hsl(var(--primary));
  content: "↳";
}

.km-collection-start-files .km-collection-more {
  font-family: inherit;
}

.km-collection-start-card > button {
  grid-column: 1 / -1;
  justify-self: start;
}

.km-collection-start-starters {
  grid-column: 1 / -1;
}

/* The card styles its own buttons as boxes; suggestions stay chips. */
.km-collection-start-card .km-followup-chip {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.km-starter-kind {
  color: hsl(var(--muted-foreground));
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.km-starter-kind::after {
  margin: 0 0.35rem;
  content: "\00b7";
}

.km-collection-panel > header {
  display: grid;
  gap: 0.55rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid hsl(var(--border));
}

.km-collection-panel button.is-danger {
  color: hsl(var(--destructive));
}

.km-collection-form.is-panel {
  grid-template-columns: 1fr;
}

.km-collection-form.is-panel > footer {
  grid-column: auto;
}

.km-document-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  border-top: 1px solid hsl(var(--border));
  list-style: none;
}

.km-document-list li {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid hsl(var(--border));
}

.km-document-copy {
  display: grid;
  min-width: 0;
  gap: 0.15rem;
}

.km-document-copy > strong,
.km-document-name strong {
  display: block;
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-document-list li span {
  color: hsl(var(--muted-foreground));
  font-size: 0.68rem;
}

.km-document-list li button {
  flex: 0 0 auto;
  padding: 0.35rem 0.52rem;
  font-size: 0.7rem;
}

.km-document-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.35rem;
}

.km-document-name {
  display: block;
  min-width: 0;
  padding: 0 !important;
  overflow: hidden;
  border: 0 !important;
  background: transparent !important;
  color: hsl(var(--foreground));
  text-align: left;
}

.km-document-name:hover strong {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 0.18rem;
}

.km-document-preview {
  color: hsl(var(--primary)) !important;
}

.km-document-delete {
  color: hsl(var(--destructive)) !important;
}

.km-pdf-workspace {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
}

.km-show-more {
  justify-self: start;
}

@media (max-width: 700px) {
  .km-collection-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .km-collection-toolbar,
  .km-collection-search,
  .km-collection-search input {
    width: 100%;
  }

  .km-collection-form {
    grid-template-columns: 1fr;
  }

  .km-collection-start-card {
    grid-template-columns: 1fr;
  }

  .km-collection-start-files {
    max-width: none;
    padding: 0.75rem 0 0;
    border-top: 1px solid hsl(var(--border));
    border-left: 0;
  }

  .km-collection-form > footer {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .km-collection-card {
    transition: none;
  }

  .km-collection-card:hover {
    transform: none;
  }

  .km-collection-dialog,
  .km-collection-dialog::backdrop {
    transition: none;
  }
}
