/* ============================================================
   paragraf — Calm Scandinavian Light (run 9 rework)

   A warm-paper reading surface where the assistant's prose is
   the hero and the interface nearly disappears. One humanist
   grotesk (Hanken Grotesk) carries the whole hierarchy; one
   muted slate-blue accent marks where you act. No dark canvas,
   no foil cards, no mono-caps eyebrows, no gradients.

   Plain hand-written CSS — no Tailwind, no PostCSS, no bundler.
   :root custom properties are the token source of truth (copied
   verbatim from DESIGN-SYSTEM.md). Hanken Grotesk, JetBrains Mono
   and Fraunces are all self-hosted woff2 below — no third-party
   font request, no render-blocking Google Fonts <link>, no swap
   flash on slow networks (F-006). Hanken is the variable latin
   (+latin-ext) subset, OFL-licensed, covering the whole weight
   range the hierarchy uses (400 body → 700 brand/CTA).
   ============================================================ */

/* Hanken Grotesk — the single humanist grotesk carrying the whole
   hierarchy. Self-hosted at /static/fonts as one variable woff2 across
   the full weight range, so a single @font-face with a weight range is
   exact (and lighter than four static cuts). latin-ext is split out for
   the rarer extended-Latin glyphs. */
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/HankenGrotesk-Variable-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/HankenGrotesk-Variable-latinExt.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* Optional warmth accent — used sparingly (the empty-state welcome
   headline only). Variable display face already on disk. */
@font-face {
  font-family: "Fraunces";
  src: url("/static/fonts/Fraunces-VariableDisplay.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Type */
  --font-display: "Hanken Grotesk", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-accent: "Fraunces", Georgia, serif; /* optional, sparing */

  /* Color — warm light */
  --paper: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #f0eee8;
  --surface-sunken: #edebe4;
  --ink: #1f2933;
  --scrim: rgba(31, 41, 51, 0.32); /* --ink @ 0.32 — rail/palette/modal overlays */
  --text-body: #3a4651;
  --text-muted: #5c6975; /* WCAG AA: 5.20:1 on --paper, >=4.5:1 on every soft surface */
  --text-faint: #94a0ad;
  --hairline: #e5e2da;
  --border: #d4d9dd;

  /* Accent — muted slate-blue (hue ~208, NOT cyan) */
  --accent: #3f6280;
  --accent-strong: #34526b;
  --accent-soft: #e7edf2;
  --accent-ring: rgba(63, 98, 128, 0.24);
  --on-accent: #ffffff;

  /* Status */
  --success: #3e7d5a;
  --success-soft: #e4efe7;
  --pending: #8a6536;
  --pending-soft: #f3ecdd;
  --danger: #a83c34; /* WCAG AA: 5.09:1 on --danger-soft, 5.78:1 on --paper (text/border only, never a fill) */
  --danger-soft: #f6e4e1;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  /* Elevation — soft and warm, never dark */
  --shadow-sm: 0 1px 2px rgba(31, 41, 51, 0.04);
  --shadow-md: 0 4px 24px rgba(31, 41, 51, 0.06);
  --shadow-lg: 0 12px 40px rgba(31, 41, 51, 0.1);

  /* Motion */
  --ease-standard: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 140ms;
  --dur-standard: 240ms;
  --dur-slow: 360ms;

  /* Layout */
  --reading-width: 760px;
  --page-width: 960px;
  --rail-w: 248px; /* widened to show conversation titles legibly */
  --topnav-h: 60px;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur-standard: 0ms;
    --dur-slow: 0ms;
  }
}

@media (max-width: 1023px) {
  :root {
    --rail-w: 0px;
  }
}

/* ============================================================
   RESET + DOCUMENT SURFACE
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  letter-spacing: -0.005em;
  color: var(--text-body);
  background: var(--paper);
  overflow: hidden; /* app-shell owns scrolling; inner panes scroll */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  color: var(--ink);
  font-weight: 600;
  margin: 0;
}

p {
  margin: 0 0 1em;
}
p:last-child {
  margin-bottom: 0;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}

input,
textarea,
select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-standard);
}
a:hover {
  color: var(--accent-strong);
}

code,
pre {
  font-family: var(--font-mono);
}

/* Focus — keyboard-visible ring only (WCAG 1.4.11). */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Quiet section/meta label — used RARELY, never as an eyebrow on every block. */
.t-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* Screen-reader-only utility: kept in the a11y tree but visually removed.
   Anchors the active-conversation page h1 that gives the answer headings
   (h2 sections, h3 argument claims) a valid document outline. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: -9999px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--on-accent);
  background: var(--accent);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  z-index: 9999;
}
.skip-link:focus {
  left: 16px;
  top: 16px;
}

/* ============================================================
   SHARED CONTROLS — buttons, inputs, selects, pills, fields
   ============================================================ */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
}
.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}
.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--text-faint);
  cursor: not-allowed;
}

/* Quiet text / icon buttons (nav, utility, inline) — sentence case, never mono-caps. */
.btn-text,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-standard),
    background var(--dur-fast) var(--ease-standard);
}
.btn-text:hover,
.btn-ghost:hover {
  color: var(--accent-strong);
  background: var(--surface-soft);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field__label {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}
.field__help {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.input,
.input--lg,
.select,
textarea.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  min-height: 44px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-standard);
}
.input--lg {
  font-size: 18px;
}
.input::placeholder {
  color: var(--text-faint);
}
.input:focus,
.input--lg:focus,
.select:focus,
textarea.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23667483' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

/* Pills / badges — soft-tone bg + matching text per semantic. Sentence case. */
.pill,
.status-badge,
.styrke-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}

/* ============================================================
   APP SHELL — light, no grain, no vignette
   ============================================================ */

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: var(--topnav-h) 1fr;
  grid-template-areas:
    "topnav topnav"
    "rail   main";
  background: var(--paper);
  z-index: 1;
}

@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topnav"
      "main";
  }
}

.shell-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   TOP UTILITY BAR
   ============================================================ */

.topnav {
  grid-area: topnav;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  z-index: 6;
}

.topnav__left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topnav__rail-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.topnav__rail-toggle:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.topnav__brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
.topnav__brand:hover {
  color: var(--ink);
}

.topnav__center {
  flex: 1 1 auto;
}

.topnav__right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

@media (max-width: 1023px) {
  .topnav__rail-toggle {
    display: inline-flex;
  }
}

/* ============================================================
   CONVERSATION RAIL (F7) — light, titles legible
   ============================================================ */

.rail {
  grid-area: rail;
  width: var(--rail-w);
  min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
  overflow: hidden;
}

.rail__group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rail__group--top {
  flex: 0 0 auto;
}
.rail__group--conversations {
  flex: 1 1 auto;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
}
.rail__group--bottom {
  flex: 0 0 auto;
  border-top: 1px solid var(--hairline);
  padding-top: 8px;
  gap: 2px;
}

.rail__new-chat-form {
  margin: 0;
}

/* "+ Ny samtale" — obvious primary new-chat affordance. */
.rail__new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
}
.rail__new-chat:hover {
  background: var(--accent-strong);
  color: var(--on-accent);
}
.rail__new-chat svg {
  flex: 0 0 auto;
}

.rail__chip-item {
  display: flex;
  align-items: center;
  position: relative;
  border-radius: var(--radius-sm);
}
.rail__chip-item:hover {
  background: var(--surface-soft);
}

/* Legible conversation entry — truncated title, not a cryptic initial. */
.rail__chip {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-size: 14.5px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail__chip:hover {
  color: var(--ink);
}
.rail__chip--active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.rail__chip-item:has(.rail__chip--active) {
  background: var(--accent-soft);
}

.rail__delete-form {
  margin: 0;
  flex: 0 0 auto;
}
.rail__delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-right: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard),
    background var(--dur-fast) var(--ease-standard);
}
.rail__chip-item:hover .rail__delete-btn,
.rail__delete-btn:focus-visible {
  opacity: 1;
}
.rail__delete-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Bottom group rows (settings, profile) */
.rail__icon-button,
.rail__chip--profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14.5px;
}
.rail__icon-button:hover,
.rail__chip--profile:hover {
  background: var(--surface-soft);
  color: var(--ink);
}
.rail__chip--profile {
  color: var(--text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail__icon-label,
.rail__chip-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail__chip-initial {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
}
.rail__empty {
  padding: 9px 12px;
  color: var(--text-faint);
  font-size: 14px;
}

/* Mobile: off-canvas rail + warm scrim */
@media (max-width: 1023px) {
  .rail {
    position: fixed;
    top: var(--topnav-h);
    bottom: 0;
    left: 0;
    width: min(300px, 84vw);
    transform: translateX(-100%);
    transition: transform var(--dur-standard) var(--ease-standard);
    box-shadow: var(--shadow-lg);
    z-index: 40;
  }
  .rail[data-mobile-open="true"] {
    transform: translateX(0);
  }
}

.rail-scrim,
.slide-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-standard) var(--ease-standard);
  z-index: 35;
}
.rail-scrim[data-active="true"],
.slide-backdrop[data-active="true"] {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   WORKBENCH + READING COLUMN
   ============================================================ */

.workbench {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

/* Wider pages (documents, account, admin) use a scrolling inner column. */
.workbench__center {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.workbench__center-inner {
  flex: 1 1 auto;
  overflow-y: auto;
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 40px 32px 80px;
}

/* Chat surface */
.chat-col,
.thread {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.chat-scroll,
.thread__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 40px 32px 32px;
}

.chat-inner,
.thread__inner {
  max-width: var(--reading-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

@media (max-width: 767px) {
  .chat-scroll,
  .thread__body {
    padding: 24px 20px;
  }
  .workbench__center-inner {
    padding: 28px 20px 72px;
  }
}

/* ============================================================
   COMPOSER (F1) — the most important element on screen
   ============================================================ */

.chat-input-wrap,
.thread__footer {
  position: sticky;
  bottom: 0;
  flex: 0 0 auto;
  padding: 12px 32px 20px;
  background: linear-gradient(
    to top,
    var(--paper) 62%,
    rgba(247, 246, 242, 0)
  );
}

.chat-input-inner,
.thread__footer-inner {
  max-width: var(--reading-width);
  margin: 0 auto;
}

.chat-input-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 12px 8px;
  transition: border-color var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-standard);
}
.chat-input-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-md);
}

.chat-input__row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input,
.chat-input__field {
  flex: 1 1 auto;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 6px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 28px;
  max-height: 240px;
  overflow-y: auto;
}
.chat-input::placeholder,
.chat-input__field::placeholder {
  color: var(--text-faint);
}

.chat-input__submit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-standard);
}
.chat-input__submit:hover {
  background: var(--accent-strong);
}
.chat-input__submit:disabled {
  background: var(--surface-soft);
  color: var(--text-faint);
  cursor: not-allowed;
}
.chat-input__submit .icon {
  width: 17px;
  height: 17px;
}

.chat-input__hint,
.input-hint {
  margin-top: 6px;
  padding: 0 6px;
  font-family: var(--font-body);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  /* Instructional text ("Enter for å sende …"), not a placeholder — must meet
     WCAG AA. --text-faint (#94a0ad) is 2.66:1 on the white composer; use the
     darkened --text-muted (5.63:1 on white). */
  color: var(--text-muted);
}

/* a quiet inline retry line on send failure (composer error state) */
.composer-error {
  margin-top: 8px;
  padding: 0 6px;
  font-size: 13px;
  color: var(--danger);
}
.composer-error button {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
}

/* ============================================================
   TEACHING EMPTY STATE / HOME HERO (F6) + MODE CHOICE (F5)
   ============================================================ */

.thread--empty .thread__body {
  display: flex;
  flex-direction: column;
}
/* Center the teaching content when there's room, but use margin-auto (not
   justify-content:center) so a tall empty state on short/mobile viewports
   stays scrollable to the top instead of clipping the welcome headline. */
.thread--empty .thread__inner {
  margin-block: auto;
}

/* .thread--empty is server-rendered on the section and lingers after htmx
   appends the first turn into #chat (only #chat is swapped, not the class).
   Once a real message exists, drop the empty-state vertical centering —
   otherwise the short (question + pending answer) floats centered and snaps to
   the top when the tall answer lands, looking "squeezed together" (run-9 fix). */
.thread--empty .thread__body:has([data-component="message"]) {
  display: block;
}
.thread--empty .thread__inner:has([data-component="message"]) {
  margin-block: 0;
}

.home-hero {
  max-width: var(--reading-width);
  margin: 0 auto;
  width: 100%;
  text-align: center;
  padding: 8px 0 4px;
}
.home-hero__title {
  font-family: var(--font-accent);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(34px, 5vw, 46px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 12px;
}
.home-hero__lead {
  font-size: 18px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
}

/* legacy welcome/empty placeholders (kept for graceful fallback) */
/* Example-question chips */
.examples {
  max-width: var(--reading-width);
  margin: 28px auto 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 600px) {
  .examples {
    grid-template-columns: 1fr;
  }
}
.example-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast) var(--ease-standard),
    background var(--dur-fast) var(--ease-standard),
    transform var(--dur-fast) var(--ease-standard);
}
.example-chip:hover {
  border-color: var(--accent);
  background: var(--surface);
}
.example-chip__arrow {
  flex: 0 0 auto;
  color: var(--text-faint);
  transition: transform var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}
.example-chip:hover .example-chip__arrow {
  color: var(--accent);
  transform: translateX(3px);
}

/* Mode choice — two plain human-worded options (default = clear answer) */
.mode-choice {
  max-width: var(--reading-width);
  margin: 28px auto 0;
  width: 100%;
}
.mode-choice__legend {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0 0 10px;
  padding: 0;
}
.mode-choice__options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 600px) {
  .mode-choice__options {
    grid-template-columns: 1fr;
  }
}
.mode-option {
  display: block;
  position: relative;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard),
    background var(--dur-fast) var(--ease-standard);
}
.mode-option:hover {
  border-color: var(--accent);
}
.mode-option__input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-option__title {
  /* Grid (not flex): the radio dot sits in a fixed first column and the title
     text wraps within the second column, so a long title ("Veie argumenter for
     og mot") wraps cleanly and stays aligned instead of overflowing the card.
     align-items:start anchors the dot to the first line on multi-line titles. */
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}
.mode-option__title::before {
  content: "";
  width: 18px;
  height: 18px;
  margin-top: 2px; /* optical: center the 18px dot on the first text line */
  border-radius: var(--radius-pill);
  border: 2px solid var(--border);
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-standard);
}
.mode-option__desc {
  margin: 6px 0 0 26px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-body); /* sits on --accent-soft when selected; body keeps AA */
}
.mode-option__input:checked + .mode-option__title::before {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px var(--accent);
}
.mode-option:has(.mode-option__input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-option__input:focus-visible + .mode-option__title::before {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   CHAT TURNS (F2)
   ============================================================ */

.turn,
.msg {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text-body);
}

/* User turn — soft accent bubble, right-aligned */
.turn-user,
.msg--user {
  align-self: flex-end;
  max-width: 80%;
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}
.turn-user .msg__content,
.msg--user .msg__content {
  color: var(--ink);
}

/* Assistant turn — full reading-column width, no bubble: it's a document. */
.turn-agent,
.msg--assistant {
  align-self: stretch;
  max-width: 100%;
}
.turn-agent .msg__content,
.msg--assistant .msg__content {
  animation: turn-arrive var(--dur-standard) var(--ease-standard);
}

.turn-meta,
.msg__speaker {
  display: block;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.msg--user .msg__speaker {
  color: var(--accent-strong);
}

.msg__content p {
  margin: 0 0 12px;
}
.msg__content p:last-child {
  margin-bottom: 0;
}
.msg__content h2 {
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 20px 0 8px;
}
.msg__content h3 {
  font-size: 18px;
  letter-spacing: -0.005em;
  line-height: 1.3;
  margin: 16px 0 6px;
}
.msg__content ul,
.msg__content ol {
  margin: 8px 0 12px;
  padding-left: 22px;
}

/* TL;DR / lead */
.tldr {
  margin-bottom: 24px;
}
.tldr__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.tldr__body {
  font-size: 20px;
  line-height: 1.5;
  font-weight: 450;
  color: var(--ink);
  margin: 0;
}

/* Thinking — calm three dots, no spinner drama */
.thinking {
  display: inline-flex;
  gap: 6px;
  font-size: 28px;
  line-height: 1;
  color: var(--text-faint);
}
.thinking span {
  animation: pulse-dot 1.4s ease-in-out infinite;
}
.thinking span:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Pending answer — a legible "it's working, not frozen" wait (run-9 gate fix):
   stage label + server-truthful elapsed seconds + a reassurance line. */
.pending {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 16px;
  color: var(--text-body);
}
.pending .thinking {
  font-size: 22px;
}
.pending__stage {
  font-weight: 500;
}
.pending__elapsed {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-weight: 400;
}
.pending__reassure {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 52ch;
}

/* Once a real message lands in the thread, retire the teaching empty-state — it
   lives inside #chat and the composer appends turns after it, so without this
   the welcome + example chips stay stranded above the conversation (run-9 fix). */
#chat:has([data-component="message"]) [data-component="home-hero"],
#chat:has([data-component="message"]) [data-component="examples"],
#chat:has([data-component="message"]) [data-component="new-chat-form"] {
  display: none;
}

/* Error turn — calm inline message, no mono-caps eyebrow */
.msg--error .msg__content {
  border-left: 3px solid var(--danger);
  padding-left: 14px;
}
.msg__error-eyebrow {
  font-size: 14px;
  font-weight: 600;
  color: var(--danger);
  margin: 0 0 4px;
}

/* ============================================================
   SOURCE BLOCK + REASONING CITATION (F3) — SIGNATURE
   ============================================================ */

/* inline reference chips in the prose */
.cite-refs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 24px;
}
.cite-refs__label {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 2px;
}
.cite-ref,
.citation-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  vertical-align: baseline;
  transition: background var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}
.cite-ref:hover,
.citation-chip:hover {
  background: var(--accent);
  color: var(--on-accent);
}

/* per-source block */
.section--source {
  border-top: 1px solid var(--hairline);
  padding-top: 20px;
  margin-top: 24px;
  scroll-margin-top: 24px;
}
.section--source:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.section__label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.section__num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12.5px;
  font-weight: 600;
}
.section__source-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.section__anchor {
  font-size: 14px;
  color: var(--text-muted);
}

/* the law's words */
.section__sitat {
  margin: 0 0 12px;
  padding: 14px 18px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  color: var(--text-body);
  font-size: 16px;
  line-height: 1.55;
  font-style: italic;
}

/* plain translation */
.section__plain {
  margin: 0 0 12px;
  color: var(--text-body);
}

/* quiet sentence-case external source link */
.section__source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}
.section__source-link:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

/* F-002 fallback: calm "full source temporarily unavailable" note shown in a
   source block whose chunk could not be resolved (verbatim quote still renders
   above). Quiet and non-alarming — a soft pending-toned left hairline, never a
   red error. */
.section__unresolved {
  margin: 0 0 12px;
  padding-left: 12px;
  border-left: 2px solid var(--pending);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

/* highlight flash when an inline ref targets a source block */
.cite-played,
.section--source.cite-played,
.kilder-card.cite-played {
  animation: cite-flash 0.8s var(--ease-standard);
}
@keyframes cite-flash {
  0% {
    background: var(--accent-soft);
  }
  100% {
    background: transparent;
  }
}

/* "Derfor brukte jeg denne" disclosure */
.reasoning {
  margin-top: 4px;
}
.reasoning__summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.reasoning__summary::-webkit-details-marker {
  display: none;
}
.reasoning__summary:hover {
  color: var(--accent-strong);
}
.reasoning__chevron {
  width: 15px;
  height: 15px;
  transition: transform var(--dur-fast) var(--ease-standard);
}
.reasoning[open] .reasoning__chevron {
  transform: rotate(90deg);
}
.reasoning__note {
  position: relative;
  margin: 8px 0 4px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-body);
  font-size: 15.5px;
  line-height: 1.55;
}
.reasoning__angle {
  display: block;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}
.reasoning__body {
  margin: 0;
}

/* animate disclosure where supported; reduced-motion handled by token zeroing */
@supports (interpolate-size: allow-keywords) {
  :root {
    interpolate-size: allow-keywords;
  }
  .reasoning::details-content {
    block-size: 0;
    overflow: hidden;
    opacity: 0;
    transition: content-visibility var(--dur-standard) allow-discrete,
      block-size var(--dur-standard) var(--ease-standard),
      opacity var(--dur-standard) var(--ease-standard);
  }
  .reasoning[open]::details-content {
    block-size: auto;
    opacity: 1;
  }
}

/* ============================================================
   CONFLICT ANSWER (F4)
   ============================================================ */

.motstrid-section {
  border-top: 1px solid var(--hairline);
  padding-top: 24px;
  margin-top: 24px;
}
.motstrid-section:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.motstrid-section__heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 14px;
}

.argument {
  margin-bottom: 20px;
}
.argument__header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}
.argument__claim {
  flex: 1 1 auto;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0;
}
.argument__body {
  color: var(--text-body);
  margin: 0 0 10px;
}

/* strength pills — desaturated, plain words, never a casino badge.
   Colours meet WCAG AA (>=4.5:1) for the 13px/500 badge text; data-strength also
   exposes the value to non-colour readers. */
.styrke-badge[data-strength="sterk"] {
  background: var(--success-soft);
  /* --success (#3e7d5a) on --success-soft is only 4.15:1; #36704f is ~4.96:1. */
  color: #36704f;
}
.styrke-badge[data-strength="moderat"] {
  background: var(--surface-soft);
  color: var(--text-muted);
}
.styrke-badge[data-strength="svak"] {
  background: var(--surface-soft);
  /* --text-faint (#94a0ad) here is 2.29:1 (fails); --text-muted is 4.85:1. */
  color: var(--text-muted);
}

.argument__cites {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

/* weaknesses well — soft warm-neutral, honest self-critique (not alarming) */
.motstrid-section--svakheter {
  background: var(--surface-soft);
  border-top: none;
  border-left: 3px solid var(--pending);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 18px 20px;
  margin-top: 28px;
}
.motstrid-section--svakheter .motstrid-section__heading {
  font-size: 18px;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  margin: 12px 0;
}

/* ============================================================
   COMMAND PALETTE (F8)
   ============================================================ */

.palette {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 100;
}
.palette[data-open="true"] {
  display: flex;
}
.palette__panel {
  width: 100%;
  max-width: 560px;
  margin: 0 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.palette__input-wrap {
  padding: 8px;
  border-bottom: 1px solid var(--hairline);
}
.palette__input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 12px 14px;
  font-size: 18px;
  color: var(--ink);
}
.palette__input::placeholder {
  color: var(--text-faint);
}
.palette__input:focus {
  outline: none;
}
.palette__results {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 52vh;
  overflow-y: auto;
}
.palette__group-label {
  padding: 10px 12px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}
.palette__empty {
  padding: 16px 14px;
  color: var(--text-muted);
  font-size: 15px;
}
.palette__empty--error {
  color: var(--danger);
}
.palette__result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 15px;
}
.palette__result[data-active="true"],
.palette__result:hover {
  background: var(--surface-soft);
}
.palette__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette__shortcut {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 12px;
}
.palette__hint {
  margin: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--hairline);
  background: var(--surface-soft);
}

/* ============================================================
   DOCUMENTS (F9)
   ============================================================ */

.page-header {
  margin-bottom: 28px;
}
.page-header__title {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--ink);
  margin: 0 0 6px;
}
.page-header__lead {
  font-size: 17px;
  color: var(--text-muted);
  margin: 0;
}

/* GIGO notice — calm card, not a shouting alert */
.gigo-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  margin-bottom: 28px;
  background: var(--surface-soft);
  border-left: 3px solid var(--pending);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.gigo-banner__eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--pending);
  letter-spacing: 0;
  text-transform: none;
}
.gigo-banner__body {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-body);
}

/* upload guidance */
.upload-guide {
  margin-bottom: 28px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}
.upload-guide__eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
  margin: 0 0 14px;
}
.upload-guide__eyebrow--sub {
  margin-top: 8px;
}
.upload-guide__cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
@media (max-width: 767px) {
  .upload-guide__cols {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}
.upload-guide__heading {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 8px;
}
.upload-guide__list {
  margin: 0;
  padding-left: 20px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text-body);
}
.upload-guide__list li {
  margin-bottom: 6px;
}
.upload-guide__types {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}
.upload-guide__defs {
  margin: 0;
}
.upload-guide__def {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.45;
}
.upload-guide__def dt {
  flex: 0 0 auto;
  min-width: 130px;
  font-weight: 600;
  color: var(--ink);
}
.upload-guide__def dd {
  margin: 0;
  color: var(--text-muted);
}
.upload-guide__processing {
  margin: 16px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

/* upload control */
.upload-panel {
  margin-bottom: 28px;
}
.upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.upload-form__field--file {
  flex: 1 1 280px;
}
.upload-form__filebtn {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.upload-form__file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.upload-form__filebtn-trigger {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}
.upload-form__filebtn:hover .upload-form__filebtn-trigger {
  background: var(--surface-soft);
}
.upload-form__file:focus-visible + .upload-form__filebtn-trigger {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.upload-form__filebtn-name {
  font-size: 14px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-form__filebtn-name[data-state="filled"] {
  color: var(--text-body);
}

/* documents table */
.doc-table,
.session-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.doc-table th,
.session-table th {
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  padding: 10px 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--hairline);
}
.doc-table th:first-child {
  border-top-left-radius: var(--radius-sm);
}
.doc-table th:last-child {
  border-top-right-radius: var(--radius-sm);
}
.doc-table td,
.session-table td {
  padding: 12px;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-body);
  vertical-align: middle;
}
.doc-table tbody tr:hover,
.session-table tbody tr:hover {
  background: var(--surface-soft);
}
.doc-table__filename a {
  color: var(--accent);
  font-weight: 500;
}
.doc-table__filename a:hover {
  text-decoration: underline;
}
.doc-table__type {
  text-transform: none;
  color: var(--text-muted);
}
.doc-table__time,
.doc-table__count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.doc-table__action {
  text-align: right;
  white-space: nowrap;
}

/* status pills — calm, soft-tone */
.status-badge[data-status="pending"] {
  background: var(--pending-soft);
  color: var(--pending);
}
.status-badge[data-status="complete"] {
  background: var(--success-soft);
  color: var(--success);
}
.status-badge[data-status="error"] {
  background: var(--danger-soft);
  color: var(--danger);
}

/* inline 2-step delete */
.doc-delete {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.doc-delete__confirm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.doc-delete__bekreft {
  color: var(--danger);
  font-weight: 600;
}
.doc-delete__bekreft:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.doc-delete__sep {
  color: var(--text-faint);
}

.empty-state-block {
  padding: 28px 0;
}
.empty-state-block__lead {
  color: var(--text-body);
  margin: 0 0 8px;
}

/* document detail */
.doc-detail__header {
  margin-bottom: 24px;
}
.doc-detail__title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 14px;
  word-break: break-word;
}
.doc-detail__meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 18px;
  margin: 0;
  font-size: 15px;
}
.doc-detail__meta dt {
  color: var(--text-muted);
}
.doc-detail__meta dd {
  margin: 0;
  color: var(--text-body);
}
.doc-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  margin: 8px 0 24px;
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  font-size: 15px;
  color: var(--text-body);
}
.doc-status--error {
  background: var(--danger-soft);
  color: var(--danger);
}
.account-section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 12px;
}
.doc-detail__chunks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.doc-detail__chunk {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}
.doc-detail__chunk-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.doc-detail__chunk-text {
  margin: 0 0 10px;
  color: var(--text-body);
}
.doc-detail__back {
  margin-top: 28px;
}

/* right-rail document panel (kilder) — the documents list + detail pages lay
   out as a flexible reading column + a fixed source panel on the right. The
   chat workbench keeps its single column (this only applies to the document
   regions). */
[data-region="documents"] .workbench,
[data-region="document-detail"] .workbench {
  flex-direction: row;
  min-height: 0;
}
[data-region="documents"] .kilder,
[data-region="document-detail"] .kilder {
  flex: 0 0 340px;
  border-left: 1px solid var(--hairline);
  overflow-y: auto;
  padding: 28px 24px;
}
@media (max-width: 1023px) {
  [data-region="documents"] .workbench,
  [data-region="document-detail"] .workbench {
    flex-direction: column;
  }
  /* the filename link's href opens the full detail page (R5) on mobile */
  [data-region="documents"] .kilder,
  [data-region="document-detail"] .kilder {
    display: none;
  }
}
.kilder {
  background: var(--surface);
}
.kilder__header {
  margin-bottom: 12px;
}
.kilder__title,
.kilder__doc-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.kilder__empty {
  color: var(--text-muted);
  font-size: 15px;
}
.kilder__doc-header {
  position: relative;
  padding-right: 36px;
  margin-bottom: 16px;
}
.kilder__close {
  position: absolute;
  top: 0;
  right: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 20px;
}
.kilder__close:hover {
  background: var(--surface-soft);
  color: var(--ink);
}
.kilder__doc-meta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.kilder__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kilder-card {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  scroll-margin-top: 24px;
}
.kilder-card__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.kilder-card__path {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}
.kilder-card__text {
  margin: 8px 0 10px;
  color: var(--text-body);
}
.kilder-card__copy {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}
.kilder-card__copy:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}
.kilder-card__copy[data-copy-state="error"] {
  color: var(--danger);
}

/* ============================================================
   ACCOUNT (F10)
   ============================================================ */

.account-section {
  margin-bottom: 32px;
}
.account-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.account-section__heading {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.account-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 18px;
  margin: 0;
  font-size: 15px;
}
.account-meta dt {
  color: var(--text-muted);
}
.account-meta dd {
  margin: 0;
  color: var(--text-body);
}
.session-table__current {
  margin-left: 8px;
  font-size: 13px;
  color: var(--accent-strong);
}
.session-id {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-body);
}
.session-time,
.session-ip {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.session-table__action {
  text-align: right;
}

/* ============================================================
   AUTH SURFACE (F11) — warm light card, no grain/vignette
   ============================================================ */

.auth-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  overflow-y: auto;
  z-index: 1;
}
.auth-shell__top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 32px;
}
.auth-shell__brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
.auth-shell__badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--pending-soft);
  color: var(--pending);
  font-size: 12px;
  font-weight: 600;
}
.auth-shell__main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 30rem;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.auth-card__heading {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(30px, 5vw, 40px);
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
  margin: 0;
}
.auth-card__lead {
  font-size: 17px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0;
}
.auth-card__form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 4px;
}
.auth-card__back {
  margin-top: 4px;
  font-size: 14px;
}
.auth-card__error {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--danger-soft);
  border-left: 3px solid var(--danger);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.auth-card__error-eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  letter-spacing: 0;
  text-transform: none;
}
.auth-card__error-body {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-body);
}

/* ============================================================
   ADMIN AUDIT (F12) — light system; mono only in <pre> traces
   ============================================================ */

.audit-header {
  margin-bottom: 24px;
}
.audit-header__title {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 14px;
}
.audit-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 18px;
  margin: 0;
  font-size: 14px;
}
.audit-meta dt {
  color: var(--text-muted);
}
.audit-meta dd {
  margin: 0;
  color: var(--text-body);
  word-break: break-word;
}
.audit-card {
  margin-bottom: 24px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}
.audit-card__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 12px;
}
.audit-card h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.audit-card pre {
  margin: 0;
  padding: 14px 16px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-body);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
.audit-card ul {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
}

/* ============================================================
   SOURCE FEEDBACK (F13)
   ============================================================ */

.feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}
.feedback__prompt {
  font-size: 13px;
  color: var(--text-muted);
}
.feedback__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.feedback__btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}
.feedback__btn[data-chosen="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.feedback-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  z-index: 200;
  animation: toast-in var(--dur-standard) var(--ease-standard),
    toast-out var(--dur-standard) 2000ms forwards;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes turn-arrive {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%,
  80%,
  100% {
    opacity: 0.2;
    transform: translateY(0);
  }
  40% {
    opacity: 0.9;
    transform: translateY(-2px);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translate(-50%, -4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .thinking span {
    animation: none;
  }
}
