/* Chat_Agent design layer.
   Loaded after portal-v4.html's own stylesheet and layered on top of it: the
   portal's rules, markup ids and scripts are unchanged, this file only restyles
   them into the Chat_Agent design (sidebar + rounded panel, hero empty state,
   compact composer, output sliding in beside the chat). Every colour, in both
   themes, is a Jockibox Design Language token from tokens.css. */

/* Figtree is the portal's one face (the design language's --font-sans). It ships
   with the portal (latin subset, SIL OFL), so no third-party CDN is involved.
   Figtree is variable. */
@font-face { font-family: "Figtree"; font-style: normal; font-weight: 300 900; font-display: swap; src: url("/js/design/fonts/figtree.woff2") format("woff2"); }

/* Colours, sizes and type come from the Jockibox Design Language (tokens.css).
   App tokens: values the design language doesn't carry, in its brand layer
   (design language §1, rule 3), each built from design-language tokens. */
@layer brand {
  :root {
    --jb-sidebar-w: 239px;               /* the sidebar slides by exactly this */
    --jb-gutter: var(--space-5);         /* animated with the sidebar */
    --jb-reply-avatar-w: 19px;           /* the face beside a reply; reply timestamps indent past it */
    /* The rounded app shell (chat and output panels): an approved exception to crisp corners (ui-audit.md) */
    --jb-radius-shell: 40px;
    --jb-radius-shell-sm: 28px;
    /* Display sizes above the type scale; the hero's staggered entrance is built around them */
    --jb-font-size-hero: 32px;
    --jb-font-size-hero-sm: 26px;
    --jb-font-size-login: 36px;
    --jb-font-size-login-sm: 32px;
    /* Translucent, so one hover works on the page, the panel and the sidebar alike */
    --jb-hover: color-mix(in srgb, var(--text-strong) 6%, transparent);
    --jb-glass: color-mix(in srgb, var(--bg-surface) 60%, transparent);
    --jb-glass-strong: color-mix(in srgb, var(--bg-surface) 85%, transparent);
    --jb-login-title: var(--navy-500);   /* large type, so 3:1 is its floor */
    /* Shadows that grow on hover keep their exact shape; only their ink is a token */
    --jb-shadow-ink: var(--brand-navy);
    /* The portal's stacking order, bottom to top, anchored on the design language's
       layers. Values under 60 only stack things inside one panel and stay local. */
    --jb-z-scrim: calc(var(--z-dropdown) - 2);       /* small screens: behind the sidebar drawer */
    --jb-z-sidebar: calc(var(--z-dropdown) - 1);
    --jb-z-command: calc(var(--z-dropdown) + 1);     /* slash commands, above other dropdowns */
    --jb-z-fullscreen: calc(var(--z-popover) + 10);  /* the report viewer, above menus and modals */
    --jb-z-drawer: calc(var(--z-popover) + 20);      /* Getting Started, What's New */
    --jb-z-support: calc(var(--z-popover) + 30);     /* the support tab; its drawer sits one above */
    --jb-z-login: calc(var(--z-tooltip) + 100);      /* sign-in covers everything */
  }
  :root[data-theme="dark"] {
    --jb-hover: color-mix(in srgb, var(--text-strong) 8%, transparent);
    --jb-glass: color-mix(in srgb, var(--white) 5%, transparent);
    --jb-login-title: var(--navy-400);
  }
}

/* Artwork drawn in navy: one-colour icons and wordmarks go off-white; two-tone
   marks swap to their -dark.svg (design.js); the face and dividers follow the theme. */
.jb-face-body { stroke: var(--text-strong); }
:root[data-theme="dark"] .jb-sidebar .jb-icon img,
:root[data-theme="dark"] .jb-toggle-show img,
:root[data-theme="dark"] .jb-chat-item img,
:root[data-theme="dark"] .jb-brand img:not([data-src-dark]),
:root[data-theme="dark"] .jb-login-logo img:not([data-src-dark]) { filter: brightness(0) invert(0.95); }
:root[data-theme="dark"] .jb-divider,
:root[data-theme="dark"] .jb-login-divider { opacity: 0.3; }
:root[data-theme="dark"] .msg-row.in:not(.will-msg) .msg-avatar,
:root[data-theme="dark"] .typing-row::before { background-image: url("/js/design/jb-avatar-dark.svg"); }

html, body { font-family: var(--font-sans); }
body { flex-direction: row; background: var(--bg-page); color: var(--text-strong); }
button, input, textarea, select { font-family: inherit; }
/* Tabular figures (design language §5, .ds-num): numbers that are compared or sit
   in a column (times and dates, counts, sizes, versions) keep one digit width. */
.ts, .typing-timer, .overlay-session-time, .chat-session-info, .jb-support-msg time,
.wn-date, .wn-version, .top-version, .file-item .fsize, .jb-lib-date,
.poc-steps-item::before { font-variant-numeric: tabular-nums; }
html.jb-enter [data-enter] { opacity: 0; }
html.jb-no-transition * { transition: none !important; }

/* Menus and modals: brand chips instead of the maroon ones the markup inlines. */
.waffle-icon { background: var(--bg-selected) !important; color: var(--text-strong) !important; }
.send-btn, .jb-login-button, .sys-connect-btn { box-shadow: none; }

/* ================= Sidebar ================= */
.topbar { display: none; }

.jb-sidebar {
  flex: none;
  width: var(--jb-sidebar-w);
  height: 100%;
  overflow: hidden;
  transition: width var(--duration-enter) var(--ease-enter), visibility 0s;
}
.jb-sidebar-inner {
  display: flex;
  flex-direction: column;
  width: var(--jb-sidebar-w);
  height: 100%;
  padding: var(--space-7) var(--space-6) var(--space-7);
}
.jb-sidebar img { display: block; }
.jb-brand { display: flex; align-items: center; gap: var(--space-3); height: 32.675px; }

/* Facility · agent, and the signed-in row, under the logo. */
.jb-sidebar .top-info { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-4); min-width: 0; }
.jb-sidebar .top-name {
  font-size: var(--font-size-xs); font-weight: 600; color: var(--text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.jb-sidebar .top-user-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin: 0; }
.jb-sidebar .user-name { font-size: var(--font-size-2xs); font-weight: 500; color: var(--text-muted); }
.jb-sidebar .top-status { font-size: var(--font-size-2xs); color: var(--text-link); }
.jb-sidebar .top-status.typing { color: var(--text-link); }
.jb-sidebar .typing-dots span { background: var(--color-primary-500); }
.jb-sidebar .top-version { font-size: var(--font-size-2xs); color: var(--text-muted); }
.jb-sidebar .jb-channel:not([hidden]) { margin: 0; padding: 1px var(--space-2); font-size: var(--font-size-2xs); }

.jb-new-chat {
  display: flex; align-items: center; justify-content: center;
  width: 175px; height: 30px; margin-top: var(--space-4); padding: var(--space-2) var(--space-4);
  border: 0; border-radius: var(--radius-control); background: var(--interactive-bg); color: var(--interactive-fg);
  font: 400 var(--font-size-md)/1 var(--font-sans); cursor: pointer;
  transition: background-color .15s ease;
}
.jb-new-chat:hover { background: var(--interactive-bg-hover); }

.jb-side-row {
  display: flex; align-items: center; gap: var(--space-2);
  width: 175px; height: 32px; padding: 0 var(--space-2);
  border: 0; border-radius: var(--radius-control); background: none; color: var(--text-strong);
  font: 400 var(--font-size-md)/1 var(--font-sans); text-align: left; white-space: nowrap; cursor: pointer;
  transition: background-color .15s ease;
}
.jb-side-row:hover { background: var(--jb-hover); }
.jb-side-row[hidden] { display: none; }
.jb-icon { display: grid; place-items: center; flex: none; width: 16px; height: 18px; }
.jb-toggle-hide { margin-top: var(--space-2); }
.jb-divider { flex: none; margin: var(--space-2) 0; }
.jb-new-chat:focus-visible, .jb-side-row:focus-visible, .jb-chat-item:focus-visible,
.jb-chip:focus-visible, .jb-tool-card:focus-visible, .jb-toggle-show:focus-visible {
  outline: 2px solid var(--color-primary-500); outline-offset: 2px;
}

.jb-history {
  flex: 1; min-height: 0;
  margin: 0 calc(-1 * var(--space-1)); padding: 0 var(--space-1);
  overflow-y: auto; scrollbar-width: thin;
}
.jb-history ul { margin: 0; padding: 0; list-style: none; }
.jb-chat-item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 175px; height: 30px; padding: 0 var(--space-2);
  border: 0; border-radius: var(--radius-control); background: none; color: var(--text-strong);
  font: 400 var(--font-size-md)/1 var(--font-sans); text-align: left; cursor: pointer;
  transition: background-color .15s ease;
}
.jb-chat-item:hover { background: var(--jb-hover); }
/* The current chat keeps its hover rectangle, so the sidebar always shows where you are. */
.jb-chat-item.is-active { font-weight: 600; background: var(--jb-hover); }
.jb-chat-item img { flex: none; }
.jb-chat-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jb-history-empty { padding: var(--space-2) var(--space-2); font-size: var(--font-size-xs); line-height: 1.4; color: var(--text-muted); }

.jb-side-bottom { flex: none; margin-top: var(--space-4); }
.jb-side-bottom .jb-divider:first-child { margin-top: 0; }
.jb-account-menu:not([hidden]) {
  display: flex; flex-direction: column; gap: var(--space-2);
  width: 175px; margin: var(--space-px) 0 var(--space-2); padding: var(--space-2);
  border-radius: var(--radius-container); background: var(--jb-glass);
}
.jb-account-email { font-size: var(--font-size-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jb-account-signout {
  align-self: flex-start; padding: var(--space-1) var(--space-3);
  border: 1px solid var(--text-strong); border-radius: var(--radius-control); background: transparent;
  color: var(--text-strong); font: 500 var(--font-size-xs)/1 var(--font-sans); cursor: pointer;
}
.jb-account-signout:hover { background: var(--interactive-bg); border-color: var(--interactive-bg); color: var(--interactive-fg); }

/* ================= Main panel ================= */
.main-split {
  position: relative;
  flex: 1; min-width: 0;
  display: block;
  margin: var(--jb-gutter) var(--jb-gutter) var(--jb-gutter) 0;
  padding: 0; gap: 0;
  background: var(--bg-surface);
  border-radius: var(--jb-radius-shell);
  overflow: hidden;
  container: jbpanel / inline-size;
  transition: margin var(--duration-enter) var(--ease-enter);
}

.jb-toggle-show {
  position: absolute; z-index: 4; top: 24px; left: 24px;
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 0; border-radius: var(--radius-control); background: none; cursor: pointer;
  opacity: 0; visibility: hidden;
  transition: background-color .15s ease, opacity .2s ease, visibility 0s linear .2s;
}
.jb-toggle-show:hover { background: var(--jb-hover); }

/* The chat column: centred at 523px, moves to a 353px column on the left when the
   output opens beside it. */
.panel-chat {
  position: absolute; top: 0; bottom: 0;
  left: calc((100% - min(523px, 100% - 48px)) / 2);
  width: min(523px, calc(100% - 48px));
  flex: none;
  background: transparent; border-radius: 0; box-shadow: none;
  overflow: visible;
}
.panel-chat-main {
  height: 100%;
  display: flex; flex-direction: column;
  padding-bottom: var(--space-5);
  overflow-x: hidden; overflow-y: auto;
  scrollbar-width: none;
}
.panel-chat-main > .panel-header { display: none; }

/* Empty state */
.jb-hero {
  flex: 1 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--space-10) + var(--space-2)) 0 var(--space-8);
}
.jb-hero-title { margin: var(--space-4) 0 0; font-weight: 600; font-size: var(--jb-font-size-hero); line-height: 33px; color: var(--color-primary-500); text-align: center; }
.jb-hero-title strong { font-weight: 600; color: var(--text-strong); }
.jb-hero-line { display: block; }
.jb-hero-mark-wrap { position: relative; }
.jb-hero-glow {
  position: absolute; inset: -56px; border-radius: var(--radius-circle);
  background: radial-gradient(circle, color-mix(in srgb, var(--color-primary-500) 22%, transparent) 0%, color-mix(in srgb, var(--color-primary-500) 8%, transparent) 38%, transparent 68%);
  filter: blur(14px); opacity: 0; pointer-events: none;
}
/* A small 3D rig: the navy mark is a flat card and the eye floats in front of it,
   so turning the head gives real perspective. */
.jb-hero-mark { position: relative; width: 109px; height: 112.879px; perspective: 360px; }
.jb-face-rig { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 50% 100%; }
.jb-face-rig svg { position: absolute; top: 0; left: 0; overflow: visible; }
.jb-face-eye-layer { transform: translateZ(16px) scale(0.9556); transform-origin: 54.5px 56.44px; }
.jb-face-eye-layer * { transform-box: fill-box; }
.jb-face-eye { transform-origin: 50% 50%; }
.jb-face-happy { transform-origin: 50% 100%; opacity: 0; }

.jb-chips { flex: none; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.jb-chip {
  height: 30px; padding: var(--space-2) var(--space-4);
  border: 0; border-radius: var(--radius-control); background: var(--bg-page); color: var(--text-default);
  font: 400 var(--font-size-md)/1 var(--font-sans); white-space: nowrap; cursor: pointer;
  transition: background-color .15s ease;
}
.jb-chip:hover { background: var(--interactive-quiet-bg); }

.jb-tools { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-top: var(--space-2); }
.jb-tool-card {
  display: flex; gap: var(--space-2); min-height: 95px; padding: var(--space-3) var(--space-3) var(--space-3);
  border: 0; border-radius: var(--radius-container); background: var(--border-subtle);
  font: 400 var(--font-size-md)/1.23 var(--font-sans); color: var(--text-strong); text-align: left; cursor: pointer;
  transition: background-color .15s ease;
}
.jb-tool-card:hover { background: var(--interactive-quiet-bg-hover); }
.jb-tool-card .jb-icon { place-items: start center; height: 14.4px; }
.jb-tool-card strong { display: block; font-weight: 700; line-height: 1; color: var(--text-strong); }
.jb-tool-desc { display: block; max-width: 201px; margin-top: var(--space-1); color: var(--text-muted); }

.jb-disclaimer { display: none; flex: none; margin: var(--space-1) 0 0; font: 400 var(--font-size-2xs)/12px var(--font-sans); color: var(--text-muted); text-align: center; }

/* ================= Composer ================= */
/* The box is a wrapping flex row: the textarea takes the first line full-width,
   the model toggle + Tools and attach / mic / send share the line under it. In
   flow rather than absolutely placed, so the Tools menu can anchor to the box. */
.input-bar {
  position: relative; flex: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-top: 8px; padding: 0 10px 3px 8px;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-container);
  background: var(--bg-surface);
  box-shadow: 0 4px 10px color-mix(in srgb, var(--jb-shadow-ink) 10%, transparent);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input-bar:focus-within {
  border-color: color-mix(in srgb, var(--color-primary-500) 50%, transparent);
  box-shadow: 0 4px 10px color-mix(in srgb, var(--jb-shadow-ink) 10%, transparent), 0 0 0 3px color-mix(in srgb, var(--color-primary-500) 12%, transparent);
}
.input-bar .msg-input {
  order: 0; flex: 0 0 calc(100% + 18px);
  margin: 0 -10px 0 -8px;
  min-height: 89px; max-height: none;
  padding: 8px 15px 4px;
  border: 0; border-radius: var(--radius-control);
  background: transparent;
  font: 400 var(--font-size-md)/1.3 var(--font-sans); color: var(--text-strong);
}
.input-bar .msg-input:focus { background: transparent; }
.input-bar .msg-input::placeholder { font-family: var(--font-sans); font-style: italic; color: var(--text-placeholder); opacity: 1; }
.input-bar #attachBtn, .input-bar #micBtn, .input-bar .send-btn {
  position: static; flex: none;
  width: 26px; height: 26px; border-radius: var(--radius-control);
  background: transparent; color: var(--color-primary-500); box-shadow: none;
}
.input-bar #attachBtn { order: 2; }
.input-bar #micBtn { order: 3; }
.input-bar .send-btn { order: 4; }
.input-bar #attachBtn:hover, .input-bar #micBtn:hover, .input-bar .send-btn:hover { background: var(--jb-hover); color: var(--color-primary-500); transform: none; box-shadow: none; }
.input-bar .input-icon-btn svg, .input-bar .send-btn svg { width: 16px; height: 16px; }
.input-bar #micBtn.listening { color: var(--text-link); background: var(--bg-selected); }
/* The design's paper plane; the stop square stays the portal's own. */
.input-bar .send-btn .send-icon { display: none; }
.input-bar .send-btn:not(.stopping) { background: url("/js/design/icon-send.svg") center / 16px 16px no-repeat; }
.input-bar .send-btn:not(.stopping):hover { background-color: var(--jb-hover); }
.input-bar .send-btn.stopping { color: var(--color-primary-500); }

/* Model toggle + Tools, bottom-left inside the box. */
.jb-composer-tools { order: 1; margin-right: auto; display: flex; align-items: center; gap: var(--space-1); }
.jb-composer-tools .tools-menu { position: static; }
.jb-composer-tools .model-toggle-group { margin: 0; padding: 1px; border-radius: var(--radius-control); background: var(--jb-hover); }
.jb-composer-tools .model-btn { width: 26px; height: 22px; border-radius: var(--radius-control); color: var(--color-primary-500); }
.jb-composer-tools .model-btn svg { width: 14px; height: 14px; }
.jb-composer-tools .model-btn.active { background: var(--interactive-bg); color: var(--interactive-fg); box-shadow: none; }
.jb-composer-tools .model-btn .model-tooltip { bottom: auto; top: -28px; }
.jb-composer-tools .icon-btn { width: 26px; height: 26px; border-radius: var(--radius-control); color: var(--color-primary-500); }
.jb-composer-tools .icon-btn svg { width: 16px; height: 16px; }
.jb-composer-tools .icon-btn:hover { background: var(--jb-hover); color: var(--color-primary-500); }
.jb-composer-tools .waffle-dropdown { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; width: 280px; border: 1px solid var(--border-subtle); border-radius: var(--radius-container); box-shadow: var(--elevation-dropdown); }
.slash-popup { bottom: calc(100% + 6px); left: 0; right: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-container); }
.slash-cmd { color: var(--text-link); }
.image-preview { margin: var(--space-2) 0 0; }

/* ================= Conversation mode ================= */
.main-split[data-mode="empty"] .chat { display: none; }
.main-split[data-mode="chat"] .panel-chat-main { padding-bottom: var(--space-2); overflow-y: hidden; }
.main-split[data-mode="chat"] .jb-hero,
.main-split[data-mode="chat"] .jb-chips,
.main-split[data-mode="chat"] .jb-tools { display: none; }
.main-split[data-mode="chat"] .input-bar { margin-top: 0; }
.main-split[data-mode="chat"] .input-bar .msg-input { min-height: 28px; }
.main-split[data-mode="chat"] .jb-disclaimer { display: block; }

.chat {
  flex: 1; min-height: 0;
  margin: 0 calc(-1 * var(--space-2)); padding: var(--space-5) var(--space-2) var(--space-4);
  gap: 0;
  scrollbar-width: thin;
}
.chat > :first-child { margin-top: auto; }

/* User: a soft grey bubble on the right. */
.msg-row { max-width: 88%; }
.msg-row.out .bubble {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-container) var(--radius-container) var(--radius-control) var(--radius-container);   /* round, but for the corner nearest the sender */
  background: var(--bg-page);
  color: var(--text-default); font-weight: 400; font-size: var(--font-size-md); line-height: 1.3;
  letter-spacing: 0;
}
/* JB: the logo mark as the avatar, no name line, plain text beside it. */
.msg-row.in { max-width: 100%; gap: var(--space-4); padding-left: var(--space-2); }
.msg-row.in:not(.will-msg) .msg-avatar {
  align-self: flex-start;
  width: var(--jb-reply-avatar-w); height: 20px; margin-top: var(--space-1);
  border-radius: 0;
  background: url("/js/design/jb-avatar.svg") center / contain no-repeat;
  color: transparent; font-size: 0;
}
.msg-row.in:not(.will-msg) .agent-name { display: none; }
.msg-row.in .bubble { padding: 0; color: var(--text-default); font-weight: 400; font-size: var(--font-size-md); line-height: 1.45; letter-spacing: 0; }
/* The logo lines up with the first line of the reply, so nothing may push that
   line down: a leading button or report bar drops its top margin (formatMsg
   also trims leading line breaks). */
.msg-row.in .bubble > :first-child { margin-top: 0 !important; }
.ts { margin: var(--space-1) 0 var(--space-4); font-size: var(--font-size-2xs); color: var(--text-muted); }
/* Under the reply text: the row's padding, the avatar and the gap, summed so they can't drift apart. */
.ts.left { padding-left: calc(var(--space-2) + var(--jb-reply-avatar-w) + var(--space-4)) !important; }

/* "Thinking…": the mini face breathes while a light sweeps the status text; the
   portal's elapsed-time counter stays beside it. */
.typing-row { gap: var(--space-4); margin: var(--space-1) 0 var(--space-4) var(--space-2); font-size: var(--font-size-md); }
.typing-row::before {
  content: ""; flex: none; width: 19px; height: 20px;
  background: url("/js/design/jb-avatar.svg") center / contain no-repeat;
  animation: jb-breathe 1.4s ease-in-out infinite alternate;
}
.typing-row .typing-bar { display: none; }
.typing-row::after {
  content: "Thinking…"; order: 1;
  color: transparent;
  background: linear-gradient(90deg, var(--text-muted) 0 38%, var(--color-primary-500) 50%, var(--text-muted) 62% 100%) 0 0 / 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  animation: jb-shimmer 1.8s linear infinite;
}
.typing-row .typing-timer { order: 2; margin-left: 0 !important; color: var(--text-muted) !important; }
@keyframes jb-shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes jb-breathe { from { transform: scale(1); opacity: 1; } to { transform: scale(1.08); opacity: .7; } }

/* Report / download controls under a message: the design's report card. */
button.jb-dl, button.jb-open {
  height: 30px; margin: var(--space-2) var(--space-2) 0 0; padding: 0 var(--space-3);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-control); background: var(--bg-subtle);
  color: var(--text-default); font-size: var(--font-size-xs); font-weight: 500;
}
button.jb-dl:hover, button.jb-open:hover { background: var(--bg-hover); }
button.jb-dl:focus-visible, button.jb-open:focus-visible { outline-color: var(--color-primary-500); }

/* History overlay inside the column */
.chat-history-overlay { background: var(--bg-surface); border-radius: 0; }
.chat-history-overlay .overlay-session:hover { background: var(--jb-hover); }
.chat-history-overlay .overlay-session.active { background: var(--jb-hover); }

/* ================= Output: slides over the right of the panel ================= */
.panel-output {
  position: absolute !important;
  z-index: 1;
  top: 0; right: 0; bottom: 0; left: 385px;
  flex: none; height: auto;
  background: var(--bg-surface); border-radius: var(--jb-radius-shell); box-shadow: none;
}
.panel-output.empty-output { display: none; }
/* hairline between the chat and the output */
.panel-output::before {
  content: ""; position: absolute; top: 32px; bottom: 32px; left: 0; width: 1px; background: var(--border-subtle);
}
.panel-output > .panel-header { height: auto; padding: var(--space-5) var(--space-5) var(--space-2) var(--space-7); border-bottom: 0; }
.panel-output .jb-dash-close { width: 32px; height: 32px; justify-content: center; border-radius: var(--radius-control); color: var(--text-strong); }
.panel-output .jb-dash-close svg { width: 16px; height: 16px; }
.panel-output .jb-dash-close:hover { background: var(--jb-hover); color: var(--text-strong); }
.panel-output .output-scroll { margin: 0 var(--space-5) var(--space-5) var(--space-7); border: 1px solid var(--border-subtle); border-radius: var(--radius-container); overflow: hidden; }
.panel-output.report-flows .output-scroll { overflow-y: auto; }
.output-frame iframe { border-radius: 0; }
.output-chips { border-radius: 0; }
.visual-actions .va-btn { background: var(--jb-glass-strong) !important; color: var(--color-primary-500) !important; border: 1px solid var(--border-subtle); }
.visual-actions .va-btn:hover { background: var(--bg-surface) !important; }

.main-split[data-dash="open"] .panel-chat { left: 16px; width: 353px; }

/* Not enough room beside the chat: the output covers the whole panel instead. */
@container jbpanel (max-width: 1000px) {
  .main-split[data-dash="open"] .panel-chat { left: calc((100% - min(523px, 100% - 48px)) / 2); width: min(523px, calc(100% - 48px)); }
  .panel-output { left: 0; z-index: 3; }
  .panel-output::before { display: none; }
  .panel-output > .panel-header { padding: var(--space-5) var(--space-5) var(--space-2) var(--space-5); }
  /* clear the show-sidebar button, which sits over this corner */
  html[data-sidebar="hidden"] .panel-output > .panel-header { padding-left: var(--space-10); }
  .panel-output .output-scroll { margin: 0 var(--space-4) var(--space-4); }
}

/* ================= Hidden sidebar ================= */
html[data-sidebar="hidden"] .jb-sidebar {
  width: 0; visibility: hidden;
  transition: width var(--duration-exit) var(--ease-exit), visibility 0s linear var(--duration-exit);
}
html[data-sidebar="hidden"] .main-split { margin-left: var(--jb-gutter); transition: margin var(--duration-exit) var(--ease-exit); }
html[data-sidebar="hidden"] .jb-toggle-show {
  opacity: 1; visibility: visible;
  transition: background-color .15s ease, opacity .2s ease .12s, visibility 0s;
}
.jb-scrim { display: none; }

/* ================= Narrow screens: the sidebar becomes a drawer ================= */
@media (max-width: 767px) {
  :root { --jb-gutter: var(--space-3); }
  .jb-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: var(--jb-z-sidebar);
    background: var(--bg-page); box-shadow: var(--elevation-panel);
  }
  .main-split { margin-left: var(--jb-gutter); padding: 0; border-radius: var(--jb-radius-shell-sm); flex-direction: row; }
  .panel-chat { left: 16px; width: calc(100% - 32px); border-radius: 0; }
  .main-split[data-dash="open"] .panel-chat { left: 16px; width: calc(100% - 32px); }
  .panel-chat-main { padding-bottom: var(--space-4); }
  .panel-output { height: auto; border-radius: var(--jb-radius-shell-sm); }
  .jb-toggle-show { top: 16px; left: 16px; }
  .jb-scrim {
    display: block; position: fixed; inset: 0; z-index: var(--jb-z-scrim);
    background: var(--bg-scrim); transition: opacity var(--duration-enter) var(--ease-enter);
  }
  html[data-sidebar="hidden"] .jb-scrim { opacity: 0; pointer-events: none; transition: opacity var(--duration-exit) var(--ease-exit); }
  html[data-sidebar="hidden"] .jb-sidebar { box-shadow: none; }
  .jb-hero { padding-top: var(--space-10); }
  .jb-hero-title { font-size: var(--jb-font-size-hero-sm); line-height: 29px; }
  .jb-tools { grid-template-columns: 1fr; }
}


/* ================= Sign-in ================= */
#jbLogin:not([hidden]) {
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4); overflow: hidden;
  background: var(--bg-page); box-shadow: none;
  font-family: var(--font-sans);
}
#jbLogin img { display: block; }
.jb-login-bg {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}
.jb-login-card {
  position: relative; z-index: 1;
  width: min(370px, 100%); min-height: 338px;
  margin: 0; padding: var(--space-6) var(--space-6) var(--space-6);
  border: 0; border-radius: var(--radius-container);
  background: var(--bg-surface); box-shadow: var(--elevation-modal);
}
.jb-login-logo { display: flex; align-items: flex-end; gap: var(--space-2); height: 21.23px; }
.jb-login-title {
  margin: var(--space-4) 0 0;
  font-family: var(--font-sans); font-weight: 600; font-size: var(--jb-font-size-login); line-height: 24px;
  color: var(--jb-login-title); white-space: nowrap;
}
.jb-login-form { margin: var(--space-6) 0 0; }
.jb-login-field:not([hidden]) { display: block; margin-top: var(--space-4); }
.jb-login-field:first-child { margin-top: 0; }
.jb-login-label { display: block; font-weight: 600; font-size: var(--font-size-md); line-height: 10px; color: var(--text-default); }
.jb-login-input {
  display: block; width: 100%; height: 40px; margin-top: var(--space-1); padding: var(--space-2);
  border: 1px solid var(--border-default); border-radius: var(--radius-control); background: var(--bg-surface);
  font: 400 var(--font-size-md)/normal var(--font-sans); color: var(--text-strong);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.jb-login-input:hover { border-color: var(--border-strong); }
.jb-login-input:focus { border-color: var(--color-primary-500); background: var(--bg-surface); box-shadow: var(--focus-ring); }
.jb-login-code { letter-spacing: .2em; }
/* The portal's status line (anti-enumeration copy, errors) sits in the gap under
   the input, where the prototype put its validation message. */
.jb-login-message {
  min-height: 0; margin: var(--space-2) 0 0; padding: 0;
  border: 0; border-radius: 0; background: none;
  font-size: var(--font-size-xs); line-height: 15px; color: var(--text-muted);
}
.jb-login-button {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 40px; min-height: 0; margin-top: var(--space-4); padding: var(--space-2) var(--space-4);
  border: 1px solid var(--interactive-bg); border-radius: var(--radius-control);
  background: var(--interactive-bg); color: var(--interactive-fg);
  font: 500 var(--font-size-md)/24px var(--font-sans);
  transition: background-color .15s ease, border-color .15s ease, transform .08s ease;
}
.jb-login-button:hover:not(:disabled) { background: var(--interactive-bg-hover); border-color: var(--interactive-bg-hover); box-shadow: none; }
.jb-login-button:active:not(:disabled) { transform: translateY(1px); }
.jb-login-button:focus-visible { outline: 2px solid var(--color-primary-500); outline-offset: 2px; }
.jb-login-divider { margin-top: var(--space-4); height: 1px; max-width: 100%; }
.jb-login-device-note { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-5); }
.jb-login-device-note img { flex: none; }
.jb-login-device-note span { font-weight: 500; font-size: var(--font-size-md); line-height: 14px; color: var(--text-muted); }

@media (max-width: 480px) {
  #jbLogin:not([hidden]) { align-items: center; padding: var(--space-4); }
  .jb-login-card { padding-left: var(--space-5); padding-right: var(--space-5); }
  .jb-login-title { font-size: var(--jb-font-size-login-sm); }
  .jb-login-input { font-size: var(--font-size-lg); }
  .jb-login-device-note span { width: auto; }
}

/* ================= Library (stand-in styling until the Figma pass) ================= */
.visual-actions .va-btn.saved svg { fill: currentColor; }
.visual-actions .va-btn:disabled { opacity: .4; cursor: default; }

.jb-library:not([hidden]) {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column;
  border-radius: inherit; background: var(--bg-surface);
}
.jb-library-head { flex: none; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-6) var(--space-6) var(--space-4); }
.jb-library-title { margin: 0 auto 0 0; font: 600 var(--font-size-2xl)/1.2 var(--font-sans); color: var(--text-strong); }
.jb-library-views { display: flex; gap: var(--space-px); padding: var(--space-px); border-radius: var(--radius-control); background: var(--jb-hover); }
.jb-library-view {
  display: grid; place-items: center; width: 32px; height: 28px;
  border: 0; border-radius: var(--radius-control); background: none; color: var(--text-muted); cursor: pointer;
}
.jb-library-view[aria-pressed="true"] { background: var(--bg-surface); color: var(--text-strong); box-shadow: var(--elevation-dropdown); }
.jb-library-view:hover { background: var(--jb-hover); }
/* The Library is a sibling of the chats: its row reads as current while it shows,
   and the open chat stops reading as current. */
.jb-side-row.is-active { background: var(--jb-hover); font-weight: 600; }
html.jb-library-open .jb-chat-item.is-active { font-weight: 400; background: none; }
html.jb-library-open .jb-chat-item.is-active:hover { background: var(--jb-hover); }
/* With the sidebar hidden (or on a phone) the show-sidebar button is the way back
   to the chats, so it stays above the Library and the header clears it. */
html.jb-library-open .jb-toggle-show { z-index: 8; }
html[data-sidebar="hidden"] .jb-library-head { padding-left: calc(var(--space-10) + var(--space-2)); }
.jb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.jb-library-items { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: var(--space-2) var(--space-6) var(--space-6); list-style: none; }
.jb-library-items[data-view="grid"] { display: grid; grid-template-columns: repeat(auto-fill, 240px); gap: var(--space-4); align-content: start; }
.jb-library-items[data-view="list"] { display: flex; flex-direction: column; gap: var(--space-px); }
.jb-lib-status { grid-column: 1 / -1; padding: var(--space-8) 0; text-align: center; font-size: var(--font-size-md); color: var(--text-muted); }
.jb-lib-item { position: relative; min-width: 0; }

.jb-lib-open {
  display: flex; flex-direction: column; width: 100%; padding: 0;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-container); background: var(--bg-surface);
  color: var(--text-strong); font: inherit; text-align: left; cursor: pointer; overflow: hidden;
  transition: border-color .15s ease, background-color .15s ease;
}
.jb-lib-open:hover { border-color: var(--color-primary-500); }
.jb-lib-open:focus-visible, .jb-lib-delete:focus-visible, .jb-library-view:focus-visible { outline: 2px solid var(--color-primary-500); outline-offset: 2px; }

/* The preview is the saved page itself at 1200x900, scaled to the 240px tile. */
.jb-lib-thumb { position: relative; display: block; width: 240px; height: 180px; overflow: hidden; background: var(--bg-subtle); border-bottom: 1px solid var(--border-subtle); }
.jb-lib-thumb iframe { position: absolute; top: 0; left: 0; width: 1200px; height: 900px; border: 0; transform: scale(.2); transform-origin: 0 0; pointer-events: none; background: var(--bg-surface); }
.jb-lib-thumb-failed::after { content: "Preview unavailable"; position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--font-size-xs); color: var(--text-muted); }

.jb-lib-meta { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--space-3); row-gap: var(--space-px); align-items: center; padding: var(--space-3) var(--space-3); min-width: 0; }
.jb-lib-icon { grid-row: span 2; display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-control); background: var(--bg-selected); color: var(--text-link); }
.jb-lib-title { font-size: var(--font-size-md); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jb-lib-sub { display: flex; gap: var(--space-2); font-size: var(--font-size-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; }
/* The date stays whole; a long type name gives way first. */
.jb-lib-kind { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.jb-lib-date { flex: none; }

.jb-library-items[data-view="list"] .jb-lib-open { flex-direction: row; align-items: center; border-color: transparent; border-radius: var(--radius-control); }
.jb-library-items[data-view="list"] .jb-lib-open:hover { border-color: transparent; background: var(--jb-hover); }
.jb-library-items[data-view="list"] .jb-lib-thumb { display: none; }
.jb-library-items[data-view="list"] .jb-lib-meta { flex: 1; padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3); }

.jb-lib-delete {
  position: absolute; top: 8px; right: 8px;
  display: grid; place-items: center; width: 28px; height: 28px;
  border: 0; border-radius: var(--radius-control); background: var(--jb-glass-strong); color: var(--color-primary-500); cursor: pointer;
  opacity: 0; transition: opacity .15s ease;
}
/* On a tile it sits bottom-right, beside the title, which leaves it room. */
.jb-library-items[data-view="grid"] .jb-lib-delete { top: auto; bottom: 12px; }
.jb-library-items[data-view="grid"] .jb-lib-meta { padding-right: var(--space-8); }
.jb-lib-item:hover .jb-lib-delete, .jb-lib-delete:focus-visible { opacity: 1; }
.jb-library-items[data-view="list"] .jb-lib-delete { top: 50%; transform: translateY(-50%); }
@media (hover: none) { .jb-lib-delete { opacity: 1; } }
@media (max-width: 767px) {
  .jb-library-head { padding: var(--space-5) var(--space-4) var(--space-3) var(--space-9); }
  .jb-library-items { padding: var(--space-2) var(--space-4) var(--space-5); }
  .jb-library-items[data-view="grid"] { justify-content: center; }
}

.jb-toast:not([hidden]) {
  position: absolute; left: 50%; bottom: 24px; z-index: 7; transform: translateX(-50%);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-container); background: var(--interactive-bg); color: var(--interactive-fg);
  font: 500 var(--font-size-sm)/1.2 var(--font-sans); box-shadow: var(--elevation-toast); white-space: nowrap;
}

/* Fullscreen (Expand, and Library items): the report fills the screen and the
   close button floats over its top-right corner instead of taking a bar. */
.fullscreen-bar { position: absolute; top: 16px; right: 16px; z-index: 1; padding: 0; }
.fullscreen-close {
  width: 32px; height: 32px; border-radius: var(--radius-control);
  border: 1px solid var(--border-subtle); background: var(--jb-glass-strong); color: var(--color-primary-500);
  box-shadow: var(--elevation-dropdown);
}
.fullscreen-close:hover { background: var(--bg-surface); color: var(--color-primary-500); }
.fullscreen-close:focus-visible { outline: 2px solid var(--color-primary-500); outline-offset: 2px; }

/* ================= Chat actions (stand-in styling until the Figma pass) ================= */
.jb-history li { position: relative; }
/* "…" sits over the row's right end: shown on hover, focus, an open menu, or a touch screen. */
.jb-chat-more {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: var(--radius-control); background: none; color: var(--color-primary-500);
  font: 700 var(--font-size-md)/1 var(--font-sans); letter-spacing: 1px; cursor: pointer;
  opacity: 0; transition: opacity .15s ease, background-color .15s ease;
}
.jb-history li:hover .jb-chat-more, .jb-chat-more:focus-visible, .jb-chat-more[aria-expanded="true"] { opacity: 1; }
.jb-chat-more:hover { background: var(--jb-hover); }
.jb-chat-more:focus-visible { outline: 2px solid var(--color-primary-500); outline-offset: 1px; }
.jb-history li:hover .jb-chat-item span { padding-right: var(--space-5); }
@media (hover: none) {
  .jb-chat-more { opacity: 1; }
  .jb-chat-item span { padding-right: var(--space-5); }
}

.jb-chat-menu:not([hidden]) {
  position: fixed; z-index: var(--z-popover);
  display: flex; flex-direction: column; min-width: 160px; padding: var(--space-1);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-container); background: var(--bg-surface);
  box-shadow: var(--elevation-dropdown);
}
.jb-chat-menu button {
  display: block; width: 100%; padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-control);
  background: none; color: var(--text-strong); font: 400 var(--font-size-md)/1.2 var(--font-sans); text-align: left; cursor: pointer;
}
.jb-chat-menu button:hover, .jb-chat-menu button:focus-visible { background: var(--jb-hover); outline: none; }
.jb-chat-menu .jb-chat-menu-danger { color: var(--danger-fg); }

.jb-dialog { width: 400px; }
.jb-dialog .settings-header h3 { font-family: var(--font-sans); color: var(--text-strong); }
.jb-dialog-body { padding: 0 var(--space-5) var(--space-5); }
.jb-dialog-label { display: block; margin-bottom: var(--space-2); font-size: var(--font-size-sm); font-weight: 600; color: var(--text-strong); }
.jb-dialog-text { margin: 0; font-size: var(--font-size-md); line-height: 1.5; color: var(--text-default); overflow-wrap: anywhere; }
.jb-dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.jb-dialog-cancel, .jb-dialog-primary, .jb-dialog-danger {
  height: 36px; padding: 0 var(--space-4); border-radius: var(--radius-control); font: 500 var(--font-size-md)/1 var(--font-sans); cursor: pointer;
}
.jb-dialog-cancel { border: 1px solid var(--border-subtle); background: none; color: var(--text-strong); }
.jb-dialog-cancel:hover { background: var(--jb-hover); }
.jb-dialog-primary { border: 0; background: var(--interactive-bg); color: var(--interactive-fg); }
.jb-dialog-primary:hover { background: var(--interactive-bg-hover); }
.jb-dialog-danger { border: 0; background: var(--danger-fg); color: var(--interactive-fg); }
.jb-dialog-danger:disabled { opacity: .6; cursor: default; }
.jb-dialog-cancel:focus-visible, .jb-dialog-primary:focus-visible, .jb-dialog-danger:focus-visible { outline: 2px solid var(--color-primary-500); outline-offset: 2px; }

/* ================= Reduce Motion =================
   Last in the file, so a later hover or press rule cannot undo it. */
/* Reduce Motion stops all motion through the design language's one rule (tokens.css).
   That rule shortens a move but cannot cancel it, so what would still shift is held
   here: the "Thinking…" label gets a plain colour instead of a frozen shimmer, and
   controls that nudge or press keep their place. */
@media (prefers-reduced-motion: reduce) {
  .typing-row::before, .typing-row::after { animation: none; }
  .typing-row::after { color: var(--text-muted); }
  .output-chips button:hover > svg,
  .send-btn:hover, .send-btn:active,
  .sys-connect-btn:active:not(:disabled),
  .jb-login-button:active:not(:disabled) { transform: none; }
}
