#chat-pane .linklike { appearance: none; border: none; background: transparent; color: var(--brand-charcoal); cursor: pointer; }
/*
  BitBoard palette — earthy, low-saturation (Heath-inspired)
  Sand / Cypress / Redwood / Golden Gate / Slate
  Warm surfaces, soft radii, subtle motion
*/
:root {
  /* Earthy anchors */
  --earth-sand: #F4F2EE;       /* SAND (neutral bone) */
  --earth-cypress: #B5B8A0;    /* CYPRESS */
  /* Adjusted away from pink → brick/rust */
  --earth-redwood: #7C3F2A;    /* REDWOOD (brown rust) */
  --earth-goldengate: #C94A2A; /* GOLDEN GATE (burnt orange) */
  --earth-slate: #332B2B;      /* SLATE */

  /* Brand tokens mapped to earthy anchors */
  --brand-offwhite: #F4F2EE;
  --brand-sand-50: #F7F5F1;
  --brand-sand-100: #EFEAE3;
  --brand-sand-200: #E6E0D7;
  --brand-sand-300: #D6CFC5;
  --brand-sand-400: #BDB5AA;

  --brand-charcoal: var(--earth-slate);

  /* Primary accent → Redwood */
  --brand-terracotta-500: var(--earth-redwood);
  --brand-terracotta-600: #643422; /* deeper brown rust */
  --brand-terracotta-tint: rgba(124, 63, 42, 0.08);
  --brand-terracotta-stroke: rgba(124, 63, 42, 0.28);

  /* Supportive green (cypress) and subtle scale for timeline/status */
  --brand-sage-300: #C5C9B5;
  --brand-sage-400: #AAB398;
  --brand-sage-500: var(--earth-cypress);

  /* Shape, shadow, rhythm */
  --brand-radius: 10px;
  --brand-radius-lg: 12px;
  --brand-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  /* Warm surface whites (avoid stark #fff) */
  --surface-card: #F7F5F2;       /* warm, reads as white */
  --surface-elevated: #F3F1ED;   /* for menus/popovers */
  --surface-header: #EAE3DA;     /* slightly darker for separation */
  --app-header-height: 44px;
  --prompt-actions-height: 32px;
  --prompt-inset: 12px;
  --brand-ease: cubic-bezier(.2,.7,.2,1);
  --brand-duration-1: 120ms;
  --brand-duration-2: 160ms;
  --sidebar-width: 44px;
  --sidebar-icon-cell: 32px;
  --sidebar-rail-inset: calc((var(--sidebar-width) - var(--sidebar-icon-cell)) / 2);
  --sidebar-item-pad: 12px;
  /* Secondary text color pulled from prompt placeholder */
  --brand-text-secondary: #8E867A;
  /* Unified hairlines */
  --ui-hairline: rgba(0,0,0,0.12);
  --ui-warm-hairline: #D2C7BA;
  --ui-warm-outline: #B8AC9E; /* stronger warm outline for contrast */
  --ui-outline-strong: 1px; /* thicker luxe outline */
  --surface-sage-tint: #EEF0EA;
  /* Subtle chrome tints to reduce monochrome feel */
  --chrome-tint-cypress: rgba(181, 184, 160, 0.25);
  --chrome-tint-redwood: rgba(124, 62, 42, 0.25);
  --chrome-tint: var(--chrome-tint-redwood);
  --chrome-corner-radius: 20px;
  --chat-header-height: 44px;
  --chat-pane-top-pad: 12px;
  /* Sheet chrome alignment helpers (tune as needed) */
  --sheet-toolbar-midline: 39px;   /* distance below sheet toolbar top */
  --sheet-footer-height: 36px;     /* height of tabs/zoom chrome at bottom */
  /* Type */
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  --font-heading: "Public Sans", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
}

/* Dark theme overrides, applied via body.theme-dark */
body.theme-dark {
  --brand-offwhite: #1c1a17;
  --brand-sand-50: #26231f;
  --brand-sand-100: #2d2a25;
  --brand-sand-200: #35322b;
  --brand-sand-300: #3d3a33;
  --brand-sand-400: #4a463e;

  --brand-charcoal: #e8e4db;
  --brand-text-secondary: #8a857d;

  --surface-card: #26231f;
  --surface-elevated: #2d2a25;
  --surface-header: #1c1a17;

  --ui-hairline: #3d3a33;
  --ui-warm-hairline: #3d3a33;
  --ui-warm-outline: #6b6660;

  --chrome-tint-cypress: rgba(61, 58, 51, 0.4);
  --chrome-tint-redwood: rgba(61, 58, 51, 0.4);
  --chrome-tint: rgba(61, 58, 51, 0.4);
}
/* App shell: header + main (no sidebar) */
#app-shell { display: flex; flex-direction: column; height: 100%; }
#app-shell.no-sidebar { flex-direction: column; }
#main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--surface-elevated); }

/* App Header */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--app-header-height);
  padding: 0 12px 0 4px;
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--brand-sand-200);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--brand-sand-300);
}

/* Brand menu dropdown */
.brand-menu-wrap {
  position: relative;
}

.brand-menu-trigger {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 6px 8px 6px 4px;
  margin-left: -6px; /* optical alignment with edge */
  border-radius: var(--brand-radius);
  cursor: pointer;
  color: var(--brand-charcoal);
  transition: background var(--brand-duration-1) var(--brand-ease);
}

.brand-menu-trigger:hover,
.brand-menu-trigger[aria-expanded="true"] {
  background: var(--brand-sand-100);
}

.brand-menu-trigger .brand-logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.brand-menu-trigger .brand-wordmark {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 600;
  color: var(--brand-charcoal);
  letter-spacing: -0.01em;
}

.brand-menu-trigger .brand-caret {
  width: 14px;
  height: 14px;
  color: var(--brand-text-secondary);
  transition: transform var(--brand-duration-1) var(--brand-ease);
}

.brand-menu-trigger[aria-expanded="true"] .brand-caret {
  transform: rotate(180deg);
}

/* Brand dropdown */
.brand-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: var(--brand-radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity var(--brand-duration-1) var(--brand-ease),
              visibility var(--brand-duration-1) var(--brand-ease),
              transform var(--brand-duration-1) var(--brand-ease);
}

.brand-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.brand-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  border-radius: var(--brand-radius);
  color: var(--brand-charcoal);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--brand-duration-1) var(--brand-ease);
}

.brand-menu-item:hover {
  background: var(--brand-sand-100);
}

.brand-menu-item i,
.brand-menu-item svg {
  width: 16px;
  height: 16px;
  color: var(--brand-text-secondary);
  flex-shrink: 0;
}

.brand-menu-divider {
  height: 1px;
  background: var(--brand-sand-200);
  margin: 6px 0;
}

.brand-menu-group {
  display: flex;
  flex-direction: column;
}

/* Layout toggle in header */
.layout-toggle {
  display: flex;
  gap: 2px;
  background: var(--brand-sand-100);
  border-radius: 8px;
  padding: 3px;
}

.layout-toggle .layout-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--brand-text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--brand-duration-1) var(--brand-ease),
              color var(--brand-duration-1) var(--brand-ease);
}

.layout-toggle .layout-btn:hover {
  background: var(--brand-sand-200);
  color: var(--brand-charcoal);
}

.layout-toggle .layout-btn.active {
  background: var(--surface-card);
  color: var(--brand-charcoal);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.layout-toggle .layout-btn i,
.layout-toggle .layout-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* Toggle button: show expand icon when chat is hidden, collapse icon otherwise */
.layout-toggle .layout-btn[data-chat-position="toggle"] .icon-collapse { display: flex; }
.layout-toggle .layout-btn[data-chat-position="toggle"] .icon-expand { display: none; }
body.chat-hidden .layout-toggle .layout-btn[data-chat-position="toggle"] .icon-collapse { display: none; }
body.chat-hidden .layout-toggle .layout-btn[data-chat-position="toggle"] .icon-expand { display: flex; }

/* Workbook name field */
#app-header .project-name {
  font-family: var(--font-heading);
  appearance: none;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--brand-radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--brand-charcoal);
  min-width: 120px;
  max-width: 300px;
  height: 34px;
  transition: background var(--brand-duration-2) var(--brand-ease),
              border-color var(--brand-duration-2) var(--brand-ease),
              box-shadow var(--brand-duration-2) var(--brand-ease);
}

#app-header .project-name::placeholder { color: var(--brand-text-secondary); }

#app-header .project-name:hover { 
  border-color: var(--brand-sand-300);
  background: var(--brand-sand-50);
}

#app-header .project-name:focus { 
  border-color: var(--brand-terracotta-stroke);
  background: var(--surface-card);
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-terracotta-stroke);
}

/* Dark mode header overrides */
body.theme-dark #app-header {
  background: var(--surface-elevated);
  border-bottom-color: var(--brand-sand-300);
}

body.theme-dark .brand-menu-trigger .brand-wordmark {
  color: var(--brand-sand-50);
}

body.theme-dark .brand-dropdown {
  background: var(--surface-card);
  border-color: var(--brand-sand-300);
}

body.theme-dark .brand-menu-item {
  color: var(--brand-sand-50);
}

body.theme-dark .brand-menu-item:hover {
  background: var(--brand-sand-200);
}

body.theme-dark .layout-toggle {
  background: var(--brand-sand-200);
}

body.theme-dark .layout-toggle .layout-btn:hover {
  background: var(--brand-sand-300);
}

body.theme-dark .layout-toggle .layout-btn.active {
  background: var(--surface-card);
}

/* Invert logomark in dark mode */
body.theme-dark .brand-logo {
  filter: invert(1) hue-rotate(180deg);
}

/* Layout hygiene */
*, *::before, *::after { box-sizing: border-box; }
body { overflow-x: hidden; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--brand-offwhite);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  color: var(--brand-charcoal);
}

/* App Header */
#app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--app-header-height);
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-elevated);
  border-bottom: none;
}

/* Quick theme toggles */
body.tint-cypress { --chrome-tint: var(--chrome-tint-cypress); }
/* removed terracotta toggle; variable not defined */
body.tint-redwood { --chrome-tint: var(--chrome-tint-redwood); }

#app-header::after { content: none; }

/* Brand logomark button and app menu */
.brand-menu {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 6px 8px;
  border-radius: var(--brand-radius);
  cursor: pointer;
  color: var(--brand-charcoal);
  transition: background var(--brand-duration-2) var(--brand-ease), border-color var(--brand-duration-2) var(--brand-ease);
}
.brand-menu:hover,
.brand-menu[aria-expanded="true"] {
  background: var(--brand-sand-50);
}
.brand-logo {
  display: block;
  height: 22px;
  width: 22px;
  object-fit: contain;
}

/* Invert logomark in dark mode so it stays legible */
body.theme-dark .brand-logo {
  filter: invert(1) hue-rotate(180deg);
}
.app-menu {
  position: absolute;
  top: calc(var(--app-header-height) - 10px);
  left: 16px;
  min-width: 220px;
  background: var(--surface-elevated);
  border: 1px solid var(--brand-sand-200);
  border-radius: var(--brand-radius);
  box-shadow: var(--brand-shadow);
  padding: 6px;
  z-index: 1100;
}
.app-menu[hidden] { display: none; }
.app-menu .menu-item {
  appearance: none;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--brand-charcoal);
}
.app-menu .menu-item:hover { background: var(--brand-sand-50); }
.app-menu .menu-sep { height: 1px; background: var(--brand-sand-200); margin: 6px 4px; }

/* Generic placeholder */
.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--brand-sand-400);
  font-size: 13px;
  height: 100%;
  border: 1px dashed var(--brand-sand-200);
  border-radius: var(--brand-radius);
  background: var(--surface-card);
}

.brand-inner {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--brand-charcoal);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* (removed responsive overflow in favor of stability) */

.export-menu {
  position: relative;
}

.export-trigger {
  font-family: var(--font-heading);
  display: inline-flex;
  align-items: center;
  flex-direction: row;
  white-space: nowrap;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-charcoal);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  min-height: 28px;
}

/* consolidated icon sizing below */
.export-trigger i { width: 16px; height: 16px; }
.export-trigger i.caret { transition: transform var(--brand-duration-2) var(--brand-ease); }
.export-menu.open .export-trigger i.caret { transform: rotate(180deg); }

/* Export header CTA – neutral outline button */
.export-menu.open .export-trigger,
.export-trigger:hover {
  /* neutral button darkens slightly on hover/open */
  background: var(--brand-sand-100);
  border-color: var(--brand-sand-300);
}

.export-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  flex-direction: column;
  min-width: 160px;
  padding: 6px;
  border-radius: var(--brand-radius);
  border: var(--ui-outline-strong) solid var(--ui-warm-outline);
  background: var(--surface-elevated);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.export-menu.open .export-dropdown {
  display: flex;
}

.export-option {
  padding: 8px 10px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--brand-charcoal);
  border-radius: 6px;
  cursor: pointer;
}

.export-option:hover,
.export-option:focus {
  background: var(--brand-sand-50);
  outline: none;
}

/* Import button – primary terracotta CTA */
.import-trigger {
  font-family: var(--font-heading);
  display: inline-flex;
  align-items: center;
  flex-direction: row;
  white-space: nowrap;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-terracotta-600);
  background: var(--brand-terracotta-500);
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-offwhite);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  min-height: 28px;
}
.import-trigger i { width: 16px; height: 16px; }

.import-trigger:hover {
  /* primary button lightens slightly on hover */
  background: var(--brand-terracotta-600);
}

/* Minimal icon button */
.icon-btn {
  width: 24px;
  height: 24px;
  border: 0;
  background: var(--surface-card);
  color: var(--brand-charcoal);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--brand-duration-1) var(--brand-ease), border-color var(--brand-duration-1) var(--brand-ease), color var(--brand-duration-1) var(--brand-ease);
}
.icon-btn:hover { background: var(--brand-sand-50); }
.icon-btn i { width: 16px; height: 16px; }

/* Import modal */
.import-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.import-backdrop:not([hidden]) {
  display: flex;
}

.import-dialog {
  background: var(--surface-card);
  border-radius: var(--brand-radius-lg);
  padding: 24px;
  min-width: 480px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.import-title {
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--brand-charcoal);
}

.import-dropzone {
  border: 2px dashed var(--brand-sand-300);
  border-radius: var(--brand-radius);
  padding: 40px 20px;
  text-align: center;
  background: var(--brand-sand-50);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.import-dropzone:hover {
  border-color: var(--brand-sand-400);
  background: var(--surface-card);
}

.import-dropzone.dragover {
  border-color: var(--brand-terracotta-500);
  background: var(--brand-terracotta-tint);
}

.import-dropzone.has-file {
  border-color: var(--brand-terracotta-500);
  background: var(--surface-card);
}

.file-note {
  font-size: 12px;
  color: var(--brand-text-secondary);
  margin-top: 8px;
}

/* Import modal: destination selector */
.import-destination {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--brand-sand-200);
}

.import-section-title {
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-text-secondary);
}

.import-destination-options {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.import-option input[type="radio"] {
  margin-top: 4px;
  flex-shrink: 0;
}

.import-option-body {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--brand-sand-200);
  background: var(--surface-card);
  transition:
    border-color var(--brand-duration-2) var(--brand-ease),
    box-shadow var(--brand-duration-2) var(--brand-ease),
    background-color var(--brand-duration-2) var(--brand-ease);
}

.import-option-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--brand-charcoal);
  margin: 0 0 2px 0;
}

.import-option-desc {
  font-size: 12px;
  color: var(--brand-text-secondary);
  margin: 0;
}

.import-option input[type="radio"]:checked + .import-option-body {
  border-color: var(--brand-terracotta-500);
  background: var(--brand-terracotta-tint);
  box-shadow: 0 0 0 1px rgba(180, 74, 58, 0.18);
}

.import-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ===================== Share Modal ===================== */
.share-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.share-backdrop:not([hidden]) {
  display: flex;
}

.share-dialog {
  background: var(--surface-card);
  border-radius: var(--brand-radius-lg);
  padding: 24px;
  min-width: 480px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.share-title {
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--brand-charcoal);
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-title i,
.share-title svg {
  width: 20px;
  height: 20px;
  color: var(--brand-terracotta-500);
}

.share-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.share-email-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  font-size: 14px;
  color: var(--brand-charcoal);
  transition: border-color 0.2s ease;
}

.share-email-input:focus {
  outline: none;
  border-color: var(--brand-terracotta-500);
}

.share-email-input::placeholder {
  color: var(--brand-text-secondary);
}

.share-role-select {
  padding: 10px 12px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  font-size: 14px;
  color: var(--brand-charcoal);
  cursor: pointer;
}

.share-role-select:focus {
  outline: none;
  border-color: var(--brand-terracotta-500);
}

.share-grants-section {
  border-top: 1px solid var(--brand-sand-200);
  padding-top: 16px;
}

.share-section-label {
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-text-secondary);
  margin-bottom: 12px;
}

.share-grants-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.share-grant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--brand-sand-50);
  border-radius: var(--brand-radius);
  gap: 12px;
}

.share-grant-owner {
  background: var(--brand-sage-tint);
}

.share-grant-email {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.share-grant-email-text {
  font-size: 14px;
  color: var(--brand-charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.share-grant-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--brand-sage-300);
  color: var(--earth-slate);
  flex-shrink: 0;
}

.share-grant-role {
  font-size: 13px;
  color: var(--brand-text-secondary);
  flex-shrink: 0;
}

.share-grant-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.share-grant-role-select {
  padding: 6px 10px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  font-size: 13px;
  color: var(--brand-charcoal);
  cursor: pointer;
}

.share-grant-role-select:focus {
  outline: none;
  border-color: var(--brand-terracotta-500);
}

.share-revoke-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--brand-radius);
  background: transparent;
  color: var(--brand-text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.share-revoke-btn:hover {
  background: rgba(180, 74, 58, 0.1);
  color: var(--earth-redwood);
}

.share-revoke-btn i,
.share-revoke-btn svg {
  width: 16px;
  height: 16px;
}

.share-loading,
.share-empty,
.share-error {
  text-align: center;
  padding: 24px;
  color: var(--brand-text-secondary);
  font-size: 14px;
}

.share-error {
  color: var(--earth-redwood);
}

.share-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--brand-sand-200);
}

/* ===================== Viewer Badge ===================== */
.viewer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--brand-radius);
  background: var(--brand-sage-300);
  color: var(--earth-slate);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 500;
}

.viewer-badge svg,
.viewer-badge i {
  width: 14px;
  height: 14px;
}

/* Hide edit controls in viewer mode */
body.viewer-mode .chat-input {
  display: none;
}

body.viewer-mode #chat-new {
  display: none;
}

body.viewer-mode #project-name {
  pointer-events: none;
  opacity: 0.7;
}

body.viewer-mode [data-import-trigger] {
  display: none;
}

/* Hide add-sheet button in Univer footer for viewers */
body.viewer-mode [data-u-comp="sheet-bar-append-button"]:has(svg) {
  display: none;
}
/* Fallback: hide by structure - first button in sheet bar controls */
body.viewer-mode .univer-mr-2[data-u-comp="sheet-bar-append-button"] {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-charcoal);
  cursor: pointer;
  height: 28px;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover:not(:disabled) {
  background: var(--brand-sand-50);
  border-color: var(--brand-sand-400);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand-terracotta-500);
  color: #fff;
  border-color: var(--brand-terracotta-600);
}

.btn i,
.btn svg {
  width: 16px;
  height: 16px;
}

.btn.primary:hover:not(:disabled) {
  background: var(--brand-terracotta-600);
  border-color: var(--brand-terracotta-600);
}

.btn.primary:active:not(:disabled) {
  background: var(--brand-terracotta-600);
  border-color: var(--brand-terracotta-600);
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Sheet drag-and-drop overlay */
#import-sheet-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1500;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(2px);
}

#import-sheet-overlay.active {
  display: flex;
}

#import-sheet-overlay .hint {
  border: 3px dashed var(--brand-sand-400);
  background: var(--brand-offwhite);
  border-radius: 16px;
  padding: 24px 32px;
  color: var(--brand-charcoal);
  font-size: 16px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Container */
.container.single {
  display: flex;
  flex-direction: column;
  padding: 0;
  max-width: none;
  margin: 0;
  flex: 1;
  min-height: 0; /* allow flex shrinking */
  background: var(--surface-card);
}

.workspace-shell {
  flex: 1;
  min-height: 0; /* critical for nested flex scrolling */
  padding: 0;
  box-sizing: border-box;
  background: transparent;
  display: flex;
  flex-direction: column;
}

/* Split chat layout (sheet + chat) */
/* (removed legacy .chat-split layout) */

/* (removed old thread sidebar and unused .sheet-pane class) */

/* Expand viewport width when sheet is enabled */
body.sheet-enabled .container.single {
  max-width: none;
  width: 100%;
  padding: 0;
}

/* Workspace container: sheet + resizer + chat */
.workspace {
  background: var(--surface-elevated);
  display: flex;
  flex-direction: row; /* chat | resizer | sheet (default: chat-left) */
  flex: 1;
  min-height: 0; /* critical for nested flex scrolling */
  max-width: 100%;
  padding: 0;
  overflow: hidden;
}

/* Chat position: right (reverse the flex order) */
body.chat-right .workspace {
  flex-direction: row-reverse;
}
body.chat-right #chat-pane {
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--brand-sand-200); /* divider from sheet */
}
body.chat-right.sheet-enabled #sheet-pane {
  border-radius: 0;
  border-top: none;
  border-left: 1px solid var(--brand-sand-200);
  border-right: none;
}

/* Chat position: hidden */
body.chat-hidden #chat-pane,
body.chat-hidden #resizer {
  display: none;
}
body.chat-hidden.sheet-enabled #sheet-pane {
  border-radius: 0;
  border-top: none;
  border-left: none;
  flex: 1;
}

/* Allow scrolling for settings/account/etc pages (non-workbook views) */
.workspace:not(:has(#sheet-pane)) {
  overflow-y: auto;
  padding: 24px;
}
/* Clip overflow for workbook view (sheet handles its own scrolling) */
.workspace:has(> #sheet-pane) {
  overflow: hidden;
}
#chat-pane {
  flex: 1;
  padding: 6px 18px 18px 18px; /* balanced inner padding */
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  background: var(--surface-card);
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--brand-sand-200); /* divider from sheet */
  overflow: hidden;
}

/* Prevent flex children from forcing horizontal overflow */
.workspace > * { min-width: 0; }

/* Workbooks index view: reuse curved chrome but show a single-column list */
.workspace.workbooks-index {
  flex-direction: column;
  padding: 12px 36px 36px 36px;
}
.workspace.workbooks-index #sheet-pane,
.workspace.workbooks-index #resizer,
.workspace.workbooks-index #chat-pane {
  display: none;
}
.workspace.workbooks-index #workbooks-root {
  flex: 1;
}

/* Workbooks index layout */
.workbooks-page {
  max-width: 1120px;
  /* Match Account/Settings layout: center the column, keep header/content
     left-aligned within it, and avoid an ultra-skinny layout. */
  margin: 24px auto 32px;
  padding: 0 32px;
  min-width: 720px;
}

@media (max-width: 800px) {
  .workbooks-page {
    /* On smaller viewports, allow the page to shrink rather than forcing
       horizontal scrolling from the desktop-friendly minimum width. */
    min-width: 0;
  }
}
.workbooks-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.workbooks-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}
.workbooks-list {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px; /* row, column */
  /* Let the grid fill the available column width so the right edge
     aligns optically with the "New workbook" button above. */
  margin: 0;
}
.workbooks-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 320px;   /* fixed card width to allow 3-up on desktop */
  max-width: 320px;
  min-height: 120px; /* give cards some vertical presence */
  padding: 20px 24px; /* more padding around content */
  border-radius: var(--brand-radius-lg);
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  cursor: pointer;
  transition:
    background var(--brand-duration-2) var(--brand-ease),
    border-color var(--brand-duration-2) var(--brand-ease),
    box-shadow var(--brand-duration-2) var(--brand-ease),
    transform var(--brand-duration-2) var(--brand-ease);
}
.workbooks-row:hover {
  background: var(--surface-elevated);
  border-color: var(--brand-sand-300);
  box-shadow: var(--brand-shadow);
  transform: translateY(-1px);
}
.workbooks-row-info {
  flex: 1;
  min-width: 0;
  margin-right: 16px; /* space between title/meta and action buttons */
}
.workbooks-row-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workbooks-row-meta {
  font-size: 12px;
  color: var(--brand-text-secondary);
  margin-top: 8px; /* extra space between title and timestamp */
}
.workbooks-row-actions {
  position: relative;
  display: flex;
  align-items: center;
}

.workbooks-menu-trigger {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--brand-charcoal);
  transition: background var(--brand-duration-1) var(--brand-ease),
              color var(--brand-duration-1) var(--brand-ease);
}
.workbooks-menu-trigger:hover {
  background: var(--brand-sand-50);
}
.workbooks-menu-trigger i,
.workbooks-menu-trigger svg {
  width: 16px;
  height: 16px;
  stroke: var(--brand-charcoal) !important; /* ensure dark kebab icon */
}

.workbooks-menu {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(calc(-50% + 18px));
  min-width: 140px;
  background: var(--surface-card);
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-200);
  box-shadow: var(--brand-shadow);
  padding: 4px;
  display: none;
  z-index: 20;
}
.workbooks-menu.open {
  display: block;
}
.workbooks-menu-item {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  color: var(--brand-charcoal);
  text-align: left;
  cursor: pointer;
}
.workbooks-menu-item:hover {
  background: var(--brand-sand-50);
}
.workbooks-menu-item.danger {
  color: #b44a3a;
}
.workbooks-empty {
  font-size: 14px;
  color: var(--brand-text-secondary);
}

/* Settings page layout */
.settings-page {
  max-width: 1120px;        /* match main content width like Workbooks */
  margin: 24px auto 40px;   /* centered column, content left-aligned inside */
  padding: 0 32px;
}
.workspace > .settings-page {
  flex: 1 1 auto;           /* allow settings column to expand in flex shell */
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between; /* reserved for future actions */
  margin-bottom: 16px;
}
.settings-title {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}
.settings-card {
  width: 100%;              /* use full column width */
  max-width: none;
  background: var(--surface-card);
  border-radius: var(--brand-radius-lg);
  border: 1px solid var(--brand-sand-200);
  padding: 28px 32px 24px; /* more breathing room */
  margin-bottom: 16px;
}
.settings-card-title {
  font-family: var(--font-heading);
  font-size: 14px; /* slightly larger section labels */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-text-secondary);
  margin: 0 0 10px;
}
.settings-field {
  margin-bottom: 20px; /* more vertical spacing between fields */
}
.settings-field .file-note {
  margin-bottom: 8px;
}

.settings-field .model-input {
  display: block;
  width: 100%;
  max-width: 100%;
}

.settings-static {
  font-size: 14px;
  line-height: 1.4;
}
.settings-value {
  font-size: 14px;
  line-height: 1.4;
  color: var(--brand-charcoal);
}
.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Preserve single-pane layout for account page and others */
.single-pane-page {
  max-width: 520px;
  margin: 24px auto 32px;
}

/* Theme toggle on Settings page */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* keep switch next to label text */
  gap: 10px;
}
.theme-toggle-label {
  font-size: 14px;
}
.theme-toggle-control {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.theme-toggle-control input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--brand-sand-200);
  box-shadow: inset 0 0 0 1px var(--brand-sand-300);
  display: inline-block;
  transition:
    background var(--brand-duration-2) var(--brand-ease),
    box-shadow var(--brand-duration-2) var(--brand-ease);
}
.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-card);
  box-shadow: 0 2px 4px rgba(0,0,0,0.18);
  transition:
    transform var(--brand-duration-2) var(--brand-ease),
    background var(--brand-duration-2) var(--brand-ease);
}
.theme-toggle-control input:checked + .theme-toggle-track {
  background: var(--brand-terracotta-500);
  box-shadow: inset 0 0 0 1px var(--brand-terracotta-600);
}
.theme-toggle-control input:checked + .theme-toggle-track .theme-toggle-thumb {
  transform: translateX(18px);
}

/* Draggable vertical resizer between sheet and chat */
#resizer { flex: 0 0 6px; cursor: col-resize; background: transparent; position: relative; }
#resizer::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; right: 0; border-radius: 0; background: rgba(0,0,0,0.06); opacity: 0; transition: opacity 120ms var(--brand-ease); }
#resizer:hover::before, #resizer.active::before { opacity: 1; }
#resizer::after { content: ""; position: absolute; top: var(--sheet-toolbar-midline); bottom: var(--sheet-footer-height); width: .75px; left: 0; background: #E6E0D7; z-index: 1; pointer-events: none; }
body.resizing { cursor: col-resize; user-select: none; }

/* Hide resizer hairline in dark mode so we don't get a bright vertical seam */
body.theme-dark #resizer::after {
  background: transparent;
}

/* Two-column chat layout tweaks */
body.sheet-enabled #sheet-pane {
  background: var(--surface-card);
  border: none;
  border-left: 1px solid var(--brand-sand-200); /* divider from chat */
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  min-width: 300px;
  flex: 1 1 auto;
  min-height: 0; /* allow flex shrinking */
  position: relative; /* anchor import overlay */
  /* Prevent horizontal overscroll from triggering browser back/forward gestures */
  overscroll-behavior-x: contain;
}
body.sheet-enabled #sheet-root {
  height: 100%;
  width: 100%;
  overscroll-behavior: contain;
}

/* Prevent Univer's internal scroll from triggering browser back/forward gestures */
#univer-container {
  overscroll-behavior: contain;
}


/* Messages: scroll container for per-turn sections */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px 4px 0; /* right padding creates content margin; left handled by pane */
  margin-right: -18px; /* extend container to pane edge so scrollbar sits at edge */
  position: relative;
  background: var(--brand-offwhite);
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Firefox scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--brand-sand-300) transparent;
}

/* Webkit scrollbar styling - narrow, at right edge */
#messages::-webkit-scrollbar {
  width: 6px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--brand-sand-300);
  border-radius: 3px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background: var(--brand-sand-400);
}

/* Conversation turns (user prompt + assistant response) */
.turn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Top padding creates breathing room under the chat header without leaving a gap when sticky */
  padding: 6px 0 6px;
}

/* Sticky user prompt that acts as the header for a turn */
.turn-header {
  position: sticky;
  top: 0;
  /* Sit above turn content so collapsible chevrons pass underneath */
  z-index: 2;
  background: var(--brand-offwhite);
  /* Ensure the pinned prompt reads as a unified chip at the top */
  margin-bottom: 2px;
  /* Create a soft halo that matches the background so underlying text
     can't peek through around the rounded corners while pinned */
  box-shadow: 0 0 0 6px var(--brand-offwhite);
}

.turn-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -24px;
  height: 24px;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--brand-offwhite) 0%, rgba(247,245,242,0.8) 40%, rgba(247,245,242,0) 100%);
  z-index: -1;
}

.turn-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Leave enough space so the first line of content clears the header's
     fade zone and sits fully readable below the pinned prompt. */
  padding-top: 8px;
}

/* Fades for top/bottom of message list using dedicated overlays */
.messages-wrap { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.messages-fade { position: absolute; left: 0; right: 0; height: 12px; pointer-events: none; opacity: 0; transition: opacity var(--brand-duration-2) var(--brand-ease); z-index: 1; }
/* Top fade is effectively handled by the pinned turn header; keep this node hidden to avoid double fades. */
.messages-fade.top { top: 0; background: transparent; display: none; }
.messages-fade.bottom { bottom: 0; background: linear-gradient(to top, var(--brand-offwhite), rgba(255,255,255,0)); }
.messages-fade.show { opacity: 1; }

/* Jump to latest button */
.jump-latest { position: absolute; left: 50%; bottom: 8px; z-index: 2; border: 1px solid transparent; background: var(--brand-charcoal); color: var(--brand-offwhite); border-radius: 50%; width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 6px 12px rgba(0,0,0,0.24), 0 18px 36px rgba(0,0,0,0.22); opacity: 0; transform: translate(-50%, 6px); pointer-events: none; transition: opacity var(--brand-duration-2) var(--brand-ease), transform var(--brand-duration-2) var(--brand-ease); }
.jump-latest:hover { background: #504841; }
.jump-latest i, .jump-latest svg { width: 26px; height: 26px; }
.jump-latest.visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

/* Chat header row */
.chat-header-inner { display: flex; align-items: center; justify-content: space-between; width: 100%; }

/* Headings and UI labels use Public Sans for cohesion */
#chat-pane h1, #chat-pane h2, #chat-pane h3,
#chat-pane .section-title,
#chat-pane .chat-header,
#chat-pane .chat-title-btn,
#chat-pane .chat-header .icon-btn,
.thread-popover-head .label {
  font-family: var(--font-heading);
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Assistant expandable section summary ("Show steps") */
.message.assistant .trace-toggle summary { font-family: var(--font-heading); }
.plan-step-detail summary { font-family: var(--font-heading); font-weight: 500; }

/* Optional: try to nudge Univer toolbar labels to heading face (safe, scoped) */
#sheet-pane .univer-toolbar, #sheet-pane .univer-toolbar * { font-family: var(--font-heading); font-weight: 500; }

/* Thread title pill */
#chat-title.title-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 4px 8px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--brand-charcoal); font-size: 15px; font-weight: 600; cursor: pointer; }
#chat-title.title-btn { font-family: var(--font-heading); letter-spacing: 0.01em; }
#chat-title.title-btn { justify-content: flex-start; text-align: left; min-width: 0; }
#chat-title.title-btn:hover { background: var(--brand-sand-50); }
#chat-title.title-btn:focus-visible { outline: 2px solid var(--brand-sand-300); outline-offset: 2px; }
#chat-title i { width: 12px; height: 12px; transition: transform var(--brand-duration-2) var(--brand-ease); }
#chat-title[aria-expanded="true"] i { transform: rotate(180deg); }
/* Ensure lucide-replaced SVG also rotates/sizes */
#chat-title svg { width: 12px; height: 12px; transition: transform var(--brand-duration-2) var(--brand-ease); }
#chat-title[aria-expanded="true"] svg { transform: rotate(180deg); }

/* Title text truncation */
#chat-title-text { display: inline-block; min-width: 0; max-width: clamp(160px, 45vw, 520px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Header icon button (New thread) */
.chat-header .icon-btn { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--brand-charcoal); cursor: pointer; }
.chat-header .icon-btn:hover { background: var(--brand-sand-50); }
.chat-header .icon-btn i { width: 16px; height: 16px; }

.message {
  width: 100%;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding: 12px 0;
  box-sizing: border-box;
}

/* Flat cards for both roles (no tails) */
.message.user {
  background: var(--brand-sand-100);
  border: 0;
  border-radius: var(--brand-radius);
  padding: 10px 16px;
  color: var(--brand-charcoal);
}
.message.assistant {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px 0; /* blend into feed with vertical rhythm only */
  color: var(--brand-charcoal);
  white-space: normal;
}

/* Pinned user prompt at top of turn
   - Collapsed: show ~4 lines with a soft fade at the bottom
   - Expanded: show full content with no clipping
*/
.pinned-prompt {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pinned-prompt__body {
  position: relative;
}

/* Collapsed: clamp visual height to ~4 lines and show a fade-out */
.pinned-prompt--collapsed .pinned-prompt__body {
  max-height: calc(1.6em * 4); /* 4 lines at the base message line-height (1.6) */
  overflow: hidden;
}

.pinned-prompt--collapsed .pinned-prompt__body::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2.4em; /* soft gradient over the last ~1.5 lines */
  pointer-events: none;
  /* Fade from transparent to the user bubble background so the chip edge stays clean */
  background: linear-gradient(
    to bottom,
    rgba(244, 242, 238, 0),
    var(--brand-sand-100)
  );
}

/* Expanded: remove clamp and fade */
.pinned-prompt--expanded .pinned-prompt__body {
  max-height: none;
  overflow: visible;
}

.pinned-prompt--expanded .pinned-prompt__body::after {
  content: none;
}

.pinned-prompt__toggle {
  align-self: flex-start;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin-top: 2px;
  font-size: 12px;
  font-family: var(--font-heading);
  font-weight: 500;
  color: var(--brand-text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.pinned-prompt__toggle:focus-visible {
  outline: 2px solid var(--brand-sand-300);
  outline-offset: 2px;
}

/* Optional: nudge pointer to suggest expand-on-click when collapsed */
.pinned-prompt--collapsed .pinned-prompt__body {
  cursor: pointer;
}

/* When expanded, go back to normal text cursor for easier selection */
.pinned-prompt--expanded .pinned-prompt__body {
  cursor: text;
}

/* Collapsible assistant in main chat view */
.assistant-collapse {
  margin: 0;
}

.assistant-collapse summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  padding: 4px 0;
  user-select: none;
}

.assistant-collapse summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.assistant-collapse summary::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.assistant-collapse[open] summary::before {
  transform: rotate(180deg);
}

.assistant-content {
  margin-top: 8px;
}

/* Non-collapsible bubble for debug view */
.assistant-bubble.clickable:hover { background: var(--brand-terracotta-tint); }

.assistant-summary {
  font-weight: 600;
  margin-bottom: 8px;
}

/* Thinking/streaming message - no animation */
.message.assistant.thinking {
  color: var(--brand-sand-400);
  font-style: italic;
  padding: 16px 0;
}

/* Stopped turn indicator */
.message.assistant.stopped-message {
  padding: 12px 0;
  color: var(--brand-sand-400);
}

.stopped-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--brand-sand-100);
  color: var(--brand-sand-500);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-heading);
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* Result Card - natural text flow */
.message.assistant.result-card {
  padding: 0;
  overflow: visible;
}

.card-thinking {
  padding: 0 0 16px 0;
  font-size: 13px;
  margin-bottom: 8px;
}

.card-thinking.hidden {
  display: none;
}

.thinking-window {
  margin: 0 0 12px 0;
  background: transparent;
  border: 0;
  border-radius: var(--brand-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 240px;
}

.thinking-header {
  font-size: 12px;
  color: var(--brand-sand-400);
  padding: 6px 10px;
  border-bottom: 0;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 1;
  animation: workingPulse 3.5s ease-in-out infinite;
}

.thinking-body {
  overflow-y: auto;
  padding: 0 10px 8px 10px; /* remove top gap so blur touches header */
  position: relative;
  flex: 1;
  min-height: 0; /* allow flex child to shrink below content height */
}

/* Top blur/fade indicator for overflow above - positioned absolutely to not affect layout */
.thinking-body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px; /* more gradual fade */
  pointer-events: none;
  z-index: 2; /* above content but still below header */
  opacity: 0;
  transition: opacity var(--brand-duration-2) var(--brand-ease);
  /* Gentle feed-like fade (match messages fades) */
  background: linear-gradient(to bottom, var(--brand-offwhite), rgba(255,255,255,0));
}

.thinking-body.show-top-blur::before {
  opacity: 1;
}

/* Ensure no extra top margin sneaks in above first child */
.thinking-body > :first-child {
  margin-top: 0 !important;
}

@keyframes workingPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.thinking-dots {
  color: var(--brand-sand-400);
  font-style: italic;
  animation: dotsPulse 1.5s ease-in-out infinite;
}

.thinking-content {
  color: var(--brand-text-secondary);
  line-height: 1.6;
  margin-top: 4px;
  font-size: 13px;
  white-space: pre-wrap;
}

.thinking-content:empty {
  display: none;
}

.planning-dots {
  display: none;
  color: var(--brand-sand-400);
  font-style: italic;
  margin-top: 8px;
  animation: dotsPulse 1.5s ease-in-out infinite;
}

@keyframes dotsPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.card-plan {
  margin: 0 0 16px 0;
  padding: 12px;
  background: var(--surface-card);
  border-radius: var(--brand-radius);
  border: 1px solid var(--brand-sand-200);
}

.card-plan.hidden {
  display: none;
}

.plan-objective {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--brand-charcoal);
}

.plan-steps {
  font-size: 13px;
  line-height: 1.6;
  color: var(--brand-charcoal);
}

.plan-steps-list {
  margin-top: 8px;
}

.plan-step-detail {
  margin: 8px 0;
  padding: 0;
}

.plan-step-detail summary {
  cursor: pointer;
  padding: 4px 0;
  font-size: 13px;
  color: var(--brand-charcoal);
}

.plan-step-detail summary:hover { color: var(--brand-terracotta-500); }

.plan-step-content {
  padding: 8px 0 0 12px;
  font-size: 12px;
}

.plan-step-rationale {
  color: #6b655d;
  margin-bottom: 6px;
  font-style: italic;
}

.plan-step-actions {
  margin-top: 6px;
}

.plan-step-actions ul {
  margin: 4px 0;
  padding-left: 20px;
}

.plan-step-actions li {
  margin: 2px 0;
  font-size: 12px;
  color: var(--brand-charcoal);
}

.plan-step-actions code {
  background: var(--brand-sand-100);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.card-trace {
  margin: 0;
  padding: 0;
  color: var(--brand-text-secondary); /* make steps drawer text secondary */
}

.card-result {
  margin-top: 16px;
  padding: 0; /* no bubble */
  font-size: 14px; /* match streaming narrative sizing */
  line-height: 1.6;
  color: var(--brand-charcoal);
  white-space: normal; /* match narrative flow */
}

.card-result.hidden,
.card-result:empty {
  display: none;
  margin: 0;
}

/* Hide empty assistant bubbles to prevent orphaned whitespace */
.card-result .assistant-bubble:empty {
  display: none;
}

/* Markdown styling for observations */
.card-result h1, .card-result h2, .card-result h3, 
.observation-markdown h1, .observation-markdown h2, .observation-markdown h3 {
  margin-top: 1.2em;
  margin-bottom: 0.6em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--brand-charcoal);
}

.card-result h1, .observation-markdown h1 {
  font-size: 1.4em;
  border-bottom: 1px solid var(--brand-sand-200);
  padding-bottom: 0.3em;
}

.card-result h2, .observation-markdown h2 {
  font-size: 1.2em;
}

.card-result h3, .observation-markdown h3 {
  font-size: 1.05em;
}

.card-result p, .observation-markdown p {
  margin: 0.8em 0;
  white-space: normal;
}

.card-result ul, .card-result ol,
.observation-markdown ul, .observation-markdown ol {
  margin: 0.8em 0;
  padding-left: 1.8em;
  white-space: normal;
}

.card-result li, .observation-markdown li {
  margin: 0.4em 0;
  line-height: 1.6;
}

.card-result strong, .observation-markdown strong {
  font-weight: 600;
  color: var(--brand-charcoal);
}

.card-result em, .observation-markdown em {
  font-style: italic;
}

.card-result code, .observation-markdown code {
  background: var(--brand-sand-100);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.card-result pre, .observation-markdown pre {
  background: var(--brand-sand-100);
  padding: 1em;
  border-radius: var(--brand-radius);
  overflow-x: auto;
  margin: 1em 0;
}

.card-result pre code, .observation-markdown pre code {
  background: transparent;
  padding: 0;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Clarifying Question UI
   Agent asks structured questions; user can click options or type response
   ───────────────────────────────────────────────────────────────────────────── */

/* Clarifying question - matches chat bubble styling */
.clarifying-question-bubble {
  background: none;
  padding: 0;
}

.clarifying-question {
  background: var(--brand-sand-100);
  border-radius: var(--brand-radius);
  padding: 12px 16px;
}

.clarifying-context {
  font-size: 13px;
  color: var(--brand-text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* Markdown styling within clarifying question context */
.clarifying-context p {
  margin: 0 0 8px 0;
}

.clarifying-context p:last-child {
  margin-bottom: 0;
}

.clarifying-context strong {
  font-weight: 600;
  color: var(--brand-charcoal);
}

.clarifying-context ul, .clarifying-context ol {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}

.clarifying-context li {
  margin-bottom: 2px;
}

/* Multiple questions list */
.clarifying-questions-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.clarifying-question-item {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--brand-sand-200);
}

.clarifying-question-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.clarifying-question-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--brand-charcoal);
  margin-bottom: 10px;
  line-height: 1.5;
}

/* Markdown in question text */
.clarifying-question-text p {
  margin: 0;
}

.clarifying-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clarifying-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  color: var(--brand-charcoal);
  background: var(--brand-offwhite);
  border: 1px solid var(--brand-sand-200);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.clarifying-option:hover {
  background: var(--brand-sand-50);
  border-color: var(--brand-sand-300);
}

.clarifying-option.selected {
  background: var(--brand-sand-200);
  border-color: var(--brand-sand-400);
}

.clarifying-hint {
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--brand-text-secondary);
  background: var(--brand-sand-100);
  border-radius: 6px;
  font-style: italic;
}

/* Subtle undo turn link */
.undo-turn-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  font-size: 12px;
  font-family: inherit;
  color: var(--brand-sand-400);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease;
}

.undo-turn-link:hover {
  color: var(--brand-sand-600);
}

.undo-turn-link svg {
  opacity: 0.7;
}

.trace-content {
  font-size: 13px;
  line-height: 1.6;
  color: var(--brand-text-secondary);
}

.trace-goal {
  margin-bottom: 16px;
  padding-bottom: 10px;
  color: #6b655d;
  font-size: 13px;
  font-style: italic;
}

.trace-step {
  margin: 20px 0;
  padding-left: 16px;
  border-left: 2px solid var(--brand-sand-200);
}

.trace-step-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--brand-charcoal);
  margin-bottom: 4px;
}

.trace-step-rationale {
  font-size: 12px;
  color: #8b8579;
  margin-bottom: 8px;
  font-style: italic;
  line-height: 1.5;
}

.step-loading {
  color: var(--brand-sand-400);
  font-style: italic;
  font-size: 12px;
  margin-top: 4px;
  animation: dotsPulse 1.5s ease-in-out infinite;
}

.trace-action {
  margin: 4px 0 4px 12px;
  padding-left: 0;
}

.trace-action-desc {
  font-size: 12px;
  color: #8b8579;
}

.trace-observation {
  margin-top: 16px;
  padding-top: 12px;
  font-size: 14px;
  color: var(--brand-charcoal);
  line-height: 1.7;
  font-weight: 400;
}

/* Markdown styling within trace observations */
.trace-observation h1, .trace-observation h2, .trace-observation h3 {
  margin-top: 1.2em;
  margin-bottom: 0.6em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--brand-charcoal);
}

.trace-observation h1 {
  font-size: 1.3em;
  border-bottom: 1px solid var(--brand-sand-200);
  padding-bottom: 0.3em;
}

.trace-observation h2 {
  font-size: 1.15em;
}

.trace-observation h3 {
  font-size: 1.05em;
}

.trace-observation p {
  margin: 0.8em 0;
}

.trace-observation ul, .trace-observation ol {
  margin: 0.8em 0;
  padding-left: 1.8em;
}

.trace-observation li {
  margin: 0.4em 0;
  line-height: 1.6;
}

.trace-observation strong {
  font-weight: 600;
  color: var(--brand-charcoal);
}

.trace-observation em {
  font-style: italic;
}

.trace-observation code {
  background: var(--brand-sand-100);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.trace-observation pre {
  background: var(--brand-sand-100);
  padding: 1em;
  border-radius: var(--brand-radius);
  overflow-x: auto;
  margin: 1em 0;
}

.trace-observation pre code {
  background: transparent;
  padding: 0;
}

.hidden {
  display: none;
}

/* Plan/Step/Action structure */
.plan-header {
  margin-bottom: 8px;
  padding-left: 8px;
  border-left: 2px solid var(--brand-terracotta-stroke);
  font-weight: 600;
}

.objective-decision {
  margin: 6px 0 8px 0;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.decision-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.decision-badge.new {
  background: var(--brand-sand-200);
  color: var(--brand-sand-400);
  border: none;
}

.decision-badge.continue {
  background: var(--brand-sand-200);
  color: var(--brand-sand-400);
  border: none;
}

.decision-badge.modified {
  background: var(--brand-sand-200);
  color: var(--brand-sand-400);
  border: none;
}

.decision-reasoning {
  color: #6b655d;
  font-size: 11px;
  font-style: italic;
}

.status {
  font-size: 10px;
  color: var(--brand-sand-400);
  margin-left: 4px;
  font-weight: 400;
  font-style: italic;
}

.step-inline,
.action-inline {
  margin: 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--brand-sand-200);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.step-inline > * {
  margin: 4px 0;
}

.action-inline > * {
  margin: 3px 0;
}

.step-inline > *:first-child,
.action-inline > *:first-child {
  margin-top: 0;
}

.step-inline > *:last-child,
.action-inline > *:last-child {
  margin-bottom: 0;
}

.rationale {
  font-size: 12px;
  color: #6b655d;
  margin-top: 3px;
}

.observation {
  font-size: 12px;
  color: #333;
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(250, 247, 237, 0.6);
  border-left: 2px solid var(--brand-terracotta-stroke);
  border-radius: 4px;
}

.summary {
  font-size: 12px;
  color: #333;
  margin-top: 4px;
  padding: 4px 6px;
  background: rgba(250, 247, 237, 0.5);
  border-left: 2px solid var(--brand-sand-300);
  border-radius: 4px;
}

.evidence {
  margin-top: 6px;
}

.evidence summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  color: var(--brand-sand-400);
  font-weight: 500;
  font-size: 12px;
}

.evidence summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.evidence summary::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.evidence[open] summary::before {
  transform: rotate(180deg);
}

.evidence-box {
  background: var(--brand-sand-50);
  border: 1px solid var(--brand-sand-200);
  border-radius: 6px;
  padding: 8px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.error {
  color: #a8562f;
  font-weight: 600;
  margin-top: 4px;
}

.args summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: var(--brand-sand-400);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.args summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.args summary::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 4px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px 10px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.args[open] summary::before {
  transform: rotate(180deg);
}

.args[open] {
  margin-top: 4px;
}

/* Usage - compact footer style */
.usage-subtext {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--brand-sand-200);
  font-size: 11px;
  color: var(--brand-sand-400);
  font-style: italic;
}

/* Working memory */
.working-memory {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(250, 247, 237, 0.55);
  border: 1px solid var(--brand-sand-300);
  border-radius: 8px;
}

.working-memory summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  color: var(--brand-charcoal);
  font-size: 12px;
}

.working-memory summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.working-memory summary::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.working-memory details[open] > summary::before {
  transform: rotate(180deg);
}

.working-memory ul {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.working-memory li {
  font-size: 12px;
  color: #333;
  margin: 4px 0;
}

/* Debug page width alignment */
.debug-messages .assistant-collapse { width: 100%; }
.container.single .debug-messages { max-width: 100%; }
.container.single .debug-toolbar { max-width: 100%; }

/* Chat input area */
.chat-input {
  border-top: none; /* remove divider */
  padding: 0;
  margin: 0;
  background: transparent; /* avoid white block above the prompt */
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* Drag-over state for file drops (images + PDFs) */
.chat-input.drag-over .prompt-wrap {
  background: rgba(0, 0, 0, 0.06);
}

/* Image previews container */
.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 4px;
}
.image-previews[hidden] {
  display: none;
}

.image-preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--brand-sand-200);
  background: var(--surface-card);
  flex-shrink: 0;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-item .image-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.image-preview-item:hover .image-remove-btn {
  opacity: 1;
}

.image-preview-item .image-remove-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

.image-preview-item .image-remove-btn .lucide-icon {
  width: 12px;
  height: 12px;
}

/* Chat message images (persisted in chat history) */
.user-message-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-message-image {
  max-width: 120px;
  max-height: 90px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--brand-sand-200);
  background: var(--surface-card);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-message-image:hover {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* PDF previews container (pending attachments in chat input) */
.pdf-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 4px;
}
.pdf-previews[hidden] {
  display: none;
}

.pdf-preview-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--brand-sand-200);
  background: var(--surface-card);
  font-size: 13px;
  color: var(--text-main);
}

.pdf-preview-item .pdf-icon {
  width: 16px;
  height: 16px;
  color: var(--brand-red-500, #dc2626);
  flex-shrink: 0;
}

.pdf-preview-item .pdf-filename {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-preview-item .pdf-remove-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.pdf-preview-item:hover .pdf-remove-btn {
  opacity: 1;
}

.pdf-preview-item .pdf-remove-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

.pdf-preview-item .pdf-remove-btn .lucide-icon {
  width: 12px;
  height: 12px;
}

/* Chat message PDFs (persisted in chat history) */
.chat-message-pdfs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-message-pdf {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--brand-sand-200);
  background: var(--surface-card);
  font-size: 13px;
  color: var(--text-main);
}

.chat-message-pdf .pdf-icon {
  width: 16px;
  height: 16px;
  color: var(--brand-red-500, #dc2626);
  flex-shrink: 0;
}

.chat-message-pdf .pdf-filename {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-message-text {
  /* Inherits styling from parent .message.user */
}

.prompt-wrap {
  position: relative;
  border: var(--ui-outline-strong) solid var(--ui-warm-outline);
  border-radius: var(--brand-radius);
  background: var(--surface-card);
  margin: 0;
  padding: var(--prompt-inset);
  min-height: calc(var(--prompt-actions-height) + var(--prompt-inset) * 2 + 48px);
  transition: min-height 0.2s ease;
}
/* When todo panel is visible inside chat-input, adjust prompt-wrap */
.chat-input .todo-panel:not([hidden]) ~ .prompt-wrap {
  border-top: none;
  border-radius: 0 0 var(--brand-radius) var(--brand-radius);
}
/* Todo panel styling inside chat-input - flush with prompt-wrap */
.chat-input .todo-panel {
  margin: 0;
  padding: 0;
}
.chat-input .todo-details {
  border: var(--ui-outline-strong) solid var(--ui-warm-outline);
  border-bottom: 1px solid var(--ui-hairline);
  border-radius: var(--brand-radius) var(--brand-radius) 0 0;
  background: var(--surface-card);
  margin: 0;
  padding: 0;
}

.prompt-input {
  width: 100%;
  padding: 0;
  margin-bottom: calc(var(--prompt-actions-height) + 8px);
  min-height: 48px;
  max-height: 220px; /* cap height; allow internal scrolling past this */
  box-sizing: border-box;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 14px;
  line-height: 1.5;
  color: var(--brand-charcoal);
  font-family: inherit;
  overflow-y: auto;
  scrollbar-gutter: stable; /* avoid width jump when scrollbar appears */
}

.prompt-input:empty:before {
  content: attr(data-placeholder);
  color: #9ca3af;
}

.prompt-actions {
  position: absolute;
  left: var(--prompt-inset);
  right: var(--prompt-inset);
  bottom: var(--prompt-inset);
  height: var(--prompt-actions-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.model-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 42px);
  min-width: 0;
  font-size: 11px;
  color: var(--brand-charcoal);
}

.model-select,
.model-input {
  border: 0;
  background: transparent;
  font-size: 14px; /* align with body text on settings page */
  color: var(--brand-charcoal);
  appearance: none;
  padding: 0;
  height: auto;
  line-height: 1.4;
  font-family: inherit;
}

.model-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='10' height='10' fill='none' stroke='%232B2B2B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right center;
  padding-right: 14px;
}

.model-select:hover,
.model-input:hover {
  text-decoration: underline;
}

.model-select:focus,
.model-input:focus {
  outline: none;
  text-decoration: underline;
}

.model-input {
  border: none;
  outline: none;
  width: auto;
  min-width: 120px;
}

.separator {
  color: var(--brand-sand-300);
  font-size: 11px;
}

.send-btn { width: 28px; height: 28px; padding: 0; border: 0; background: transparent; color: var(--brand-charcoal); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.send-btn:hover { color: var(--brand-terracotta-600); filter: none; }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:focus,
.send-btn:focus-visible,
.send-btn:active { outline: none; box-shadow: none; border-radius: 999px; }
.send-btn i, .send-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; }

/* Inverted color variant for send/stop button */
.send-btn.invert {
  background: var(--brand-charcoal);
  color: var(--brand-offwhite);
  border-radius: 999px;
}
.send-btn.invert:hover { background: #504841; color: var(--brand-offwhite); }

/* During sending (Stop state): keep dark button but reduce icon size to emphasize 'stop' */
.send-btn.invert.is-sending {
  background: var(--brand-charcoal);
  color: var(--brand-offwhite);
}
.send-btn.is-sending i, .send-btn.is-sending svg { width: 14px; height: 14px; }
/* Make the stop icon a filled square (no stroke) */
.send-btn.is-sending svg,
.send-btn.is-sending svg * {
  fill: currentColor !important;
  stroke: none !important;
}

/* Chat header thread dropdown (compact) */
#chat-pane .chat-header { padding: 0; height: var(--chat-header-height); display: flex; align-items: center; font-weight: 600; border-bottom: 0; color: var(--brand-charcoal); position: relative; }
#chat-switcher {
  background: var(--surface-elevated);
  border: 1px solid var(--brand-sand-200);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
  padding: 8px;
  min-width: 220px;
  width: 320px;
  max-width: 360px;
  display: inline-block; /* prevent stretching full width */
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20; /* overlay chat content */
}
#chat-switcher[hidden] { display: none !important; }
.thread-popover-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 4px; }
.thread-popover-head .label { font-size: 12px; font-weight: 600; color: var(--brand-charcoal); opacity: 0.8; }
.thread-popover-head .filter { flex: 0 0 160px; height: 28px; border-radius: 8px; border: 1px solid var(--brand-sand-300); background: var(--surface-card); padding: 2px 8px; font-size: 12px; color: var(--brand-charcoal); }
.thread-popover-head .filter::placeholder { color: #9aa0a6; }
/* .sidebar-nav placeholder removed */
.chat-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; border-radius: 8px; }
.chat-row:hover { background: var(--brand-sand-50); }
.chat-title-btn { appearance: none; border: none; background: transparent; text-align: left; padding: 6px 8px; flex: 1; font-size: 13px; color: var(--brand-charcoal); cursor: pointer; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title-btn { font-family: var(--font-heading); }
.chat-title-btn[aria-current="true"] { font-weight: 600; }
.thread-actions { display: inline-flex; gap: 2px; }
.thread-actions .icon-btn { width: 22px; height: 22px; border: 0; background: transparent; color: var(--brand-charcoal); opacity: 0.75; }
.thread-actions .icon-btn:hover { opacity: 1; background: var(--brand-sand-50); }
.thread-actions .icon-btn svg { stroke: var(--brand-charcoal); }

/* Ensure room for scrollbar inside thread list without covering actions */
#chat-switcher #threadList { padding-right: 12px; scrollbar-gutter: stable; }

/* ─────────────────────────────────────────────────────────────────────────────
   TODO Panel - Agent verification plan (collapsible, above composer)
   ───────────────────────────────────────────────────────────────────────────── */
.todo-panel {
  padding: 0;
  margin: 0;
}
.todo-panel[hidden] { display: none !important; }

.todo-details {
  margin: 0;
  padding: 0;
}
.todo-details[open] .todo-chevron {
  transform: rotate(90deg);
}
.todo-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 13px;
  color: var(--brand-text-secondary);
}
.todo-summary::-webkit-details-marker { display: none; }
.todo-summary::marker { display: none; }
.todo-chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.todo-list {
  list-style: none;
  margin: 0;
  padding: 4px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 140px;
  overflow-y: auto;
}
.todo-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  color: var(--brand-text-secondary);
  line-height: 1.4;
}
.todo-item.in_progress {
  color: var(--brand-charcoal);
}
.todo-item.completed {
  text-decoration: line-through;
}

.todo-status-icon {
  flex-shrink: 0;
  font-size: 10px;
}

.todo-content {
  flex: 1;
  min-width: 0;
}

/* Debug panel trigger (top right) */
.debug-panel-trigger {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--brand-sand-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 120ms ease;
  z-index: 10;
}

.debug-panel-trigger:hover {
  background: var(--brand-sand-100);
  color: var(--brand-terracotta-500);
  border-color: var(--brand-sand-300);
}

.debug-panel-trigger svg {
  width: 18px;
  height: 18px;
}

/* Debug timeline button */
.debug-timeline {
  margin-top: 12px;
}

.debug-timeline-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--brand-sand-300);
  background: rgba(255, 255, 255, 0.9);
  color: var(--brand-sand-400);
  cursor: pointer;
  font-size: 11px;
  transition: all 120ms ease;
}

.debug-timeline-btn:hover {
  background: var(--brand-offwhite);
  color: var(--brand-charcoal);
  border-color: var(--brand-terracotta-stroke);
}

/* Unified focus styles */
.btn:focus-visible,
.brand-menu:focus-visible,
.export-trigger:focus-visible,
.import-trigger:focus-visible,
.icon-btn:focus-visible,
.debug-download-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-terracotta-stroke);
}

/* Thread dropdown focus-visible */
#threadList .chat-row .chat-title-btn:focus-visible,
#threadList .thread-actions .icon-btn:focus-visible,
.export-option:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-terracotta-stroke);
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.debug-timeline-btn svg {
  width: 14px;
  height: 14px;
}

/* Debug tabs */
.debug-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--brand-sand-200);
}

.debug-tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--brand-sand-400);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 120ms ease;
}

.debug-tab-btn:hover {
  color: var(--brand-charcoal);
  background: var(--brand-sand-50);
}

.debug-tab-btn.active {
  color: var(--brand-terracotta-600);
  border-bottom-color: var(--brand-terracotta-600);
}

.debug-tab-content {
  display: none;
  height: 100%;
}

.debug-tab-content.active {
  display: block;
}

/* Debug modal */
.debug-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.debug-modal {
  background: var(--surface-card);
  border-radius: var(--brand-radius-lg);
  max-width: 900px;
  max-height: 90vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.debug-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--brand-sand-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--brand-sand-100);
}

.debug-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--brand-charcoal);
}

.debug-modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-download-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--brand-sand-300);
  background: var(--surface-card);
  color: var(--brand-charcoal);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms ease;
}

.debug-download-btn:hover {
  background: var(--brand-sand-100);
  border-color: var(--brand-terracotta-stroke);
}

.debug-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--brand-sand-300);
  background: transparent;
  color: var(--brand-charcoal);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 120ms ease;
  padding: 0;
}

.debug-modal-close:hover {
  background: var(--brand-sand-200);
}

.debug-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.debug-section {
  margin-bottom: 20px;
}

.debug-section:last-child {
  margin-bottom: 0;
}

.debug-section h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-charcoal);
}

.debug-section details summary {
  cursor: pointer;
  margin-bottom: 8px;
}

.debug-code {
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--brand-charcoal);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}

/* Timeline modal split view */
.debug-timeline-modal {
  max-width: 1400px;
}

.debug-timeline-body {
  display: flex;
  gap: 0;
  padding: 0;
  height: 75vh;
}

/* Thread debug timeline - clean, no left border */
.thread-debug-row {
  margin-bottom: 16px;
}

/* Trace details expandable */
.thread-debug-trace {
  margin-top: 8px;
  border: 1px solid var(--brand-sand-200);
  border-radius: 6px;
  background: var(--brand-sand-50);
}

.thread-debug-trace summary {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-sand-400);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thread-debug-trace summary:hover {
  background: var(--brand-sand-100);
}

.thread-debug-trace summary::marker {
  color: var(--brand-terracotta-500);
}

.thread-debug-trace[open] summary {
  border-bottom: 1px solid var(--brand-sand-200);
  background: var(--brand-sand-100);
}

/* Trace content uses existing card-trace styles but refined */
.thread-debug-trace .card-trace {
  background: var(--surface-card);
  border: none;
  margin: 0;
}

.debug-calls-list {
  width: 280px;
  border-right: 1px solid var(--brand-sand-200);
  overflow-y: auto;
  background: var(--brand-sand-50);
  padding: 12px;
}

.debug-call-item {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 120ms ease;
}

.debug-call-item:hover {
  border-color: var(--brand-terracotta-stroke);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.debug-call-item.selected {
  border-color: var(--brand-terracotta-500);
  background: var(--brand-terracotta-tint);
}

.debug-call-purpose {
  font-weight: 600;
  font-size: 13px;
  color: var(--brand-charcoal);
  margin-bottom: 6px;
}

.debug-call-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--brand-sand-400);
}

.debug-call-status {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.debug-call-status.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 6px;
  border-radius: 3px;
}

.debug-call-detail {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.debug-call-detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--brand-sand-400);
  font-size: 14px;
}

.debug-call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.debug-call-detail-content h4 {
  margin: 0;
  font-size: 18px;
  color: var(--brand-charcoal);
}

.debug-view-toggle {
  display: flex;
  gap: 4px;
  background: var(--brand-sand-100);
  padding: 3px;
  border-radius: 6px;
}

.view-toggle-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-sand-400);
  cursor: pointer;
  transition: all 120ms ease;
}

.view-toggle-btn:hover {
  color: var(--brand-charcoal);
}

.view-toggle-btn.active {
  background: var(--surface-card);
  color: var(--brand-charcoal);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.debug-call-detail-content h5 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-charcoal);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.debug-call-detail-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  padding: 10px;
  background: var(--brand-sand-50);
  border-radius: 6px;
  font-size: 12px;
  color: var(--brand-charcoal);
}

.debug-call-detail-meta .warn {
  color: #d97706;
  font-weight: 600;
}

.debug-call-detail-meta .error {
  color: #dc2626;
  font-weight: 600;
}

.debug-section {
  margin-bottom: 20px;
}

.error-code {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

/* API trace and JSON dump formatting */
.api-trace {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', monospace;
  line-height: 1.5;
  white-space: pre-wrap;
}

.json-dump {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', monospace;
  line-height: 1.5;
}

/* Tool use streaming styles - legacy classes removed, see .trace-tool-call below */

/* Inline spinner - reusable component for loading states */
.loading-spinner-inline {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 6px;
  vertical-align: middle;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spinnerRotate 1.2s linear infinite;
}

@keyframes spinnerRotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Collapsible tool call block - main wrapper */
.trace-tool-call {
  margin: 8px 0;
  font-size: 13px;
}

.trace-tool-call > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: inherit;
}

.trace-tool-call > summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.trace-tool-call > summary::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.trace-tool-call[open] > summary::before {
  transform: rotate(180deg);
}

/* Hide chevron and disable interactivity for in-progress tool calls */
.trace-tool-call:has(.tool-status.pending) > summary::before,
.trace-tool-call:has(.tool-status.running) > summary::before {
  display: none;
}

.trace-tool-call:has(.tool-status.pending) > summary,
.trace-tool-call:has(.tool-status.running) > summary {
  cursor: default;
  pointer-events: none;
}

.trace-tool-call .tool-name {
  font-weight: 500;
}

.trace-tool-call .tool-status {
  opacity: 0.7;
}

.trace-tool-call .tool-status.error {
  font-weight: 600;
  opacity: 1;
}

.trace-tool-call .tool-body {
  margin-left: 16px;
  padding-top: 4px;
}

/* Nested input/result details inside tool body */
.trace-tool-input,
.trace-tool-result {
  margin-top: 4px;
  font-size: 12px;
}

.trace-tool-input summary,
.trace-tool-result summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  color: var(--brand-sand-400);
  font-weight: 500;
  padding: 2px 0;
}

.trace-tool-input summary::-webkit-details-marker,
.trace-tool-result summary::-webkit-details-marker {
  display: none;
}

/* Lucide-style chevron matching .trace-toggle */
.trace-tool-input summary::before,
.trace-tool-result summary::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23BDB5AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  transform: rotate(0deg);
  transition: transform 160ms var(--brand-ease);
}

.trace-tool-input[open] summary::before,
.trace-tool-result[open] summary::before {
  transform: rotate(180deg);
}

.trace-tool-input summary:hover,
.trace-tool-result summary:hover {
  color: var(--brand-charcoal);
}

.trace-tool-input pre,
.trace-tool-result pre {
  margin: 4px 0 0 0;
  padding: 8px;
  background: var(--surface-card);
  border-radius: 4px;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
}

/* Script execution results */
.script-image-result {
  margin: 8px 0;
}

.script-image-result img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--brand-sand-200);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.script-meta {
  font-size: 11px;
  color: var(--brand-sand-400);
  margin-top: 4px;
}

/* Hoisted chat images - rendered at top level, not inside tool calls */
.chat-image-result {
  margin: 12px 0;
  padding: 0;
}

.chat-image-result img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--brand-sand-200);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-image-result .image-meta {
  font-size: 11px;
  color: var(--brand-sand-400);
  margin-top: 6px;
}

.script-value-result {
  margin: 8px 0;
}

.script-value-result .value-display {
  font-size: 24px;
  font-weight: 600;
  color: var(--brand-terracotta-500);
  padding: 12px 16px;
  background: var(--brand-terracotta-tint);
  border-radius: 8px;
  display: inline-block;
}

.script-dataframe-result {
  margin: 8px 0;
  overflow-x: auto;
}

.dataframe-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}

.dataframe-table th {
  background: var(--brand-sand-100);
  color: var(--brand-charcoal);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--brand-sand-300);
  position: sticky;
  top: 0;
}

.dataframe-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--brand-sand-200);
  color: var(--brand-charcoal);
}

.dataframe-table tr:hover td {
  background: var(--brand-sand-50);
}

.dataframe-table tr:nth-child(even) td {
  background: var(--brand-sand-50);
}

.dataframe-table tr:nth-child(even):hover td {
  background: var(--brand-sand-100);
}

/* Thinking blocks in trace timeline */
.trace-thinking-block {
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.6; /* match streaming */
  color: inherit; /* use secondary color under steps */
  white-space: normal; /* markdown paragraphs control spacing */
}

/* Tighten markdown spacing inside thinking blocks */
.trace-thinking-block p {
  margin: 8px 0;
}

.trace-thinking-block ul,
.trace-thinking-block ol {
  margin: 8px 0;
  padding-left: 18px;
}

.trace-thinking-block li {
  margin: 4px 0;
}

/* Ensure Show steps drawer sits at a consistent position across states */
.message.assistant .trace-toggle {
  display: block;
  margin: 2px 0 4px 0; /* minimal gap - subtle, compact */
}

.message.assistant .trace-toggle > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 400;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  color: var(--brand-sand-400);
}

/* Hide default disclosure marker */
.message.assistant .trace-toggle > summary::-webkit-details-marker { display: none; }

/* Assistant narrative text in trace */
.trace-assistant-narrative {
  margin: 12px 0;
  padding: 12px;
  background: var(--brand-sand-50);
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--brand-charcoal);
}

/* --- Magic Patterns color overrides (light + dark) --- */
:root {
  --brand-offwhite: #f7f5f1;
  --brand-sand-50: #f7f5f1;
  --brand-sand-100: #ede9e3;
  --brand-sand-200: #ddd9d0;
  --brand-sand-300: #c8c2b8;
  --brand-sand-400: #b0a89d;

  --brand-charcoal: #3d3a33;
  --brand-text-secondary: #8a857d;

  --brand-terracotta-500: #c17a5f;
  --brand-terracotta-600: #d08a70;
  --brand-terracotta-tint: rgba(193, 122, 95, 0.08);
  --brand-terracotta-stroke: rgba(193, 122, 95, 0.28);

  --surface-card: #f7f5f1;
  --surface-elevated: #ede9e3;
  --surface-header: #f7f5f1;
}

body.theme-dark {
  --brand-offwhite: #1c1a17;
  --brand-sand-50: #1c1a17;
  --brand-sand-100: #2d2a25;
  --brand-sand-200: #3d3a33;
  --brand-sand-300: #47443c;
  --brand-sand-400: #545046;

  --brand-charcoal: #e8e4db;
  --brand-text-secondary: #8a857d;

  --surface-card: #1c1a17;
  --surface-elevated: #2d2a25;
  --surface-header: #1c1a17;
}

/* ========================================
   Sheet Mention System (@ mentions)
   ======================================== */

/* Mention Dropdown */
.mention-dropdown {
  position: fixed;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
}

.mention-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--brand-charcoal);
  transition: background 0.1s ease;
}

.mention-option:hover,
.mention-option.selected {
  background: var(--brand-sand-100);
}

.mention-option-icon {
  color: var(--brand-sand-400);
  display: flex;
  flex-shrink: 0;
}

.mention-option-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mention Chips (inline in chat input and messages) */
.mention-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  margin: 0 1px;
  background: var(--brand-terracotta-tint);
  border: 1px solid var(--brand-terracotta-stroke);
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--brand-terracotta-500);
  vertical-align: middle;
  user-select: none;
  cursor: default;
}

.mention-chip-icon {
  display: flex;
  align-items: center;
  opacity: 0.7;
}

.mention-chip-icon svg {
  width: 10px;
  height: 10px;
}

.mention-chip-text {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sheet mention specific styling */
.sheet-mention {
  background: var(--brand-terracotta-tint);
  border-color: var(--brand-terracotta-stroke);
  color: var(--brand-terracotta-500);
}

/* Range mention specific styling (for Phase 4) */
.range-mention {
  background: rgba(107, 142, 35, 0.1);
  border-color: rgba(107, 142, 35, 0.3);
  color: #6b8e23;
}

/* Chip in message thread (read-only context) */
.message .mention-chip {
  cursor: default;
  pointer-events: none;
}

/* Ensure chips don't add extra spacing when first element */
.message > .mention-chip:first-child,
#prompt > .mention-chip:first-child {
  margin-left: 0;
}

/* Dark mode adjustments */
body.theme-dark .mention-chip {
  background: rgba(208, 138, 112, 0.15);
  border-color: rgba(208, 138, 112, 0.3);
  color: var(--brand-terracotta-600);
}

body.theme-dark .range-mention {
  background: rgba(144, 180, 80, 0.15);
  border-color: rgba(144, 180, 80, 0.3);
  color: #90b450;
}

/* Range Action Tooltips Container (Cmd+L and Cmd+E hints) */
.range-tooltips-container {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: auto;
}

.range-action-tooltip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  opacity: 0.95;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.range-action-tooltip:hover {
  background: var(--brand-sand-50);
  border-color: var(--brand-sand-300);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
}

.range-action-tooltip:active {
  background: var(--brand-sand-100);
}

.range-action-hint {
  background: var(--brand-sand-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-weight: 600;
  font-size: 11px;
  color: var(--brand-charcoal);
}

.range-action-text {
  color: var(--brand-text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

body.theme-dark .range-action-tooltip {
  background: var(--surface-card);
  border-color: var(--brand-sand-300);
}

body.theme-dark .range-action-tooltip:hover {
  background: var(--brand-sand-100);
  border-color: var(--brand-sand-400);
}

body.theme-dark .range-action-tooltip:active {
  background: var(--brand-sand-200);
}

body.theme-dark .range-action-hint {
  background: var(--brand-sand-200);
}

/* Legacy tooltip classes for backwards compatibility */
.range-add-tooltip {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  z-index: 100;
  pointer-events: none;
  opacity: 0.95;
}

.range-add-tooltip-hint {
  background: var(--brand-sand-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-weight: 600;
  font-size: 11px;
  color: var(--brand-charcoal);
}

.range-add-tooltip-text {
  color: var(--brand-text-secondary);
  font-size: 12px;
}

body.theme-dark .range-add-tooltip {
  background: var(--surface-card);
  border-color: var(--brand-sand-300);
}

body.theme-dark .range-add-tooltip-hint {
  background: var(--brand-sand-200);
}

/* ===================================
   HOME PAGE STYLES
   =================================== */

/* Home mode: fill available space, allow content scrolling */
.container.single.home-mode {
  flex: 1;
  background: var(--surface-elevated);
  overflow-y: auto;
}

.container.single.home-mode .workspace-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.container.single.home-mode .workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Home header: minimal */
#app-header.home-header {
  height: var(--app-header-height);
  border-bottom: none;
}

/* Home page layout - matches workbooks/settings pages */
.home-page {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center; /* center children horizontally */
  justify-content: center;
  padding-bottom: 5vh;
  box-sizing: border-box;
}

/* Headline */
.home-headline {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 700;
  color: var(--brand-charcoal);
  margin: 0 0 12px;
  text-align: center;
}

.home-subline {
  font-size: 15px;
  color: var(--brand-text-secondary);
  margin: 0 0 28px;
  text-align: center;
}

/* Home prompt section - fixed width, prominent */
.home-prompt-section {
  width: min(680px, calc(100% - 40px)); /* fixed width, responsive on small screens */
  margin: 0 auto 80px; /* centered with much more space before recent workbooks */
}

.home-prompt-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-300);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  transition: border-color var(--brand-duration-1) var(--brand-ease), 
              box-shadow var(--brand-duration-1) var(--brand-ease);
}

.home-prompt-wrap:focus-within {
  border-color: var(--brand-terracotta-stroke);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.home-prompt-input {
  width: 100%;
  min-height: 52px; /* ~2 lines at 16px font with 1.6 line-height */
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 16px;
  line-height: 1.6;
  color: var(--brand-charcoal);
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

.home-prompt-input:empty::before {
  content: attr(data-placeholder);
  color: var(--brand-sand-400);
  pointer-events: none;
}

.home-prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between; /* import on left, send on right */
  gap: 8px;
}

/* File attachment chip - hidden by default */
.home-file-chip {
  display: none; /* shown via JS when file attached */
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  background: var(--brand-sand-100);
  border: 1px solid var(--brand-sand-200);
  border-radius: 20px;
  max-width: 200px;
}

.home-file-chip.visible {
  display: flex;
}

.home-file-chip > svg {
  width: 14px;
  height: 14px;
  color: var(--brand-terracotta-500);
  flex-shrink: 0;
}

.home-file-chip-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--brand-charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-file-chip-remove {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand-sand-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color var(--brand-duration-1) var(--brand-ease),
              background var(--brand-duration-1) var(--brand-ease);
}

.home-file-chip-remove:hover {
  color: var(--brand-charcoal);
  background: var(--brand-sand-200);
}

.home-file-chip-remove svg {
  width: 12px;
  height: 12px;
}

/* Import button - icon + text with border */
.home-import-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--brand-sand-300);
  background: transparent;
  color: var(--brand-sand-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 14px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  transition: color var(--brand-duration-1) var(--brand-ease),
              background var(--brand-duration-1) var(--brand-ease),
              border-color var(--brand-duration-1) var(--brand-ease);
}

.home-import-btn:hover {
  color: var(--brand-charcoal);
  background: var(--brand-sand-50);
  border-color: var(--brand-sand-400);
}

.home-import-btn[hidden] {
  display: none !important;
}

.home-import-btn svg {
  width: 14px;
  height: 14px;
}


/* Recent workbooks section */
.home-recent {
  width: 100%;
}

.home-recent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.home-recent-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-charcoal);
}

.home-recent-all {
  font-size: 13px;
  color: var(--brand-terracotta-500);
  text-decoration: none;
  font-weight: 500;
}

.home-recent-all:hover {
  text-decoration: underline;
}

/* 2-column card grid for recent workbooks */
.home-recent-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.home-recent-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: var(--brand-radius);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--brand-duration-1) var(--brand-ease),
              box-shadow var(--brand-duration-1) var(--brand-ease);
}

.home-recent-card:hover {
  border-color: var(--brand-sand-300);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.home-recent-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--brand-sand-100);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.home-recent-card-icon svg {
  width: 18px;
  height: 18px;
  color: var(--brand-sand-500);
}

.home-recent-card-content {
  flex: 1;
  min-width: 0;
}

.home-recent-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.home-recent-card-meta {
  font-size: 13px;
  color: var(--brand-sand-400);
}

.home-recent-empty {
  font-size: 14px;
  color: var(--brand-text-secondary);
  padding: 16px 0;
}

/* Hide recent section when empty */
.home-recent.is-empty {
  display: none;
}

/* Skeleton loading state (card grid) */
.home-recent-skeleton.home-recent-grid {
  gap: 12px;
}

.home-recent-skeleton-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface-card);
  border: 1px solid var(--brand-sand-200);
  border-radius: var(--brand-radius);
}

.home-recent-skeleton-card .skeleton-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.home-recent-skeleton-card .skeleton-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skeleton-icon,
.skeleton-title,
.skeleton-meta {
  background: linear-gradient(90deg, var(--brand-sand-100) 25%, var(--brand-sand-200) 50%, var(--brand-sand-100) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-title {
  height: 14px;
  width: 80%;
}

.skeleton-meta {
  width: 50%;
  height: 12px;
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Page-level drop overlay */
.home-drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.home-drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.home-drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 64px;
  background: var(--surface-card);
  border-radius: var(--brand-radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.home-drop-overlay-content svg {
  width: 48px;
  height: 48px;
  color: var(--brand-terracotta-500);
  stroke-width: 1.5;
}

.home-drop-overlay-content span {
  font-size: 18px;
  font-weight: 600;
  color: var(--brand-charcoal);
}

/* Dark theme overrides for home */
body.theme-dark .home-prompt-wrap {
  background: var(--surface-card);
  border-color: var(--brand-sand-400);
}

body.theme-dark .skeleton-icon,
body.theme-dark .skeleton-title,
body.theme-dark .skeleton-meta {
  background: linear-gradient(90deg, var(--brand-sand-200) 25%, var(--brand-sand-300) 50%, var(--brand-sand-200) 75%);
  background-size: 200% 100%;
}

/* Home loading overlay */
.home-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(244, 242, 238, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 200ms ease;
}

.home-loading-overlay.visible {
  opacity: 1;
}

body.theme-dark .home-loading-overlay {
  background: rgba(28, 26, 23, 0.9);
}

.home-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.home-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--brand-sand-200);
  border-top-color: var(--brand-terracotta-500);
  border-radius: 50%;
  animation: homeSpinner 800ms linear infinite;
}

@keyframes homeSpinner {
  to {
    transform: rotate(360deg);
  }
}

.home-loading-message {
  font-size: 14px;
  color: var(--brand-text-secondary);
}

/* Home prompt actions layout with left/right grouping */
.home-prompt-actions-left,
.home-prompt-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─────────────────────────────────────────────────────────────
   Model Mode Toggle
   Toggle between Fast (rabbit) and Thoughtful (brain) modes
   ───────────────────────────────────────────────────────────── */

.model-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--brand-sand-100);
  border-radius: 20px;
  border: 1px solid var(--brand-sand-200);
}

.model-mode-toggle .mode-btn {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand-sand-400);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  transition: color var(--brand-duration-1) var(--brand-ease),
              background var(--brand-duration-1) var(--brand-ease);
}

.model-mode-toggle .mode-btn:hover {
  color: var(--brand-charcoal);
}

.model-mode-toggle .mode-btn.active {
  background: var(--surface-card);
  color: var(--brand-charcoal);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.model-mode-toggle .mode-btn:focus,
.model-mode-toggle .mode-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-terracotta-200);
}

.model-mode-toggle .mode-btn svg,
.model-mode-toggle .mode-btn i {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .home-page {
    padding: 0 20px;
    padding-bottom: 5vh;
  }
  
  .home-headline {
    font-size: 24px;
  }
  
  .home-prompt-section {
    margin-bottom: 48px;
  }
  
  .home-recent-grid {
    grid-template-columns: 1fr;
  }
  
  .home-recent-card-meta {
    display: none;
  }
}
