/* Dark is the default: an unset data-theme means dark, and `light` is the
   opt-in the toggle writes. Both themes are the same warm palette — the
   dark one is not a separate design, just the other end of it. */
:root {
  color-scheme: dark;
  /* Aeonik is declared first to mirror the reference site's intent, but it is
     not served there (or here) so UI text resolves to Inter — exactly what the
     live workbench renders. */
  font-family: Aeonik, Inter, ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* DM Mono drives the logo, the small uppercase labels, and code/inputs. */
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    monospace;

  /* Surfaces. Black page, warm greys raised above it — the values are the
     UI study's (_misc/BioM3_UX/), converted from oklch. Note the direction:
     every surface sits *above* the page rather than recessed below it. */
  --bg: rgb(0, 0, 0);                  /* page */
  --bg-raised: rgb(16, 13, 11);        /* cards / panels */
  --bg-input: rgb(34, 30, 29);         /* fields */

  /* Neutral hairlines, not terracotta. On a black page a tinted border
     outlines every panel in rust; white at low alpha divides without
     drawing attention to the division.

     The study's own value is 12%, which is 1.27:1 against black -- invisible.
     It gets away with that because it separates regions by whitespace and has
     three sparse routes to do it in; our tool pages are fieldsets, tables and
     nested <details> that need an actual edge. 22% reads as a hairline at
     1.8:1 without becoming a grey cage (3:1 would need 36%). */
  --border: rgba(255, 255, 255, 0.22);
  --border-strong: rgba(255, 255, 255, 0.32);
  --border-hover: rgba(255, 255, 255, 0.32);

  /* Ink */
  --text: rgb(251, 243, 239);
  --text-muted: rgb(157, 151, 148);

  /* Terracotta accent — links, active-nav, quota fill, chat prompt.
     The exact brand hex: on black it reaches 5.2:1, so it needs none of
     the lightening the warm near-black page used to require. */
  --accent: rgb(224, 76, 36);
  --accent-hover: rgb(232, 110, 74);
  --accent-soft: rgba(224, 76, 36, 0.18);

  /* Cool blue-grey focus ring + sage highlight */
  --ring: rgba(116, 177, 193, 0.7);
  --ring-soft: rgba(116, 177, 193, 0.4);
  --sage: rgb(178, 210, 110);

  /* Brand accent rotation — the four non-neutral brand colors, cycled
     across nav items and prompt chips so the chrome carries the palette
     rather than one accent. The brand hexes (#E04C24 #B2D26E #74B1C1
     #DFBA51) are tuned per theme: on the near-black the sage/blue/gold
     pastels carry themselves and only the terracotta needs lifting; on
     cream those three fall under 3:1 and get darkened instead. */
  --accent-1: rgb(224, 76, 36);
  --accent-2: rgb(178, 210, 110);
  --accent-3: rgb(116, 177, 193);
  --accent-4: rgb(223, 186, 81);

  /* The composer's ring. On black the study rings it in near-solid cream
     rather than a border tint, which is what makes it the one thing on an
     empty landing page that asks to be used. */
  --composer-border: rgba(251, 243, 239, 0.8);

  /* Light "ink" on dark */
  --btn-bg: rgb(244, 234, 227);
  --btn-text: rgb(0, 0, 0);

  --error: rgb(248, 113, 113);
  --error-soft: rgba(248, 113, 113, 0.12);
  --link: rgb(224, 76, 36);

  /* Theme-aware overlay tints (replace hardcoded rgba in component rules).
     Cream-tinted rather than pure white, matching the warmth of the raised
     surfaces above. */
  --overlay: rgba(251, 243, 239, 0.07);
  --overlay-strong: rgba(251, 243, 239, 0.14);

  --radius: 8px;
  --radius-lg: 14px;
}

/* Light theme — the warm "paper" tones of the same palette (same fonts) */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: rgb(251, 243, 239);
  --bg-raised: rgb(244, 234, 227);
  --bg-input: rgb(234, 223, 214);

  --border: rgba(224, 76, 36, 0.18);
  --border-strong: rgba(224, 76, 36, 0.32);
  --border-hover: rgba(224, 76, 36, 0.32);

  --text: rgb(0, 0, 0);
  --text-muted: rgba(0, 0, 0, 0.72);

  --accent: rgb(224, 76, 36);
  --accent-hover: rgb(196, 64, 28);
  --accent-soft: rgba(224, 76, 36, 0.12);

  --ring: rgba(116, 177, 193, 0.6);
  --ring-soft: rgba(116, 177, 193, 0.4);

  --accent-1: rgb(224, 76, 36);
  --accent-2: rgb(94, 130, 42);
  --accent-3: rgb(44, 108, 128);
  --accent-4: rgb(148, 113, 20);

  /* Paper keeps the terracotta ring — a cream one would vanish here. */
  --composer-border: rgba(224, 76, 36, 0.32);

  /* Ink primary button on paper */
  --btn-bg: rgb(0, 0, 0);
  --btn-text: rgb(251, 243, 239);

  --error: rgb(192, 57, 43);
  --error-soft: rgba(192, 57, 43, 0.1);
  --link: rgb(196, 64, 28);

  --overlay: rgba(0, 0, 0, 0.05);
  --overlay-strong: rgba(0, 0, 0, 0.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
a { color: var(--link); }

/* ---------- Logged-out: centered login ---------- */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.auth-card {
  max-width: 28rem;
  text-align: center;
}
.auth-card h1 {
  font-size: clamp(2rem, 5vw, 2.5rem);
  margin: 0 0 0.5rem;
  font-weight: 500;
  letter-spacing: -0.025em;
}
.auth-brand {
  margin: 0 0 1rem;
}
.auth-logo {
  width: 100%;
  max-width: 18rem;
  height: auto;
}
/* Logo art is pure black on transparent, so it needs flipping on the (now
   default) dark background and leaving alone on paper. */
.auth-logo {
  filter: invert(1);
}
:root[data-theme="light"] .auth-logo {
  filter: none;
}
.auth-card p {
  margin: 0.25rem 0 1.5rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- Buttons ---------- */
button {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease, border-color 0.15s ease;
}
button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.12);
}
button:active { transform: translateY(0); box-shadow: none; }
button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
button.secondary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}
button.secondary:hover { border-color: var(--border-hover); }

/* ---------- App shell (logged in) ---------- */
.app {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main";
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
  transition: grid-template-columns 180ms ease;
}
/* Collapsing the nav is what gives the chat its full width on the home
   route. Column goes to zero rather than the sidebar going display:none,
   so the transition has something to animate. */
.app.sidebar-collapsed { grid-template-columns: 0 1fr; }
.app.sidebar-collapsed .app-sidebar {
  overflow: hidden;
  padding-left: 0;
  padding-right: 0;
}
/* Header and sidebar sit directly on the page background — no raised bar,
   no dividing rules. The content column is what the eye should land on. */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: transparent;
}
.app-header .sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.3rem 0.4rem;
  margin-right: 0.35rem;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 150ms ease, color 120ms ease;
}
.app-header .sidebar-toggle:hover {
  color: var(--text);
  background: var(--overlay-strong);
  box-shadow: none;
}
.app.sidebar-collapsed .app-header .sidebar-toggle { transform: rotate(-90deg); }
.app-header .header-left {
  display: flex;
  align-items: center;
}
.app-header .brand-link {
  text-decoration: none;
  color: inherit;
}
.app-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}
.app-header .brand-logo {
  display: block;
  height: 20px;
  width: auto;
}
.app-header .brand-logo {
  filter: invert(1);
}
:root[data-theme="light"] .app-header .brand-logo {
  filter: none;
}
.app-header .brand small {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.app-header .profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.app-header .profile .who { color: var(--text-muted); }
.app-header .profile .who strong { color: var(--text); font-weight: 500; }
.app-header .profile .settings-cog {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
}
.app-header .profile .settings-cog:hover {
  color: var(--text);
  background: var(--overlay-strong);
}

/* ---------- Settings page layout ---------- */
.settings {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.5rem;
  max-width: 64rem;
}
.settings-sidenav { display: flex; flex-direction: column; }
.settings-sidenav .section-label {
  padding: 0.5rem 0 0.5rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}
.settings-sidenav a {
  display: block;
  padding: 0.45rem 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.settings-sidenav a:hover {
  color: var(--text);
  background: var(--overlay);
}
.settings-sidenav a.active {
  color: var(--text);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.settings-content { max-width: 44rem; }
.settings-content h2 { margin-top: 0; }

/* Admin link in settings sub-nav is hidden unless the user is in admins */
.settings-nav-admin { display: none; }
body.is-admin .settings-nav-admin { display: block; }

/* Account description list */
.account-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  margin: 1rem 0;
}
.account-dl dt {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  align-self: center;
}
.account-dl dd { margin: 0; word-break: break-all; }

/* Transparent, but not unbounded: the nav keeps a right edge so the content
   column reads as a column. Losing the raised fill was the point; losing the
   boundary with it left the two regions running together. */
.app-sidebar {
  grid-area: sidebar;
  background: transparent;
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  overflow-y: auto;
}
/* Collapsed, the edge would sit against the window with nothing behind it. */
.app.sidebar-collapsed .app-sidebar { border-right: none; }
.app-sidebar .section-label {
  padding: 0.5rem 1rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}
.app-sidebar nav a {
  display: block;
  padding: 0.5rem 1rem 0.5rem 1.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: color 120ms ease;
}
/* Hover tints the label rather than filling the row. Each nav block cycles
   the four brand accents so the palette shows up in the chrome; --nav-accent
   is set per <nav> below and inherited by the links inside it. */
.app-sidebar nav a:hover,
.app-sidebar summary.nav-group-label:hover {
  color: var(--nav-accent, var(--accent));
  background: transparent;
}
.app-sidebar nav:nth-of-type(4n + 1) { --nav-accent: var(--accent-1); }
.app-sidebar nav:nth-of-type(4n + 2) { --nav-accent: var(--accent-2); }
.app-sidebar nav:nth-of-type(4n + 3) { --nav-accent: var(--accent-3); }
.app-sidebar nav:nth-of-type(4n + 4) { --nav-accent: var(--accent-4); }
.app-sidebar nav .nav-empty {
  display: block;
  padding: 0.5rem 1rem 0.5rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}
/* Marked with weight and a rule, not a filled block — a tinted slab was
   legible against the old raised sidebar but is the loudest thing on the
   page now that the sidebar is transparent. */
.app-sidebar nav a.active {
  background: transparent;
  border-left-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}
.app-sidebar .nav-group-label {
  padding: 0.4rem 1rem 0.15rem 1.5rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin-top: 0.25rem;
}
.app-sidebar summary.nav-group-label {
  position: relative;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.app-sidebar summary.nav-group-label::-webkit-details-marker { display: none; }
.app-sidebar summary.nav-group-label::before {
  content: "›";
  position: absolute;
  left: 0.55rem;
  top: 50%;
  transform: translateY(-55%);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  transition: transform 150ms ease;
}
.app-sidebar details.nav-group[open] > summary.nav-group-label::before {
  transform: translateY(-55%) rotate(90deg);
}
.app-sidebar nav a.nav-child {
  padding-left: 2.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.app-sidebar nav a.nav-child.active { color: var(--text); }

.app-main {
  grid-area: main;
  padding: 1.5rem 2rem;
  overflow-y: auto;
}
.app-main h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.015em;
}
.app-main .hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Welcome card on the home view */
.welcome {
  max-width: 36rem;
  padding: 1.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.welcome h2 { margin-top: 0; }
.welcome ul { padding-left: 1.25rem; color: var(--text-muted); }
.welcome ul li { margin: 0.4rem 0; }

/* Home view: My Jobs + Reference Data tables */
.home-section {
  max-width: 56rem;
  margin-top: 2rem;
}
.home-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}
.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: var(--overlay);
  color: var(--text-muted);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .muted { color: var(--text-muted); }
.data-table .mono {
  font-family: var(--mono);
  font-size: 0.85rem;
}
.data-table .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1rem;
}

/* Global-data directory tree (My Data → Global data). Folders are native
   collapsible <details>; files are flex rows. Nested levels are indented
   with a guide border. */
.data-tree {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
}
.data-tree .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1rem;
}
.data-tree-dir > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.3rem 0.4rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-radius: 4px;
  user-select: none;
}
.data-tree-dir > summary::-webkit-details-marker { display: none; }
.data-tree-dir > summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--accent);
  transition: transform 0.12s ease;
}
.data-tree-dir[open] > summary::before { transform: rotate(90deg); }
.data-tree-dir > summary:hover { background: var(--overlay); }
/* Indent + guide line for everything nested under a folder. */
.data-tree-dir > *:not(summary) {
  margin-left: 1em;
  padding-left: 0.4rem;
  border-left: 1px solid var(--border);
}
.data-tree-file {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
}
.data-tree-file:hover { background: var(--overlay); }
.data-tree-name { flex: 1 1 auto; overflow-wrap: anywhere; }
.data-tree-size { flex: 0 0 auto; font-size: 0.8rem; }
.data-tree-dl { flex: 0 0 auto; }

/* My Jobs: toolbar above table (count + page-size selector) */
.data-page .data-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.data-page .data-toolbar label { color: var(--text-muted); }
.data-page .data-toolbar select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  margin-left: 0.4rem;
  font-size: 0.85rem;
  font-family: inherit;
}
.data-page .data-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.data-page .data-toolbar button.pager-btn {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.data-page .data-toolbar button.pager-btn:hover:not(:disabled) {
  background: var(--bg-raised);
}
.data-page .data-toolbar button.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* My Jobs: clickable rows + preview pane */
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--overlay); }
.data-table tr.clickable.active {
  background: var(--accent-soft);
}
.data-page { max-width: 64rem; }
.data-page h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}
.job-preview {
  padding: 1rem 1.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  min-height: 6rem;
}
.job-preview.muted { color: var(--text-muted); }
.job-preview.error { border-color: var(--error); color: var(--error); }
.preview-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}
.preview-dl dt {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  align-self: center;
}
.preview-dl dd {
  margin: 0;
  word-break: break-all;
}
.preview-dl .error-text { color: var(--error); }

/* My Data: section header with action button */
.home-section .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
}
.home-section .section-head h3 { margin: 0; }
.home-section .section-head button { padding: 0.35rem 0.9rem; font-size: 0.85rem; }
.home-section .section-foot {
  display: flex;
  justify-content: flex-start;
  margin: 0.75rem 0 0;
}
.home-section .section-foot button { padding: 0.35rem 0.9rem; font-size: 0.85rem; }
.data-table .delete-link {
  color: var(--error);
  text-decoration: none;
}
.data-table .delete-link:hover { text-decoration: underline; }

/* Upload modal form layout */
#dataUploadForm .field { display: block; margin-top: 0.6rem; }
#dataUploadForm input[type="text"],
#dataUploadForm input[type="file"],
#dataUploadForm select,
#dataUploadForm textarea {
  width: 100%;
  margin-top: 0.25rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  font-size: 0.9rem;
}
#dataUploadForm textarea { resize: vertical; }
#dataUploadForm input[type="text"]:focus,
#dataUploadForm select:focus,
#dataUploadForm textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px var(--ring-soft);
}

/* Quota meter on My Data */
.quota-meter {
  margin: 0.5rem 0 0.75rem;
}
.quota-meter-track {
  height: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.quota-meter-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}
.quota-meter-fill.near-full { background: var(--error); }
.quota-meter-label {
  font-size: 0.78rem;
  margin-top: 0.25rem;
}

/* Tool / workflow view */
.workflow {
  max-width: 48rem;
}
.workflow .field {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.workflow textarea,
.workflow input[type="text"],
.workflow input[type="number"],
.workflow input[type="file"],
.workflow select {
  width: 100%;
  margin-top: 0.25rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.workflow textarea:focus,
.workflow input[type="text"]:focus,
.workflow input[type="number"]:focus,
.workflow select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px var(--ring-soft);
}
.workflow input:disabled,
.workflow select:disabled,
.workflow textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.workflow textarea {
  min-height: 12rem;
  resize: vertical;
}
.workflow .field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.6rem;
  margin-top: 0.75rem;
}
.workflow .field-row .field { margin-top: 0; }
.workflow .arg-group {
  margin: 1rem 0 0;
  padding: 0.6rem 1rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.workflow .arg-group > legend {
  padding: 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.01em;
}
.workflow .arg-group .field:first-of-type { margin-top: 0.25rem; }
.workflow .arg-group .field-row:first-of-type { margin-top: 0.25rem; }
.workflow .arg-group.is-inactive .field,
.workflow .arg-group.is-inactive .field-row { opacity: 0.5; }
.workflow .arg-group .field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text);
}
.workflow .arg-group .field-checkbox input { margin: 0; }
/* Field picker (the dataset-build tools). The field list runs to ~28 entries,
   so it is laid out in columns and grouped: a single flat column would push
   the submit button off the screen and give no sense of what relates to what. */
.workflow .field-picker {
  margin-top: 0.5rem;
}
.workflow .field-picker-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.workflow .field-picker-group {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.workflow .field-picker-heading {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.workflow .field-picker-group .field-checkbox {
  display: inline-flex;
  width: 15rem;
  margin-right: 0.75rem;
  vertical-align: top;
}
.workflow .link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}
.workflow .link-button:hover { color: var(--text); }

.workflow details.advanced {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--bg-raised);
}
.workflow details.advanced > summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.workflow details.advanced[open] > summary { margin-bottom: 0.25rem; }
.workflow .actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.workflow .status {
  margin-top: 1rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
}
.workflow .status.error {
  border-color: var(--error);
  color: var(--error);
}

/* Upload control: a <label> styled as a button (it drives a hidden file input,
   which a real <button> cannot do), plus the notice line that replaces the
   textarea once a file is attached. */
.workflow .upload-btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}
.workflow .upload-btn:hover { border-color: var(--border-hover); }
/* A previewed upload: readable and scrollable, but not editable. Deliberately
   NOT the greyed :disabled treatment — the whole point is that you can read
   it. The tint plus the notice line above carry the "this is the file, not
   your typing" signal. */
.workflow textarea.is-preview {
  background: var(--bg-raised);
  cursor: default;
}
.workflow .upload-notice {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.workflow .upload-notice strong {
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
}
.workflow .upload-notice.error {
  border-color: var(--error);
  color: var(--error);
}
.workflow .upload-notice .link-btn {
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.workflow .upload-notice .link-btn:hover { transform: none; }

/* Resumed-jobs strip on the SCA tool */
#myscaResumedJobs {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
#myscaResumedJobs:empty { display: none; }
.resumed-job {
  padding: 0.5rem 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.resumed-job .label {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-bottom: 0.15rem;
}

/* Reference-picker dialog */
.picker-dialog {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 32rem;
  width: 90vw;
}
.picker-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.picker-dialog h3 { margin: 0 0 0.5rem; }

/* MCP key reveal — the plaintext value shown once after generation. */
.mcp-key-reveal {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.mcp-key-reveal code {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.82rem;
  word-break: break-all;
  color: var(--text);
}
.mcp-key-reveal button {
  flex: 0 0 auto;
}
.picker-list {
  margin-top: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.picker-row .meta { font-size: 0.8rem; color: var(--text-muted); }
.picker-row button { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.picker-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1rem;
}

/* Inline "no job selected" row for the prior-job picker (Core tool) */
.prior-job-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.prior-job-row #myscaPriorJobDisplay {
  flex: 1;
  font-size: 0.85rem;
}
.prior-job-row button { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

/* ---------- Home view: inline chat ---------- */
/* Shared by the home route and the thermostability workbench. Only the
   home partial carries #homeChat and the `.empty` landing state; the
   workbench keeps its own intro paragraph as a direct child, which is
   why the hero/suggestion hiding below is scoped to .home-chat-hero and
   .home-suggestions rather than to .home-chat-intro. */
/* .home-chat's height:100% only resolves if its parent has a definite
   height, and #appContent is auto. Establish it here — scoped to the chat
   views — rather than changing the height chain for the other ~30 views.
   Without this the log never scrolls and the composer drifts down the page
   instead of staying pinned. */
#appContent:has(> .home-chat) { height: 100%; }

.home-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0.75rem;
}
.home-chat-intro { margin: 0; }
.chat-host {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* --- Landing state --- */
.home-chat-hero,
.home-suggestions { display: none; }

.home-chat.empty {
  justify-content: center;
  gap: 1.75rem;
  /* Sit the stack slightly above true center — optically centered rather
     than measured, and it leaves room for the transcript to grow down. */
  padding-bottom: 8vh;
}
.home-chat.empty .home-chat-hero { display: flex; }
.home-chat.empty .home-suggestions { display: flex; }
.home-chat.empty .chat-host { flex: 0 0 auto; overflow: visible; }
/* Nothing in the log yet, so the scroll region would only add dead space. */
.home-chat.empty .chat-log { display: none; }

.home-chat-hero {
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}
.brand-mark {
  height: 2.5rem;
  width: auto;
  color: var(--text);
}
.home-chat-hero .home-chat-intro {
  max-width: 30rem;
  text-align: center;
}

.home-suggestions {
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}
.home-suggestions .suggestion {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  transition: color 120ms ease, border-color 120ms ease;
}
.home-suggestions .suggestion:hover {
  color: var(--chip);
  border-color: var(--chip);
  background: transparent;
  transform: none;
  box-shadow: none;
}
.home-suggestions .suggestion:nth-child(4n + 1) { --chip: var(--accent-1); }
.home-suggestions .suggestion:nth-child(4n + 2) { --chip: var(--accent-2); }
.home-suggestions .suggestion:nth-child(4n + 3) { --chip: var(--accent-3); }
.home-suggestions .suggestion:nth-child(4n + 4) { --chip: var(--accent-4); }

/* When #chatPanel is relocated into .chat-host, drop the drawer styling
 * (fixed position, slide-in transform, left border + shadow) and let it
 * fill the container as a normal flex child. */
.chat-panel.chat-inline {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  max-width: none;
  background: transparent;
  border-left: none;
  box-shadow: none;
  transform: none !important;
  transition: none;
  flex: 1 1 auto;
}
/* Inline, the transcript is a reading column rather than a full-bleed
   panel — the composer tracks the same measure so the two stay aligned. */
.chat-panel.chat-inline .chat-log,
.chat-panel.chat-inline .chat-shell,
.chat-panel.chat-inline .chat-hint,
.chat-panel.chat-inline .chat-panel-header {
  width: 100%;
  max-width: 44rem;
  margin-left: auto;
  margin-right: auto;
}
.chat-panel.chat-inline .chat-panel-header {
  background: transparent;
  border-bottom: none;
  justify-content: flex-end;
}
/* Inline, the page *is* the assistant — the drawer's title only earns its
   space when the panel is floating over another view. */
.chat-panel.chat-inline .chat-panel-title { display: none; }
/* ...except in history mode, where it's the only label on the list. */
.chat-panel.chat-inline:has(#chatHistoryView:not([hidden])) .chat-panel-title {
  display: block;
}
/* Landing state has one visible affordance: the composer — the header's
   controls act on a conversation that doesn't exist yet. History mode is
   the exception, and syncHomeChatState drops `.empty` for it so the back
   button stays reachable. */
.home-chat.empty .chat-panel-header { display: none; }
.home-chat.empty .chat-shell { margin-bottom: 0; }

/* ---------- Assistant chat panel (right-side drawer) ---------- */
.chat-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  z-index: 49;
}
.chat-toggle:hover { background: var(--accent-hover); }

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: -6px 0 18px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 200ms ease;
}
.chat-panel.open { transform: translateX(0); }

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex: 0 0 auto;
}
.chat-panel-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}
.chat-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.2rem 0.45rem;
  line-height: 1;
  border-radius: 4px;
}
.chat-icon-btn:hover {
  color: var(--text);
  background: var(--overlay-strong);
  transform: none;
  box-shadow: none;
}

.chat-shell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0.75rem;
  background: var(--bg-raised);
  border: 2px solid var(--composer-border);
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  font-family: var(--mono);
  flex: 0 0 auto;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.chat-shell:focus-within {
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--overlay-strong);
}
.chat-shell .prompt {
  color: var(--accent);
  user-select: none;
}
.chat-shell input {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
  min-width: 0;
}
.chat-shell input::placeholder { color: var(--text-muted); }

.chat-hint {
  margin: 0 0.75rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: left;
  flex: 0 0 auto;
}
/* No hint text -> collapse it entirely (no empty-gap above the input). */
.chat-hint:empty {
  display: none;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem;
  min-height: 0;
}

/* ---------- Past-conversations view (history mode) ---------- */
.chat-history {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-history-status {
  padding: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}
.chat-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.chat-history-list li {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
}
.chat-history-list li:hover { background: var(--overlay); }
.chat-history-list li.active { background: var(--accent-soft); }
.chat-history-preview {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-history-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.chat-message {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 90%;
}
.chat-message.user {
  background: var(--bg-input);
  border-radius: var(--radius-lg);
  align-self: flex-end;
  max-width: 80%;
}
/* The assistant gets no bubble. Its turns are long rendered markdown —
   headings, lists, tables — and a card around that reads as a quotation
   of the page rather than the page itself. Only the user's turns are
   short enough to want a container, which is also what distinguishes the
   two speakers now that the assistant has no frame. */
.chat-message.assistant {
  background: transparent;
  border: none;
  padding: 0.25rem 0;
  align-self: stretch;
  max-width: 100%;
  /* assistant turns hold rendered markdown (real block elements), so
     the pre-wrap used for plain-text user/error bubbles would add stray
     gaps between blocks. Let the elements own their own spacing. */
  white-space: normal;
}
/* ---- Rendered-markdown elements inside assistant bubbles ---- */
.chat-message.assistant > :first-child { margin-top: 0; }
.chat-message.assistant > :last-child { margin-bottom: 0; }
.chat-message.assistant p { margin: 0.5rem 0; }
.chat-message.assistant ul,
.chat-message.assistant ol {
  margin: 0.5rem 0;
  padding-left: 1.4rem;
}
.chat-message.assistant li { margin: 0.15rem 0; }
.chat-message.assistant li > ul,
.chat-message.assistant li > ol { margin: 0.15rem 0; }
.chat-message.assistant h1,
.chat-message.assistant h2,
.chat-message.assistant h3,
.chat-message.assistant h4 {
  margin: 0.75rem 0 0.35rem;
  line-height: 1.25;
  font-weight: 600;
}
.chat-message.assistant h1 { font-size: 1.15rem; }
.chat-message.assistant h2 { font-size: 1.05rem; }
.chat-message.assistant h3 { font-size: 0.95rem; }
.chat-message.assistant h4 { font-size: 0.88rem; }
.chat-message.assistant blockquote {
  margin: 0.5rem 0;
  padding: 0.1rem 0.75rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.chat-message.assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}
.chat-message.assistant table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.8rem;
  display: block;
  overflow-x: auto;
}
.chat-message.assistant th,
.chat-message.assistant td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.55rem;
  text-align: left;
}
.chat-message.assistant th {
  background: var(--bg-input);
  font-weight: 600;
}
.chat-message.error {
  background: var(--error-soft);
  border-color: var(--error);
  color: var(--error);
  align-self: flex-start;
}
.chat-message pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  margin: 0.35rem 0;
  overflow-x: auto;
  font-size: 0.78rem;
  white-space: pre;
}
.chat-message code {
  font-family: var(--mono);
  font-size: 0.85em;
}
.chat-message :not(pre) > code {
  background: var(--bg-input);
  padding: 0.05em 0.3em;
  border-radius: 3px;
}
.chat-message pre code { display: block; font-size: inherit; }
.chat-message a {
  color: var(--link);
  text-decoration: underline;
}
.chat-message strong { font-weight: 600; }
.chat-message em { font-style: italic; }
/* Tool calls are a collapsed <details> disclosure: de-emphasized by
   default so the prose answer leads, with the full JSON one click away. */
.chat-tool {
  align-self: flex-start;
  max-width: 90%;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-left: 2px solid var(--border-strong);
  margin: 0.05rem 0;
}
.chat-tool > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.15rem 0.5rem;
  font-family: var(--mono);
  user-select: none;
}
.chat-tool > summary::-webkit-details-marker { display: none; }
.chat-tool > summary:hover { color: var(--text); }
.chat-tool[open] { border-left-color: var(--accent); }
.chat-tool.error { border-left-color: var(--error); }
.chat-tool.error > summary { color: var(--error); }
.chat-tool > pre {
  margin: 0.1rem 0 0.3rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-input);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.7rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}
.chat-pending {
  align-self: flex-start;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
}

/* Thinking indicator — the two brand solids, pulsing out of phase and
   cycling the palette. Replaces the italic "Thinking…" while a turn is in
   flight; the plain .chat-pending text is still used for the (much
   shorter) conversation-load wait. */
.chat-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0;
}
.chat-thinking svg {
  height: 1.6rem;
  width: 1.6rem;
  overflow: visible;
}
.chat-thinking .mark-a,
.chat-thinking .mark-b {
  transform-origin: center;
  transform-box: fill-box;
}
.chat-thinking .mark-a { animation: nm-pulse-a 1.8s ease-in-out infinite; }
.chat-thinking .mark-b { animation: nm-pulse-b 1.8s ease-in-out infinite; }
.chat-thinking .thinking-label {
  font-family: var(--mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

@keyframes nm-pulse-a {
  0%, 100% { transform: scale(0.55); fill: var(--accent-1); }
  25%      { transform: scale(1);    fill: var(--accent-4); }
  50%      { transform: scale(0.55); fill: var(--accent-2); }
  75%      { transform: scale(0.55); fill: var(--accent-3); }
}
@keyframes nm-pulse-b {
  0%, 100% { transform: scale(0.55); fill: var(--accent-3); }
  25%      { transform: scale(0.55); fill: var(--accent-2); }
  50%      { transform: scale(0.55); fill: var(--accent-4); }
  75%      { transform: scale(1);    fill: var(--accent-1); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-thinking .mark-a,
  .chat-thinking .mark-b {
    animation: none;
    fill: var(--text-muted);
  }
}

.error-banner {
  margin: 1rem auto;
  max-width: 36rem;
  padding: 0.6rem 0.75rem;
  background: var(--error-soft);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-align: center;
}

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
