
:root {
  --ink:          #1F1E1D;
  --ink-2:        #2E2C2A;
  --ink-3:        #6B6762;
  --ink-4:        #A4A09A;
  --border:       #E6E1D8;
  --border-2:     #D2CCC0;
  --sage:         #C3D4B6;
  --sage-soft:    #E7EEDC;
  --sage-ink:     #3F5A32;
  --clay:         #B85C3E;
  --clay-soft:    #F1DDCD;
  --bg:           #FAF7F1;
  --bg-card:      #FFFFFF;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
/* Bumped 14→16 to reduce squint. Side-effect: card-internal text-[12px]/[13px]
   classes (Tailwind-like) inherit unchanged but most prose flows from body. */
.serif { font-family: 'Instrument Serif', Georgia, serif; font-weight: 400; letter-spacing: -0.01em; }
.serif-it { font-family: 'Instrument Serif', Georgia, serif; font-style: italic; font-weight: 400; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-feature-settings: "zero" 0, "calt" 0; }

/* ── TOP NAV ─────────────────────────────────────────── */
/* Softened 2026-05-12 to match the main Cortex page's editorial chrome —
   transparent over the body background instead of a separate white bar,
   no harsh border, slimmer vertical padding. */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 32px; background: transparent;
  border-bottom: 1px solid rgba(216, 207, 190, 0.5);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
/* Triangle mark matches the main Cortex brand identity (index.html sidebar).
   SVG path: M12 2 L4 22 L12 17 L20 22 Z — upward-pointing A/triangle.
   No background fill, just ink stroke — quieter than the old solid clay box. */
.brand-mark { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { font-family: 'Inter', system-ui, sans-serif; font-size: 16px; font-weight: 600; letter-spacing: -0.005em; color: var(--ink); }
.brand-sub { font-size: 10px; color: var(--ink-4); letter-spacing: 0.12em; text-transform: uppercase; font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.nav { display: flex; gap: 4px; }
.nav-item {
  padding: 8px 16px; border-radius: 6px; font-size: 13px; color: var(--ink-3);
  text-decoration: none; cursor: pointer; transition: all 0.15s ease;
}
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.active { background: var(--clay-soft); color: var(--clay); font-weight: 500; }

/* ── MAIN LAYOUT (2-column · chat collapsed to floating bubble) ─────────── */
.studio {
  display: grid; grid-template-columns: 280px 1fr; gap: 0;
  min-height: 100vh;
}

/* ── PIPELINE (left) ────────────────────────────────── */
/* Sticky sidebar — pins to viewport top (no topbar above it as of 2026-05-23).
   Internal scroll if bid list overflows.  align-self:start prevents the grid
   from stretching it to match the workspace's height. */
.pipeline {
  /* Tan/beige sidebar to match the master Cortex dashboard's editorial
     palette.  Body stays --bg cream so cards on the workspace pop in white;
     the sidebar gets the slightly-darker --cream #F5F1EB tone. */
  background: var(--cream); border-right: 1px solid var(--border); padding: 20px 0 0;
  position: sticky; top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  display: flex; flex-direction: column;
}
/* ── Sidebar brand row + tenant block (cloned from index.html .sb-brand
       + .sb-label + .sb-org-picker) ───────────────────────────────────── */
.sb-brand-row {
  display: flex; align-items: center; gap: 9px;
  padding: 0 24px 12px;
}
.sb-brand-mark { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.sb-brand-mark svg { width: 22px; height: 22px; stroke: var(--ink); stroke-width: 1.5; fill: none; }
.sb-brand-name {
  font-family: 'Inter', system-ui, sans-serif; font-size: 16px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.005em;
}
.sb-label {
  font-family: 'JetBrains Mono', monospace; font-size: 9.5px; font-weight: 500;
  color: var(--ink-4); letter-spacing: 0.16em; text-transform: uppercase;
  padding: 16px 24px 6px;
}
.sb-tenant {
  padding: 0 24px 4px;
  font-family: 'Inter', system-ui, sans-serif; font-size: 13px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 6px;
}
.sb-tenant .sb-caret { color: var(--ink-4); font-size: 11px; }
/* Bottom-sticky CTA · upload bid folder (replaces the topbar button) */
.sb-upload-cta {
  margin-top: auto;
  padding: 16px 18px 22px;
  border-top: 1px solid var(--border);
}
.sb-upload-cta button {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px; background: var(--clay); color: white; border: none;
  border-radius: 6px; font-family: inherit; font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em; cursor: pointer; transition: background 0.12s;
}
.sb-upload-cta button:hover { background: #a14d23; }
.pipeline-head { padding: 0 24px 12px; }
.pipeline-title { font-family: 'Instrument Serif', Georgia, serif; font-size: 18px; }
.pipeline-meta { font-size: 11px; color: var(--ink-4); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 4px; }
.dropzone {
  margin: 12px 24px; padding: 18px 16px; text-align: center;
  border: 1.5px dashed var(--border-2); border-radius: 10px; background: var(--bg);
  cursor: pointer; transition: all 0.15s ease;
}
.dropzone:hover { background: var(--clay-soft); border-color: var(--clay); }
.dropzone-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.dropzone-sub { font-size: 11px; color: var(--ink-4); }
.stage-label {
  padding: 16px 24px 6px; font-size: 10px; font-weight: 500;
  color: var(--ink-4); letter-spacing: 0.1em; text-transform: uppercase;
}
.bid-card {
  padding: 12px 24px; cursor: pointer; transition: all 0.15s ease;
  border-left: 3px solid transparent;
}
.bid-card:hover { background: var(--bg); }
.bid-card.active { background: var(--bg); border-left-color: var(--clay); }
.bid-id { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--clay); font-weight: 500; }
.bid-name { font-size: 14px; font-weight: 500; margin-top: 2px; line-height: 1.3; }
.bid-meta { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.bid-amount { font-family: 'JetBrains Mono', monospace; font-size: 14px; color: var(--ink); margin-top: 4px; }
.chip {
  display: inline-block; padding: 2px 8px; font-size: 10px;
  border-radius: 999px; font-weight: 500; letter-spacing: 0.04em;
}
.chip-clay { background: var(--clay-soft); color: var(--clay); }
.chip-sage { background: var(--sage-soft); color: var(--sage-ink); }
.chip-ink  { background: #EFECE6; color: var(--ink-3); }

/* ── WORKSPACE (center) ─────────────────────────────── */
.workspace { padding: 32px 32px 64px; overflow-y: auto; min-width: 0; }
/* The ingest-status banner (#cortex-ingest-statusbar) is position:fixed over the
   top of the workspace (top:12px, 54px tall, z-index 8500). Without clearance it
   sits on top of the home header — hiding the "Start new bid" button. When the
   banner is showing, pad the workspace top so content drops below it.
   SY 2026-07-12: "i cant see the start a new bid button". */
body:has(#cortex-ingest-statusbar:not([hidden])) .workspace { padding-top: 82px; }
.ws-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.ws-title { font-family: 'Instrument Serif', Georgia, serif; font-size: 32px; line-height: 1.1; letter-spacing: -0.02em; }
.ws-sub { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.ws-budget { text-align: right; }
.ws-budget-val { font-family: 'Instrument Serif', Georgia, serif; font-size: 36px; color: var(--clay); letter-spacing: -0.02em; line-height: 1; }
.ws-budget-lab { font-size: 11px; color: var(--ink-4); margin-top: 4px; letter-spacing: 0.06em; text-transform: uppercase; }
@media (max-width: 720px) {
  .studio { display: block; min-width: 0; }
  .pipeline {
    position: relative;
    width: 100%;
    height: auto;
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .workspace { width: 100%; padding: 18px 12px 48px; }
  .ws-head { gap: 14px; flex-wrap: wrap; }
  .ws-budget { text-align: left; }
}

/* minmax(0,1fr) not 1fr — 1fr has an implicit min-content floor, so a wide
   nowrap filename in Card 2 forced the column to ~1972px and the whole grid
   ran off the right edge (SY 2026-06-09 "fix formatting for everything"). */
.layer-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 24px; }
/* numeric cells must NEVER wrap mid-digit — minmax(0,1fr) lets columns shrink below content width (SY 2026-06-10) */
td.num, .num, .phase-rownum, td[class*=money], .c5 td:not(:nth-child(2)) { white-space: nowrap; }

/* ROOT CAUSE of the Card-5 mid-digit wrap (SY 2026-06-10): the buildup table
   #ws-table lives in a .panel, which sets `overflow-wrap: anywhere` (for long
   filenames). That broke EVERY cell at any character — "$1,673"→"$1,67/3",
   header "MATERIAL"→"MATERI/AL" — AND let columns collapse to 1-char width, so
   the table looked squeezed with empty space on the right. Restore normal
   word-handling on the table; numbers + headers never break; columns size to
   content and the table uses the available width (scrolls if it exceeds). */
#ws-table, #ws-table th, #ws-table td { overflow-wrap: normal; word-break: keep-all; }
#ws-table th { white-space: nowrap; }

.panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px;
  min-width: 0;                 /* let the panel shrink inside the grid cell */
  overflow-wrap: anywhere;      /* long filenames / urls wrap instead of pushing width */
}
#single-bid-view { width: 100%; max-width: none; }
#single-bid-view .panel { width: 100%; box-sizing: border-box; }
.panel-tag { font-size: 10px; font-weight: 500; color: var(--clay); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 10px; }
.panel-title { font-size: 15px; font-weight: 500; margin-bottom: 12px; }

/* ───────────────────────────────────────────────────────────────────
   .tip — hover-tooltip for jargon terms.  Adds a dotted underline so
   users know the term is explainable.  On hover, a dark tooltip pops
   up above with the plumber-friendly explanation.  Steven 2026-05-21:
   "make it so 60-year-old plumbers can use this".
   Usage: <span class="tip" data-tip="...">P(win)</span>
   ─────────────────────────────────────────────────────────────────── */
.tip {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted currentColor;
  text-decoration: none;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--ink, #1F1E1D);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.01em;
  font-family: 'Inter', sans-serif;
  font-style: normal;
  text-transform: none;
  width: 280px;
  white-space: normal;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transform: translateY(2px);
  transition: opacity 0.12s ease-out, transform 0.12s ease-out;
  z-index: 1000;
}
.tip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 12px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--ink, #1F1E1D);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease-out;
  z-index: 1001;
}
.tip:hover::after, .tip:hover::before { opacity: 1; transform: translateY(0); }
/* When tooltip would overflow the right edge, anchor to the right side */
.tip.tip-right::after { left: auto; right: 0; }
.tip.tip-right::before { left: auto; right: 12px; }

/* ───────────────────────────────────────────────────────────────────
   .card-next-action — clear "what to do next" chip pinned to the
   bottom of every card.  Three tones via .nx-* modifier classes:
     sage : ✓ confirmed / positive next step
     clay : ⚠ verify / warning state
     ink  : neutral instructional ("review the N anchors")
   The right side hosts an optional action button (.nx-action) that
   links to / fires a behavior (e.g. "Apply Cortex optimal →").
   Steven 2026-05-21: "tell the user what to do".
   ─────────────────────────────────────────────────────────────────── */
.card-next-action {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  font-family: 'Inter', sans-serif;
}
.card-next-action .nx-text { flex: 1; min-width: 0; }
.card-next-action .nx-text b { font-weight: 600; }
.card-next-action.nx-sage {
  background: rgba(135, 158, 107, 0.10);
  border-color:  rgba(135, 158, 107, 0.35);
  color: var(--sage-ink);
}
.card-next-action.nx-clay {
  background: rgba(184, 92, 62, 0.08);
  border-color:  rgba(184, 92, 62, 0.30);
  color: var(--clay);
}
.card-next-action.nx-ink {
  background: rgba(31, 30, 29, 0.04);
  border-color:  rgba(31, 30, 29, 0.12);
  color: var(--ink);
}
.card-next-action .nx-action {
  flex-shrink: 0;
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: none;
  background: var(--ink); color: white;
  font-family: inherit;
  transition: background 0.15s;
}
.card-next-action .nx-action:hover { background: #000; }
.card-next-action.nx-sage .nx-action { background: var(--sage-ink); }
.card-next-action.nx-sage .nx-action:hover { background: #4a5934; }
.card-next-action.nx-clay .nx-action { background: var(--clay); }
.card-next-action.nx-clay .nx-action:hover { background: #a14d23; }
.card-next-action:empty { display: none; }

.fact-table { width: 100%; font-size: 14px; }
.fact-table td { padding: 5px 0; border-bottom: 1px dashed var(--border); }
.fact-table tr:last-child td { border-bottom: none; }
.fact-table td:first-child { color: var(--ink-3); }
.fact-table td:last-child  { text-align: right; font-weight: 500; }

/* Cards 1 and 2 can each contain dozens of source-backed rows. Let the grid
   stretch both panels to one shared height while each card scrolls its own
   evidence region below the fixed heading/actions. */
#legacy-cards-1-2 { align-items: stretch; }
#legacy-cards-1-2 > .panel { align-self: stretch; }
.itb-summary-scroll,
.document-receipt-scroll {
  max-height: clamp(360px, 60vh, 640px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 8px;
}
.itb-summary-scroll:focus-visible,
.document-receipt-scroll:focus-visible {
  outline: 2px solid rgba(184, 92, 62, 0.45);
  outline-offset: 4px;
  border-radius: 6px;
}

.cohort-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg); border-radius: 8px; margin-bottom: 6px; font-size: 12px;
}
.cohort-row:last-child { margin-bottom: 0; }
.cohort-pct { font-family: 'JetBrains Mono', monospace; font-weight: 500; }

.envelope-strip {
  margin-top: 14px; padding: 12px; background: var(--clay-soft); border-radius: 8px;
  font-size: 12px; color: var(--clay);
}
.envelope-row { display: flex; justify-content: space-between; }
.envelope-row strong { color: #7C2C0F; font-family: 'JetBrains Mono', monospace; }

.deliverable-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.deliverable {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--bg); border-radius: 8px;
  font-size: 12px; cursor: pointer; transition: all 0.12s ease;
  text-decoration: none; color: var(--ink);
}
.deliverable:hover { background: var(--clay-soft); }
.deliverable-name { display: flex; flex: 1 1 auto; min-width: 0; align-items: center; gap: 8px; }
.deliverable-name > span:last-child { min-width: 0; }
.deliverable-icon {
  width: 30px; height: 30px; flex: 0 0 30px; box-sizing: border-box;
  border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; white-space: nowrap; overflow-wrap: normal; word-break: keep-all;
  font-size: 9px; line-height: 1; letter-spacing: -0.02em; font-weight: 600;
}
.icon-doc   { background: #DCE7F1; color: #2D5078; }
.icon-xlsx  { background: var(--sage-soft); color: var(--sage-ink); }
.icon-md    { background: var(--clay-soft); color: var(--clay); }
.icon-json  { background: #EFECE6; color: var(--ink-3); }
.icon-xml   { background: #E7DEF1; color: #553C7C; }
.deliverable-meta { flex: 0 1 36%; min-width: 0; font-size: 10px; color: var(--ink-4); font-family: 'JetBrains Mono', monospace; }

/* ── CHAT — minimal floating bubble (collapsed) + expandable popover ─────
   Bubble: 58px black circle with navigation-arrow icon + clay dot badge,
   pinned bottom-right of viewport. Click to open chat. EXACTLY matches
   the cortex-mini-launcher pattern from index.html (the main page).
   Open state: 380×600 popover anchored bottom-right, scrollable, dismissable.
   Replaces the prior 320px sticky right-column so the table view extends
   to full width. ────────────────────────────────────────────────────────── */
.chat {
  background: var(--ink);
  border: none;
  display: flex; flex-direction: column;
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 58px;
  height: 58px;
  max-height: 58px;
  border-radius: 50%;
  overflow: visible;
  box-shadow: 0 8px 24px -8px rgba(31,30,29,0.35), 0 2px 6px rgba(31,30,29,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: width 0.22s cubic-bezier(.4,.0,.2,1),
              height 0.22s cubic-bezier(.4,.0,.2,1),
              border-radius 0.22s cubic-bezier(.4,.0,.2,1),
              max-height 0.22s cubic-bezier(.4,.0,.2,1),
              background 0.18s ease;
}
.chat:not(.chat-open):hover { transform: scale(1.04); }
/* Launcher icon (collapsed state): nav-arrow SVG + clay dot badge.
   Mirrors index.html's .cortex-mini-launcher exactly. */
.chat-launcher {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--cream);
  z-index: 2;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.chat-launcher svg { width: 26px; height: 26px; }
.chat-launcher .badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--clay); color: var(--cream);
  font-family: 'JetBrains Mono', monospace; font-size: 8px; font-weight: 700;
  padding: 2px 5px; border-radius: 999px;
  border: 2px solid var(--cream);
  line-height: 1;
}
.chat.chat-open .chat-launcher { opacity: 0; pointer-events: none; }
/* Hide all interior chrome when collapsed (except the launcher icon) */
.chat:not(.chat-open) > *:not(.chat-launcher) { opacity: 0; pointer-events: none; transition: opacity 0.12s ease; }
/* Open state — expand to 380×min(600px, viewport) popover.
   Switch from black bubble to cream popover background. */
.chat.chat-open {
  width: 380px;
  height: min(600px, calc(100vh - 80px));
  max-height: min(600px, calc(100vh - 80px));
  border-radius: 18px;
  cursor: default;
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 24px 48px -16px rgba(31,30,29,0.28), 0 6px 16px -8px rgba(31,30,29,0.14);
}
.chat.chat-open > *:not(.chat-launcher) { opacity: 1; pointer-events: auto; transition: opacity 0.18s ease 0.06s; }
@media (max-width: 480px) {
  .chat.chat-open { width: calc(100vw - 32px); right: 16px; }
}
.chat-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-title { font-family: 'Instrument Serif', Georgia, serif; font-size: 18px; line-height: 1; }
.chat-meta { font-size: 11px; color: var(--ink-4); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 4px; }
.chat-feed { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; min-height: 480px; }
.msg { display: flex; gap: 10px; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 500;
}
.msg-avatar.r { background: var(--clay-soft); color: var(--clay); }
.msg-avatar.c { background: #E7DEF1; color: #553C7C; }
.msg-body { flex: 1; padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.55; }
.msg-body.r { background: var(--bg); }
.msg-body.c { background: #F4EFFA; color: #2D2354; }
.msg-body strong { font-weight: 500; }
.msg-body code { background: rgba(0,0,0,0.04); padding: 1px 5px; border-radius: 3px; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; }
.severity-flag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.severity-critical { background: #F8DCD3; color: #7C2C0F; }
.chat-input {
  padding: 14px 20px 18px; border-top: 1px solid var(--border);
}
.chat-input-box {
  border: 1px solid var(--border-2); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; color: var(--ink-4);
}
.regenerated {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--sage-soft); color: var(--sage-ink);
  padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 500;
  margin-left: 4px;
}

/* ── PIPELINE EMPTY STATES ────────────────────────────── */
.pipeline-empty { padding: 16px 24px; font-size: 13px; color: var(--ink-4); font-style: italic; }
