/* ==========================================================================
   Fixxit — design system
   Light, warm, industrial-refined. D-DIN everywhere, one accent (signal orange).
   ========================================================================== */

@font-face {
  font-family: "D-DIN";
  src: url("../fonts/d-din-400.woff2") format("woff2"), url("../fonts/d-din-400.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "D-DIN";
  src: url("../fonts/d-din-400italic.woff2") format("woff2"), url("../fonts/d-din-400italic.woff") format("woff");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "D-DIN";
  src: url("../fonts/d-din-700.woff2") format("woff2"), url("../fonts/d-din-700.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Surfaces */
  --bg: #fafafa;            /* page */
  --bg-sunken: #f6f6f6;     /* sidebar, wells (brand hover gray) */
  --surface: #ffffff;       /* cards, composer */
  --surface-2: #fcfcfc;     /* subtle raised */
  --surface-hover: #f0f2f5;
  --surface-active: #e6ebf1;

  /* Ink */
  --ink: #1b1b1b;           /* brand text-dark */
  --ink-2: #3a3a3a;
  --muted: #5e5e5e;           /* brand text-secondary */
  --faint: #9a9a9a;

  /* Lines */
  --line: #e5e5e5;          /* brand border-light */
  --line-strong: #d2d6dc;

  /* Accent: Fixxit navy (brand primary-blue) */
  --accent: #0c3455;
  --accent-hover: #082944;
  --accent-ink: #0c3455;
  --accent-soft: #e8eef4;
  --accent-line: #b9c8d7;

  /* Status */
  --ok: #228b22;             /* brand success-green */
  --ok-soft: #e6f3e6;
  --warn: #a85c00;           /* readable brand warning-orange */
  --warn-soft: #fff1de;
  --danger: #b42318;
  --danger-soft: #fbe7e4;
  --info: #0c3455;
  --info-soft: #e8eef4;

  /* Type */
  --font: "D-DIN", "DIN Alternate", "Bahnschrift", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 16.5px;
  --fs-lg: 20px;
  --fs-xl: 28px;
  --fs-2xl: 36px;
  --tracking-label: 0.12em;

  /* Shape & depth */
  --radius-xs: 4px;
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-xs: 0 1px 0 rgba(12, 28, 45, 0.04);
  --shadow-sm: 0 1px 2px rgba(12, 28, 45, 0.06), 0 1px 1px rgba(12, 28, 45, 0.03);
  --shadow: 0 4px 16px -6px rgba(12, 28, 45, 0.12), 0 1px 3px rgba(12, 28, 45, 0.06);
  --shadow-lg: 0 24px 48px -16px rgba(12, 28, 45, 0.22), 0 2px 6px rgba(12, 28, 45, 0.06);
  --ring: 0 0 0 3px rgba(12, 52, 85, 0.22);

  --sidebar-w: 272px;
  --chat-w: 780px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* --- Reset / base ---------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern", "tnum";
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.005em; line-height: 1.2; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); color: var(--ink); }

:focus-visible { outline: none; box-shadow: var(--ring); }

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

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }
.icon-xs { width: 13px; height: 13px; }
.icon-lg { width: 22px; height: 22px; }

.label {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--muted);
}

.mono { font-family: var(--mono); font-size: 0.9em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* --- Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
  text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #971c12; border-color: #971c12; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; height: 42px; font-size: 15px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--ink); }
.icon-btn.is-on { color: var(--ink); background: var(--surface-active); }

/* --- Form controls --------------------------------------------------------- */

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 14px; }
.field-label {
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: var(--tracking-label); color: var(--ink-2);
}
.field-hint { font-size: var(--fs-sm); color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.field-row .field + .field { margin-top: 0; }

.input, .select, .textarea {
  width: 100%;
  height: 40px; padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23736f64' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input-sm, .select-sm { height: 34px; font-size: 14px; }

.search-input { position: relative; }
.search-input .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; width: 16px; height: 16px; }
.search-input .input { padding-left: 34px; }

/* --- Flash / callouts ------------------------------------------------------ */

.flash {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 14px;
}
.flash .icon { margin-top: 1px; }
.flash-error { background: var(--danger-soft); border-color: #f1c6c0; color: #7d1810; }
.flash-success { background: var(--ok-soft); border-color: #c4e0cd; color: #1f5636; }
.flash + .flash { margin-top: 8px; }

/* --- Badges & chips -------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--surface-hover); color: var(--ink-2);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge-plain::before { display: none; }
.badge-ready { background: var(--ok-soft); color: var(--ok); }
.badge-queued { background: var(--surface-hover); color: var(--muted); }
.badge-processing { background: var(--warn-soft); color: var(--warn); }
.badge-processing::before { animation: pulse 1.2s ease-in-out infinite; }
.badge-failed { background: var(--danger-soft); color: var(--danger); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-size: 13px; white-space: nowrap;
}
.chip-mono { font-family: var(--mono); font-size: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap;
}
.tag .icon { width: 12px; height: 12px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 14px; height: 14px; flex: none;
  border: 1.6px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==========================================================================
   App shell
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh; height: 100dvh;
  transition: grid-template-columns 0.25s var(--ease);
}
body.nav-collapsed .shell { grid-template-columns: 0 minmax(0, 1fr); }
body.nav-collapsed .sidebar { visibility: hidden; }

.sidebar {
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  background: var(--bg-sunken);
  border-right: 1px solid var(--line);
}
.sidebar-inner { display: flex; flex-direction: column; width: var(--sidebar-w); height: 100%; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; }
/* The logo's XX sits below the image centre (the ✦ rises above it); lift the mark
   so the wordmark lines up with the letters, not the image box. */
.brand .brand-mark, .auth-brand .brand-mark { transform: translateY(-14%); }
.brand-word { font-size: 19px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent); }
.brand-word b { color: var(--accent); font-weight: 700; }

.sidebar-new { padding: 6px 12px 10px; }
.new-chat {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 14.5px; letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.new-chat:hover { border-color: var(--ink-2); box-shadow: var(--shadow); }
.new-chat kbd { margin-left: auto; font-family: var(--font); font-size: 11px; color: var(--faint); letter-spacing: 0.04em; }
.new-chat .icon { color: var(--accent); }

.nav { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; padding: 4px 12px 12px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14.5px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface-hover); color: var(--ink); }
.nav-link.is-active { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-xs); }
.nav-link.is-active .icon { color: var(--accent); }

.history { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 12px 16px; border-top: 1px solid var(--line); }
.history-group { margin-top: 14px; }
.history-group > .label { display: block; padding: 0 10px 6px; font-size: 10.5px; color: var(--faint); }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.history-item { min-width: 0; }
.history-item { position: relative; }
.history-link {
  display: block; padding: 7px 34px 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.12s;
}
.history-link:hover { background: var(--surface-hover); color: var(--ink); }
.history-item.is-active .history-link { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-xs); }
.history-item.is-active .history-link::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 2px; border-radius: 2px; background: var(--accent);
}
.history-more {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; opacity: 0;
}
.history-item:hover .history-more,
.history-item.is-active .history-more,
.history-more:focus-visible,
.history-more[aria-expanded="true"] { opacity: 1; }
.history-rename { width: 100%; height: 32px; padding: 0 9px; font-size: 14px; border-radius: var(--radius-sm); border: 1px solid var(--accent); box-shadow: var(--ring); background: var(--surface); }
.history-empty { padding: 18px 10px; font-size: 13.5px; color: var(--faint); }
.history-skel { height: 30px; margin: 4px 0; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--bg-sunken), var(--surface-hover), var(--bg-sunken)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }

.user-menu { position: relative; padding: 10px 12px 14px; border-top: 1px solid var(--line); }
.user-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px; border: 0; border-radius: var(--radius);
  background: transparent; text-align: left;
  transition: background 0.15s;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--surface-hover); }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em;
}
.user-meta { min-width: 0; flex: 1; display: grid; }
.user-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-org { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-btn .icon { color: var(--faint); }

.popover {
  position: fixed; z-index: 60;
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: rise 0.14s var(--ease);
}
.popover-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.popover-head .strong { font-weight: 700; }
.popover-head .muted { font-size: 13px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 34px; padding: 0 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2);
  font-size: 14px; text-align: left; text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); color: var(--ink); box-shadow: none; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }

.main { position: relative; min-width: 0; height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.page-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.nav-toggle { color: var(--ink-2); }
.scrim { display: none; }

/* Page header shared by Library / Document / Skills */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  padding: 28px 40px 22px;
  border-bottom: 1px solid var(--line);
}
.page-head-lead { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.page-head .nav-toggle { margin-top: 2px; }
.page-title { font-size: var(--fs-xl); letter-spacing: -0.01em; }
.page-sub { margin-top: 6px; color: var(--muted); font-size: 14.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow { display: block; margin-bottom: 8px; }
.page-body { padding: 24px 40px 56px; }

/* ==========================================================================
   Chat
   ========================================================================== */

.chat { position: relative; display: flex; flex-direction: column; height: 100%; }
.chat-top {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 16px;
  flex: none;
}
.chat-title {
  min-width: 0; font-size: 15px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink-2);
}
.chat-top .spacer { flex: 1; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: auto; }
.chat-column { max-width: calc(var(--chat-w) + 48px); margin: 0 auto; padding: 8px 24px 32px; }
.thread { display: grid; gap: 30px; }

/* Empty state: greeting + composer centred together */
.chat.is-empty .chat-scroll { flex: 0 1 auto; margin-top: auto; }
.chat.is-empty .suggestions { margin-bottom: auto; padding-bottom: 6vh; }
.chat.is-empty .composer-note { display: none; }

.empty { padding: 0 0 22px; text-align: left; animation: rise 0.3s var(--ease); }
.empty-mark { width: 40px; height: 40px; margin-bottom: 20px; }
.empty-greeting { font-size: var(--fs-2xl); letter-spacing: -0.015em; font-weight: 700; }
.empty-greeting span { color: var(--muted); font-weight: 400; }
.empty-sub { margin-top: 8px; font-size: var(--fs-md); color: var(--muted); max-width: 560px; }
.empty-cta {
  display: flex; align-items: center; gap: 14px;
  margin-top: 20px; padding: 14px 16px;
  border: 1px dashed var(--accent-line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
}
.empty-cta .icon { color: var(--accent); width: 22px; height: 22px; }
.empty-cta p { flex: 1; font-size: 14.5px; color: var(--ink-2); }
.empty-cta strong { color: var(--ink); }

.suggestions {
  max-width: calc(var(--chat-w) + 48px); width: 100%; margin: 0 auto; padding: 16px 24px 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
}
.chat:not(.is-empty) .suggestions { display: none; }
.suggestion {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  animation: rise 0.35s var(--ease) both;
}
.suggestion:nth-child(2) { animation-delay: 0.04s; }
.suggestion:nth-child(3) { animation-delay: 0.08s; }
.suggestion:nth-child(4) { animation-delay: 0.12s; }
.suggestion:hover { border-color: var(--line-strong); background: var(--surface); }
.suggestion .icon { margin-top: 1px; color: var(--accent); }
.suggestion-title { display: block; font-weight: 700; font-size: 14.5px; }
.suggestion-sub { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }

/* Messages */
.msg { animation: rise 0.22s var(--ease); }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble {
  max-width: min(85%, 620px);
  padding: 11px 16px;
  border-radius: 18px 18px 4px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  font-size: var(--fs-md); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-scope { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }

.msg-assistant { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 14px; }
.msg-avatar { width: 30px; height: 30px; margin-top: 1px; }
.msg-body { min-width: 0; }
.msg-name { display: flex; align-items: center; gap: 8px; height: 30px; }
.msg-name .label { color: var(--ink); letter-spacing: 0.16em; }

.thinking {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 4px; font-size: 14.5px; color: var(--muted);
}
.thinking-dots { display: inline-flex; gap: 4px; }
.thinking-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

/* Activity trail */
.activity { margin: 4px 0 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); max-width: 100%; }
.activity > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; list-style: none; cursor: pointer;
  font-size: 13.5px; color: var(--ink-2);
  border-radius: var(--radius);
}
.activity > summary::-webkit-details-marker { display: none; }
.activity > summary:hover { color: var(--ink); }
.activity-title { font-weight: 700; }
.activity-count { color: var(--muted); }
.activity-chev { margin-left: auto; color: var(--faint); transition: transform 0.2s var(--ease); }
.activity[open] .activity-chev { transform: rotate(180deg); }
.activity-state { display: grid; place-items: center; width: 16px; height: 16px; color: var(--ok); }
.activity-list { list-style: none; margin: 0; padding: 2px 12px 10px 12px; display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.step {
  display: grid; grid-template-columns: 16px auto minmax(0, 1fr) 16px; align-items: center; gap: 9px;
  min-height: 26px; font-size: 13.5px; color: var(--ink-2);
  animation: rise 0.18s var(--ease);
}
.step > .icon { width: 15px; height: 15px; color: var(--muted); }
.step-verb { font-weight: 700; color: var(--ink); white-space: nowrap; }
.step-target { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-state { display: grid; place-items: center; }
.step-state .icon { width: 14px; height: 14px; }
.step.is-ok .step-state { color: var(--ok); }
.step.is-failed .step-state { color: var(--danger); }
.step.is-failed .step-verb { color: var(--danger); }

/* Prose (markdown) */
.prose { font-size: var(--fs-md); line-height: 1.62; color: var(--ink); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose .table-wrap, .prose hr { margin: 0 0 0.85em; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1.35em 0 0.5em; letter-spacing: -0.005em; }
.prose h1 { font-size: 1.5em; }
.prose h2 { font-size: 1.28em; }
.prose h3 { font-size: 1.1em; }
.prose h4 { font-size: 0.8em; text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--ink-2); }
.prose strong { font-weight: 700; }
.prose a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: var(--accent); }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.25em 0; }
.prose li::marker { color: var(--muted); }
.prose ol > li::marker { font-weight: 700; color: var(--ink-2); }
.prose li > p { margin: 0.2em 0; }
.prose blockquote {
  padding: 2px 0 2px 16px; border-left: 2px solid var(--accent);
  color: var(--ink-2); font-style: italic;
}
.prose hr { border: 0; height: 1px; background: var(--line); margin: 1.4em 0; }
.prose code {
  font-family: var(--mono); font-size: 0.84em;
  padding: 0.12em 0.38em; border-radius: var(--radius-xs);
  background: var(--surface-hover); border: 1px solid var(--line);
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.prose pre {
  position: relative;
  padding: 14px 16px; border-radius: var(--radius);
  background: #0f2233; color: #f6f6f6;
  overflow-x: auto; font-size: 13.5px; line-height: 1.55;
}
.prose pre code { padding: 0; background: none; border: 0; color: inherit; font-size: inherit; }
.code-copy {
  position: absolute; top: 8px; right: 8px;
  height: 26px; padding: 0 8px; border: 1px solid rgba(255,255,255,0.14); border-radius: var(--radius-xs);
  background: rgba(255,255,255,0.06); color: #cfcabe; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0; transition: opacity 0.15s;
}
.prose pre:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.prose table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.prose th, .prose td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.prose th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); background: var(--surface-2); }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover td { background: var(--surface-2); }
.prose img { max-width: 100%; border-radius: var(--radius); }

.cite {
  display: inline-flex; align-items: baseline; gap: 0; vertical-align: baseline;
  margin: 0 1px; border-radius: var(--radius-xs); overflow: hidden;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 0.78em; line-height: 1.5; text-decoration: none !important; color: var(--ink-2) !important;
  white-space: nowrap; max-width: 100%;
  transition: border-color 0.15s;
}
.cite:hover { border-color: var(--accent); }
.cite-doc { padding: 0 6px; overflow: hidden; text-overflow: ellipsis; max-width: 36ch; }
.cite-page { padding: 0 6px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }

.caret { display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -0.15em; background: var(--accent); animation: blink 0.9s steps(1) infinite; }

.msg-error {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid #f1c6c0; border-radius: var(--radius);
  background: var(--danger-soft); color: #7d1810; font-size: 14px;
}
.msg-error .icon { margin-top: 1px; }
.msg-stopped { margin-top: 10px; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }

.msg-foot { display: flex; align-items: center; gap: 4px; margin-top: 10px; color: var(--faint); font-size: 12.5px; }
.msg-foot .icon-btn { width: 28px; height: 28px; }
.msg-foot .icon-btn .icon { width: 15px; height: 15px; }
.msg-meta { display: inline-flex; gap: 10px; margin-left: 6px; letter-spacing: 0.02em; }
.msg-meta span + span::before { content: "·"; margin-right: 10px; color: var(--line-strong); }

.jump {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  box-shadow: var(--shadow); display: grid; place-items: center;
}

/* Composer */
.composer-wrap { flex: none; padding: 0 24px 14px; }
.composer {
  position: relative;
  max-width: var(--chat-w); margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: #bfb9ab; box-shadow: var(--shadow-lg); }
.composer-scope { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.composer-scope:empty { display: none; }
.scope-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 4px 0 9px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink);
  font-size: 13px; font-weight: 700;
}
.scope-chip button { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: transparent; color: inherit; padding: 0; }
.scope-chip button:hover { background: rgba(159, 52, 9, 0.12); }
.scope-chip .icon { width: 12px; height: 12px; }
.composer textarea {
  display: block; width: 100%;
  min-height: 56px; max-height: 260px;
  padding: 16px 20px 6px;
  border: 0; outline: none; resize: none; background: transparent;
  font-size: var(--fs-md); line-height: 1.5;
}
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:focus-visible { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px 10px 12px; }
.composer-bar .spacer { flex: 1; }
.focus-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13.5px; font-weight: 700; letter-spacing: 0.02em;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.focus-btn:hover, .focus-btn[aria-expanded="true"] { border-color: var(--line-strong); background: var(--surface-hover); color: var(--ink); }
.focus-btn.has-scope { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-ink); }
.focus-btn .icon { width: 16px; height: 16px; }
.focus-btn .focus-chev { width: 13px; height: 13px; opacity: 0.6; }
.hint-key { font-size: 12px; color: var(--faint); letter-spacing: 0.03em; }
.send-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--surface-active); color: var(--faint); cursor: default; }
.send-btn .icon { width: 18px; height: 18px; stroke-width: 2; }
.send-btn.is-stop { background: var(--ink); }
.send-btn.is-stop:hover { background: var(--danger); }
.composer-note { max-width: var(--chat-w); margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--faint); letter-spacing: 0.02em; }

/* Focus popover */
.focus-pop { width: 340px; max-width: calc(100vw - 24px); padding: 0; overflow: hidden; }
.focus-pop-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.focus-pop-head p { margin-top: 3px; font-size: 13px; color: var(--muted); }
.focus-pop-search { padding: 10px 10px 6px; }
.focus-list { max-height: 280px; overflow-y: auto; padding: 4px 6px 6px; margin: 0; list-style: none; }
.focus-opt {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  width: 100%; padding: 8px; border: 0; border-radius: var(--radius-sm);
  background: transparent; text-align: left;
}
.focus-opt:hover, .focus-opt:focus-visible { background: var(--surface-hover); box-shadow: none; }
.focus-check {
  display: grid; place-items: center; width: 18px; height: 18px;
  border: 1.5px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: #fff;
}
.focus-check .icon { width: 12px; height: 12px; stroke-width: 2.6; opacity: 0; }
.focus-opt[aria-checked="true"] .focus-check { background: var(--accent); border-color: var(--accent); }
.focus-opt[aria-checked="true"] .focus-check .icon { opacity: 1; }
.focus-opt-name { display: block; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.focus-opt-sub { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.focus-opt-count { font-size: 12px; color: var(--faint); }
.focus-pop-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 10px 14px; border-top: 1px solid var(--line); background: var(--surface-2); font-size: 13px; color: var(--muted); }
.focus-empty { padding: 16px 10px; font-size: 13.5px; color: var(--muted); text-align: center; }

/* ==========================================================================
   Library
   ========================================================================== */

.lib { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 28px; align-items: start; }
.lib-rail { position: sticky; top: 24px; }
.rail-section + .rail-section { margin-top: 22px; }
.rail-section > .label { display: flex; align-items: center; justify-content: space-between; padding: 0 10px 8px; }
.rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.rail-item { position: relative; }
.rail-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 36px; padding: 6px 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; text-align: left; color: var(--ink-2); font-size: 14.5px;
}
.rail-btn:hover { background: var(--surface-hover); color: var(--ink); }
.rail-btn.is-active { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-sm); }
.rail-btn.is-active .icon { color: var(--accent); }
.rail-btn .icon { color: var(--muted); width: 16px; height: 16px; }
.rail-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-count { font-size: 12.5px; color: var(--faint); font-weight: 400; }
.rail-empty { padding: 6px 10px; font-size: 13px; color: var(--faint); }

.machine-card {
  margin-bottom: 18px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-xs);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 20px;
}
.machine-card h2 { font-size: var(--fs-lg); }
.machine-facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 8px; }
.fact { display: grid; gap: 1px; }
.fact .label { font-size: 10px; }
.fact span:last-child { font-size: 14px; }
.machine-desc { grid-column: 1 / -1; font-size: 14.5px; color: var(--ink-2); max-width: 70ch; }
.machine-aliases { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.machine-card-actions { display: flex; gap: 4px; align-self: start; }

.lib-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.lib-toolbar .search-input { flex: 1 1 200px; }
.lib-toolbar .select { width: auto; min-width: 132px; }
.lib-actions { display: flex; gap: 8px; margin-left: auto; }
.readonly-note { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.stats { display: flex; gap: 28px; }
.stat { display: grid; }
.stat-num { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat .label { font-size: 10px; }
.stat-num.is-live { color: var(--warn); }

.doc-table-wrap { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.doc-table th {
  position: sticky; top: 0;
  padding: 10px 14px; text-align: left;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.doc-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.doc-table tr:last-child td { border-bottom: 0; }
.doc-table tbody tr { cursor: pointer; transition: background 0.12s; }
.doc-table tbody tr:hover { background: var(--surface-2); }
.doc-table .num, .doc-table .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-table td.col-title { width: 100%; max-width: 0; min-width: 220px; }
.doc-title-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.doc-icon {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 40px; border-radius: 5px;
  border: 1px solid var(--line-strong); background: var(--surface-2);
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--muted);
  position: relative;
}
.doc-icon::after { content: ""; position: absolute; top: -1px; right: -1px; width: 9px; height: 9px; background: linear-gradient(225deg, var(--bg) 50%, var(--line-strong) 50%); border-bottom-left-radius: 2px; }
.doc-icon.is-pdf { color: var(--accent-ink); border-color: var(--accent-line); background: var(--accent-soft); }
.doc-name { min-width: 0; overflow: hidden; }
.doc-name a { display: block; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.doc-name a:hover { color: var(--accent-ink); }
.doc-file { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.doc-table td.col-num, .doc-table td.col-status { white-space: nowrap; }
.doc-machine { color: var(--ink-2); }
.doc-machine.is-shared { color: var(--muted); font-style: italic; }
.doc-type { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.doc-date { color: var(--muted); white-space: nowrap; }
.doc-status-detail { display: block; margin-top: 3px; font-size: 12px; color: var(--danger); max-width: 22ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-actions { width: 44px; text-align: right; }

.empty-panel {
  display: grid; justify-items: center; gap: 10px; text-align: center;
  padding: 56px 24px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.empty-panel .empty-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); color: var(--accent); margin-bottom: 4px; }
.empty-panel h3 { font-size: 18px; }
.empty-panel p { color: var(--muted); max-width: 44ch; font-size: 14.5px; }
.empty-panel .btn { margin-top: 8px; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: rgba(246, 244, 239, 0.86);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay-box { padding: 36px 48px; border: 2px dashed var(--accent); border-radius: var(--radius-xl); background: var(--surface); text-align: center; box-shadow: var(--shadow-lg); }
.drop-overlay-box .icon { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--accent); }
.drop-overlay-box strong { display: block; font-size: 18px; }

/* ==========================================================================
   Modal (native <dialog>)
   ========================================================================== */

.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.modal[open] { animation: rise 0.18s var(--ease); display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(12, 28, 45, 0.34); backdrop-filter: blur(1px); }
.doc-notice { margin-bottom: 14px; }
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 4px; }
.modal-head h2 { font-size: 19px; }
.modal-head p { margin-top: 4px; font-size: 14px; color: var(--muted); }
.modal-body { padding: 16px 22px 8px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 14px 22px 18px; }
.modal-foot .spacer { flex: 1; }
.modal-error { margin-top: 12px; }

.dropzone {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 28px 16px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .icon { width: 28px; height: 28px; color: var(--accent); margin-bottom: 4px; }
.dropzone strong { font-size: 15px; }
.dropzone span { font-size: 13px; color: var(--muted); }
.dropzone u { text-decoration-color: var(--accent); text-underline-offset: 3px; }
.file-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; max-height: 190px; overflow-y: auto; }
.file-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 7px 8px 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 14px; }
.file-row .icon { color: var(--muted); width: 16px; height: 16px; }
.file-row-main { display: flex; flex-direction: column; min-width: 0; }
.file-row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-row-size { font-size: 12.5px; color: var(--faint); }
.file-row .icon-btn { width: 26px; height: 26px; }
.progress { height: 4px; border-radius: 4px; background: var(--surface-active); overflow: hidden; margin-top: 14px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* Toasts */
.toasts { position: fixed; z-index: 90; right: 20px; bottom: 20px; display: grid; gap: 8px; justify-items: end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  max-width: 420px; padding: 11px 14px;
  border-radius: var(--radius); background: var(--ink); color: #ffffff;
  font-size: 14px; box-shadow: var(--shadow-lg);
  animation: rise 0.2s var(--ease); pointer-events: auto;
}
.toast .icon { width: 16px; height: 16px; }
.toast-ok .icon { color: #8fd3a8; }
.toast-error { background: #7d1810; }
.toast-error .icon { color: #ffb4aa; }

/* ==========================================================================
   Document page
   ========================================================================== */

.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.crumbs .icon { width: 12px; height: 12px; color: var(--faint); }

.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  position: relative; height: 40px; padding: 0 14px;
  border: 0; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--accent); }
.tabs .spacer { flex: 1; }
.tabs .select { height: 32px; width: auto; align-self: center; font-size: 13px; }

.paper {
  padding: 36px 44px 48px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.paper.prose { font-size: 15.5px; line-height: 1.7; max-width: none; }
.paper.prose h2.page-heading {
  display: flex; align-items: center; gap: 12px;
  margin: 2.2em 0 1em;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted);
  scroll-margin-top: 20px;
}
.paper.prose h2.page-heading::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.paper.prose h2.page-heading:first-child { margin-top: 0; }
.paper-plain { white-space: pre-wrap; font-family: var(--mono); font-size: 13px; line-height: 1.65; }

.viewer { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.viewer iframe { display: block; width: 100%; height: calc(100dvh - 240px); min-height: 520px; border: 0; background: var(--bg-sunken); }
.viewer img { max-width: 100%; margin: 0 auto; }
.viewer-img { padding: 24px; background: var(--bg-sunken); }

.meta-card { position: sticky; top: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); overflow: hidden; }
.meta-card-head { padding: 16px 18px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.meta-list { margin: 0; padding: 6px 18px 12px; }
.meta-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.meta-row:last-child { border-bottom: 0; }
.meta-row dt { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); padding-top: 2px; }
.meta-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.meta-row dd a { color: var(--ink); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.meta-path { padding: 14px 18px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }
.meta-path .label { display: block; margin-bottom: 6px; font-size: 10px; }
.meta-path code { display: block; font-family: var(--mono); font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; line-height: 1.5; }

.status-panel { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 64px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); }
.status-panel .spinner { width: 22px; height: 22px; border-width: 2px; }
.status-panel h3 { font-size: 17px; }
.status-panel p { color: var(--muted); max-width: 46ch; font-size: 14.5px; }
.status-panel .icon { width: 26px; height: 26px; color: var(--muted); }
.status-panel.is-failed .icon { color: var(--danger); }

/* ==========================================================================
   Skills
   ========================================================================== */

.skills-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.skill-card {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.skill-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.skill-card.is-open { grid-column: 1 / -1; border-color: var(--line-strong); box-shadow: var(--shadow); }
.skill-toggle { display: block; width: 100%; padding: 18px 20px 16px; border: 0; background: transparent; text-align: left; border-radius: var(--radius-lg); }
.skill-top { display: flex; align-items: center; gap: 12px; }
.skill-glyph { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); }
.skill-name { font-size: 17px; font-weight: 700; }
.skill-qname { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.skill-top .icon-chev { margin-left: auto; color: var(--faint); transition: transform 0.2s var(--ease); }
.skill-card.is-open .icon-chev { transform: rotate(180deg); }
.skill-desc { display: block; margin-top: 12px; font-size: 14.5px; color: var(--ink-2); line-height: 1.55; }
.skill-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.skill-chips .chip .icon { width: 12px; height: 12px; color: var(--muted); }
.skill-body { border-top: 1px solid var(--line); padding: 22px 24px 26px; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.skill-body .label { display: block; margin-bottom: 12px; }

.explainer {
  display: flex; gap: 14px; align-items: flex-start;
  margin-bottom: 22px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); font-size: 14.5px; color: var(--ink-2);
}
.explainer .icon { color: var(--accent); margin-top: 1px; }

/* Loading skeleton rows */
.skel { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-hover), var(--bg), var(--surface-hover)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }

/* ==========================================================================
   Auth
   ========================================================================== */

.auth-body {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 40px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(255,255,255,0.9), transparent 70%),
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--bg);
  background-blend-mode: normal;
}
.auth-body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 30%, var(--bg) 78%);
}
.auth { position: relative; width: 100%; max-width: 420px; }
.auth-brand { display: flex; justify-content: center; margin-bottom: 26px; }
.auth-brand .brand-mark { width: 32px; height: 32px; }
.auth-brand .brand-word { font-size: 23px; }
.auth-card {
  padding: 32px 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-card::before {
  content: ""; display: block; height: 3px; margin: -32px -32px 28px; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--accent);
}
.auth-title { font-size: 24px; }
.auth-sub { margin-top: 6px; margin-bottom: 22px; font-size: 14.5px; color: var(--muted); }
.auth-flashes { margin-bottom: 18px; }
.auth-card .btn-block { margin-top: 22px; }
.auth-alt { margin-top: 20px; text-align: center; font-size: 14.5px; color: var(--muted); }
.auth-alt a { color: var(--ink); font-weight: 700; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.auth-foot { margin-top: 26px; text-align: center; font-size: 11px; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .meta-card { position: static; order: -1; }
  .col-date { display: none; }
}

@media (max-width: 900px) {
  .shell, body.nav-collapsed .shell { grid-template-columns: minmax(0, 1fr); }
  body.nav-collapsed .sidebar { visibility: visible; }
  .sidebar {
    position: fixed; z-index: 50; inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-inner { width: 100%; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(12, 28, 45, 0.3); }

  .page-head { padding: 18px 16px 16px; }
  .page-body { padding: 18px 16px 40px; }
  .page-title { font-size: 24px; }
  .chat-column { padding: 8px 16px 24px; }
  .composer-wrap { padding: 0 12px 10px; }
  .suggestions { padding: 14px 16px 0; grid-template-columns: minmax(0, 1fr); }
  .suggestion:nth-child(n+3) { display: none; }
  .empty-greeting { font-size: 28px; }
  .hint-key { display: none; }
  .msg-assistant { grid-template-columns: minmax(0, 1fr); }
  .msg-avatar { display: none; }
  .bubble { max-width: 92%; }
  .jump { bottom: 140px; }

  .lib { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .lib-rail { position: static; }
  .rail-section + .rail-section { margin-top: 12px; }
  .rail-list { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .rail-btn { width: auto; white-space: nowrap; border: 1px solid var(--line); background: var(--surface); }
  .rail-section > .label { padding: 0 2px 6px; }
  .stats { gap: 18px; }

  .doc-table thead { display: none; }
  .doc-table, .doc-table tbody, .doc-table tr, .doc-table td { display: block; }
  .doc-table tr { position: relative; padding: 12px 48px 12px 14px; border-bottom: 1px solid var(--line); }
  .doc-table tr:last-child { border-bottom: 0; }
  .doc-table td { padding: 0; border: 0; }
  .doc-table td.col-title { max-width: none; min-width: 0; }
  .doc-table td.col-machine, .doc-table td.col-type, .doc-table td.col-status, .doc-table td.col-date { display: inline-block; margin: 8px 10px 0 0; }
  .doc-table td.col-date { font-size: 12.5px; }
  .doc-table td.col-actions { position: absolute; top: 12px; right: 8px; width: auto; }
  .doc-name a, .doc-file { max-width: 100%; }

  .paper { padding: 22px 18px 28px; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .skills-grid { grid-template-columns: minmax(0, 1fr); }
  .toasts { left: 12px; right: 12px; justify-items: stretch; }
}

@media (min-width: 901px) {
  .only-mobile { display: none !important; }
  body:not(.nav-collapsed) .main .nav-toggle { display: none; }
}

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

/* ---------- PDF viewer (pdf.js) ---------- */
.icon.flip { transform: rotate(180deg); }
.pdfv { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.pdfv-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 2;
}
.pdfv-page { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.pdfv-page .input { width: 52px; height: 30px; padding: 0 6px; text-align: center; }
.pdfv-count { white-space: nowrap; }
.pdfv-scroll {
  height: calc(100dvh - 250px); min-height: 520px; overflow: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 16px; background: var(--bg-sunken); outline: none;
}
.pdfv-slot {
  position: relative; flex: none; background: #fff;
  box-shadow: var(--shadow); border-radius: 2px; scroll-margin-top: 12px;
  transition: box-shadow 0.3s var(--ease);
}
.pdfv-slot canvas { display: block; width: 100%; height: 100%; border-radius: 2px; }
.pdfv-slot.is-target { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.pdfv-num {
  position: absolute; right: -2px; bottom: -22px; font-size: 11px; color: var(--faint);
  letter-spacing: var(--tracking-label);
}
@media (max-width: 700px) {
  .pdfv-scroll { height: calc(100dvh - 200px); min-height: 360px; padding: 10px; }
  .pdfv-bar .btn-sm[data-act="fit"] { display: none; }
}
.page-heading.is-target { background: var(--accent-soft); border-radius: var(--radius-xs); transition: background 0.6s var(--ease); }

/* Per-file upload status */
.file-row-status { flex: none; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.file-row[data-state="uploading"] .file-row-status { color: var(--accent); }
.file-row[data-state="done"] .file-row-status { color: var(--ok); }
.file-row[data-state="skipped"] .file-row-status { color: var(--warn); }
.file-row[data-state="failed"] .file-row-status { color: var(--danger); white-space: normal; text-align: right; max-width: 55%; }

/* ==========================================================================
   Upload: folders, collections, AI detection
   ========================================================================== */

.modal-upload { width: min(640px, calc(100vw - 32px)); }

.upload-pick { display: grid; gap: 10px; }
.upload-pick .dropzone { padding: 24px 16px; }
.upload-pick-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.upload-files:not(:empty) { margin-top: 12px; }
.upload-pick.is-compact { grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
.upload-pick.is-compact .dropzone { grid-template-columns: auto minmax(0, 1fr); justify-items: start; text-align: left; align-items: center; column-gap: 10px; padding: 10px 14px; }
.upload-pick.is-compact .dropzone .icon { width: 20px; height: 20px; margin: 0; grid-row: span 2; }
.upload-pick.is-compact .dropzone strong { font-size: 14px; }
.upload-pick.is-compact .dropzone span { font-size: 12px; }
.upload-pick.is-compact .upload-pick-actions { flex-direction: column; justify-content: center; gap: 6px; }
.upload-files .file-list { margin-top: 0; }

.file-note { display: inline-flex; align-items: center; gap: 4px; margin-top: 1px; font-size: 12px; color: var(--muted); }
.file-note .icon { width: 12px; height: 12px; }
.file-note.is-warn { color: var(--warn); }
.file-note.is-danger { color: var(--danger); }
.file-row-dir { color: var(--faint); }
.file-row[data-state="cancelled"] .file-row-status { color: var(--faint); }
.file-row[data-state="toolarge"] .file-row-status { color: var(--danger); }
.file-row[data-state="toolarge"] .file-row-name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.file-row[data-state="failed"] { border-color: #f1c6c0; background: color-mix(in srgb, var(--danger-soft) 45%, transparent); }
.file-row[data-state="done"] > .icon { color: var(--ok); }

.upload-reading { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 13.5px; color: var(--muted); }

.upload-warn {
  display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--warn-soft); color: #6d3c00; font-size: 13px; line-height: 1.4;
}
.upload-warn .icon { margin-top: 1px; flex: none; }
.upload-warn.is-danger { background: var(--danger-soft); color: #7d1810; }

/* Collection (grouped) view */
.upload-collection { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.upload-collection-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.upload-collection-glyph { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); }
.upload-collection-titles { flex: 1 1 200px; min-width: 0; display: grid; }
.upload-collection-titles strong { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-collection-titles span { font-size: 12.5px; color: var(--muted); }
.ugroups { max-height: min(320px, 40dvh); overflow-y: auto; overscroll-behavior: contain; }
.ugroup + .ugroup { border-top: 1px solid var(--line); }
.ugroup-head { display: flex; align-items: center; gap: 4px; padding-right: 6px; }
.ugroup-head .icon-btn { width: 28px; height: 28px; flex: none; }
.ugroup-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 6px 8px 6px 10px; border: 0; background: transparent; text-align: left; font-size: 14px; color: var(--ink);
}
.ugroup-toggle:hover { background: var(--surface-hover); }
.ugroup-toggle .icon { color: var(--muted); }
.ugroup-chev { width: 14px; height: 14px; transition: transform 0.15s var(--ease); }
.ugroup-toggle[aria-expanded="true"] .ugroup-chev { transform: rotate(90deg); }
.ugroup-name { font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ugroup-meta { flex: none; font-size: 12.5px; color: var(--faint); }
.ugroup-state { margin-left: auto; flex: none; font-size: 12.5px; color: var(--muted); }
.ugroup-state .is-ok { color: var(--ok); }
.ugroup-state .is-danger { color: var(--danger); }
.ugroup-list { max-height: none; margin: 0; padding: 0 8px 8px 30px; gap: 0; overflow: visible; }
.file-row.is-compact { gap: 8px; padding: 5px 4px 5px 6px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: 13.5px; }
.file-row.is-compact:last-child { border-bottom: 0; }
.file-row.is-compact .icon { width: 14px; height: 14px; }
.file-row.is-compact .icon-btn { width: 24px; height: 24px; }
.file-row.is-compact[data-state="failed"] { background: color-mix(in srgb, var(--danger-soft) 55%, transparent); }
.ugroup-more { list-style: none; padding: 6px 0 0; }

/* Progress while uploading */
.upload-run { margin-bottom: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.upload-run-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.upload-run-head span { font-size: 13px; color: var(--muted); }
.upload-run .progress { height: 6px; margin-top: 10px; }
.upload-run-summary { margin-top: 12px; }
.upload-run-summary .flash { align-items: flex-start; }
.upload-run-summary .flash strong { display: block; }
.upload-run-summary .muted { display: block; margin-top: 4px; font-size: 13px; }
.upload-reasons { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }

/* Settings */
.upload-settings { margin: 16px 0 0; padding: 0; border: 0; min-width: 0; }
.upload-settings:disabled { opacity: 0.62; }
.upload-settings:disabled .ai-option { filter: grayscale(0.4); }

.ai-option {
  padding: 12px 14px; border: 1px solid var(--accent-line); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 35%, var(--surface)));
}
.ai-switch { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.ai-glyph { display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; }
.ai-glyph .icon { width: 16px; height: 16px; }
.ai-switch-title { flex: 1; font-weight: 700; font-size: 15px; }
.ai-switch input { position: absolute; z-index: 1; right: 0; top: 50%; width: 38px; height: 22px; margin: -11px 0 0; opacity: 0; cursor: pointer; }
.switch {
  position: relative; flex: none; width: 38px; height: 22px; border-radius: 11px;
  background: var(--line-strong); transition: background 0.15s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.15s var(--ease);
}
.ai-switch input:checked + .switch { background: var(--accent); }
.ai-switch input:checked + .switch::after { transform: translateX(16px); }
.ai-switch input:focus-visible + .switch { box-shadow: var(--ring); }
.ai-desc { margin-top: 6px; padding-left: 38px; font-size: 13px; color: var(--ink-2); line-height: 1.45; }

.check-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; margin-top: 12px; font-size: 14px; }
.check-row input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); }
.check-row label { font-weight: 700; cursor: pointer; }
.check-row .field-hint { display: block; margin-top: 2px; font-size: 12.5px; }

/* --- Library: batch card, chips, AI badge, source paths ---------------------- */

.batch-card {
  margin-bottom: 18px; padding: 16px 18px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-xs);
}
.batch-card.is-entering { animation: rise 0.2s var(--ease); }
.batch-card.is-pending { border-color: var(--accent-line); }
.batch-head { display: flex; align-items: flex-start; gap: 12px; }
.batch-glyph { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.batch-card.is-done .batch-glyph { background: var(--ok-soft); color: var(--ok); }
.batch-card.is-failed .batch-glyph { background: var(--danger-soft); color: var(--danger); }
.batch-titles { flex: 1; min-width: 0; }
.batch-titles h2 { font-size: 16.5px; }
.batch-titles p { margin-top: 2px; font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.batch-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.batch-bar { display: flex; height: 6px; margin: 14px 0 10px; border-radius: 6px; background: var(--surface-active); overflow: hidden; }
.batch-bar i { display: block; height: 100%; transition: width 0.4s var(--ease); }
.batch-bar .is-ready { background: var(--ok); }
.batch-bar .is-failed { background: var(--danger); }
.batch-card.is-pending .batch-bar { background-image: linear-gradient(90deg, var(--surface-active), var(--accent-soft), var(--surface-active)); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }
.batch-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13.5px; color: var(--ink-2); }
.batch-stat { display: inline-flex; align-items: center; gap: 5px; }
.batch-stat b { font-weight: 700; }
.batch-stat.is-ready b { color: var(--ok); }
.batch-stat.is-pending b { color: var(--warn); }
.batch-stat.is-failed { padding: 0; border: 0; background: none; color: var(--danger); text-decoration: underline; text-decoration-color: #f1c6c0; text-underline-offset: 3px; }
.batch-stat.is-ai .icon { color: var(--accent); }
.batch-machines { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.batch-machines .label { margin-right: 4px; font-size: 10px; }
.batch-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); font-size: 13px; color: var(--ink-2);
}
.batch-chip:hover { border-color: var(--line-strong); background: var(--surface-hover); color: var(--ink); }
.batch-chip .icon { color: var(--muted); }
.batch-chip .num { color: var(--faint); }
.batch-chip.is-new { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-ink); }
.batch-new { padding: 1px 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

.filter-chips { display: flex; gap: 6px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px 0 12px;
  border: 1px solid var(--accent-line); border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13.5px; font-weight: 700;
}
.filter-chip:hover { border-color: var(--accent); }
.filter-chip .num { font-weight: 400; opacity: 0.75; }

.doc-name-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.doc-name-line a { flex: 0 1 auto; min-width: 0; }
.ai-badge {
  display: inline-flex; align-items: center; gap: 3px; flex: none; height: 19px; padding: 0 6px;
  border-radius: 999px; background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--accent-ink);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; cursor: help;
}
.ai-badge .icon { width: 11px; height: 11px; }
.doc-path { display: flex; align-items: center; gap: 4px; margin-top: 1px; font-size: 12px; color: var(--faint); min-width: 0; }
.doc-path .icon { width: 12px; height: 12px; flex: none; }
.doc-path span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-status-detail.is-live { color: var(--muted); }

/* --- Document page: AI detection panel --------------------------------------- */

.meta-ai { border-top: 1px solid var(--line); }
.meta-card-head + .meta-ai { border-top: 0; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--accent-soft), var(--surface)); }
.meta-ai-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px 4px; }
.meta-ai-head .icon { width: 15px; height: 15px; color: var(--accent); }
.meta-ai-head .label { flex: 1; }
.meta-ai-engine { font-size: 11.5px; color: var(--faint); }
.meta-ai-body { padding: 6px 18px 16px; display: grid; gap: 10px; font-size: 14px; }
.meta-ai-summary { color: var(--ink-2); line-height: 1.5; }
.ai-facts { display: grid; gap: 8px; margin: 0; }
.ai-fact { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; }
.ai-fact dt { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); padding-top: 2px; }
.ai-fact dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ai-conf { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.ai-meter { width: 56px; height: 4px; border-radius: 4px; background: var(--surface-active); overflow: hidden; flex: none; }
.ai-meter i { display: block; height: 100%; background: var(--accent); }
.ai-meter.is-low i { background: var(--warn); }
.ai-note { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--accent-ink); }
.ai-note .icon { width: 11px; height: 11px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.meta-ai-state { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 13.5px; }
.meta-ai-state .spinner { margin-top: 2px; }
.meta-ai-state.is-failed { color: var(--danger); }
.meta-ai-state.is-failed .icon { flex: none; margin-top: 1px; }
.meta-ai .btn { justify-self: start; }

@media (max-width: 900px) {
  .upload-pick-actions .btn { flex: 1 1 140px; }
  .upload-pick.is-compact { grid-template-columns: minmax(0, 1fr); }
  .upload-pick.is-compact .upload-pick-actions { flex-direction: row; }
  .ugroup-meta { display: none; }
  .upload-collection-glyph { display: none; }
  .file-row.is-compact { grid-template-columns: auto minmax(0, 1fr) auto; }
  .file-row.is-compact .file-row-size { display: none; }
  .file-row.is-compact .file-row-status { max-width: 42vw; white-space: normal; text-align: right; }
  .ugroup-list { padding-left: 12px; }
  .batch-head { flex-wrap: wrap; }
  .batch-actions { width: 100%; order: 3; }
  .batch-actions .btn { flex: 1; }
  .filter-chips { order: 2; }
  .ai-desc { padding-left: 0; }
}
