/* =================================================================
   AI CHAT — REIzer Copilot floating launcher + chat panel (DP-6b)
   -----------------------------------------------------------------
   Auto-injected on every authenticated page by ai-chat.js. All
   selectors namespaced `.aic-*` so they don't collide with the
   in-page mockup in _index-sandbox-c.html or other UI.
   ================================================================= */

:root {
  --aic-z: 9000;
  /* Copilot accent: theme-aware green->teal gradient (rich in light, bright in
     dark) — distinct from the flat brand logo to signal the AI agent. */
  --aic-grad: linear-gradient(135deg, var(--accent) 0%, var(--accent-4) 100%);
}

/* ===========================================
   FLOATING LAUNCHER
   =========================================== */

.aic-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--aic-z);
  display: none; /* shown by JS only when user is authed */
}
.aic-launcher.is-mounted { display: block; }
.aic-launcher.is-hidden  { display: none; }

.aic-launcher-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--brand-fill);
  color: var(--brand-ink);
  cursor: pointer;
  box-shadow:
    0 8px 24px -8px color-mix(in srgb, var(--brand-fill) 55%, transparent),
    0 2px 6px color-mix(in srgb, var(--brand-fill) 22%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
/* AI-agent cue — a soft pulsing ring around the launcher (button only, not the
   chevron logo) to signal a live AI assistant. */
.aic-launcher-btn::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--brand-fill) 60%, transparent);
  opacity: 0;
  pointer-events: none;
  animation: aic-launcher-pulse 2.8s ease-out infinite;
}
@keyframes aic-launcher-pulse {
  0%   { transform: scale(0.9);  opacity: 0.6; }
  70%  { transform: scale(1.28); opacity: 0; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .aic-launcher-btn::after { animation: none; } }
.aic-launcher-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 30px -8px color-mix(in srgb, var(--brand-fill) 65%, transparent),
    0 4px 10px color-mix(in srgb, var(--brand-fill) 25%, transparent);
}
.aic-launcher-btn svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.aic-launcher-tip {
  position: absolute;
  right: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: var(--on-dark);
  padding: 7px 12px;
  border-radius: 8px;
  font-family: var(--font-display), sans-serif;
  font-size: 12.5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.aic-launcher-tip::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: #0f172a;
}
.aic-launcher-btn:hover + .aic-launcher-tip,
.aic-launcher-btn:focus-visible + .aic-launcher-tip {
  opacity: 1;
}

/* ===========================================
   CHAT PANEL
   =========================================== */

.aic-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: min(480px, calc(100vw - 48px));
  height: min(720px, calc(100vh - 48px));
  background: var(--surface-solid);
  border-radius: 16px;
  box-shadow:
    0 20px 50px -16px rgba(15,23,42,0.40),
    0 6px 18px -10px rgba(15,23,42,0.25);
  z-index: calc(var(--aic-z) + 1);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-display), sans-serif;
  border: 1px solid rgba(15,23,42,0.08);
  transition: width 0.25s cubic-bezier(0.32, 0.72, 0, 1),
              height 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.aic-panel.is-open { display: flex; }

/* ===========================================
   EMBEDDED (inline) MODE — dashboard home
   The same panel, re-parented into a host card and laid out as a
   static inline block instead of a floating overlay. Higher
   specificity (.aic-panel.aic-embedded) beats the fixed/mobile/docked
   rules regardless of source order. */
.aic-panel.aic-embedded {
  /* relative (not static) so absolutely-positioned children — the history
     overlay, the quota popover — anchor to the panel, not the viewport.
     With inset:auto the box stays exactly where normal flow puts it. */
  position: relative;
  inset: auto;
  width: 100%;
  max-width: none;
  height: 560px;
  max-height: none;
  border-radius: 16px;
  border: 1px solid rgba(15,23,42,0.10);
  box-shadow: 0 14px 34px -22px rgba(15,23,42,0.30);
  transition: none;
}
.aic-panel.aic-embedded.is-open { display: flex; }
/* Inline chat lives in the card — there's nothing to close, and the
   dock animation doesn't apply. */
.aic-panel.aic-embedded [data-aic="close"] { display: none; }
@media (max-width: 900px) {
  .aic-panel.aic-embedded { height: 480px; }
}

/* Mobile / narrow — full-screen modal */
@media (max-width: 480px) {
  .aic-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    /* 100vh counts the area BEHIND the mobile address bar, so the bottom
       input row (with the send button) was pushed off-screen. dvh tracks the
       actually-visible height; vh stays as a fallback for old browsers.
       The keyboard case is handled in JS (visualViewport) — see ai-chat.js
       syncPanelViewport(), which sets an explicit pixel height when open. */
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    max-height: none;
  }
  /* Keep the send button clear of the iOS home-indicator gesture bar. */
  .aic-input-bar {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .aic-launcher { bottom: 18px; right: 18px; }
}

/* Docked sidebar — VS-Code-style. Active on viewports wide enough
   that there's still room for the analyzer next to a 480px column.
   The chat panel becomes a full-height fixed right column; the rest
   of the page is pushed left via body padding so the analyzer's own
   side-panels (Comps overlay, MAO panel) shift to make room. */
@media (min-width: 1100px) {
  html.aic-docked body {
    padding-right: 480px;
    transition: padding-right 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  }
  html.aic-docked .aic-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: 480px;
    height: 100vh;
    max-width: 480px;
    max-height: none;
    border-radius: 0;
    border: 0;
    border-left: 1px solid rgba(15,23,42,0.10);
    box-shadow: -16px 0 40px -22px rgba(15,23,42,0.20);
  }
  /* In-page side panels (MAO panel, analyzer results) are
     position:fixed; right:0 — push them left so the docked chat
     doesn't stack on top. */
  html.aic-docked .side-panel { right: 480px; }
  /* CompsOverlay is a full-viewport overlay (.strc-overlay {inset:0}),
     so we trim its right edge to land flush with the chat column.
     Same fix for any future inset-0 host. */
  html.aic-docked .strc-overlay {
    right: 480px !important;
    width: auto;
  }
}

/* --- Header — neutral surface, brand mark provides the gradient pop --- */
.aic-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-solid);
  color: #0f172a;
  border-bottom: 1px solid rgba(15,23,42,0.08);
  flex-shrink: 0;
}
.aic-header-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand-fill);
  color: var(--brand-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aic-header-mark svg {
  width: 16px;
  height: 16px;
}
.aic-header-title {
  flex: 1;
  min-width: 0;
}
.aic-header-h {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: #0f172a;
}
.aic-header-sub {
  font-size: 11px;
  color: #64748b;
  letter-spacing: 0.02em;
  margin-top: 2px;
}

/* --- Quota ring + tooltip + popover --- */
.aic-quota-ring {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aic-quota-ring svg.aic-ring {
  width: 26px;
  height: 26px;
  transform: rotate(-90deg);
  overflow: visible;
}
.aic-ring-bg {
  fill: none;
  stroke: rgba(15,23,42,0.12);
  stroke-width: 3;
}
.aic-ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 62.83;
  stroke-dashoffset: 62.83;
  transition: stroke-dashoffset 0.35s ease, stroke 0.2s ease;
}
.aic-quota-ring.is-low    .aic-ring-fg { stroke: var(--warn); }
.aic-quota-ring.is-blocked .aic-ring-fg { stroke: var(--neg); }
.aic-quota-ring.is-infinite .aic-ring-fg { stroke: var(--pos); }
.aic-quota-ring:hover .aic-ring-bg { stroke: rgba(15,23,42,0.20); }
.aic-quota-ring:focus-visible { outline: 2px solid rgba(126,232,106,0.40); outline-offset: 2px; }

.aic-quota-tip {
  position: absolute;
  top: 50%;
  right: calc(100% + 6px);
  transform: translateY(-50%);
  background: #0f172a;
  color: var(--on-dark);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 5px 9px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 2;
  font-variant-numeric: tabular-nums;
}
.aic-quota-ring:hover .aic-quota-tip { opacity: 1; }

/* Popover hangs below the actions, contained within the panel */
.aic-quota-pop {
  position: absolute;
  top: 56px;
  right: 12px;
  width: 280px;
  background: var(--surface-solid);
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,0.10);
  box-shadow: 0 16px 36px -10px rgba(15,23,42,0.35);
  padding: 18px;
  z-index: 5;
  display: none;
}
.aic-quota-pop.is-open { display: block; }
.aic-quota-pop-kicker {
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.aic-quota-pop-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.aic-quota-pop-big {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.aic-quota-pop-of {
  font-size: 13px;
  color: #64748b;
  font-variant-numeric: tabular-nums;
}
.aic-quota-pop-of strong { color: #0f172a; font-weight: 700; }
.aic-quota-pop-bar {
  height: 6px;
  background: rgba(15,23,42,0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.aic-quota-pop-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-3) 60%, var(--accent-4) 100%);
  width: 0%;
  transition: width 0.35s ease, background 0.2s ease;
  border-radius: 3px;
}
.aic-quota-pop.is-low    .aic-quota-pop-bar-fill { background: var(--warn); }
.aic-quota-pop.is-blocked .aic-quota-pop-bar-fill { background: var(--neg); }
.aic-quota-pop-meta {
  font-size: 12px;
  color: #64748b;
  line-height: 1.5;
}
.aic-quota-pop-meta strong { color: #0f172a; font-weight: 600; }
.aic-quota-pop-note {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.25);
  color: var(--warn-strong);
  font-size: 12px;
  line-height: 1.5;
  border-radius: 8px;
}
.aic-quota-pop-cta {
  display: block;
  margin-top: 12px;
  text-align: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%);
  color: var(--on-dark) !important;
  border-radius: 8px;
  padding: 9px 12px;
  text-decoration: none !important;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.12s ease;
}
.aic-quota-pop-cta:hover { transform: translateY(-1px); }

/* Soft-throttle / over-quota banner between header and stream */
.aic-banner {
  display: none;
  padding: 8px 14px;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  border-bottom: 1px solid transparent;
}
.aic-banner.is-on { display: block; }
.aic-banner-throttle {
  background: rgba(245,158,11,0.08);
  color: var(--warn-strong);
  border-bottom-color: rgba(245,158,11,0.20);
}
.aic-banner-throttle a {
  color: var(--warn-strong);
  font-weight: 700;
  text-decoration: underline;
}
.aic-header-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.aic-header-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--ink-4);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.aic-header-btn:hover {
  background: rgba(15,23,42,0.06);
  color: var(--ink-3);
}
.aic-header-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Message stream --- */
.aic-stream {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 16px;
  background: #fafbfd;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
/* Slim, arrow-less scrollbars across the whole panel — covers the
   message stream's vertical scroll, the textarea's vertical scroll,
   and horizontal scrolls on wide <pre>/<table> blocks. ::-webkit-
   scrollbar-button: none hides the up/down/left/right arrow buttons
   that the OS-default scrollbar renders. */
.aic-panel,
.aic-panel * {
  scrollbar-width: thin;
  scrollbar-color: rgba(15,23,42,0.22) transparent;
}
.aic-panel ::-webkit-scrollbar,
.aic-panel::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.aic-panel ::-webkit-scrollbar-track,
.aic-panel::-webkit-scrollbar-track {
  background: transparent;
}
.aic-panel ::-webkit-scrollbar-thumb,
.aic-panel::-webkit-scrollbar-thumb {
  background: rgba(15,23,42,0.20);
  border-radius: 4px;
}
.aic-panel ::-webkit-scrollbar-thumb:hover,
.aic-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(15,23,42,0.36);
}
.aic-panel ::-webkit-scrollbar-button,
.aic-panel::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
.aic-panel ::-webkit-scrollbar-corner,
.aic-panel::-webkit-scrollbar-corner {
  background: transparent;
}

.aic-msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
}
.aic-msg-user { justify-content: flex-end; }

.aic-bubble {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  background: var(--surface-solid);
  color: #1f2937;
  border: 1px solid rgba(15,23,42,0.08);
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.aic-msg-ai .aic-bubble {
  border-radius: 12px 12px 12px 4px;
}
.aic-msg-user .aic-bubble {
  border-radius: 12px 12px 4px 12px;
}

/* Markdown styles inside AI bubble */
.aic-bubble > *:first-child { margin-top: 0; }
.aic-bubble > *:last-child  { margin-bottom: 0; }
.aic-bubble h1,
.aic-bubble h2,
.aic-bubble h3,
.aic-bubble h4 {
  font-weight: 700;
  line-height: 1.25;
  margin: 14px 0 6px;
  color: #0f172a;
}
.aic-bubble h1 { font-size: 17px; }
.aic-bubble h2 { font-size: 16px; }
.aic-bubble h3 { font-size: 14.5px; }
.aic-bubble h4 { font-size: 13.5px; }
.aic-bubble p { margin: 8px 0; }
.aic-bubble ul,
.aic-bubble ol {
  margin: 8px 0;
  padding-left: 22px;
}
.aic-bubble li { margin: 3px 0; }
.aic-bubble strong { color: #0f172a; font-weight: 700; }
.aic-bubble em     { font-style: italic; }
.aic-bubble code {
  font-family: var(--font-mono), monospace;
  font-size: 12.5px;
  background: rgba(126,232,106,0.10);
  color: var(--accent-strong);
  padding: 1px 6px;
  border-radius: 4px;
}
.aic-bubble pre {
  background: #0f172a;
  color: var(--line);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.5;
}
.aic-bubble pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
/* Tables — wrap in a scroll container so wide tables don't blow out
   the chat panel. The wrapping happens via the parent .aic-bubble
   which we keep at max-width 84%; the table itself gets a min-width
   so columns don't collapse, but overflow-x scrolls horizontally. */
.aic-bubble table {
  border-collapse: separate;
  border-spacing: 0;
  margin: 12px 0;
  display: block;
  width: 100%;
  overflow-x: auto;
  font-size: 13px;
  border: 1px solid var(--line, rgba(15,23,42,0.10));
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.aic-bubble th,
.aic-bubble td {
  border: 0;
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.07));
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
}
/* Header row — subtle tint band, uppercase mono labels. */
.aic-bubble th {
  background: var(--tint, rgba(15,23,42,0.035));
  color: var(--ink-3, #5B6472);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.12));
}
/* Zebra striping for legibility on longer records/input tables. */
.aic-bubble tbody tr:nth-child(even) td { background: rgba(15,23,42,0.02); }
.aic-bubble tbody tr:hover td { background: var(--tint, rgba(126,232,106,0.06)); }
.aic-bubble tr:last-child td { border-bottom: 0; }
/* The value column carries the number → give it weight + full ink; the
   label column stays quieter. Requested 2026-07-26. */
.aic-bubble td:first-child { color: var(--ink-2, #334155); font-weight: 500; }
.aic-bubble td:last-child  { color: var(--ink-1, #0f172a); font-weight: 600; }
/* Strikethrough — keep it readable rather than making text look
   "deleted". Used by the model when contrasting an alternate value
   with the user's actual entry. */
.aic-bubble del,
.aic-bubble s {
  text-decoration: line-through;
  text-decoration-color: rgba(15,23,42,0.30);
  text-decoration-thickness: 1px;
  color: var(--ink-3);
  opacity: 0.85;
}
/* Default blockquote = NEUTRAL note (never green — green reads as
   "success" and misleads on a caution/estimate callout). Cautionary
   callouts (⚠️ / ℹ️ / 💳) are upgraded to the amber .is-warn style by
   decorateBubble() in ai-chat.js. */
.aic-bubble blockquote {
  border-left: 3px solid var(--line, rgba(15,23,42,0.18));
  margin: 10px 0;
  padding: 8px 14px;
  background: rgba(15,23,42,0.035);
  border-radius: 0 8px 8px 0;
  color: var(--ink-2, #334155);
}
/* Amber warning/caution style — applied via JS when the bubble is
   finalized if a blockquote starts with ⚠️ / ℹ️ / 💳. */
.aic-bubble blockquote.is-warn {
  border-left: 3px solid var(--warn);
  background: rgba(245,158,11,0.10);
  color: var(--warn-strong);
}
.aic-bubble blockquote.is-warn strong { color: #78350f; }
html[data-theme="dark"] .aic-bubble blockquote.is-warn,
html[data-theme="midnight"] .aic-bubble blockquote.is-warn {
  background: rgba(245,158,11,0.14);
  color: var(--warn);
  border-left-color: var(--warn);
}
html[data-theme="dark"] .aic-bubble blockquote.is-warn strong,
html[data-theme="midnight"] .aic-bubble blockquote.is-warn strong { color: #fde68a; }
.aic-bubble a {
  color: var(--accent);
  text-decoration: underline;
}
.aic-bubble hr {
  border: 0;
  border-top: 1px solid rgba(15,23,42,0.10);
  margin: 12px 0;
}

/* Streaming caret */
.aic-bubble.is-streaming::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  vertical-align: -2px;
  margin-left: 3px;
  animation: aic-caret 0.9s steps(2) infinite;
  opacity: 0.7;
}
@keyframes aic-caret { 50% { opacity: 0; } }

/* REIzer chevron mark — the brand logo shared by launcher, header,
   welcome state, and thinking bubble. Spins in place when its parent
   carries the .is-thinking class. svg.aic-roof selector (specificity
   0,1,1) overrides the more general .aic-launcher-btn svg etc. rules
   so the chevron gets a heavier stroke than the close/clear/send
   icons. Sizing comes from each parent container. */
svg.aic-roof {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Spin only the chevron inside the in-stream thinking bubble. The
   header mark stays static — keeping the brand calm in the chrome. */
.aic-thinking-mark.is-thinking > .aic-roof {
  animation: aic-roof-spin 2.4s cubic-bezier(.65,.05,.25,1) infinite;
  transform-origin: 50% 50%;
}
@keyframes aic-roof-spin {
  0%   { transform: rotate(0deg);   }
  50%  { transform: rotate(360deg); }
  100% { transform: rotate(360deg); }
}

/* DP-6e — Tool-running inline pill (e.g. "Pulling property comps…") */
.aic-tool {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  padding: 9px 14px 9px 10px;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  font-family: var(--font-display), sans-serif;
}
.aic-tool-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-2);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aic-tool-mark .aic-roof { width: 10px; height: 10px; }
.aic-tool-label { line-height: 1.3; }
.aic-tool.is-ok {
  background: rgba(0,0,0,0.04);
  border-color: var(--line);
  color: var(--ink-2);
}
.aic-tool.is-ok .aic-tool-mark { background: var(--ink-2); }
.aic-tool.is-error {
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.25);
  color: var(--neg-strong);
}
.aic-tool.is-error .aic-tool-mark { background: var(--neg); }
html[data-theme="dark"] .aic-tool,
html[data-theme="midnight"] .aic-tool {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
  color: var(--ink-2);
}
html[data-theme="dark"] .aic-tool.is-ok,
html[data-theme="midnight"] .aic-tool.is-ok {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
  color: var(--ink-2);
}
html[data-theme="dark"] .aic-tool-mark,
html[data-theme="midnight"] .aic-tool-mark { background: var(--ink-3); }
html[data-theme="dark"] .aic-tool.is-error,
html[data-theme="midnight"] .aic-tool.is-error {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.30);
  color: #fca5a5;
}

/* =================================================================
   Phase A viz — sentiment-colored numbers + structured tool cards
================================================================= */
/* Signed numbers in AI answers (incl. inside tables): green = positive
   money / return, red = negative. Applied by enhanceBubble() on finalize. */
.aic-num.is-pos { color: var(--pos-strong); font-weight: 600; }
.aic-num.is-neg { color: var(--neg-strong); font-weight: 600; }
html[data-theme="dark"] .aic-num.is-pos,
html[data-theme="midnight"] .aic-num.is-pos { color: #6ee7b7; }
html[data-theme="dark"] .aic-num.is-neg,
html[data-theme="midnight"] .aic-num.is-neg { color: #fca5a5; }

/* Structured tool-result card — replaces the one-line pill for tools
   that return useful structured data (MAO solver, property comps). */
.aic-toolcard {
  display: inline-block;
  min-width: 210px;
  max-width: 100%;
  background: rgba(126,232,106,0.07);
  border: 1px solid rgba(126,232,106,0.24);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--font-display), sans-serif;
}
.aic-tc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.aic-tc-icon { font-size: 14px; line-height: 1; }
.aic-tc-title { font-size: 12.5px; font-weight: 700; color: var(--accent-strong); }
.aic-tc-body { display: flex; flex-direction: column; gap: 5px; }
.aic-tc-metric { display: flex; justify-content: space-between; gap: 16px; font-size: 12.5px; }
.aic-tc-k { color: var(--ink-3); }
.aic-tc-v { font-weight: 700; color: #0f172a; font-variant-numeric: tabular-nums; }

/* Stress / sensitivity engine card — clean full-width data table (neutral,
   not the green toolcard tint) with color-coded numbers + a term legend. */
.aic-toolcard.aic-stress {
  display: block; width: 100%;
  background: var(--surface-solid, #fff);
  border: 1px solid var(--line);
  padding: 0; overflow: hidden;
}
.aic-toolcard.aic-stress .aic-tc-head { padding: 10px 12px 0; margin-bottom: 8px; }
.aic-toolcard.aic-stress .aic-tc-title { color: var(--ink); }
.aic-stress-tbl { display: flex; flex-direction: column; }
.aic-stress-row {
  display: grid; grid-template-columns: 1.5fr 1fr 0.7fr 0.9fr;
  gap: 8px; align-items: center;
  padding: 7px 12px; border-top: 1px solid var(--line); font-size: 12.5px;
}
.aic-stress-row.is-head {
  border-top: 0; color: var(--ink-3);
  font-family: var(--font-mono, monospace);
  font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 700;
}
.aic-stress-row > span:not(:first-child){ text-align: right; font-variant-numeric: tabular-nums; }
.aic-stress-sc { display: flex; flex-direction: column; color: var(--ink); font-weight: 600; }
.aic-stress-sc em { font-style: normal; font-weight: 500; font-size: 10.5px; color: var(--ink-3); margin-top: 1px; }
.aic-stress-legend {
  padding: 8px 12px 10px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-3); line-height: 1.5;
}
.aic-stress-legend strong { color: var(--ink-2); font-weight: 600; }
/* MAO Solver card — hero max-offer + per-target breakdown. */
.aic-toolcard.aic-mao { display: block; width: 100%; background: var(--surface-solid, #fff); border: 1px solid var(--line); padding: 0; overflow: hidden; }
.aic-toolcard.aic-mao .aic-tc-head { padding: 10px 12px 0; margin-bottom: 8px; }
.aic-toolcard.aic-mao .aic-tc-title { color: var(--ink); }
.aic-mao-hero { padding: 2px 12px 10px; border-bottom: 1px solid var(--line); }
.aic-mao-hero-k { font-family: var(--font-mono, monospace); font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.aic-mao-hero-v { font-size: 26px; font-weight: 800; color: var(--ink); line-height: 1.1; margin-top: 2px; font-variant-numeric: tabular-nums; }
.aic-mao-hero-sub { font-size: 12.5px; font-weight: 600; margin-top: 3px; }
.aic-mao-hero-sub.is-pos { color: var(--pos-strong); }
.aic-mao-hero-sub.is-neg { color: var(--neg-strong); }
.aic-mao-rows { display: flex; flex-direction: column; }
.aic-mao-rows-h { padding: 8px 12px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); font-family: var(--font-mono, monospace); font-weight: 700; }
.aic-mao-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 12px; font-size: 12.5px; color: var(--ink-2); }
.aic-mao-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.aic-mao-row.is-binding { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.aic-mao-row.is-binding span:last-child { color: var(--brand-green-ink); }
.aic-mao-row.is-warn span:last-child { color: var(--warn); }

/* Captured analyzer chart figures (the REAL engine charts, as PNGs). */
.aic-chartfigs { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; }
.aic-chartfig {
  display: block; width: 100%; max-width: 560px; height: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
html[data-theme="dark"] .aic-toolcard,
html[data-theme="midnight"] .aic-toolcard {
  background: rgba(126,232,106,0.12);
  border-color: rgba(126,232,106,0.28);
}
html[data-theme="dark"] .aic-tc-title,
html[data-theme="midnight"] .aic-tc-title { color: var(--accent-3); }
html[data-theme="dark"] .aic-tc-k,
html[data-theme="midnight"] .aic-tc-k { color: var(--ink-3); }
html[data-theme="dark"] .aic-tc-v,
html[data-theme="midnight"] .aic-tc-v { color: #e2e8f0; }

/* Market Trends leaderboard (rank_markets) — ranked bar list */
.aic-leaderboard { display: block; width: 100%; min-width: 240px; }
/* Neutral card (not the green toolcard tint) — a data table, not a green block. */
.aic-toolcard.aic-leaderboard { background: var(--surface-solid, #fff); border: 1px solid var(--line); }
.aic-toolcard.aic-leaderboard .aic-tc-title { color: var(--ink); }
.aic-lb-body { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.aic-lb-row {
  display: grid;
  grid-template-columns: 16px 104px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.aic-lb-rank { color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.aic-lb-name { color: #0f172a; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aic-lb-bar { height: 7px; border-radius: 999px; background: rgba(0,0,0,0.06); overflow: hidden; }
.aic-lb-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--brand-green-ink, #17A34A); }
.aic-lb-val { font-weight: 700; color: #0f172a; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.aic-lb-foot { margin-top: 8px; font-size: 10.5px; color: var(--ink-3); }
html[data-theme="dark"] .aic-lb-name, html[data-theme="midnight"] .aic-lb-name,
html[data-theme="dark"] .aic-lb-val,  html[data-theme="midnight"] .aic-lb-val { color: #e2e8f0; }
html[data-theme="dark"] .aic-lb-bar,  html[data-theme="midnight"] .aic-lb-bar { background: rgba(255,255,255,0.10); }
html[data-theme="dark"] .aic-lb-bar > span, html[data-theme="midnight"] .aic-lb-bar > span { background: var(--brand-fill, #7EE86A); }

/* Property comps list (pull_property_comps) — NEUTRAL card, matching the
   analyzer's comps overlay (white surface, gray hairlines; green only as
   the data accent inside the box plots). Same de-green treatment as the
   market leaderboard card. */
.aic-comps { display: block; min-width: 244px; max-width: 100%; }
.aic-toolcard.aic-comps {
  background: var(--surface-solid, #fff);
  border: 1px solid var(--line, rgba(15,23,42,0.12));
}
.aic-toolcard.aic-comps .aic-tc-title { color: var(--ink-1, #0f172a); }
.aic-toolcard.aic-comps .aic-complist { border-top-color: var(--line, rgba(15,23,42,0.08)); }
html[data-theme="dark"] .aic-toolcard.aic-comps,
html[data-theme="midnight"] .aic-toolcard.aic-comps {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.12);
}
.aic-tc-count {
  margin-left: auto;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-3, #5B6472);
  white-space: nowrap;
}

/* Comp distribution box plots — same visual language as the analyzer's
   comps overlay (whisker min→max, box p25–p75, median tick). */
.aic-boxes { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 2px; }
.aic-box { --box-c: #2E8B3A; --box-fill: rgba(46,139,58,0.18); }
.aic-box-blue { --box-c: #3B82F6; --box-fill: rgba(59,130,246,0.16); }
.aic-box-amber { --box-c: #C77F00; --box-fill: rgba(199,127,0,0.16); }
.aic-box-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.aic-box-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2, #334155);
}
.aic-box-med {
  font-family: var(--font-display), sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--box-c);
  white-space: nowrap;
}
.aic-box-med small { font-size: 10px; font-weight: 500; color: var(--ink-3, #5B6472); }
.aic-box-track {
  position: relative;
  height: 18px;
  border-radius: 6px;
}
.aic-box-whisker {
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--line, rgba(15,23,42,0.14));
  border-radius: 1px;
}
.aic-box-whisker::before,
.aic-box-whisker::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 2px; height: 10px;
  background: var(--line, rgba(15,23,42,0.18));
  border-radius: 1px;
}
.aic-box-whisker::before { left: 0; }
.aic-box-whisker::after { right: 0; }
.aic-box-iqr {
  position: absolute;
  top: 1px; bottom: 1px;
  background: var(--box-fill);
  border: 1.5px solid var(--box-c);
  border-radius: 5px;
}
.aic-box-tick {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--box-c);
  border-radius: 2px;
}
.aic-box-scale {
  position: relative;
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  min-height: 27px;   /* row 1: min/max · row 2: the anchored mid-50% label */
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  color: var(--ink-3, #5B6472);
  white-space: nowrap;
}
/* min/max sit at the whisker ends on the first line; the mid-50% label
   gets its OWN line below, still anchored under the box's actual center
   (inline left:%) — so it can never collide with min/max. */
.aic-box-iqr-lbl {
  position: absolute;
  top: 13px;
  transform: translateX(-50%);
  color: var(--ink-2, #334155);
  font-weight: 600;
}
.aic-box-iqr-lbl small { font-weight: 400; color: var(--ink-3, #5B6472); }

/* ---- Mobile safety for chat cards (records / comps / box plots) ----
   Cards must never force the bubble wider than the phone screen; long
   labels shrink instead of truncating the surrounding prose. */
.aic-toolcard, .aic-rec { max-width: 100%; }
.aic-bubble { overflow-wrap: break-word; min-width: 0; }
@media (max-width: 480px) {
  .aic-comps { min-width: 0; }
  .aic-box-scale { font-size: 9px; }
  .aic-box-med { font-size: 13px; }
  .aic-rec-addr { font-size: 13px; }
  .aic-rec-facts { font-size: 11.5px; gap: 6px; }
  .aic-rec-tiles { grid-template-columns: repeat(2, 1fr); }
  .aic-rec-tile { padding: 8px 12px 10px; }
  .aic-rec-tile-v { font-size: 13.5px; white-space: normal; }
  .aic-comp-row { font-size: 11.5px; }
  .aic-next-chip { font-size: 12px; padding: 7px 11px; }
}
.aic-complist {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(126,232,106,0.18);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.aic-complist-h {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 1px;
}
.aic-comp-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "addr price" "meta meta";
  gap: 1px 8px;
  font-size: 11.5px;
}
.aic-comp-addr { grid-area: addr; color: #0f172a; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aic-comp-price { grid-area: price; font-weight: 700; color: var(--pos-strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.aic-comp-meta { grid-area: meta; color: var(--ink-3); font-size: 10.5px; font-variant-numeric: tabular-nums; }
html[data-theme="dark"] .aic-comp-addr, html[data-theme="midnight"] .aic-comp-addr { color: #e2e8f0; }

/* Compact nav confirmation chip (open_tool) */
.aic-navchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-family: var(--font-display), sans-serif;
}
.aic-navchip-arrow { font-weight: 700; }
.aic-navchip strong { font-weight: 700; color: var(--ink); }

/* Prefill CTA — "Open the STR analyzer with these numbers". REIzer-green
   fill with black text (the deliberate primary action of an example). */
.aic-prefill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 2px;
  padding: 10px 16px;
  background: var(--brand-fill);
  color: var(--brand-ink);
  border: 0;
  border-radius: 10px;
  font-family: var(--font-display), sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
}
.aic-prefill-btn:hover { filter: brightness(1.05); }
.aic-prefill-btn:active { transform: scale(0.99); }
.aic-prefill-btn strong { font-weight: 700; }
.aic-prefill-ic { font-weight: 700; }

/* Public-records property card — rendered from a ```rei:records```
   directive. Header (kicker + address + type badge), facts strip,
   money tiles. Replaces the plain markdown table for records pulls. */
.aic-rec {
  margin: 12px 0;
  border: 1px solid var(--line, rgba(15,23,42,0.10));
  border-radius: 14px;
  background: var(--surface-solid, #fff);
  box-shadow: 0 1px 3px rgba(15,23,42,0.06);
  overflow: hidden;
}
.aic-rec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--tint, rgba(15,23,42,0.03));
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.08));
}
.aic-rec-kicker {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3, #5B6472);
  margin-bottom: 2px;
}
.aic-rec-addr {
  font-family: var(--font-display), sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-1, #0f172a);
  line-height: 1.25;
}
.aic-rec-badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-fill, rgba(126,232,106,0.14));
  color: var(--accent-strong, #2E8B3A);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.aic-rec-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--ink-2, #334155);
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.06));
}
.aic-rec-fact strong { color: var(--ink-1, #0f172a); font-weight: 700; }
.aic-rec-dot { color: var(--ink-4, #94a3b8); }
.aic-rec-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--line, rgba(15,23,42,0.06));
}
.aic-rec-tile {
  background: var(--surface-solid, #fff);
  padding: 10px 16px 12px;
}
.aic-rec-tile-k {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3, #5B6472);
  margin-bottom: 3px;
  white-space: nowrap;
}
.aic-rec-tile-v {
  font-family: var(--font-display), sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-1, #0f172a);
  white-space: nowrap;
}
.aic-rec-tile.is-missing .aic-rec-tile-v { color: var(--warn-strong, #b45309); }
.aic-rec-tile.is-missing { background: rgba(245,158,11,0.05); }
.aic-rec-map { position: relative; border-top: 1px solid var(--line, rgba(15,23,42,0.06)); }
/* REIzer teardrop pin overlaid on the static map — the map is centered
   on the property, so the pin tip (2px above the svg bottom) anchors to
   the exact image center. */
.aic-rec-pin {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-100% + 2px));
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(15,23,42,0.35));
}
.aic-rec-map img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}
@media (max-width: 480px) { .aic-rec-map img { height: 120px; } }
html[data-theme="dark"] .aic-rec,
html[data-theme="midnight"] .aic-rec {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.12);
}
html[data-theme="dark"] .aic-rec-head,
html[data-theme="midnight"] .aic-rec-head { background: rgba(255,255,255,0.04); }
html[data-theme="dark"] .aic-rec-tile,
html[data-theme="midnight"] .aic-rec-tile { background: rgba(255,255,255,0.02); }

/* STR market-trends card (pull_str_market_analysis) — mirrors the
   analyzer panel: smoothed-over-raw trend rows with High/Low, the
   %-share seasonality grid, and the red RIX block. */
.aic-mkt .aic-tc-head { flex-wrap: nowrap; }
.aic-mkt .aic-tc-title { white-space: nowrap; }
.aic-mkt-tgls { margin-left: auto; display: inline-flex; gap: 4px; }
.aic-mkt-tgl {
  padding: 3px 10px;
  border: 1px solid var(--line, rgba(15,23,42,0.16));
  border-radius: 999px;
  background: var(--surface-solid, #fff);
  color: var(--ink-3, #5B6472);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.aic-mkt-tgl.is-on {
  background: var(--ink-1, #0f172a);
  border-color: var(--ink-1, #0f172a);
  color: #fff;
}
.aic-mkt-name {
  margin: 2px 0 4px;
  font-size: 11px;
  color: var(--ink-3, #5B6472);
  overflow-wrap: anywhere;
}
.aic-mkt-sum {
  margin: 8px 0 4px;
  padding: 8px 12px;
  border-left: 3px solid var(--line, rgba(15,23,42,0.16));
  background: rgba(15,23,42,0.03);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
  color: var(--ink-2, #334155);
}
.aic-tr-row { margin: 12px 0 4px; }
.aic-tr-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.aic-tr-lbl {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2, #334155);
}
.aic-tr-hl { font-size: 10.5px; color: var(--ink-3, #5B6472); white-space: nowrap; }
.aic-tr-hl em { font-style: normal; font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em; }
.aic-tr-hl strong { color: var(--ink-1, #0f172a); font-variant-numeric: tabular-nums; }
.aic-spark { display: block; width: 100%; height: 46px; }

/* Seasonality — %-share grid, analyzer buckets (green scale). */
.aic-sh-wrap { margin: 14px 0 4px; }
.aic-sh-title, .aic-rix-title {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2, #334155);
  margin-bottom: 6px;
}
.aic-sh-title span, .aic-rix-title span {
  font-family: inherit;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-3, #5B6472);
}
.aic-sh {
  display: grid;
  grid-template-columns: 34px repeat(12, 1fr);
  gap: 3px;
  align-items: center;
}
.aic-sh-y, .aic-sh-m {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9.5px;
  color: var(--ink-3, #5B6472);
  text-align: center;
}
.aic-sh-y { text-align: right; padding-right: 4px; }
.aic-sh-c {
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ink-2, #334155);
}
.aic-sh-c.is-vlow { background: rgba(46,139,58,0.07); }
.aic-sh-c.is-low  { background: rgba(46,139,58,0.16); }
.aic-sh-c.is-mid  { background: rgba(46,139,58,0.30); }
.aic-sh-c.is-high { background: rgba(46,139,58,0.52); color: #fff; }
.aic-sh-c.is-peak { background: #2E8B3A; color: #fff; }
.aic-sh-note { margin-top: 6px; font-size: 11.5px; color: var(--ink-3, #5B6472); }
.aic-sh-note strong { color: var(--ink-1, #0f172a); }

/* RIX — red risk block with the big /100 hero + per-year bars. */
.aic-rix { margin: 14px 0 2px; }
.aic-rix-body { display: flex; gap: 16px; align-items: flex-end; }
.aic-rix-hero { flex: 0 0 auto; }
.aic-rix-big {
  font-family: var(--font-display), sans-serif;
  font-size: 30px;
  font-weight: 800;
  color: #dc2626;
  line-height: 1;
}
.aic-rix-of { font-size: 12px; color: var(--ink-3, #5B6472); font-weight: 600; }
.aic-rix-lvl { font-size: 11px; font-weight: 700; color: var(--ink-1, #0f172a); margin-top: 2px; }
.aic-rix-delta {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border: 1px solid rgba(220,38,38,0.35);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  color: #dc2626;
}
/* Bars plot in a dedicated bottom-anchored region so labels can never
   flex-squash the bar heights (the bug where taller RIX values rendered
   SHORTER). Plot box = container minus the 16px year-label strip; the
   connector overlay covers exactly that box, so its y-coords land on
   the bar tops. */
.aic-rix-bars { flex: 1; display: flex; align-items: stretch; gap: 8px; height: 84px; position: relative; }
.aic-rix-line {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: calc(100% - 16px);
  width: 100%;
  pointer-events: none;
}
.aic-rix-bar { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.aic-rix-plot { position: relative; flex: 1 1 auto; }
.aic-rix-plot span {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 30px;
  background: #dc2626;
  border-radius: 3px 3px 0 0;
  opacity: 0.85;
  display: block;
}
.aic-rix-plot i {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-style: normal;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9.5px;
  color: var(--ink-2, #334155);
  line-height: 1;
}
.aic-rix-bar em {
  height: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-style: normal;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9px;
  color: var(--ink-3, #5B6472);
}
@media (max-width: 480px) {
  .aic-sh { grid-template-columns: 28px repeat(12, 1fr); gap: 2px; }
  .aic-sh-c { height: 18px; font-size: 8.5px; }
  .aic-rix-body { gap: 10px; }
  /* Trend-row High/Low annotations wrap to their own line instead of
     overflowing/overlapping the label on narrow screens. */
  .aic-tr-head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .aic-tr-hl { white-space: normal; font-size: 10px; }
  .aic-mkt .aic-tc-title { font-size: 12.5px; }
  .aic-mkt-tgl { padding: 3px 8px; }
}

/* Deal-inputs card (rei:inputs) — the professional replacement for the
   model's bare INPUT/VALUE markdown table. */
.aic-inp {
  margin: 12px 0;
  border: 1px solid var(--line, rgba(15,23,42,0.10));
  border-radius: 14px;
  background: var(--surface-solid, #fff);
  box-shadow: 0 1px 3px rgba(15,23,42,0.06);
  overflow: hidden;
  max-width: 100%;
}
.aic-inp-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 16px;
  background: var(--tint, rgba(15,23,42,0.03));
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.08));
}
.aic-inp-kicker {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3, #5B6472);
}
.aic-inp-title {
  font-family: var(--font-display), sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-1, #0f172a);
}
.aic-inp-body { padding: 4px 0; }
.aic-inp-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 16px;
}
.aic-inp-row:nth-child(even) { background: rgba(15,23,42,0.02); }
.aic-inp-k { font-size: 12px; color: var(--ink-2, #334155); }
.aic-inp-v {
  font-family: var(--font-display), sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-1, #0f172a);
  text-align: right;
  white-space: nowrap;
}
.aic-inp-est {
  font-style: normal;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warn-strong, #b45309);
  background: rgba(245,158,11,0.12);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: 1px;
}
.aic-inp-foot {
  padding: 7px 16px 9px;
  border-top: 1px solid var(--line, rgba(15,23,42,0.06));
  font-size: 10.5px;
  color: var(--ink-3, #5B6472);
}
html[data-theme="dark"] .aic-inp,
html[data-theme="midnight"] .aic-inp {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.12);
}
html[data-theme="dark"] .aic-inp-head,
html[data-theme="midnight"] .aic-inp-head { background: rgba(255,255,255,0.04); }
@media (max-width: 480px) {
  .aic-inp-v { white-space: normal; }
}

/* Amenities Impact card (str_amenities_impact, Elite) — top-25% vs
   bottom-25% quartile comparison: paired earnings bars + feature rows. */
.aic-am-explain { font-size: 11.5px; color: var(--ink-3, #5B6472); margin: 4px 0 8px; }
.aic-am-explain .is-top-tag { color: var(--accent-strong, #2E8B3A); }
.aic-am-explain .is-bot-tag { color: var(--ink-2, #334155); }
.aic-am-bars { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 4px; }
.aic-am-k {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2, #334155);
  margin-bottom: 3px;
}
.aic-am-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}
.aic-am-bar span {
  display: block;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
  max-width: 62%;
}
.aic-am-bar.is-top span { background: #2E8B3A; }
.aic-am-bar.is-bot span { background: rgba(15,23,42,0.18); }
.aic-am-bar b {
  font-family: var(--font-display), sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-1, #0f172a);
  white-space: nowrap;
}
.aic-am-bar.is-bot b { color: var(--ink-3, #5B6472); font-weight: 600; }
.aic-am-sec {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2, #334155);
  margin: 12px 0 4px;
}
.aic-am-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line, rgba(15,23,42,0.06));
  font-size: 12px;
}
.aic-am-row:last-of-type { border-bottom: 0; }
.aic-am-name { color: var(--ink-1, #0f172a); font-weight: 600; }
.aic-am-pres { color: var(--ink-3, #5B6472); font-size: 11px; white-space: nowrap; }
.aic-am-row.is-pos .aic-am-pres b { color: var(--accent-strong, #2E8B3A); }
.aic-am-row.is-neg .aic-am-pres b { color: var(--warn-strong, #b45309); }
.aic-am-pres i { font-style: normal; }
.aic-am-foot { margin-top: 8px; font-size: 10.5px; color: var(--ink-3, #5B6472); }

/* Next-step suggestion chips — clickable follow-ups the model offers
   after an analysis. Outlined pills; clicking sends that request. */
.aic-next {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 10px 0 2px;
}
.aic-next-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  background: var(--surface-solid, #fff);
  color: var(--ink-1, #0f172a);
  border: 1px solid var(--line, rgba(15,23,42,0.16));
  border-radius: 999px;
  font-family: var(--font-display), sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.aic-next-chip::before { content: "→"; color: var(--accent-strong, #2E8B3A); font-weight: 700; }
.aic-next-chip:hover { background: var(--brand-fill, rgba(126,232,106,0.12)); border-color: var(--accent-3, #7EE86A); }
.aic-next-chip:active { transform: scale(0.98); }
html[data-theme="dark"] .aic-next-chip,
html[data-theme="midnight"] .aic-next-chip {
  background: rgba(255,255,255,0.04);
  color: var(--ink-1, #e8edf4);
  border-color: rgba(255,255,255,0.14);
}
/* Secondary "open a page" variant — outlined, charcoal (not a fill). */
.aic-prefill-btn.is-open {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.aic-prefill-btn.is-open:hover { filter: none; border-color: var(--ink-3); color: var(--ink); }
.aic-prefill-btn.is-open strong { color: var(--ink); }
html[data-theme="dark"] .aic-navchip,
html[data-theme="midnight"] .aic-navchip {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
  color: var(--ink-2);
}

/* =================================================================
   Chat history — opaque drawer sliding in from the right, anchored
   BELOW the chat header (JS sets `top` to the header height so the
   REIzer Copilot header stays visible above it).
================================================================= */
.aic-history-panel {
  position: absolute;
  top: 0;                 /* JS overrides with the header height */
  left: 0; right: 0; bottom: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  background: var(--surface-solid);   /* fully opaque — no chat bleed-through */
  border-top: 1px solid var(--line);
  box-shadow: -16px 0 34px -22px rgba(15,23,42,0.5);
  animation: aic-hist-in 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes aic-hist-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.aic-history-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.aic-history-title {
  flex: 1;
  font-family: var(--font-display), sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}
.aic-history-newbtn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  border: none;
  background: var(--ink-2);          /* charcoal in light, light chip in dark */
  color: var(--surface-solid);
  font-family: var(--font-display), sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.aic-history-newbtn:hover { filter: brightness(1.08); }
.aic-history-newbtn svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; }
.aic-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.aic-history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}
.aic-history-row:hover { background: var(--surface-2); }
.aic-history-row.is-active { border-color: var(--line); background: var(--surface-2); }
.aic-history-row-main { flex: 1; min-width: 0; }
.aic-history-row-title {
  font-family: var(--font-display), sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aic-history-row-time { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.aic-history-del {
  flex-shrink: 0;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--ink-3);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
}
.aic-history-del:hover { color: var(--neg-strong, #dc2626); background: rgba(239,68,68,0.09); opacity: 1; }
.aic-history-del svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.aic-history-empty {
  padding: 30px 22px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  font-family: var(--font-display), sans-serif;
  line-height: 1.55;
}

/* Deal-score gauge — half-circle, rendered in chat on "analyze this deal".
   Matches the on-page DealScore gauge bands. */
/* Suppress the "black box" flash: rei:* directives (rei:score / rei:tiles)
   are replaced by enhanceBubble() with a gauge / tile grid ONLY on message
   finalize. While the message is still streaming, the raw fenced block would
   render as a dark code box (.aic-bubble pre, #0f172a) and flash black for a
   couple seconds. Hide the raw fence so only the finished visualization shows.
   (:has unsupported → graceful fallback to the old dark-box behavior.) */
.aic-bubble pre:has(> code[class*="language-rei"]) { display: none; }

/* Metric-tile grid (rei:tiles) — at-a-glance analyze-this-deal numbers */
.aic-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.aic-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px 11px;
  min-width: 0;
  overflow: hidden;
}
/* Top color stripe — tier indicator, mirrors the on-page .be-kpi card */
.aic-tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--line);
  border-radius: 10px 10px 0 0;
}
.aic-tile-k {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-3);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aic-tile-v {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink, #0f172a);
  font-variant-numeric: tabular-nums;
}
/* Explainer sub-line under the value — mirrors the on-page .bek-sub */
.aic-tile-s {
  margin-top: 4px;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--ink-3);
}

/* Tier coloring — mirrors the on-page .be-kpi hero cards (same thresholds,
   same hues) so the Copilot's tiles read identically to the analyzer panel.
   Applied from outputs.headlineTiers; when a tier is absent the value falls
   back to sign-based color (see .aic-tile-v.is-pos / .is-neg). */
.aic-tile.is-pos  { background: rgba(16,185,129,0.08); border-color: rgba(16,185,129,0.20); }
.aic-tile.is-pos::before  { background: var(--pos); }
.aic-tile.is-pos  .aic-tile-v { color: var(--pos-strong); }
.aic-tile.is-ok   { background: rgba(59,130,246,0.05); border-color: rgba(59,130,246,0.18); }
.aic-tile.is-ok::before   { background: var(--accent); }
.aic-tile.is-warn { background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.22); }
.aic-tile.is-warn::before { background: var(--warn); }
.aic-tile.is-warn .aic-tile-v { color: var(--warn-strong); }
.aic-tile.is-neg  { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.25); }
.aic-tile.is-neg::before  { background: var(--neg); }
.aic-tile.is-neg  .aic-tile-v { color: var(--neg-strong); }

/* Sign-based value color — fallback for analyzers not yet sending tiers */
.aic-tile-v.is-pos { color: var(--pos-strong); }
.aic-tile-v.is-neg { color: var(--neg-strong, #dc2626); }

html[data-theme="dark"] .aic-tile-v,
html[data-theme="midnight"] .aic-tile-v { color: #e2e8f0; }
html[data-theme="dark"] .aic-tile.is-pos,
html[data-theme="midnight"] .aic-tile.is-pos { background: rgba(16,185,129,0.14); border-color: rgba(52,211,153,0.30); }
html[data-theme="dark"] .aic-tile.is-pos .aic-tile-v,
html[data-theme="midnight"] .aic-tile.is-pos .aic-tile-v { color: #6ee7b7; }
html[data-theme="dark"] .aic-tile.is-ok,
html[data-theme="midnight"] .aic-tile.is-ok { background: rgba(126,232,106,0.10); border-color: rgba(126,232,106,0.30); }
html[data-theme="dark"] .aic-tile.is-warn,
html[data-theme="midnight"] .aic-tile.is-warn { background: rgba(245,158,11,0.14); border-color: rgba(251,191,36,0.30); }
html[data-theme="dark"] .aic-tile.is-warn .aic-tile-v,
html[data-theme="midnight"] .aic-tile.is-warn .aic-tile-v { color: #fcd34d; }
html[data-theme="dark"] .aic-tile.is-neg,
html[data-theme="midnight"] .aic-tile.is-neg { background: rgba(239,68,68,0.14); border-color: rgba(248,113,113,0.32); }
html[data-theme="dark"] .aic-tile.is-neg .aic-tile-v,
html[data-theme="midnight"] .aic-tile.is-neg .aic-tile-v { color: #fca5a5; }
html[data-theme="dark"] .aic-tile-v.is-pos,
html[data-theme="midnight"] .aic-tile-v.is-pos { color: #6ee7b7; }
html[data-theme="dark"] .aic-tile-v.is-neg,
html[data-theme="midnight"] .aic-tile-v.is-neg { color: #fca5a5; }

.aic-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 12px 0;
  padding: 12px 14px 10px;
  background: rgba(15,23,42,0.03);
  border: 1px solid rgba(15,23,42,0.08);
  border-radius: 14px;
}
.aic-gauge-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #64748b;
  text-align: center;
  margin-bottom: 2px;
}
.aic-gauge-svg {
  width: 216px;
  max-width: 100%;
  height: auto;
  display: block;
}
.aic-gauge-score {
  font-family: var(--font-display), sans-serif;
  font-size: 38px;
  font-weight: 800;
}
.aic-gauge-band {
  font-family: var(--font-display), sans-serif;
  font-size: 13px;
  font-weight: 700;
  fill: var(--ink-3);
}
.aic-gauge-scale {
  display: flex;
  justify-content: space-between;
  width: 196px;
  max-width: 100%;
  margin-top: -6px;
  font-size: 10.5px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
html[data-theme="dark"] .aic-gauge,
html[data-theme="midnight"] .aic-gauge {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .aic-gauge-band,
html[data-theme="midnight"] .aic-gauge-band { fill: var(--ink-2); }
html[data-theme="dark"] .aic-gauge-title,
html[data-theme="midnight"] .aic-gauge-title { color: var(--ink-3); }

/* Thinking bubble — REIzer mark + "Thinking" + dots */
.aic-thinking {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  padding: 11px 16px 11px 11px;
  background: var(--surface-solid);
  border-radius: 14px 14px 14px 4px;
  border: 1px solid rgba(15,23,42,0.08);
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.aic-thinking-mark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-fill);
  color: var(--brand-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aic-thinking-mark .aic-roof {
  width: 13px;
  height: 13px;
}
.aic-thinking-text {
  font-size: 13.5px;
  color: var(--ink-3);
  font-weight: 500;
}
.aic-thinking-dots {
  display: inline-flex;
  gap: 4px;
}
.aic-thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-4);
  animation: aic-bounce 1.4s ease-in-out infinite both;
}
.aic-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.aic-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes aic-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1;   }
}

/* Empty / welcome state */
.aic-welcome {
  text-align: center;
  padding: 32px 18px 12px;
  color: var(--ink-3);
}
.aic-welcome-mark {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--brand-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-ink);
  margin-bottom: 12px;
  box-shadow: 0 6px 18px -6px rgba(126,232,106,0.5);
}
.aic-welcome-mark svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.aic-welcome-h {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}
.aic-welcome-p {
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0;
}
.aic-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
  padding: 0 6px;
}
.aic-suggest-btn {
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  background: var(--surface-solid);
  border: 1px solid rgba(15,23,42,0.10);
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  color: #334155;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease,
              box-shadow 0.18s ease, transform 0.18s ease;
}
/* Soft bright-green glow around the frame on hover — no fill. */
.aic-suggest-btn:hover {
  border-color: rgba(126,232,106,0.55);
  color: #0f172a;
  box-shadow: 0 0 0 3px rgba(126,232,106,0.14),
              0 10px 24px -12px rgba(126,232,106,0.55);
  transform: translateY(-1px);
}

/* Inline error banner */
.aic-error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.30);
  color: var(--neg-strong);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}
.aic-error a {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}

/* --- Input bar --- */
.aic-input-bar {
  border-top: 1px solid rgba(15,23,42,0.08);
  padding: 12px 14px;
  background: var(--surface-solid);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.aic-input {
  flex: 1;
  border: 1px solid rgba(126,232,106,0.30);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: #1f2937;
  resize: none;
  outline: none;
  line-height: 1.45;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
/* Soft bright-green glow on focus rather than a flat dark-green ring. */
.aic-input:focus {
  border-color: rgba(126,232,106,0.70);
  background: var(--surface-solid);
  box-shadow: 0 0 0 3px rgba(126,232,106,0.16),
              0 6px 20px -10px rgba(126,232,106,0.55);
}
.aic-input::placeholder { color: var(--ink-4); }
/* Phones: any focused field under 16px makes iOS Safari zoom the page in,
   which shoves the send button half off-screen until the user pinches back
   out. 16px suppresses that auto-zoom. */
@media (max-width: 767px) {
  .aic-input { font-size: 16px; }
}
.aic-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.aic-send {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  background: var(--brand-fill);
  color: var(--brand-ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.aic-send:hover:not(:disabled) { transform: translateY(-1px); }
.aic-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.aic-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.aic-footnote {
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-4);
  padding: 6px 12px 8px;
  background: var(--surface-solid);
  border-top: 1px solid rgba(15,23,42,0.04);
}

/* ===========================================
   DARK / MIDNIGHT theme
   =========================================== */

html[data-theme="dark"] .aic-panel,
html[data-theme="midnight"] .aic-panel {
  background: #0f172a;
  border-color: rgba(126,232,106,0.18);
}
html[data-theme="dark"] .aic-header,
html[data-theme="midnight"] .aic-header {
  background: #111c33;
  color: var(--ink);
  border-bottom-color: rgba(126,232,106,0.18);
}
html[data-theme="dark"] .aic-header-h,
html[data-theme="midnight"] .aic-header-h { color: var(--ink); }
html[data-theme="dark"] .aic-header-sub,
html[data-theme="midnight"] .aic-header-sub { color: var(--ink-3); }
html[data-theme="dark"] .aic-ring-bg,
html[data-theme="midnight"] .aic-ring-bg { stroke: rgba(255,255,255,0.14); }
html[data-theme="dark"] .aic-quota-ring:hover .aic-ring-bg,
html[data-theme="midnight"] .aic-quota-ring:hover .aic-ring-bg { stroke: rgba(255,255,255,0.24); }
html[data-theme="dark"] .aic-quota-pop,
html[data-theme="midnight"] .aic-quota-pop {
  background: #1e293b;
  border-color: rgba(126,232,106,0.20);
  box-shadow: 0 16px 36px -10px rgba(0,0,0,0.55);
}
html[data-theme="midnight"] .aic-quota-pop { background: #141414; border-color: var(--line-2); }
html[data-theme="dark"] .aic-quota-pop-big,
html[data-theme="midnight"] .aic-quota-pop-big { color: var(--ink); }
html[data-theme="dark"] .aic-quota-pop-of,
html[data-theme="dark"] .aic-quota-pop-meta,
html[data-theme="midnight"] .aic-quota-pop-of,
html[data-theme="midnight"] .aic-quota-pop-meta { color: var(--ink-3); }
html[data-theme="dark"] .aic-quota-pop-of strong,
html[data-theme="dark"] .aic-quota-pop-meta strong,
html[data-theme="midnight"] .aic-quota-pop-of strong,
html[data-theme="midnight"] .aic-quota-pop-meta strong { color: var(--ink); }
html[data-theme="dark"] .aic-quota-pop-bar,
html[data-theme="midnight"] .aic-quota-pop-bar { background: rgba(255,255,255,0.10); }
html[data-theme="dark"] .aic-quota-pop-note,
html[data-theme="midnight"] .aic-quota-pop-note {
  background: rgba(245,158,11,0.12);
  color: var(--warn);
  border-color: rgba(245,158,11,0.28);
}
html[data-theme="dark"] .aic-banner-throttle,
html[data-theme="midnight"] .aic-banner-throttle {
  background: rgba(245,158,11,0.12);
  color: var(--warn);
  border-bottom-color: rgba(245,158,11,0.25);
}
html[data-theme="dark"] .aic-banner-throttle a,
html[data-theme="midnight"] .aic-banner-throttle a { color: var(--warn); }
html[data-theme="dark"] .aic-header-btn,
html[data-theme="midnight"] .aic-header-btn { color: var(--ink-4); }
html[data-theme="dark"] .aic-header-btn:hover,
html[data-theme="midnight"] .aic-header-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--ink-2);
}
html[data-theme="dark"] .aic-stream,
html[data-theme="midnight"] .aic-stream {
  background: #0b1325;
}
html[data-theme="dark"] .aic-bubble,
html[data-theme="midnight"] .aic-bubble {
  background: #1e293b;
  color: #e2e8f0;
  border-color: rgba(126,232,106,0.18);
}
html[data-theme="dark"] .aic-bubble h1,
html[data-theme="dark"] .aic-bubble h2,
html[data-theme="dark"] .aic-bubble h3,
html[data-theme="dark"] .aic-bubble h4,
html[data-theme="dark"] .aic-bubble strong,
html[data-theme="midnight"] .aic-bubble h1,
html[data-theme="midnight"] .aic-bubble h2,
html[data-theme="midnight"] .aic-bubble h3,
html[data-theme="midnight"] .aic-bubble h4,
html[data-theme="midnight"] .aic-bubble strong { color: var(--ink); }
html[data-theme="dark"] .aic-bubble code,
html[data-theme="midnight"] .aic-bubble code {
  background: rgba(126,232,106,0.18);
  color: var(--accent-3);
}
html[data-theme="dark"] .aic-thinking,
html[data-theme="midnight"] .aic-thinking {
  background: #1e293b;
  border-color: rgba(126,232,106,0.18);
}
html[data-theme="dark"] .aic-input-bar,
html[data-theme="midnight"] .aic-input-bar {
  background: #0f172a;
  border-top-color: rgba(126,232,106,0.15);
}
html[data-theme="dark"] .aic-input,
html[data-theme="midnight"] .aic-input {
  background: #1e293b;
  color: var(--ink);
  border-color: rgba(126,232,106,0.20);
}
html[data-theme="dark"] .aic-input:focus,
html[data-theme="midnight"] .aic-input:focus {
  background: #0f172a;
}
html[data-theme="dark"] .aic-welcome,
html[data-theme="midnight"] .aic-welcome { color: var(--ink-3); }
html[data-theme="dark"] .aic-welcome-h,
html[data-theme="midnight"] .aic-welcome-h { color: var(--ink); }
html[data-theme="dark"] .aic-suggest-btn,
html[data-theme="midnight"] .aic-suggest-btn {
  background: #1e293b;
  color: var(--ink-2);
  border-color: rgba(126,232,106,0.25);
}
html[data-theme="dark"] .aic-suggest-btn:hover,
html[data-theme="midnight"] .aic-suggest-btn:hover {
  background: rgba(126,232,106,0.12);
  color: var(--accent-3);
}
html[data-theme="dark"] .aic-footnote,
html[data-theme="midnight"] .aic-footnote {
  background: #0f172a;
  color: var(--ink-4);
  border-top-color: rgba(126,232,106,0.10);
}

/* Scrollbars — dark + midnight (both inherit a brighter thumb) */
html[data-theme="dark"] .aic-panel,
html[data-theme="dark"] .aic-panel *,
html[data-theme="midnight"] .aic-panel,
html[data-theme="midnight"] .aic-panel * {
  scrollbar-color: rgba(255,255,255,0.20) transparent;
}
html[data-theme="dark"] .aic-panel ::-webkit-scrollbar-thumb,
html[data-theme="dark"] .aic-panel::-webkit-scrollbar-thumb,
html[data-theme="midnight"] .aic-panel ::-webkit-scrollbar-thumb,
html[data-theme="midnight"] .aic-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
}
html[data-theme="dark"] .aic-panel ::-webkit-scrollbar-thumb:hover,
html[data-theme="dark"] .aic-panel::-webkit-scrollbar-thumb:hover,
html[data-theme="midnight"] .aic-panel ::-webkit-scrollbar-thumb:hover,
html[data-theme="midnight"] .aic-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.32);
}

/* =================================================================
   MIDNIGHT theme — true black surfaces, OLED-friendly. Overrides
   the dark/midnight shared rules above (same specificity, later
   source order). Variable names mirror the global theme.css palette
   for visual consistency with the rest of the app.
   ================================================================= */
html[data-theme="midnight"] .aic-panel {
  background: var(--surface-2);
  border-color: var(--line);
}
html[data-theme="midnight"] .aic-header {
  background: #0f0f0f;
  border-bottom-color: var(--line);
}
html[data-theme="midnight"] .aic-header-h { color: var(--ink); }
html[data-theme="midnight"] .aic-header-sub { color: var(--ink-3); }
html[data-theme="midnight"] .aic-header-btn { color: var(--ink-4); }
html[data-theme="midnight"] .aic-header-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--ink-2);
}
html[data-theme="midnight"] .aic-stream {
  background: var(--bg);
}
html[data-theme="midnight"] .aic-bubble {
  background: #141414;
  color: var(--ink-2);
  border-color: var(--line-2);
}
html[data-theme="midnight"] .aic-bubble h1,
html[data-theme="midnight"] .aic-bubble h2,
html[data-theme="midnight"] .aic-bubble h3,
html[data-theme="midnight"] .aic-bubble h4,
html[data-theme="midnight"] .aic-bubble strong { color: var(--ink); }
html[data-theme="midnight"] .aic-bubble code {
  background: rgba(126,232,106,0.16);
  color: var(--accent-3);
}
html[data-theme="midnight"] .aic-bubble pre {
  background: #050505;
  color: var(--ink-2);
  border: 1px solid var(--line);
}
html[data-theme="midnight"] .aic-bubble th,
html[data-theme="midnight"] .aic-bubble td {
  border-color: var(--line-2);
}
html[data-theme="midnight"] .aic-bubble th {
  background: transparent;
  color: var(--ink-3);
}
html[data-theme="midnight"] .aic-bubble blockquote {
  color: var(--ink-3);
}
html[data-theme="midnight"] .aic-bubble a { color: var(--accent-3); }
html[data-theme="midnight"] .aic-thinking {
  background: #141414;
  border-color: var(--line-2);
}
html[data-theme="midnight"] .aic-thinking-text { color: var(--ink-3); }
html[data-theme="midnight"] .aic-input-bar {
  background: var(--surface-2);
  border-top-color: var(--line);
}
html[data-theme="midnight"] .aic-input {
  background: #141414;
  color: var(--ink);
  border-color: var(--line-2);
}
html[data-theme="midnight"] .aic-input:focus {
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(126,232,106,0.18);
}
html[data-theme="midnight"] .aic-welcome { color: var(--ink-3); }
html[data-theme="midnight"] .aic-welcome-h { color: var(--ink); }
html[data-theme="midnight"] .aic-suggest-btn {
  background: #141414;
  color: #d4d4d4;
  border-color: var(--line-2);
}
html[data-theme="midnight"] .aic-suggest-btn:hover {
  background: rgba(126,232,106,0.10);
  color: var(--accent-3);
  border-color: var(--accent);
}
html[data-theme="midnight"] .aic-footnote {
  background: var(--surface-2);
  color: var(--ink-4);
  border-top-color: var(--line);
}
html[data-theme="midnight"] .aic-error {
  background: rgba(239,68,68,0.10);
  border-color: rgba(239,68,68,0.35);
  color: #fca5a5;
}
