/* ═══════════════════════════════════════════════════════════════════════════
   Exhibit — Document Intelligence Studio design system
   Modern SaaS (light). Flat surfaces, hairline borders as the primary
   structure, tight radii, square-ish badges, underline tabs. No gradients,
   no backdrop-filter.

   The :root token block is carried over verbatim from
   ~/Claude/document-studio/frontend/assets/css/style.css so the two apps stay
   visually identical. The one addition is a spacing scale: that file hardcodes
   every padding in px, which is the single thing about it that does not scale.
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
  color-scheme: light;

  /* ── System Backgrounds (iOS light) ── */
  --bg-primary:    #ffffff;   /* main content surface          */
  --bg-secondary:  #f2f2f7;   /* systemGray6 — side panels      */
  --bg-tertiary:   #ffffff;   /* inputs / cards (with border)   */
  --bg-elevated:   #ffffff;   /* popovers / modals (w/ shadow)  */
  --bg-quaternary: #e5e5ea;   /* systemGray5                    */
  --bg-grouped:    #f2f2f7;   /* grouped table background       */

  /* ── Labels ── */
  --label:         rgba(0,0,0,0.88);
  --label-2:       rgba(60,60,67,0.6);
  --label-3:       rgba(60,60,67,0.56);
  --label-4:       rgba(60,60,67,0.18);

  /* ── Separators / hairline borders (borders are the primary structure) ── */
  --sep:           rgba(0,0,0,0.12);
  --sep-opaque:    #dadadd;
  --border:        rgba(0,0,0,0.14);
  --border-strong: rgba(0,0,0,0.20);

  /* ── Fills ── */
  --fill-1:        rgba(0,0,0,0.07);
  --fill-2:        rgba(0,0,0,0.05);
  --fill-3:        rgba(0,0,0,0.04);
  --fill-4:        rgba(0,0,0,0.025);

  /* ── System Colors ── */
  --blue:    #007aff;
  --blue-hover:  #0a6ae6;
  --blue-active: #0057cc;
  --green:   #34c759;
  --green-text: #1e803a;   /* AA-safe (~5:1) green for text on light */
  --indigo:  #5856d6;
  --orange:  #ff9500;
  --orange-text: #b8690a;
  --purple:  #af52de;
  --red:     #ff3b30;
  --red-text: #d70015;
  --teal:    #30b0c7;

  /* ── Typography ── */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Menlo', 'Cascadia Code', 'Courier New', monospace;

  /* ── Radius ── */
  --r-xs: 3px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 10px;
  --r-badge: 5px;

  /* ── Shadows (flat — shadow only lifts true overlays) ── */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-xl: 0 8px 24px rgba(0,0,0,0.12);

  /* ── Transitions ── */
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 0.12s;
  --dur-normal: 0.2s;
  --dur-slow: 0.32s;

  /* ── Spacing scale (new) ── */
  --s-1: 4px;  --s-2: 6px;  --s-3: 8px;  --s-4: 10px;
  --s-5: 12px; --s-6: 16px; --s-7: 20px; --s-8: 24px; --s-9: 32px;

  --panel-left: 280px;
  --panel-right: 340px;
  --header-h: 48px;
}

/* Self-hosted so the intended typeface actually renders. Both are OFL; run
   scripts/fetch_fonts.sh to place the files. Missing files degrade to the
   system stack rather than breaking the page. */
@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-Variable.woff2') format('woff2-variations');
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--label);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--label-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--label-3); }

:focus-visible { outline: 2.5px solid var(--blue); outline-offset: 2px; border-radius: var(--r-md); }
:focus:not(:focus-visible) { outline: none; }
.doc-item:focus-visible, [role="menuitem"]:focus-visible { outline-offset: -2px; }

/* ═══ BUTTONS ═══ */
button { font-family: inherit; font-size: 13px; cursor: pointer; border: none; background: none; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 7px 12px; border-radius: var(--r-md); font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--label);
  transition: background var(--dur-fast), border-color var(--dur-fast);
  white-space: nowrap;
}
.btn:hover { background: var(--fill-3); border-color: var(--border-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
.btn-danger { color: var(--red-text); border-color: rgba(255,59,48,0.3); }
.btn-danger:hover { background: rgba(255,59,48,0.08); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-icon { padding: 5px; border-radius: var(--r-sm); color: var(--label-2); }
.btn-icon:hover { background: var(--fill-2); color: var(--label); }

/* ═══ HEADER ═══ */
.app-header {
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--s-5);
  padding: 0 var(--s-5); padding-left: max(var(--s-5), env(safe-area-inset-left));
  border-bottom: 1px solid var(--sep); background: var(--bg-primary);
  flex: 0 0 auto;
}
.app-title { font-size: 14px; font-weight: 650; letter-spacing: -0.015em; }
.app-title .dot { color: var(--blue); }
.gate-title + .gate-tagline {
  font-size: 12.5px; color: var(--label-2); margin: -2px 0 var(--s-6);
}
.app-user {
  font-size: 13px; color: var(--label-2); font-weight: 500;
  max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-spacer { flex: 1; }
.header-stat {
  display: inline-flex; align-items: baseline; gap: var(--s-1);
  font-size: 11px; color: var(--label-2); text-transform: uppercase; letter-spacing: .5px;
}
.header-stat b { font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 12.5px; font-weight: 600; color: var(--label); letter-spacing: 0; }
.btn-drawer { display: none; }

/* ═══ LAYOUT ═══ */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: var(--panel-left) 1fr var(--panel-right);
}
.layout.no-sources { grid-template-columns: var(--panel-left) 1fr 0; }
body { display: flex; flex-direction: column; }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-left { background: var(--bg-secondary); border-right: 1px solid var(--sep); }
.panel-center { background: var(--bg-primary); }
.panel-right { background: var(--bg-secondary); border-left: 1px solid var(--sep); overflow: hidden; }
.layout.no-sources .panel-right { display: none; }

.panel-head {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-4) var(--s-5) var(--s-3);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--label-2);
  flex: 0 0 auto;
}
.panel-head .count {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  letter-spacing: 0; color: var(--label-3);
}
.panel-body { flex: 1; overflow-y: auto; min-height: 0; contain: content; }

/* ═══ UPLOAD ═══ */
.upload-zone {
  margin: var(--s-3) var(--s-5);
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  padding: var(--s-7) var(--s-5); text-align: center; cursor: pointer;
  transition: border-color var(--dur-normal), background var(--dur-normal);
  flex: 0 0 auto;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--blue); background: rgba(0,122,255,0.06); }
.upload-icon { font-size: 22px; line-height: 1; margin-bottom: var(--s-2); opacity: .75; }
.upload-hint { font-size: 12.5px; font-weight: 550; color: var(--label); }
.upload-or { font-size: 11px; color: var(--label-3); margin-top: 3px; }
.upload-zone label[role="button"] {
  display: inline-block; margin-top: var(--s-3); padding: 5px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-elevated); font-size: 12px; font-weight: 500; cursor: pointer;
}

/* ═══ BATCH QUEUE ═══ */
.batch-panel {
  margin: 0 var(--s-5) var(--s-3); border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--bg-elevated); overflow: hidden; flex: 0 0 auto;
}
.batch-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--sep);
  font-size: 11px; font-weight: 600; color: var(--label-2);
}
.batch-list { list-style: none; max-height: 150px; overflow-y: auto; }
.batch-item {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3); font-size: 12px; border-bottom: 1px solid var(--fill-3);
}
.batch-item:last-child { border-bottom: none; }
.batch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-status { font-size: 11px; font-weight: 600; white-space: nowrap; }
.batch-status.pending   { color: var(--label-3); }
.batch-status.uploading { color: var(--orange-text); }
.batch-status.done      { color: var(--green-text); }
.batch-status.error     { color: var(--red-text); }
.batch-bar-bg { height: 4px; background: var(--fill-2); }
.batch-bar { height: 100%; background: var(--blue); width: 0; transition: width var(--dur-normal) var(--ease); }

/* ═══ DOCUMENT LIST ═══ */
.doc-list { list-style: none; padding: 0 var(--s-3) var(--s-6); }
.doc-item {
  position: relative; display: block; width: 100%; text-align: left;
  padding: var(--s-3) var(--s-3) var(--s-4); margin-bottom: var(--s-1);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.doc-item:hover { background: var(--bg-elevated); border-color: var(--border); }
.doc-item.active { background: var(--bg-elevated); border-color: var(--blue); }
.doc-item.selected-scope { box-shadow: inset 3px 0 0 var(--blue); }
.doc-row { display: flex; align-items: center; gap: var(--s-2); }
.doc-name {
  flex: 1; font-size: 12.5px; font-weight: 550; color: var(--label);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-meta {
  display: flex; align-items: center; gap: var(--s-2);
  margin-top: 3px; font-size: 11px; color: var(--label-3);
  font-variant-numeric: tabular-nums;
}
.doc-actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur-fast); }
.doc-item:hover .doc-actions, .doc-item:focus-within .doc-actions { opacity: 1; }
.doc-bar { height: 3px; margin-top: var(--s-2); background: var(--fill-2); border-radius: 2px; overflow: hidden; }
.doc-bar > span { display: block; height: 100%; background: var(--blue); width: 0; transition: width var(--dur-normal) var(--ease); }
.doc-item.is-ready .doc-bar { display: none; }

/* Search without AI. The banner is orange, not red: the system still works,
   it is doing less, and it says how much less. */
.ai-banner {
  margin-top: var(--s-2); padding: var(--s-2) var(--s-3);
  font-size: 11.5px; line-height: 1.5; color: var(--orange-text);
  background: color-mix(in srgb, var(--orange-text) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--orange-text) 30%, transparent);
  border-radius: var(--r-md);
}
.chat-tools { display: flex; justify-content: flex-end; padding: var(--s-1) 2px 0; }
.kw-toggle {
  display: inline-flex; align-items: center; gap: var(--s-1);
  font-size: 11.5px; color: var(--label-2); cursor: pointer; user-select: none;
}
.kw-toggle input { accent-color: var(--blue); margin: 0; }
.kw-toggle:has(input:disabled) { cursor: default; opacity: .75; }
.srcbadge.keyword { color: var(--orange-text); background: color-mix(in srgb, var(--orange-text) 12%, transparent); }

/* Tags: square badges, same family as the status pills but neutral, so a
   tag never reads as a state. `.on` marks one that is scoping retrieval. */
.doc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: var(--s-2); }
.doc-tags:empty { display: none; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px; border-radius: var(--r-badge);
  font-size: 10.5px; font-weight: 550; color: var(--label-2);
  background: var(--fill-2); box-shadow: inset 0 0 0 1px var(--border);
}
.tag.on { color: var(--blue); background: color-mix(in srgb, var(--blue) 12%, transparent);
          box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--blue) 35%, transparent); }
.tag-filter { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 var(--s-4) var(--s-3); }
.tag-btn { cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast); }
.tag-btn:hover:not(:disabled) { color: var(--label); }
.tag-btn:disabled { opacity: .45; cursor: default; }
.tag-count { font-variant-numeric: tabular-nums; color: var(--label-3); font-weight: 500; }
.tag.on .tag-count { color: inherit; }
.tag-input {
  width: 100%; margin-top: var(--s-2); padding: 3px 6px; font: inherit; font-size: 11.5px;
  border: 1px solid var(--blue); border-radius: var(--r-sm); background: var(--bg-elevated); color: var(--label);
}

/* Status pills. One `color-mix` rule per state — adding a status is one line.
   The inset shadow gives a same-hue hairline with zero layout shift. */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px; border-radius: var(--r-badge);
  font-size: 10.5px; font-weight: 650; letter-spacing: .2px; white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06),
              inset 0 0 0 1px color-mix(in srgb, currentColor 26%, transparent);
}
.pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.st-queued     { color: var(--label-2);     background: color-mix(in srgb, var(--label-2) 14%, transparent); }
.st-extracting,
.st-chunking,
.st-embedding  { color: var(--orange-text); background: color-mix(in srgb, var(--orange-text) 14%, transparent); }
.st-ready      { color: var(--green-text);  background: color-mix(in srgb, var(--green-text) 16%, transparent); }
.st-failed     { color: var(--red-text);    background: color-mix(in srgb, var(--red-text) 14%, transparent); }
.st-cancelled  { color: var(--label-3);     background: color-mix(in srgb, var(--label-3) 12%, transparent); }
.st-extracting::before, .st-chunking::before, .st-embedding::before, .st-queued::before {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.doc-error {
  margin-top: var(--s-2); font-size: 11.5px; line-height: 1.4; color: var(--red-text);
  background: rgba(255,59,48,0.07); border-radius: var(--r-sm); padding: var(--s-2);
}

/* ═══ EMPTY STATES ═══ */
.empty { margin: auto; text-align: center; color: var(--label-2); padding: var(--s-9) var(--s-6); max-width: 460px; }
.empty-icon { font-size: 28px; margin-bottom: var(--s-3); opacity: .6; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--label); margin-bottom: var(--s-2); }
.empty-sub { font-size: 12.5px; line-height: 1.6; }

/* ═══ CHAT ═══ */
.chat-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 0 var(--s-7); }
.chat-scope {
  display: none; align-items: center; gap: var(--s-2);
  font-size: 11.5px; color: var(--label-2);
  padding: var(--s-2) 0; margin-top: var(--s-2); border-bottom: 1px solid var(--sep);
}
.chat-scope.show { display: flex; }
.chat-scope b { color: var(--label); font-weight: 600; }
.chat-messages {
  flex: 1; overflow-y: auto; min-height: 0; contain: content;
  display: flex; flex-direction: column; gap: var(--s-6);
  padding: var(--s-6) 2px var(--s-5);
}
.chat-empty { margin: auto; text-align: center; color: var(--label-2); max-width: 460px; padding: var(--s-8) var(--s-6); }
.chat-empty-ico { font-size: 30px; margin-bottom: var(--s-3); opacity: .7; }
.chat-empty p { font-size: 13.5px; line-height: 1.6; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: var(--s-3); justify-content: center; margin-top: var(--s-6); }
.chat-chip {
  font-size: 12.5px; padding: 7px 12px; border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--bg-elevated); color: var(--label);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.chat-chip:hover { background: var(--fill-3); border-color: var(--border-strong); }

.chat-msg { display: flex; max-width: 88%; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.assistant { align-self: flex-start; max-width: 94%; }
.bubble { padding: var(--s-4) var(--s-5); border-radius: var(--r-lg); font-size: 14px; line-height: 1.6; word-break: break-word; }
.chat-msg.user .bubble { background: var(--blue); color: #fff; white-space: pre-wrap; }
.chat-msg.assistant .bubble { background: var(--fill-3); border: 1px solid var(--border); color: var(--label); }

/* Provenance. The single most important honesty signal in the interface:
   "from your documents" and "general knowledge" are different claims. */
.srcbadge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; padding: 2px 8px;
  border-radius: var(--r-badge); margin-bottom: var(--s-3);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 26%, transparent);
}
.srcbadge.docs    { background: rgba(0,122,255,0.12); color: var(--blue); }
.srcbadge.general { background: rgba(255,149,0,0.14); color: var(--orange-text); }
.srcbadge.none    { background: var(--fill-2); color: var(--label-2); }

.cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; margin: 0 1px;
  font-size: 10.5px; font-weight: 700; line-height: 1; vertical-align: 1px;
  border-radius: var(--r-sm); background: rgba(0,122,255,0.16); color: var(--blue);
  cursor: pointer; font-family: var(--font-mono);
}
.cite:hover { background: rgba(0,122,255,0.3); }

.chat-typing { align-self: flex-start; font-size: 13px; color: var(--label-3); padding: 2px; }
.chat-typing span { display: inline-block; animation: blink 1.2s infinite; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

.chat-err, .chat-notice {
  align-self: stretch; font-size: 12.5px; line-height: 1.5;
  border-radius: var(--r-md); padding: var(--s-3) var(--s-5);
}
.chat-err { color: var(--red-text); background: rgba(255,59,48,0.08); border: 1px solid rgba(255,59,48,0.25); }
.chat-notice { color: var(--orange-text); background: rgba(255,149,0,0.1); border: 1px solid rgba(255,149,0,0.28); }

.chat-input-bar {
  display: flex; gap: var(--s-3); align-items: flex-end;
  border-top: 1px solid var(--sep); padding: var(--s-5) 0;
  padding-bottom: max(var(--s-5), env(safe-area-inset-bottom));
  flex: 0 0 auto;
}
.chat-input-bar textarea {
  flex: 1; resize: none; max-height: 130px; padding: var(--s-4) var(--s-5);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-elevated); color: var(--label);
  font-family: inherit; font-size: 14px; line-height: 1.45; outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.chat-input-bar textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.14); }
.btn-send {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: var(--r-md);
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast);
}
.btn-send:hover { background: var(--blue-hover); }
.btn-send:disabled { opacity: .45; cursor: not-allowed; }

/* ═══ RENDERED MARKDOWN (inside chat bubbles) ═══ */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 var(--s-4); }
.md h1, .md h2, .md h3, .md h4 { margin: var(--s-5) 0 var(--s-3); font-weight: 650; letter-spacing: -0.01em; }
.md h1 { font-size: 16px; } .md h2 { font-size: 15px; } .md h3 { font-size: 14px; } .md h4 { font-size: 13.5px; }
.md ul, .md ol { margin: 0 0 var(--s-4); padding-left: var(--s-7); }
.md li { margin-bottom: 3px; }
.md code { font-family: var(--font-mono); font-size: 12px; background: var(--fill-2); padding: 1px 5px; border-radius: var(--r-xs); }
.md pre { background: var(--bg-secondary); border: 1px solid var(--sep); border-radius: var(--r-md); padding: var(--s-4); overflow-x: auto; margin: 0 0 var(--s-4); }
.md pre code { background: none; padding: 0; font-size: 12px; line-height: 1.5; }
.md blockquote { border-left: 3px solid var(--border-strong); padding-left: var(--s-4); color: var(--label-2); margin: 0 0 var(--s-4); }
.md a { color: var(--blue); }
.md hr { border: none; border-top: 1px solid var(--sep); margin: var(--s-5) 0; }
.md-table-wrap { overflow-x: auto; margin: 0 0 var(--s-4); }
.md table { border-collapse: collapse; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--sep); padding: var(--s-2) var(--s-3); text-align: left; }
.md th { background: var(--bg-secondary); font-weight: 600; }

/* ═══ SOURCES PANEL ═══ */
.src-list { padding: 0 var(--s-5) var(--s-6); display: flex; flex-direction: column; gap: var(--s-3); }
.src-card {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-elevated); padding: var(--s-4); cursor: pointer;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  text-align: left; width: 100%;
}
.src-card:hover { border-color: var(--border-strong); }
.src-card.flash { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.14); }
/* Surrounding context, not a match. Recessed so the eye finds real hits first. */
.src-card.adjacent { background: var(--bg-secondary); border-style: dashed; }
.src-card.adjacent .src-n { background: var(--fill-2); color: var(--label-2); }
.src-card.adjacent .tag { color: var(--label-2); background: color-mix(in srgb, var(--label-2) 12%, transparent); }
.src-card-head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); }
.src-n {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  min-width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); background: rgba(0,122,255,0.16); color: var(--blue);
}
.src-title { flex: 1; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-score { font-family: var(--font-mono); font-size: 10.5px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.src-loc { font-size: 11px; color: var(--label-3); margin-bottom: var(--s-2); }
.src-snippet { font-size: 12px; line-height: 1.5; color: var(--label-2); }

/* Only visible while the panel holds an earlier answer's sources. */
.src-scope {
  margin: 0 var(--s-5) var(--s-3); padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md); background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--orange-text) 26%, transparent);
  color: var(--orange-text); font-size: 11px; font-weight: 600;
}

.retrieval-meta {
  margin: 0 var(--s-5) var(--s-4); padding: var(--s-3) var(--s-4);
  border: 1px solid var(--sep); border-radius: var(--r-md); background: var(--bg-elevated);
  font-size: 11px; color: var(--label-2);
  display: grid; grid-template-columns: auto auto; gap: 3px var(--s-4);
}
.retrieval-meta b { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--label); font-weight: 600; }

/* ═══ CHUNK INSPECTOR (slide-over) ═══ */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.25); z-index: 40;
  touch-action: none;
}
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(620px, 100vw); background: var(--bg-primary);
  border-left: 1px solid var(--sep); box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column;
  animation: slide-in var(--dur-slow) var(--ease);
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--sep); flex: 0 0 auto;
}
.sheet-title { flex: 1; font-size: 14px; font-weight: 650; }
.sheet-body { flex: 1; overflow-y: auto; padding: var(--s-5) var(--s-6); contain: content; }

.chunk-card { border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: var(--s-3); overflow: hidden; }
.chunk-head {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-2) var(--s-4); background: var(--bg-secondary);
  border-bottom: 1px solid var(--sep); font-size: 11px; color: var(--label-2);
}
.chunk-head .idx { font-family: var(--font-mono); font-weight: 700; color: var(--label); }
.chunk-head .path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chunk-text { padding: var(--s-4); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; max-height: 220px; overflow-y: auto; }
.tag {
  font-size: 10px; font-weight: 650; padding: 1px 5px; border-radius: var(--r-badge);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 26%, transparent);
}
.tag.ok { color: var(--green-text); background: color-mix(in srgb, var(--green-text) 14%, transparent); }
.tag.warn { color: var(--red-text); background: color-mix(in srgb, var(--red-text) 12%, transparent); }

.log-line { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7; }
.log-line.warn { color: var(--orange-text); }
.log-line.error { color: var(--red-text); }
.log-line.ok { color: var(--green-text); }

/* ═══ TOASTS ═══ */
.toasts {
  position: fixed; bottom: calc(var(--s-8) + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: var(--s-3); align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  background: #1c1c1e; color: #fff; font-size: 13px; font-weight: 500;
  padding: var(--s-4) var(--s-6); border-radius: var(--r-lg); box-shadow: var(--shadow-xl);
  animation: toast-in var(--dur-slow) var(--ease-spring);
  max-width: min(90vw, 520px);
}
.toast.ok::before  { content: '✓'; color: #34c759; font-weight: 700; }
.toast.err::before { content: '✕'; color: #ff6961; font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ═══ LOGIN ═══ */
.gate { height: 100%; display: flex; align-items: center; justify-content: center; padding: var(--s-6); }
.gate-card {
  width: 100%; max-width: 380px; border: 1px solid var(--border);
  border-radius: var(--r-xl); background: var(--bg-elevated);
  padding: var(--s-9) var(--s-8); box-shadow: var(--shadow-lg);
}
.gate-title { font-size: 18px; font-weight: 680; letter-spacing: -0.02em; margin-bottom: var(--s-2); }
.gate-sub { font-size: 12.5px; color: var(--label-2); line-height: 1.6; margin-bottom: var(--s-7); }
.field { display: block; margin-bottom: var(--s-5); }
.field span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--label-2); margin-bottom: var(--s-2); }
.field input {
  width: 100%; padding: var(--s-4) var(--s-5); font-family: var(--font-mono); font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-tertiary); color: var(--label); outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.14); }
.gate .btn { width: 100%; justify-content: center; padding: var(--s-4); }
.gate-err { font-size: 12.5px; color: var(--red-text); margin-bottom: var(--s-5); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1100px) {
  :root { --panel-right: 0px; }
  .layout { grid-template-columns: var(--panel-left) 1fr; }
  .panel-right { display: none; }
}

@media (max-width: 820px) {
  .layout, .layout.no-sources { grid-template-columns: 1fr; }
  .btn-drawer { display: inline-flex; }
  .panel-left {
    position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 30;
    width: min(320px, 86vw); transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    padding-left: env(safe-area-inset-left);
    box-shadow: var(--shadow-xl);
  }
  body.nav-open .panel-left { transform: none; }
  body.nav-open::after {
    content: ''; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0,0,0,0.25); z-index: 29;
  }
  .chat-wrap { padding: 0 var(--s-5); }
  html, body { font-size: 14px; }
}

/* Touch: 44px targets, and 16px inputs so iOS does not zoom on focus. */
@media (pointer: coarse) {
  .btn, .btn-icon { min-height: 36px; }
  .btn-send { width: 44px; height: 44px; }
  .chat-input-bar textarea, .field input { font-size: 16px; }
  .doc-actions { opacity: 1; }
}
@media (hover: none) {
  .upload-zone:hover { border-color: var(--border-strong); background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .pill::before { animation: none !important; }
}
