/* ============================================================
   ETV2026 Eigentümer Analyzer — "Forensic Dossier"
   Two-pane workspace · on-demand assistant · dark + light
   ============================================================ */

:root {
  --font-sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  /* Heading tiers: H1/H2 = sans, smaller headings = Fraunces, tile numbers = Spectral */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif; /* smaller headings (h3, block titles, card h4) */
  --font-heading: var(--font-sans); /* large headings (H1 / view-head h2 / detail h2) */
  --font-figure: "Spectral", Georgia, "Times New Roman", serif; /* large tile metric numbers */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --rail-w: 280px;
  --content-max: 1080px;
}

[data-theme="dark"] {
  --bg: #131210;
  --bg-grain: #181613;
  --panel: #1b1916;
  --panel-2: #211e1a;
  --panel-hover: #232019;
  --line: #2c2823;
  --line-strong: #3a342c;
  --text: #efe9dd;
  --text-strong: #fbf7ee;
  --muted: #968d7d;
  --faint: #6c6457;

  --gold: #d6a84e;
  --gold-bright: #e9bc63;
  --gold-soft: rgba(214, 168, 78, 0.14);
  --gold-line: rgba(214, 168, 78, 0.42);

  --red: #e57a68;
  --red-soft: rgba(229, 122, 104, 0.13);
  --red-line: rgba(229, 122, 104, 0.4);
  --amber: #e3aa4d;
  --amber-soft: rgba(227, 170, 77, 0.13);
  --amber-line: rgba(227, 170, 77, 0.38);
  --green: #57c0a0;
  --green-soft: rgba(87, 192, 160, 0.13);
  --green-line: rgba(87, 192, 160, 0.36);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 24px 70px -28px rgba(0, 0, 0, 0.85);
  --glow: radial-gradient(1100px 600px at 18% -10%, rgba(214, 168, 78, 0.07), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(87, 192, 160, 0.045), transparent 55%);
}

[data-theme="light"] {
  --bg: #f1ece1;
  --bg-grain: #efe9dc;
  --panel: #fbf8f1;
  --panel-2: #f3eee2;
  --panel-hover: #f6f1e6;
  --line: #e1dac9;
  --line-strong: #d2c9b3;
  --text: #2a261e;
  --text-strong: #1c1913;
  --muted: #6f685a;
  --faint: #948c7b;

  --gold: #9c6f1c;
  --gold-bright: #b3811f;
  --gold-soft: rgba(156, 111, 28, 0.1);
  --gold-line: rgba(156, 111, 28, 0.4);

  --red: #b13f2e;
  --red-soft: rgba(177, 63, 46, 0.08);
  --red-line: rgba(177, 63, 46, 0.32);
  --amber: #9a6a13;
  --amber-soft: rgba(154, 106, 19, 0.1);
  --amber-line: rgba(154, 106, 19, 0.32);
  --green: #1c7a5d;
  --green-soft: rgba(28, 122, 93, 0.09);
  --green-line: rgba(28, 122, 93, 0.3);

  --shadow: 0 1px 2px rgba(58, 48, 28, 0.06), 0 10px 26px -20px rgba(58, 48, 28, 0.35);
  --shadow-lg: 0 24px 70px -30px rgba(58, 48, 28, 0.4);
  --glow: radial-gradient(1100px 600px at 16% -12%, rgba(156, 111, 28, 0.06), transparent 60%);
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--glow);
  pointer-events: none;
  z-index: 0;
}
button,
input,
textarea {
  font: inherit;
  color: inherit;
}
::selection {
  background: var(--gold-soft);
  color: var(--text-strong);
}
.small {
  font-size: 12px;
}
.muted {
  color: var(--muted);
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--faint);
  background-clip: padding-box;
}

/* ---- Buttons ---- */
button {
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease), transform 0.12s var(--ease),
    color 0.16s var(--ease);
}
button:hover {
  border-color: var(--faint);
  background: var(--panel-hover);
}
button:active {
  transform: translateY(1px);
}
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold-line);
  outline-offset: 1px;
}
.primary-btn {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border-color: var(--gold);
  color: #1a1206;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 6px 16px -10px var(--gold);
}
.primary-btn:hover {
  background: var(--gold-bright);
  border-color: var(--gold-bright);
}
.primary-btn:disabled {
  opacity: 0.5;
  cursor: progress;
}
.ghost-btn {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 6px 10px;
}
.ghost-btn:hover {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}
.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover {
  color: var(--gold);
  background: var(--panel-2);
  border-color: var(--line);
}
.link-btn,
.btn-link {
  border: 0;
  background: transparent;
  color: var(--gold);
  padding: 4px 2px;
  font-weight: 600;
  font-size: 12.5px;
}
.link-btn:hover {
  background: transparent;
  color: var(--gold-bright);
}
.btn-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
}
.btn-link:hover {
  background: var(--gold-soft);
  border-color: var(--gold-line);
  text-decoration: none;
}

/* ============================================================
   Shell — two columns
   ============================================================ */
.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: 100vh;
  overflow: hidden;
}
.rail {
  background: linear-gradient(180deg, var(--panel), var(--bg-grain));
  border-right: 1px solid var(--line);
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.content {
  overflow: auto;
  padding: 30px 40px 80px;
  scroll-behavior: smooth;
}
.view {
  max-width: var(--content-max);
}

/* ---- Brand ---- */
.brand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 13px;
  align-items: center;
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  background: linear-gradient(155deg, var(--gold-bright), var(--gold));
  color: #1a1206;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 18px -10px var(--gold), 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}
.brand-text h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.1;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}
.brand-text p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.brand-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.account-menu {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 70;
  display: grid;
}
.account-menu.open .account-btn {
  color: var(--gold);
  background: var(--panel-2);
  border-color: var(--line);
}
.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  min-width: 168px;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}
.account-menu-user {
  max-width: 220px;
  overflow: hidden;
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--text-strong);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}
.account-menu-item svg {
  flex: none;
  color: var(--faint);
}
.account-menu-item:hover {
  background: var(--red-soft);
  border-color: var(--red-line);
  color: var(--red);
}
.account-menu-item:hover svg {
  color: var(--red);
}
[data-theme="dark"] .icon-sun,
[data-theme="light"] .icon-moon {
  display: none;
}

/* ---- Auth ---- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}
.auth-panel h2 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-heading);
  font-size: 24px;
}
.auth-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}
.auth-panel label {
  display: grid;
  gap: 6px;
}
.auth-panel label span {
  color: var(--muted);
  font-size: 12px;
}
.auth-panel input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  background: var(--bg-grain);
  color: var(--text);
}
.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-status {
  min-height: 18px;
  color: var(--red);
  font-size: 12px;
}

/* ---- Search ---- */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  margin: 16px 16px 8px;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--faint);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 10px 38px 10px 36px;
  background: var(--panel-2);
  color: var(--text);
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease);
}
.search-box input::placeholder {
  color: var(--faint);
}
.search-box input:focus {
  background: var(--panel);
  border-color: var(--gold-line);
}
.search-kbd {
  position: absolute;
  right: 11px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 1px 6px;
  pointer-events: none;
}
.search-box input:not(:placeholder-shown) ~ .search-kbd {
  opacity: 0;
}

/* ---- Primary nav ---- */
.primary-nav {
  display: grid;
  gap: 2px;
  padding: 8px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  color: var(--muted);
  border-color: transparent;
  background: transparent;
}
.nav-item svg {
  color: var(--faint);
  flex: none;
  transition: color 0.16s var(--ease);
}
.nav-item span:first-of-type {
  flex: 1;
}
.nav-item:hover {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}
.nav-item.active {
  background: var(--gold-soft);
  border-color: var(--gold-line);
  color: var(--text-strong);
  font-weight: 600;
}
.nav-item.active svg {
  color: var(--gold);
}
.nav-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid var(--red-line);
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
  padding: 0 6px;
}
.nav-count:empty {
  display: none;
}

/* ---- Rail section header (Tagesordnung) ---- */
.rail-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 18px 8px;
}
.rail-section-toggle {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--faint);
}
.rail-section-toggle:hover,
.rail-section-toggle:focus-visible {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}
.rail-section-toggle::before {
  content: "›";
  display: inline-block;
  color: var(--faint);
  font-size: 14px;
  line-height: 1;
  transition: transform 0.14s var(--ease), color 0.14s var(--ease);
}
.rail-section-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}
.rail-section-title {
  color: var(--faint);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.13em;
}
.rail-section-toggle:hover .rail-section-title,
.rail-section-toggle:focus-visible .rail-section-title {
  color: var(--text);
}
.rail-section-count {
  min-width: 20px;
  text-align: right;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
}
.rail-section--documents,
.rail-section--attachments {
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.filter-toggle {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
}
.filter-toggle.active {
  color: var(--gold);
  background: var(--gold-soft);
  border-color: var(--gold-line);
}

/* ---- Tagesordnung list ---- */
.top-nav {
  display: grid;
  gap: 2px;
  padding: 0 10px 24px;
  flex: 1;
}
.top-link {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  text-align: left;
  padding: 9px 12px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}
.top-link:hover {
  background: var(--panel-2);
  border-color: var(--line);
}
.top-link.active {
  background: var(--gold-soft);
  border-color: var(--gold-line);
}
.risk-dot {
  grid-row: 1 / 3;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  align-self: center;
}
.risk-dot--high {
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.risk-dot--med {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.risk-dot--low {
  background: transparent;
  border: 1.5px solid var(--line-strong);
}
.risk-dot--neutral {
  background: var(--panel-2);
  border: 1.5px solid var(--line-strong);
}
.top-number {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 500;
}
.top-link.active .top-number {
  color: var(--gold-bright);
}
.top-title {
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.nav-empty {
  color: var(--faint);
  font-size: 12.5px;
  padding: 10px 14px;
}

/* ---- Anhänge list ---- */
.document-nav,
.attachment-nav {
  display: grid;
  gap: 2px;
  padding: 0 10px 18px;
  flex: none;
}
.attachment-link {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 9px;
  row-gap: 1px;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}
.attachment-link:hover {
  background: var(--panel-2);
  border-color: var(--line);
}
.attachment-link.active {
  background: var(--gold-soft);
  border-color: var(--gold-line);
}
.attachment-number {
  grid-row: 1 / 3;
  align-self: start;
  padding-top: 1px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
}
.attachment-link.active .attachment-number {
  color: var(--gold-bright);
}
.attachment-title {
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.28;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.attachment-pages {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.25;
}

/* ============================================================
   Content — headings
   ============================================================ */
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--gold);
  margin: 0 0 8px;
}
.view-head h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}
.view-head .muted {
  margin: 8px 0 0;
}
.view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: none;
}

/* ---- Detail header (TOP / attachment / issue) ---- */
.detail-head {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "back aside" "title aside";
  gap: 6px 18px;
  align-items: start;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.back-btn {
  grid-area: back;
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 2px 0;
  font-size: 12.5px;
  font-weight: 600;
}
.back-btn:hover {
  background: transparent;
  color: var(--gold);
}
.detail-title {
  grid-area: title;
}
.detail-title h2 {
  margin: 2px 0 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 27px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}
.detail-aside {
  grid-area: aside;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ---- JPEG page viewer ---- */
.page-viewer {
  display: grid;
  gap: 14px;
}
.page-viewer-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  user-select: none;
  -webkit-user-select: none;
}
.page-viewer-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-strong);
}
.page-viewer-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px 12px;
}
.page-stack {
  display: grid;
  gap: 18px;
}
.page-viewer-shell {
  position: relative;
  width: var(--page-viewer-w, 100%);
  min-width: min(100%, 360px);
}
.page-viewer-resizer {
  position: absolute;
  top: 0;
  right: -12px;
  bottom: 0;
  z-index: 4;
  width: 20px;
  cursor: col-resize;
  touch-action: none;
}
.page-viewer-resizer::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 9px;
  width: 1px;
  border-radius: 999px;
  background: var(--line-strong);
  opacity: 0.55;
  transition: background 0.14s var(--ease), box-shadow 0.14s var(--ease), opacity 0.14s var(--ease);
}
.page-viewer-resizer:hover::before,
.page-viewer-resizer:focus-visible::before,
body.page-viewer-resizing .page-viewer-resizer::before {
  background: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
  opacity: 1;
}
body.page-viewer-resizing {
  cursor: col-resize;
  user-select: none;
}
.page-image-frame {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.page-image-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  user-select: none;
  -webkit-user-select: none;
}
.page-image-toolbar a {
  color: var(--gold);
  font-weight: 600;
}
.page-ocr-status {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}
.page-image-sheet {
  position: relative;
  overflow: hidden;
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
}
.page-image-sheet img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
}
.page-ocr-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  overflow: hidden;
  color: transparent;
  -webkit-text-fill-color: transparent;
  font-family: Arial, Helvetica, sans-serif;
  transform-origin: left top;
  user-select: none;
  -webkit-user-select: none;
  cursor: text;
}
.page-ocr-box {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: transparent;
  -webkit-text-fill-color: transparent;
  white-space: pre;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
  cursor: text;
  letter-spacing: 0;
  transform-origin: left top;
}
.page-ocr-line {
  font-family: Arial, Helvetica, sans-serif;
}
.page-ocr-word {
  font-family: Arial, Helvetica, sans-serif;
}
.page-ocr-box.selected {
  background: rgba(190, 132, 35, 0.35);
  color: transparent;
  -webkit-text-fill-color: transparent;
}
.page-image-missing {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  background: var(--panel-2);
}

/* ---- Tiles (summary metrics) ---- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.tile {
  position: relative;
  padding: 16px 17px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tile.tile-link {
  width: 100%;
  text-align: left;
  color: var(--text);
}
.tile.tile-link:hover {
  border-color: var(--gold-line);
  background: var(--panel-hover);
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent 70%);
  opacity: 0.5;
}
.tile.alert::before {
  background: linear-gradient(90deg, var(--red), transparent 70%);
  opacity: 0.9;
}
.tile.good::before {
  background: linear-gradient(90deg, var(--green), transparent 70%);
}
.tile-value {
  font-family: var(--font-figure);
  font-size: 27px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.tile.alert .tile-value {
  color: var(--red);
}
.tile-value .delta {
  font-family: var(--font-figure);
  font-size: 26px;
}
.tile-sub {
  font-size: 16px;
  color: var(--faint);
  font-weight: 500;
}
.tile-label {
  color: var(--text);
  margin-top: 8px;
  font-size: 12.5px;
  font-weight: 500;
}
.tile-note {
  color: var(--muted);
  margin-top: 3px;
  font-size: 11px;
}

/* ---- Panels ---- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel {
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3,
.panel > h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  color: var(--text-strong);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head h3::before,
.panel > h3::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--gold);
  flex: none;
}
.panel-body {
  padding: 16px 18px;
}
.panel-body.flush {
  padding: 0;
}

.settings-form {
  max-width: 720px;
}
.settings-panel-body {
  display: grid;
  gap: 18px;
}
.settings-field {
  min-width: 0;
  display: grid;
  gap: 7px;
}
.settings-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.settings-field input[type="text"],
.settings-field input[type="password"],
.settings-field input:not([type]),
.settings-field select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.settings-field select {
  max-width: 360px;
}
.settings-field input:focus,
.settings-field select:focus {
  border-color: var(--gold-line);
}
.settings-segment {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: min(100%, 420px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.settings-segment label {
  min-width: 0;
  cursor: pointer;
}
.settings-segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.settings-segment span {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}
.settings-segment input:checked + span {
  color: #1a1206;
  background: var(--gold);
}
.settings-segment label:hover span,
.settings-segment input:focus-visible + span {
  color: var(--text);
  background: var(--panel-2);
}
.settings-segment input:checked:focus-visible + span,
.settings-segment label:hover input:checked + span {
  color: #1a1206;
  background: var(--gold-bright);
}
.settings-actions {
  display: flex;
  justify-content: flex-start;
}
.settings-status {
  color: var(--muted);
  font-size: 12px;
}
.settings-prompt-panel {
  max-width: 1040px;
}
.settings-prompt-field {
  gap: 8px;
}
.settings-prompt-textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}
.settings-prompt-textarea.medium {
  min-height: 170px;
}
.settings-prompt-textarea.compact {
  min-height: 78px;
}
.settings-prompt-textarea:focus {
  border-color: var(--gold-line);
}
.settings-prompt-tools {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.settings-prompt-catalog {
  display: grid;
  gap: 10px;
}
.settings-prompt-entry {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.settings-prompt-entry summary,
.settings-prompt-tools summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.settings-prompt-entry summary {
  display: grid;
  gap: 3px;
}
.settings-prompt-entry summary span {
  color: var(--text-strong);
}
.settings-prompt-entry summary small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.settings-prompt-entry p {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 12px;
}
.settings-prompt-entry .settings-prompt-textarea {
  border-left: 0;
  border-right: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  display: block;
}
.settings-prompt-entry.dirty {
  border-color: var(--gold-line);
}
.settings-prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
}
.settings-prompt-actions .primary-btn,
.settings-prompt-actions .ghost-btn {
  min-height: 32px;
  padding: 6px 10px;
}
.settings-prompt-actions .ghost-btn:disabled,
.settings-prompt-actions .primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.settings-prompt-actions .ghost-btn.confirm {
  color: var(--red);
}
.settings-prompt-status {
  color: var(--muted);
  font-size: 12px;
}
.settings-prompt-status.modified {
  color: var(--gold-bright);
}
.settings-prompt-status.dirty {
  color: var(--text-strong);
}
.settings-tool-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}
.settings-tool-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(170px, 0.34fr) minmax(0, 1fr);
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.settings-tool-row:first-child {
  border-top: 0;
}
.settings-tool-row strong {
  min-width: 0;
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.settings-tool-row span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
@media (max-width: 720px) {
  .settings-tool-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
.admin-user-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 12px;
}
.settings-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}
.settings-check input {
  accent-color: var(--gold);
}
.settings-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}
.user-list {
  display: grid;
  gap: 8px;
}
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.user-row div {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.user-row strong {
  color: var(--text-strong);
  font-size: 13px;
}
.user-row span {
  color: var(--muted);
  font-size: 11.5px;
}
.user-role {
  flex: none;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.user-role.admin {
  background: var(--gold-soft);
  color: var(--gold);
}
@media (max-width: 760px) {
  .admin-user-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

/* ---- Blocks (inside tab panels / details) ---- */
.block {
  margin-bottom: 26px;
}
.block-title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}
.expandable-card {
  margin-bottom: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.expandable-card summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  padding: 13px 15px;
  color: var(--text-strong);
  font-weight: 700;
}
.expandable-card summary::-webkit-details-marker {
  display: none;
}
.expandable-card summary::before {
  content: ">";
  color: var(--gold);
  font-size: 12px;
  transition: transform 0.14s var(--ease);
}
.expandable-card[open] summary::before {
  transform: rotate(90deg);
}
.expandable-card summary span {
  margin-right: auto;
}
.expandable-card summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.expandable-card-body {
  padding: 0 15px 15px;
}
.facts {
  display: grid;
  gap: 10px;
}
.fact {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.fact p {
  margin: 0 0 8px;
}
.fact-numbers,
.fact-cite {
  display: inline-flex;
  margin-right: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.fact-cite {
  color: var(--gold);
}
.fact-cite a,
.finding-facts em a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.claim-list,
.finding-list {
  display: grid;
  gap: 12px;
}
.claim-card,
.finding-card {
  position: relative;
  padding: 14px 15px 14px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.claim-card::before,
.finding-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: var(--gold);
  opacity: 0.72;
}
.finding-card.sev-high::before {
  background: var(--red);
}
.finding-card.sev-medium::before {
  background: var(--amber);
}
.finding-card.sev-low::before,
.finding-card.sev-neutral::before {
  background: var(--green);
}
.claim-head,
.ref-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}
.claim-head {
  margin-bottom: 9px;
}
.claim-card p,
.finding-card p {
  margin: 7px 0 0;
}
.claim-collapse,
.fact-collapse {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.claim-collapse summary,
.fact-collapse summary {
  cursor: pointer;
  padding: 10px 14px;
  color: var(--gold);
  font-size: 12.5px;
  font-weight: 700;
}
.claim-collapse summary:hover,
.fact-collapse summary:hover {
  color: var(--gold-bright);
}
.claim-list-nested,
.fact-list-nested {
  padding: 0 12px 12px;
}
.finding-card h4 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--text-strong);
}
.ref-row {
  margin-top: 10px;
}
.ref-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
}
button.ref-chip {
  cursor: pointer;
}
button.ref-chip:hover {
  border-color: var(--line-strong);
  background: var(--panel-hover);
}
.finding-facts {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
}
.finding-facts li + li {
  margin-top: 6px;
}
.finding-facts span,
.finding-facts em {
  font-family: var(--font-mono);
  color: var(--gold);
  font-style: normal;
}
.question-list {
  margin-top: 10px;
  color: var(--text);
}
.question-list ul {
  margin: 7px 0 0;
  padding-left: 18px;
}
.question-list li + li {
  margin-top: 5px;
}
.codex-result {
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.codex-result.failed {
  border-color: color-mix(in srgb, var(--red), var(--line) 55%);
}
.codex-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}
.codex-result pre {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
}
.codex-result details {
  margin-top: 12px;
}

/* ---- Triage cards ---- */
.top-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 12px;
}
.top-card {
  text-align: left;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  display: grid;
  gap: 8px;
  align-content: start;
}
.top-card:hover {
  border-color: var(--gold-line);
  background: var(--panel-hover);
}
.top-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.top-card h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
  color: var(--text-strong);
}

/* ---- Document cards ---- */
.doc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 12px;
}
.doc-card {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 118px;
  padding: 14px 15px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.doc-card:hover {
  border-color: var(--gold-line);
  background: var(--panel-hover);
}
.doc-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.doc-card h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.28;
  color: var(--text-strong);
}

/* ---- Mini rows (cost focus / issue list) ---- */
.mini-rows {
  display: grid;
  gap: 2px;
}
.mini-rows.tight {
  margin-top: 14px;
}
.mini-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: left;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
}
.mini-row:last-child {
  border-bottom: 0;
}
.mini-row.link {
  cursor: pointer;
}
.mini-row.link:hover {
  background: var(--panel-2);
}
.mini-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
}
.mini-delta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---- Severity breakdown ---- */
.sev-breakdown {
  display: grid;
  gap: 10px;
}
.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.summary-strip div {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.summary-strip strong {
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 15px;
}
.summary-strip span {
  color: var(--muted);
  font-size: 11.5px;
}
.scan-controls {
  display: grid;
  gap: 10px;
}
.scan-model-toggle {
  width: min(100%, 320px);
}
.settings-segment input:disabled + span {
  opacity: 0.55;
  cursor: progress;
}
.scan-job {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-grain);
}
.scan-job.running {
  border-color: var(--amber-line);
  background: var(--amber-soft);
}
.scan-job.failed {
  border-color: var(--red-line);
  background: var(--red-soft);
}
.scan-job strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-strong);
  font-size: 13px;
}
.scan-job p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}
.scan-job p + p {
  margin-top: 5px;
}
.scan-rescan-instructions {
  display: grid;
  gap: 8px;
}
.scan-rescan-instructions label {
  display: grid;
  gap: 3px;
}
.scan-rescan-instructions strong {
  color: var(--text-strong);
  font-size: 13px;
}
.scan-rescan-instructions span {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}
.scan-rescan-instructions textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-grain);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
}
.scan-rescan-instructions textarea:focus {
  border-color: var(--gold-line);
}
.scan-rescan-instructions textarea:disabled {
  opacity: 0.65;
  cursor: progress;
}
.scan-field-error {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
}
.scan-result {
  display: grid;
  gap: 16px;
}
.scan-note {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-grain);
}
.scan-note h4,
.scan-card h4 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.3;
}
.scan-note p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.scan-grid {
  display: grid;
  gap: 12px;
}
.scan-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 15px 16px 15px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.scan-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: var(--line-strong);
}
.scan-card.sev-high::before {
  background: var(--red);
}
.scan-card.sev-medium::before {
  background: var(--amber);
}
.scan-card.sev-low::before,
.scan-card.sev-neutral::before {
  background: var(--green);
}
.scan-card p {
  margin: 0;
}
.scan-subblock {
  display: grid;
  gap: 6px;
}
.scan-subblock strong {
  color: var(--muted);
  font-size: 12px;
}
.scan-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}
.scan-workflow pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}
.sev-line {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: center;
  gap: 12px;
}
.sev-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
}
.sev-track {
  height: 7px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.sev-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
}
.sev-fill.sev-high {
  background: var(--red);
}
.sev-fill.sev-medium {
  background: var(--amber);
}
.sev-fill.sev-low {
  background: var(--green);
}
.sev-fill.sev-neutral {
  background: var(--line-strong);
}
.sev-count {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-strong);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  overflow-x: auto;
}
.tab {
  border: 0;
  background: transparent;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab:hover {
  background: transparent;
  color: var(--text);
}
.tab.active {
  color: var(--text-strong);
  border-bottom-color: var(--gold);
}
.tab-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
}
.tab.active .tab-count {
  color: var(--gold);
  border-color: var(--gold-line);
  background: var(--gold-soft);
}

/* ---- Chips (filters) ---- */
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 6px 13px;
  color: var(--muted);
  background: var(--panel-2);
}
.chip.active {
  color: var(--text-strong);
  background: var(--gold-soft);
  border-color: var(--gold-line);
}
.chip-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}
.chip.active .chip-count {
  color: var(--gold);
}
.chip-link {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  color: var(--gold);
  border-color: var(--line-strong);
  background: transparent;
}
.chip-link:hover {
  background: var(--gold-soft);
  border-color: var(--gold-line);
}

/* ---- Callout (signal / status) ---- */
.callout {
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 24px;
}
.callout-high {
  border-left-color: var(--red);
  background: var(--red-soft);
}
.callout-med {
  border-left-color: var(--amber);
  background: var(--amber-soft);
}
.callout-low {
  border-left-color: var(--green);
}
.callout-medium {
  border-left-color: var(--amber);
  background: var(--amber-soft);
}
.callout-ok {
  border-left-color: var(--green);
  background: var(--green-soft);
}
.callout-neutral {
  border-left-color: var(--line-strong);
}
.callout-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.callout-head strong {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--text-strong);
}
.callout p {
  margin: 6px 0 0;
}

/* ---- Tables ---- */
.table-wrap {
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 16px;
  text-align: left;
  vertical-align: middle;
}
thead th {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line-strong);
}
tbody tr {
  transition: background 0.13s var(--ease);
}
tbody tr:hover {
  background: var(--panel-hover);
}
tbody tr:last-child td {
  border-bottom: 0;
}
td.amount,
th.amount {
  text-align: right;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.cell-label {
  font-weight: 500;
  color: var(--text-strong);
}
td.refs {
  white-space: nowrap;
}
td.refs a {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-right: 8px;
}

/* ---- Risk meter ---- */
.risk {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 96px;
}
.risk-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--line);
  min-width: 48px;
}
.risk-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s var(--ease);
}
.risk-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 20px;
  text-align: right;
}
.risk--high .risk-bar span {
  background: linear-gradient(90deg, var(--red), var(--amber));
}
.risk--high .risk-num {
  color: var(--red);
}
.risk--med .risk-bar span {
  background: linear-gradient(90deg, var(--amber), var(--gold));
}
.risk--med .risk-num {
  color: var(--amber);
}
.risk--low .risk-bar span {
  background: var(--green);
}
.risk--low .risk-num {
  color: var(--green);
}
.risk--neutral .risk-bar span {
  background: var(--line-strong);
}
.risk--neutral .risk-num {
  color: var(--muted);
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.high,
.badge.medium,
.badge.low,
.badge.neutral {
  font-weight: 600;
}
.badge.high::before,
.badge.medium::before,
.badge.low::before,
.badge.neutral::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}
.badge.dotonly {
  padding: 0;
  min-height: 0;
  width: 9px;
  height: 9px;
  border: 0;
  background: currentColor;
  border-radius: 999px;
}
.badge.high {
  color: var(--red);
  border-color: var(--red-line);
  background: var(--red-soft);
}
.badge.medium {
  color: var(--amber);
  border-color: var(--amber-line);
  background: var(--amber-soft);
}
.badge.low {
  color: var(--green);
  border-color: var(--green-line);
  background: var(--green-soft);
}
.badge.neutral {
  color: var(--muted);
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.badge.amount {
  font-family: var(--font-mono);
  color: var(--text);
}
.cost-priority-badge {
  cursor: help;
}
.cost-priority-badge:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.cost-tooltip {
  position: fixed;
  z-index: 80;
  max-width: min(360px, calc(100vw - 20px));
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}

/* ---- Delta ---- */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.delta.up {
  color: var(--red);
}
.delta.down {
  color: var(--green);
}
.delta.flat {
  color: var(--muted);
}
.delta-arrow {
  font-size: 9px;
}

/* ---- Cards ---- */
.list {
  display: grid;
  gap: 12px;
}
.issue-card,
.attachment-card,
.evidence-card {
  position: relative;
  padding: 15px 16px 15px 17px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease);
}
.issue-card::before,
.evidence-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: var(--line-strong);
}
.issue-card.sev-high::before {
  background: var(--red);
}
.issue-card.sev-medium::before {
  background: var(--amber);
}
.issue-card.sev-ok::before {
  background: var(--green);
}
.evidence-card::before {
  background: var(--gold);
  opacity: 0.6;
}
.issue-card:hover,
.attachment-card:hover,
.evidence-card:hover {
  border-color: var(--line-strong);
  background: var(--panel-hover);
}
.card-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin-bottom: 9px;
}
.issue-card h4,
.attachment-card h4,
.evidence-card h4 {
  margin: 0 0 5px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
  color: var(--text-strong);
}
.issue-card p,
.attachment-card p,
.evidence-card p {
  margin: 5px 0 0;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.card-actions button,
.card-actions a {
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.card-actions a {
  border: 1px solid var(--line-strong);
  color: var(--gold);
}
.card-actions a:hover {
  background: var(--gold-soft);
  border-color: var(--gold-line);
  text-decoration: none;
}

/* ---- Prose (agenda text) ---- */
.prose {
  max-width: 70ch;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}
.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  margin: 0 0 0.8em;
  line-height: 1.3;
  color: var(--text);
  font-weight: 650;
}
.prose h1 {
  font-size: 1.72em;
}
.prose h2 {
  font-size: 1.38em;
}
.prose h3 {
  font-size: 1.15em;
}
.prose h4 {
  font-size: 1.05em;
}
.prose ul,
.prose ol {
  margin: 0 0 1.1em;
  padding-left: 1.35rem;
}
.prose li {
  margin: 0 0 0.45em;
}
.prose blockquote {
  margin: 0 0 1.1em;
  padding: 0.2rem 0.8rem;
  border-left: 3px solid var(--line-strong);
  background: var(--bg-grain);
  color: var(--muted);
}
.prose pre {
  margin: 0 0 1.1em;
  padding: 0.85rem 0.95rem;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.8px;
  line-height: 1.5;
}
.prose code {
  font-family: var(--font-mono);
  background: var(--bg-grain);
  padding: 0.06rem 0.2rem;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
}
.prose p {
  margin: 0 0 1.1em;
}
.prose p:first-child {
  margin-top: 0;
}

/* ---- Preformatted ---- */
.pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--bg-grain);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 560px;
  overflow: auto;
  color: var(--text);
}

/* ---- Scratchpad ---- */
.scratch textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  transition: border-color 0.16s var(--ease);
}
.scratch textarea:focus {
  border-color: var(--gold-line);
}
.scratch.scratch-dirty textarea {
  border-color: var(--amber-line);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.scratch-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 11px;
}
.scratch-status {
  color: var(--muted);
  font-size: 12px;
}
.scratch-status.dirty {
  color: var(--amber);
  font-weight: 600;
}
.scratch-actions .primary-btn.dirty {
  box-shadow: 0 0 0 3px var(--amber-soft), 0 1px 0 rgba(255, 255, 255, 0.18) inset;
}

/* ---- TOP analysis document ---- */
.top-analysis-doc {
  display: grid;
  gap: 14px;
  container-type: inline-size;
}
.analysis-doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
  gap: 14px;
}
.analysis-doc-panel {
  min-width: 0;
}
.analysis-doc-note {
  color: var(--muted);
  font-size: 12px;
}
.analysis-doc-textarea {
  width: 100%;
  min-height: 310px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.analysis-doc-textarea:focus {
  border-color: var(--gold-line);
}
.analysis-doc-editor-host {
  min-width: 0;
}
.analysis-doc-editor {
  width: 100%;
  min-height: 310px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
  background: var(--bg-grain);
  overflow: hidden;
}
.analysis-doc-editor-content {
  min-height: 280px;
  outline: none;
  padding: 18px 20px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  white-space: normal;
  /* shared rhythm unit so every block lines up to the same baseline */
  --flow: 0.95em;
}

/* ---- TipTap document flow: balanced vertical rhythm ----
   Every block clears the same gap below; the first/last clear their edges
   so the editor never opens with a stray top margin. */
.analysis-doc-editor-content > * {
  margin: 0 0 var(--flow);
}
.analysis-doc-editor-content > :first-child {
  margin-top: 0;
}
.analysis-doc-editor-content > :last-child {
  margin-bottom: 0;
}

/* Headings — same scale as the read-side .prose, with extra space above
   so a heading breathes away from the block before it. */
.analysis-doc-editor-content h1,
.analysis-doc-editor-content h2,
.analysis-doc-editor-content h3,
.analysis-doc-editor-content h4 {
  margin: 1.5em 0 0.5em;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text-strong);
}
.analysis-doc-editor-content > h1:first-child,
.analysis-doc-editor-content > h2:first-child,
.analysis-doc-editor-content > h3:first-child,
.analysis-doc-editor-content > h4:first-child {
  margin-top: 0;
}
.analysis-doc-editor-content h1 {
  font-size: 1.55em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--line);
}
.analysis-doc-editor-content h2 {
  font-size: 1.3em;
}
.analysis-doc-editor-content h3 {
  font-size: 1.12em;
}
.analysis-doc-editor-content h4 {
  font-size: 1em;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-sans);
  font-weight: 700;
}

/* Lists — controlled indent + tight, even rhythm between items. */
.analysis-doc-editor-content ul,
.analysis-doc-editor-content ol {
  padding-left: 1.4em;
}
.analysis-doc-editor-content li {
  margin: 0 0 0.3em;
}
.analysis-doc-editor-content li > ul,
.analysis-doc-editor-content li > ol {
  margin: 0.3em 0 0;
}
.analysis-doc-editor-content li > p {
  margin: 0 0 0.3em;
}
.analysis-doc-editor-content ul {
  list-style: none;
}
.analysis-doc-editor-content ul > li {
  position: relative;
  padding-left: 0.2em;
}
.analysis-doc-editor-content ul > li::before {
  content: "";
  position: absolute;
  left: -0.95em;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 1.5px;
  background: var(--gold);
  transform: rotate(45deg);
}
.analysis-doc-editor-content ol {
  list-style: decimal;
}
.analysis-doc-editor-content ol > li::marker {
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.92em;
}

/* Task lists (StarterKit / GFM checkboxes) */
.analysis-doc-editor-content ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0.1em;
}
.analysis-doc-editor-content ul[data-type="taskList"] > li {
  display: flex;
  gap: 0.55em;
  padding-left: 0;
}
.analysis-doc-editor-content ul[data-type="taskList"] > li::before {
  display: none;
}
.analysis-doc-editor-content ul[data-type="taskList"] li > label {
  flex: none;
  margin-top: 0.12em;
}
.analysis-doc-editor-content ul[data-type="taskList"] input[type="checkbox"] {
  accent-color: var(--gold);
}

/* Blockquote — matches the read-side, with a gold rule. */
.analysis-doc-editor-content blockquote {
  padding: 0.35em 0.9em;
  border-left: 3px solid var(--gold-line);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--gold-soft);
  color: var(--muted);
}
.analysis-doc-editor-content blockquote > :last-child {
  margin-bottom: 0;
}

/* Inline + block code — mono only here, not on the whole body. */
.analysis-doc-editor-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--panel-2);
  padding: 0.08em 0.34em;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--gold-bright);
}
.analysis-doc-editor-content pre {
  padding: 0.85em 1em;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-grain);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}
.analysis-doc-editor-content pre code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}

/* Inline emphasis + rule + links */
.analysis-doc-editor-content strong {
  font-weight: 700;
  color: var(--text-strong);
}
.analysis-doc-editor-content em {
  font-style: italic;
}
.analysis-doc-editor-content a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.analysis-doc-editor-content hr {
  border: 0;
  height: 1px;
  margin: 1.6em 0;
  background: linear-gradient(90deg, var(--line-strong), transparent);
}
.analysis-doc-editor-content hr.ProseMirror-selectednode {
  outline: 2px solid var(--gold-line);
  outline-offset: 3px;
}
.analysis-doc-editor-content:focus-within,
.analysis-doc-editor:focus-within {
  border-color: var(--gold-line);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.analysis-doc-dirty .analysis-doc-textarea {
  border-color: var(--amber-line);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.analysis-doc-dirty .analysis-doc-editor {
  border-color: var(--amber-line);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.analysis-doc-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.analysis-doc-status {
  color: var(--muted);
  font-size: 12px;
}
.analysis-doc-status.dirty {
  color: var(--amber);
  font-weight: 600;
}
.analysis-doc-preview-panel {
  min-width: 0;
}
.analysis-doc-preview {
  max-width: 860px;
}
@container (max-width: 760px) {
  .analysis-doc-grid {
    grid-template-columns: 1fr;
  }
}

/* ---- Empty ---- */
.empty {
  color: var(--muted);
  padding: 18px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color 0.14s var(--ease);
}
a:hover {
  color: var(--gold-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ============================================================
   Assistant drawer
   ============================================================ */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: transparent;
  opacity: 0;
  transition: opacity 0.22s var(--ease);
}
.scrim.show {
  opacity: 0;
}
.assistant {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  height: 100vh;
  width: min(var(--assistant-w, 520px), calc(100vw - 16px));
  background: linear-gradient(180deg, var(--panel), var(--bg-grain));
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  transform: translateX(100%);
  transition: transform 0.28s var(--ease);
}
.assistant.open {
  transform: none;
}
.assistant:not(.open) .assistant-resources {
  opacity: 0;
  pointer-events: none;
}
.assistant.resizing {
  transition: none;
}
.assistant-resizer {
  position: absolute;
  top: 0;
  left: -5px;
  width: 10px;
  height: 100%;
  z-index: 2;
  cursor: ew-resize;
  touch-action: none;
}
.assistant-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: transparent;
  transition: background 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.assistant-resizer:hover::after,
.assistant-resizer:focus-visible::after,
.assistant.resizing .assistant-resizer::after {
  background: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}
body.assistant-resizing {
  cursor: ew-resize;
  user-select: none;
}
.assistant-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line);
}
.assistant-head h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 17px;
  color: var(--text-strong);
}
.assistant-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.assistant-head p span {
  color: var(--gold);
  font-weight: 600;
}
.assistant-model-picker {
  width: min(100%, 220px);
  display: grid;
  gap: 5px;
  margin-top: 10px;
}
.assistant-model-picker span {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}
.assistant-model-picker select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  background: var(--bg-grain);
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}
.assistant-model-picker select:focus {
  border-color: var(--gold-line);
}
.chat-scope {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 9px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
}
.chat-scope:empty {
  display: none;
}
.chat-scope button {
  min-width: 0;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}
.chat-scope button:hover {
  color: var(--text);
  background: var(--panel-2);
}
.chat-scope button.active {
  color: #1a1206;
  background: var(--gold);
  font-weight: 700;
}
.chat-session-picker {
  width: min(100%, 280px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 5px;
  align-items: center;
  margin-top: 8px;
}
.chat-session-picker select {
  min-width: 0;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  background: var(--bg-grain);
  color: var(--text);
  font-size: 11.5px;
}
.chat-session-picker button {
  min-width: 0;
  height: 30px;
  padding: 4px 7px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 11px;
}
.chat-session-picker button:hover:not(:disabled) {
  color: var(--text);
  background: var(--gold-soft);
}
.chat-session-picker button:disabled,
.chat-session-picker select:disabled {
  opacity: 0.55;
  cursor: default;
}
.assistant-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.assistant-body {
  min-height: 0;
  position: relative;
  overflow: visible;
  isolation: isolate;
}
.assistant-chat {
  position: relative;
  z-index: 2;
  min-width: 0;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-grain));
}
.chat-drop-overlay {
  position: absolute;
  inset: 10px;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 1px dashed var(--gold-line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-grain) 86%, transparent);
  box-shadow: inset 0 0 0 2px var(--gold-soft);
  pointer-events: none;
}
.chat-drop-overlay div {
  display: grid;
  gap: 3px;
  min-width: 210px;
  padding: 16px 18px;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
  box-shadow: var(--shadow);
}
.chat-drop-overlay strong {
  color: var(--text-strong);
}
.chat-drop-overlay span {
  color: var(--muted);
  font-size: 12px;
}
.assistant-resources {
  position: absolute;
  top: 0;
  right: calc(100% + 1px);
  bottom: 0;
  width: min(292px, calc(100vw - var(--assistant-w, 520px) - 18px));
  min-width: 240px;
  min-height: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius);
  background: color-mix(in srgb, var(--bg-grain) 72%, var(--panel));
  box-shadow: var(--shadow);
  transform: translateX(0);
  opacity: 1;
  transition: transform 0.2s var(--ease), opacity 0.16s var(--ease);
}
.assistant.resources-collapsed .assistant-resources {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}
.assistant-resources-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.assistant-resources-head h3 {
  margin: 0;
  color: var(--text-strong);
  font-size: 13px;
}
.assistant-resources-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}
.assistant-context-breakdown {
  min-height: 0;
  overflow: visible;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.assistant-context-breakdown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0;
}
.assistant-context-breakdown h4 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.assistant-context-breakdown-head span,
.assistant-context-part-main b,
.assistant-context-part-children b {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
}
.assistant-context-breakdown p {
  margin: 0;
  color: var(--faint);
  font-size: 11px;
}
.assistant-context-parts {
  min-height: 0;
  display: grid;
  gap: 5px;
}
.assistant-context-part {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.assistant-context-part details {
  min-width: 0;
  display: grid;
  gap: 5px;
}
.assistant-context-part summary {
  cursor: pointer;
  list-style: none;
}
.assistant-context-part summary::-webkit-details-marker {
  display: none;
}
.assistant-context-part summary strong::before {
  content: "›";
  display: inline-block;
  width: 10px;
  margin-right: 2px;
  color: var(--muted);
  transition: transform 0.14s var(--ease);
}
.assistant-context-part details[open] summary strong::before {
  transform: rotate(90deg);
}
.assistant-context-part-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: baseline;
}
.assistant-context-part-main strong {
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.assistant-context-part-main span {
  grid-column: 1;
  color: var(--muted);
  font-size: 10.5px;
}
.assistant-context-part-main b {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.assistant-context-part-children {
  display: grid;
  gap: 3px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}
.assistant-context-part-children div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10.5px;
}
.assistant-resource-filter {
  width: 100%;
  min-width: 0;
  height: 34px;
  min-height: 34px;
  max-height: 34px;
  box-sizing: border-box;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  line-height: 16px;
}
.assistant-resource-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-right: 2px;
}
.assistant-resource-category {
  display: grid;
  gap: 6px;
}
.assistant-resource-category-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 2px 0;
  background: color-mix(in srgb, var(--bg-grain) 72%, var(--panel));
}
.assistant-resource-category-toggle {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.assistant-resource-category-toggle:hover,
.assistant-resource-category-toggle:focus-visible,
.assistant-resource-category-toggle[aria-expanded="true"] {
  border-color: transparent;
  background: transparent;
  color: var(--text);
}
.assistant-resource-category-toggle::before {
  content: "›";
  flex: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  transition: transform 0.14s var(--ease);
}
.assistant-resource-category-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}
.assistant-resource-category-toggle span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.assistant-resource-category-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.assistant-resource-category-actions button {
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 11px;
}
.assistant-resource-category-actions button:hover {
  color: var(--text);
  background: var(--gold-soft);
}
.assistant-resource-items {
  display: grid;
  gap: 4px;
}
.assistant-resource-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
}
.assistant-resource-item:hover,
.assistant-resource-item:has(input:checked) {
  border-color: var(--gold-line);
  background: var(--gold-soft);
}
.assistant-resource-item.implicit {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--gold-soft) 42%, var(--panel));
}
.assistant-resource-item.implicit:not(:has(input:checked)) {
  border-color: transparent;
  background: var(--panel);
}
.assistant-resource-item input {
  margin-top: 2px;
  accent-color: var(--gold);
}
.assistant-resource-item input:disabled {
  opacity: 0.75;
}
.assistant-resource-item-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.assistant-resource-item strong {
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.assistant-resource-item span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.assistant-resource-empty {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}
.chat-context {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
  container-type: inline-size;
}
.chat-context-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg-grain);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}
.chat-context-toggle:hover,
.chat-context-toggle[aria-expanded="true"] {
  border-color: var(--gold-line);
  background: var(--gold-soft);
  color: var(--text);
}
.chat-context-icon {
  flex: none;
  color: var(--muted);
}
.chat-context-icon-close {
  display: none;
}
.chat-context-toggle[aria-expanded="true"] .chat-context-icon-open {
  display: none;
}
.chat-context-toggle[aria-expanded="true"] .chat-context-icon-close {
  display: block;
}
.chat-context-size {
  min-width: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow-wrap: anywhere;
}
.chat-context-sources {
  min-width: 0;
  justify-self: end;
  color: var(--muted);
  text-align: right;
  overflow-wrap: anywhere;
}
@container (max-width: 700px) {
  .chat-context-toggle {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 9px;
  }
  .chat-context-sources {
    grid-column: 2;
    justify-self: start;
    text-align: left;
  }
}
.chat-log {
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  max-width: 240px;
  line-height: 1.55;
}
.chat-empty svg {
  display: block;
  margin: 0 auto 12px;
  color: var(--line-strong);
}
.message {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  background: var(--panel);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.55;
  min-width: 0;
  max-width: 92%;
  animation: msg-in 0.32s var(--ease) both;
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.message.user-message {
  align-self: flex-end;
  border-color: var(--gold-line);
  background: var(--gold-soft);
  border-bottom-right-radius: 4px;
}
.message.assistant-message {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.message p,
.message ul,
.message ol,
.message blockquote,
.message pre,
.message h3,
.message h4,
.message h5,
.message h6 {
  margin: 0 0 9px;
}
.message > :last-child {
  margin-bottom: 0;
}
.message h3,
.message h4,
.message h5,
.message h6 {
  color: var(--text-strong);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.35;
}
.message ul,
.message ol {
  padding-left: 18px;
}
.message li + li {
  margin-top: 3px;
}
.message blockquote {
  padding-left: 10px;
  border-left: 2px solid var(--gold-line);
  color: var(--muted);
}
.message code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 4px;
  background: var(--bg-grain);
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 12px;
}
.message pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--bg-grain);
}
.message pre code {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  white-space: pre;
}
.message a {
  color: var(--gold-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--gold-line);
}
.message a:hover {
  color: var(--gold);
}
.message hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}
.message.error {
  align-self: stretch;
  max-width: 100%;
  border-color: var(--red-line);
  background: var(--red-soft);
  color: var(--red);
}
.message-pending {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}
.lookup-message {
  display: grid;
  gap: 9px;
  max-width: 96%;
  color: var(--muted);
}
.lookup-message-head {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.lookup-message-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-strong);
}
.lookup-message-head span:last-child {
  color: var(--faint);
  font-size: 11px;
}
.lookup-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.message .lookup-list {
  padding-left: 0;
}
.lookup-list li {
  min-width: 0;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel-2) 72%, transparent);
}
.lookup-list li + li {
  margin-top: 0;
}
.lookup-status {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.lookup-list li.running .lookup-status {
  background: var(--amber);
  animation: lookup-pulse 1.1s ease-in-out infinite;
}
.lookup-list li.error .lookup-status {
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.lookup-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.lookup-text strong {
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.35;
}
.lookup-text span {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
}
.lookup-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
@keyframes lookup-pulse {
  50% {
    opacity: 0.45;
    transform: scale(0.82);
  }
}
.chat-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--gold);
  border-radius: 999px;
  animation: chat-spin 0.8s linear infinite;
  flex: none;
}
@keyframes chat-spin {
  to {
    transform: rotate(360deg);
  }
}
.chat-input {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  gap: 10px;
  background: var(--panel);
}
.chat-attachments {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-grain);
}
.chat-attachments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11.5px;
}
.chat-attachments-head button {
  padding: 3px 6px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}
.chat-attachments-head button:hover {
  color: var(--text);
  background: var(--panel-2);
}
.chat-attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-attachment {
  min-width: 0;
  max-width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 7px;
  padding: 6px 7px 6px 9px;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--muted);
  font-size: 11px;
}
.chat-attachment-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}
.chat-attachment button {
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  border-color: transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}
.chat-attachment button:hover {
  color: var(--red);
  background: var(--red-soft);
}
.chat-input textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg-grain);
  color: var(--text);
  transition: border-color 0.16s var(--ease);
}
.chat-input textarea:focus {
  border-color: var(--gold-line);
}
.chat-input textarea::placeholder {
  color: var(--faint);
}
.chat-input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.chat-input-tools {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.chat-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}
.chat-reset-btn {
  min-height: 28px;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}
.chat-reset-btn:hover:not(:disabled),
.chat-reset-btn:focus-visible:not(:disabled) {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.chat-reset-btn.confirm {
  color: var(--red);
}
.chat-reset-btn:disabled {
  color: var(--faint);
  cursor: default;
  opacity: 0.58;
}
.chat-input-row .primary-btn.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.chat-input-row .primary-btn.loading::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid rgba(26, 18, 6, 0.32);
  border-top-color: #1a1206;
  border-radius: 999px;
  animation: chat-spin 0.8s linear infinite;
}
.chat-usage {
  min-width: 0;
  padding: 7px 14px 9px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 86%, var(--bg-grain));
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Assistant FAB ---- */
.assistant-fab {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 13px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: 1px solid var(--gold);
  color: #1a1206;
  font-weight: 600;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}
.assistant-fab:hover {
  background: var(--gold-bright);
  transform: translateY(-1px);
}
.assistant.open ~ .assistant-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
.fab-label {
  font-size: 13px;
}

/* ============================================================
   Reveal animation
   ============================================================ */
.view > * {
  animation: rise 0.5s var(--ease) both;
}
.view > *:nth-child(1) {
  animation-delay: 0.02s;
}
.view > *:nth-child(2) {
  animation-delay: 0.08s;
}
.view > *:nth-child(3) {
  animation-delay: 0.14s;
}
.view > *:nth-child(4) {
  animation-delay: 0.2s;
}
.view > *:nth-child(n + 5) {
  animation-delay: 0.26s;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1080px) {
  .content {
    padding: 24px 26px 80px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .rail {
    grid-column: 1;
    grid-row: 1;
    position: fixed;
    z-index: 60;
    width: 84vw;
    max-width: 320px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.26s var(--ease);
  }
  .rail.open {
    transform: none;
  }
  .content {
    padding: 20px 18px 90px;
  }
  .page-viewer-shell {
    width: 100%;
    min-width: 0;
  }
  .page-viewer-resizer {
    display: none;
  }
  .view-head {
    flex-direction: column;
  }
  .view-head h2 {
    font-size: 24px;
  }
  .detail-head {
    grid-template-columns: 1fr;
    grid-template-areas: "back" "title" "aside";
  }
  .detail-aside {
    align-items: flex-start;
    flex-direction: row;
  }
  .assistant {
    width: 100vw;
  }
  .assistant-body {
    overflow: hidden;
  }
  .assistant-resources {
    left: 0;
    right: auto;
    width: min(320px, calc(100vw - 44px));
    max-width: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    border-left: 0;
    border-right: 1px solid var(--line-strong);
  }
  .assistant.resources-collapsed .assistant-resources {
    transform: translateX(-100%);
  }
  .assistant-resizer {
    display: none;
  }
}
