/* ============================================================================
   Nury Chat — design system
   Ported from the Nur Docs Platform. Gemini-inspired: near-black cool neutrals,
   blue→purple→coral gradient, mouse-reactive ambient light. Dark is default.
   ========================================================================== */

/* ------------------------------------------------------------ tokens */
:root, :root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #090710;
  --bg-soft: #110e1a;
  --surface: #1a1626;
  --surface-2: #231e33;
  --surface-3: #2d2740;
  --text: #e3e3e3;
  --muted: #9aa0a6;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  --accent: #e10076;
  --accent-2: #4cb6ae;
  --primary-bg: #624692;
  --primary-text: #ffffff;
  --grad: linear-gradient(74deg, #624692 0%, #e10076 40%, #689dca 75%, #4cb6ae 100%);

  /* animated: --mx/--my/--breathe come from js/ambient.js */
  --glow:
    radial-gradient(calc(640px * var(--breathe, 1)) calc(500px * var(--breathe, 1)) at var(--mx, 50%) var(--my, 44%), rgba(225, 0, 118, 0.14), transparent 70%),
    radial-gradient(calc(520px * var(--breathe, 1)) calc(430px * var(--breathe, 1)) at calc(var(--mx, 50%) + 14%) calc(var(--my, 44%) + 16%), rgba(98, 70, 146, 0.10), transparent 70%),
    radial-gradient(calc(720px * var(--breathe, 1)) calc(560px * var(--breathe, 1)) at calc(var(--mx, 50%) - 16%) calc(var(--my, 44%) + 6%), rgba(76, 182, 174, 0.05), transparent 72%);

  --ok-text: #81c995; --ok-bg: rgba(129, 201, 149, 0.12);
  --warn-text: #fdd663; --warn-bg: rgba(253, 214, 99, 0.10);
  --danger-text: #f28b82; --danger-bg: rgba(242, 139, 130, 0.12);

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 1px 8px rgba(0, 0, 0, 0.30);

  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 28px;
  --control-h: 40px;
  --header-h: 57px;
}

:root[data-theme='light'] {
  color-scheme: light;

  --bg: #ffffff;
  --bg-soft: #faf9fc;
  --surface: #f3f0f7;
  --surface-2: #e8e4f1;
  --surface-3: #dcd6e8;
  --text: #1f1f1f;
  --muted: #5a5762;
  --border: rgba(31, 31, 31, 0.09);
  --border-strong: rgba(31, 31, 31, 0.18);

  --accent: #624692;
  --accent-2: #4cb6ae;
  --primary-bg: #624692;
  --primary-text: #ffffff;
  --grad: linear-gradient(74deg, #624692 0%, #e10076 40%, #689dca 75%, #4cb6ae 100%);

  --glow:
    radial-gradient(calc(640px * var(--breathe, 1)) calc(500px * var(--breathe, 1)) at var(--mx, 50%) var(--my, 44%), rgba(225, 0, 118, 0.07), transparent 70%),
    radial-gradient(calc(520px * var(--breathe, 1)) calc(430px * var(--breathe, 1)) at calc(var(--mx, 50%) + 14%) calc(var(--my, 44%) + 16%), rgba(98, 70, 146, 0.05), transparent 70%),
    radial-gradient(calc(720px * var(--breathe, 1)) calc(560px * var(--breathe, 1)) at calc(var(--mx, 50%) - 16%) calc(var(--my, 44%) + 6%), rgba(76, 182, 174, 0.03), transparent 72%);

  --ok-text: #146c2e; --ok-bg: rgba(20, 108, 46, 0.09);
  --warn-text: #8a5a00; --warn-bg: rgba(180, 130, 20, 0.12);
  --danger-text: #b3261e; --danger-bg: rgba(179, 38, 30, 0.08);

  --shadow: 0 4px 20px rgba(40, 60, 100, 0.12);
  --shadow-soft: 0 1px 8px rgba(40, 60, 100, 0.08);
}

/* ------------------------------------------------------------ base */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

h1 { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------ utilities */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger-text); }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.center { display: grid; place-items: center; height: 60vh; text-align: center; padding: 0 20px; }
[hidden] { display: none !important; }
/* Off-screen but still rendered. Used for the file/folder <input>s: Safari (and
   some other engines) refuse to open the native picker for a display:none input,
   so `hidden` would make the "Choose folder" button do nothing. This keeps the
   input in the layout while remaining invisible. */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ------------------------------------------------------------ background layers */
/* dash field (js/starfield.js) — bottom layer of the background stack */
.starfield {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  width: 100%; height: 100%; display: block;
}
/* the living light: hue drifts, saturation flares with pointer speed,
   size breathes — all driven by js/ambient.js vars */
.glow-layer {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: var(--glow);
  filter: hue-rotate(var(--hue, 0deg)) saturate(var(--sat, 1));
}

/* ------------------------------------------------------------ shell */
.shell { display: flex; flex-direction: column; height: 100dvh; }

.app-header {
  display: flex; align-items: center; gap: 22px;
  height: var(--header-h); padding: 0 22px; flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 10;
}
.brand {
  font-weight: 700; font-size: 17px; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.brand img { display: block; object-fit: contain; height: 28px; width: auto; }
.brand-sub {
  border-left: 1px solid var(--border); padding-left: 8px; margin-left: 2px;
  font-size: 13px; font-weight: 500; opacity: 0.8;
}
/* primary nav — styled as clear pill buttons/tabs */
.app-header nav { display: flex; gap: 8px; min-width: 0; }
.app-header nav a {
  padding: 7px 18px; border-radius: var(--radius-pill);
  color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.app-header nav a:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.app-header nav a:active { transform: scale(0.97); }
.app-header nav a.active {
  background: var(--primary-bg); color: var(--primary-text);
  border-color: transparent; box-shadow: var(--shadow-soft);
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-email {
  color: var(--muted); font-size: 13px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* theme slider: moon | sun in the track, thumb slides over the active one */
.theme-switch {
  width: 56px; height: 28px; border-radius: 20px; position: relative;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  cursor: pointer; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  transition: border-color 0.25s ease;
}
.theme-switch:hover { border-color: var(--accent); }
.theme-icon {
  width: 28px; display: grid; place-items: center;
  color: var(--muted); position: relative; z-index: 1;
  transition: color 0.25s ease;
}
.theme-icon svg { display: block; }
.theme-switch.dark .theme-icon:first-child,
.theme-switch.light .theme-icon:nth-child(2) { color: var(--primary-text); }
.theme-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 24px; height: 22px; border-radius: 14px;
  background: var(--primary-bg); box-shadow: var(--shadow-soft);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.theme-switch.light .theme-thumb { transform: translateX(26px); }

/* background-animation switch: sparkle lit while the dash field runs,
   dimmed with a slash when it's off */
.fx-toggle {
  height: 28px; width: 28px; padding: 0; border-radius: 50%; flex-shrink: 0;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; position: relative;
  transition: color 0.25s ease;
}
.fx-toggle:hover { background: var(--surface-2); color: var(--text); }
.fx-toggle svg { display: block; }
.fx-toggle::after {
  content: ''; position: absolute; left: 5px; right: 5px; top: 50%; height: 2px;
  background: currentColor; border-radius: 1px;
  transform: rotate(-45deg) scaleX(0); transition: transform 0.2s ease;
}
.fx-toggle.off { opacity: 0.6; }
.fx-toggle.off::after { transform: rotate(-45deg) scaleX(1); }

/* ------------------------------------------------------------ layout */
.app-main {
  flex: 1; min-height: 0; overflow-y: auto; position: relative;
  display: flex; flex-direction: column;
}
.page { position: relative; z-index: 1; width: 100%; max-width: 920px; margin: 0 auto; padding: 30px 22px 40px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* ------------------------------------------------------------ controls */
input, select {
  height: var(--control-h);
  padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; background: var(--surface); color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 0;
}
input::placeholder { color: var(--muted); }
input:focus-visible, select:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

button, .btn {
  height: 38px; padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--border-strong); }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: default; }
button.small { height: 30px; padding: 0 12px; font-size: 13px; }

.primary {
  background: var(--primary-bg); border-color: transparent;
  color: var(--primary-text); font-weight: 600; box-shadow: var(--shadow-soft);
}
.primary:hover:not(:disabled) { filter: brightness(1.1); border-color: transparent; }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.ghost.danger { color: var(--danger-text); }
.icon-btn {
  height: 30px; width: 30px; padding: 0; border-radius: 50%;
  background: transparent; border: none; color: var(--muted); font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border: none; }
.icon-btn.danger:hover { color: var(--danger-text); }

/* ------------------------------------------------------------ auth / unlock cards */
.login-page {
  display: grid; place-items: center; height: 100dvh;
  position: relative; z-index: 1; padding: 20px;
}
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 36px; box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 4px; }
.login-card .stack { margin-top: 20px; }
.login-logo-container { display: flex; justify-content: center; margin-bottom: 24px; }
.login-logo {
  height: 52px; width: auto; object-fit: contain;
  filter: drop-shadow(0 0 20px rgba(225, 0, 118, 0.35));
  animation: logo-float 4s ease-in-out infinite;
}
@keyframes logo-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.brand-lg {
  font-weight: 750; font-size: 30px; letter-spacing: -0.02em;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 10px;
}
.warn-box {
  font-size: 13px; color: var(--warn-text); background: var(--warn-bg);
  border-radius: var(--radius-sm); padding: 10px 12px;
}

/* ------------------------------------------------------------ vault: upload + docs */
.upload-zone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.upload-zone:hover { border-color: var(--accent); background: var(--surface-2); }
.uz-icon { font-size: 22px; color: var(--muted); line-height: 1; }
.uz-drop { display: none; }
/* while dragging: swap the copy, tint, lift, and pulse the ring */
.upload-zone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  transform: scale(1.01);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
  animation: uz-pulse 1.1s ease-in-out infinite;
}
.upload-zone.dragover .uz-idle { display: none; }
.upload-zone.dragover .uz-drop { display: block; color: var(--accent); }
.upload-zone.dragover .uz-icon { color: var(--accent); animation: drop-bob 1s ease-in-out infinite; }
@keyframes uz-pulse {
  50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 7%, transparent); }
}

/* full-screen drag-and-drop overlay (works anywhere on either page) */
.global-drop {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: drop-in 0.15s ease-out;
}
.global-drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 40px 56px; border-radius: 22px;
  border: 2px dashed var(--accent);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  box-shadow: var(--shadow);
  animation: drop-bob 1.1s ease-in-out infinite;
}
.global-drop-card .drop-emoji { font-size: 40px; color: var(--accent); line-height: 1; }
.global-drop-text { font-size: 19px; font-weight: 650; color: var(--accent); text-align: center; }
.drop-emoji { font-size: 26px; }
@keyframes drop-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
@keyframes drop-bob { 50% { transform: translateY(-5px); } }
.upload-status { min-height: 18px; font-size: 13px; color: var(--muted); margin: 10px 2px; }

/* upload progress — determinate across a batch; the indeterminate sweep is for
   a single file whose parse duration can't be known in advance. */
.upload-progress { margin: 12px 2px 0; }
.upload-track {
  height: 6px; background: var(--surface-3); border-radius: 6px;
  overflow: hidden; position: relative;
}
.upload-fill {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 6px; transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.upload-fill.indeterminate {
  width: 32%; transition: none;
  animation: upload-sweep 1.15s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes upload-sweep {
  0% { transform: translateX(-105%); } 100% { transform: translateX(320%); }
}
.upload-count { font-size: 12px; color: var(--muted); margin-top: 6px; }
@media (prefers-reduced-motion: reduce) {
  .upload-fill { transition: none; }
  .upload-fill.indeterminate { animation-duration: 2.4s; }
}

/* library: model-context capacity meter */
.capacity {
  margin: 16px 0 4px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.capacity-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.capacity-label { font-size: 13px; font-weight: 600; }
.capacity-text { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.capacity-track { height: 7px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.capacity-fill {
  height: 100%; width: 0%; border-radius: 6px; background: var(--accent-2);
  transition: width 0.35s ease, background-color 0.25s ease;
}
.capacity-fill.warn { background: var(--warn-text); }
.capacity-fill.danger { background: var(--danger-text); }
.capacity-note { margin-top: 7px; font-size: 12px; color: var(--muted); }
.capacity-note.full { color: var(--danger-text); font-weight: 500; }

/* library: search toolbar + nested folder tree */
.library-toolbar { display: flex; align-items: center; gap: 12px; margin: 18px 0 8px; flex-wrap: wrap; }
.library-toolbar #doc-search { flex: 1; min-width: 160px; height: 38px; }
.select-all {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap;
}
input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; margin: 0; }

.bulk-bar {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px;
  padding: 8px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.bulk-bar #bulk-count { font-size: 13px; font-weight: 600; margin-right: auto; }

.doc-tree {
  display: flex; flex-direction: column; gap: 1px; padding-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px;
}
.doc-tree .empty { color: var(--muted); padding: 16px 6px; }

.folder-header, .tree-file {
  display: flex; align-items: center; gap: 9px;
  min-height: 40px; padding-right: 10px; border-radius: var(--radius-sm);
}
.folder-header { cursor: pointer; font-weight: 600; }
.folder-header:hover, .tree-file:hover { background: var(--surface-2); }
.tw-caret { display: inline-flex; color: var(--muted); transition: transform 0.15s ease; flex-shrink: 0; }
.folder-header.collapsed .tw-caret { transform: rotate(-90deg); }
.tw-caret svg { width: 14px; height: 14px; display: block; }
.tw-icon { display: inline-flex; color: var(--muted); flex-shrink: 0; }
.tree-file .tw-icon { color: var(--accent-2); }
.tw-icon svg { width: 17px; height: 17px; display: block; }
.tw-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tw-count {
  color: var(--muted); font-weight: 500; font-size: 12px; margin-left: auto; flex-shrink: 0;
  background: var(--surface-2); padding: 1px 9px; border-radius: 12px;
}
.folder-header:hover .tw-count { background: var(--surface-3); }
.folder-body { display: flex; flex-direction: column; gap: 1px; }
.tree-file .grow { overflow: hidden; }
.tree-file .doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn svg { width: 15px; height: 15px; display: block; }

.list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px; min-height: 52px;
}
.list-item .grow { overflow-wrap: anywhere; }
.list .empty { color: var(--muted); padding: 10px 2px; border: none; background: none; min-height: 0; }
.badge {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  white-space: nowrap; flex-shrink: 0;
}
.badge-ready { background: var(--ok-bg); color: var(--ok-text); }
.badge-inline { background: var(--surface-2); color: var(--muted); }
.badge-image { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.doc-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.doc-tokens { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 8px; }
.folder-tokens { margin-left: auto; font-weight: 500; flex-shrink: 0; }
.folder-header .tw-count { margin-left: 10px; }

/* ------------------------------------------------------------ chat */
.chat-page {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  max-width: 840px; padding-bottom: 18px;
}
.chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  padding: 8px 2px 18px;
}
/* Empty chat: greeting and composer travel together, vertically centred, so the
   input sits directly under the suggestion chips. `flex: 0 1 auto` lets the
   greeting still shrink/scroll on a short viewport. app.js runs a FLIP to slide
   the composer down to the bottom once the first message is sent. */
.chat-page.chat-empty { justify-content: center; }
.chat-page.chat-empty .chat-messages { flex: 0 1 auto; }
.chat-hello {
  margin: auto; text-align: center; padding: 30px 10px;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1); max-height: 500px;
}
.chat-hello.fade-out {
  opacity: 0; transform: scale(0.95) translateY(-24px);
  max-height: 0; padding: 0 10px; margin: 0; overflow: hidden;
}
.hello-gradient {
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 600; letter-spacing: -0.02em; margin: 0 0 2px;
  background: var(--grad); background-size: 220% 220%;
  background-position: var(--gx, 50%) 50%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: hue-rotate(var(--hue, 0deg)) saturate(var(--sat, 1));
  will-change: background-position, filter;
}
.hello-sub { font-size: clamp(17px, 3vw, 22px); color: var(--muted); margin: 0; font-weight: 400; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 28px; }
.suggestion {
  height: auto; background: var(--surface); border: none;
  border-radius: var(--radius); padding: 14px 16px; font-size: 14px; color: var(--text);
  max-width: 230px; text-align: left; white-space: normal; line-height: 1.4;
}
.suggestion:hover { background: var(--surface-2); }

.msg { max-width: 88%; position: relative; animation: msg-entry 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes msg-entry { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { align-self: flex-end; }
.msg.user .msg-body {
  background: var(--surface-3); color: var(--text);
  border-radius: 20px 20px 6px 20px; padding: 11px 17px; overflow-wrap: anywhere;
}
.msg.assistant { align-self: flex-start; width: 88%; padding-left: 32px; }
.msg-avatar { position: absolute; left: 0; top: 12px; width: 20px; height: 20px; object-fit: contain; }
.msg-avatar.pulsing { animation: pulse 1.2s infinite; }
.msg.assistant .msg-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px 20px 20px 20px; padding: 14px 18px;
  box-shadow: var(--shadow-soft); overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg-body.error-bubble { color: var(--danger-text); border-color: color-mix(in srgb, var(--danger-text) 40%, transparent); }

/* ---- thinking indicator ----
   .msg.assistant is width:88%, which left a near-empty full-width bubble while
   waiting. Shrink to content until real text arrives (JS drops .is-thinking). */
.msg.assistant.is-thinking { width: auto; }
.msg.assistant.is-thinking .msg-body {
  display: inline-flex; align-items: center;
  padding: 12px 16px; white-space: nowrap;
}
.thinking { display: inline-flex; align-items: center; gap: 10px; }
.typing { display: inline-flex; align-items: center; gap: 5px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  opacity: 0.3; animation: typing-bounce 1.3s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing-bounce {
  0%, 65%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 0.95; }
}
.thinking-phase {
  font-size: 13px; color: var(--muted);
  opacity: 1; transition: opacity 0.14s ease;
}
.thinking-phase:empty { display: none; }
.thinking-phase.fading { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  /* keep a liveness cue, drop the motion */
  .typing i { animation: typing-fade 1.6s ease-in-out infinite; }
  @keyframes typing-fade { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.85; } }
  .msg-avatar.pulsing { animation-duration: 2.4s; }
}
/* Attached images sit below the bubble; the wrapper keeps them aligned with
   the message side and stops a tall photo from dominating the thread. */
/* flex-start, not the default stretch: otherwise a short image's box is pulled
   to the tallest sibling's height and the picture letterboxes inside it. */
.chat-imgs { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin-top: 8px; }
.msg.user .chat-imgs { justify-content: flex-end; }
.chat-img {
  max-width: min(240px, 100%); max-height: 260px; width: auto; height: auto;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); display: block; object-fit: contain;
}
.chip-thumb { width: 18px; height: 18px; border-radius: 4px; object-fit: cover; display: block; }
.attach-chip, .pending-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); font-size: 12px;
  padding: 4px 10px; border-radius: 20px; margin: 6px 6px 0 0;
}
.chip-label { display: inline-flex; align-items: center; gap: 6px; }
.chip-icon { display: inline-flex; align-items: center; }
.chip-icon svg { width: 13px; height: 13px; display: block; }
.chip-remove { height: auto; width: auto; padding: 0; border: none; background: none; color: var(--muted); }
.chip-remove svg { width: 12px; height: 12px; display: block; }
.chip-remove:hover { color: var(--danger-text); border: none; background: none; }

/* citations — rendered below the bubble, not inside it */
.citations { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 0; }
.cite-label { font-size: 12px; color: var(--muted); margin-right: 8px; font-weight: 500; }
.chip {
  display: inline-block; background: var(--surface-2); color: var(--accent);
  border: 1px solid var(--border); font-size: 12px;
  padding: 3px 10px; border-radius: 20px; margin: 2px 6px 2px 0;
}

@keyframes pulse { 50% { opacity: 0.35; } }

.chat-pending { display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.chat-input-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; margin-top: 12px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill); box-shadow: var(--shadow-soft);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-input-bar:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.chat-input-bar input { flex: 1; height: 38px; border: none; background: none; padding: 0 4px; font-size: 15px; }
.chat-input-bar input:focus-visible { box-shadow: none; outline: none; }
/* Matches the input/send height so the three sit on one line. The svg rule is
   load-bearing: without an explicit size the icon renders at its intrinsic
   32px and fills the button edge to edge. 18/38 keeps the same glyph-to-button
   ratio as .icon-btn (15/30). */
.attach-btn {
  flex-shrink: 0; height: 38px; width: 38px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: transparent;
  border: 1px solid var(--border); color: var(--muted);
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.attach-btn svg { width: 18px; height: 18px; display: block; }
.attach-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-strong); }
.chat-view.dragover .chat-messages { outline: 2px dashed var(--accent); outline-offset: -8px; border-radius: var(--radius); }

/* ------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, #000 55%, transparent);
  backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(460px, 100%); background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 24px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 4px; }
.modal .row.end { justify-content: flex-end; margin-top: 8px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 720px) {
  .user-email { display: none; }
  .app-header { gap: 12px; padding: 0 14px; }
  .page { padding: 22px 16px 30px; }
  .msg, .msg.assistant { max-width: 100%; width: 100%; }
}
@media (max-width: 520px) {
  .brand-sub { display: none; }
  .header-actions button.labelled { padding: 0 12px; font-size: 13px; }
  .suggestion { max-width: 100%; }
}

/* respect users who opt out of motion */
@media (prefers-reduced-motion: reduce) {
  .msg-avatar.pulsing { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
