/* =========================================================================
   AI CO-BUILDER CHAT DEMO (#aiCoBuilderChatDemo).
   Duplicate of BudgetDetailDemo — see src/components/AiCoBuilderChatDemo.astro
   for the storyboard.
   Timeline: public/js/ai-cobuilder-chat-demo.js toggles `is-*` classes and
   `data-cursor` on the root.

   Two full-width scenes crossfade (AI Co-Builder chat → bottom-up table)
   instead of a permanent chat/table split — same single-scene-at-a-time
   approach as the homepage hero demo (BudgetDemo), which is what makes
   this scale to any width, mobile included, with no per-breakpoint layout
   rework.

   The --acb-* palette mirrors the PRODUCT (webapp_v3 src/styles/_theme.scss),
   same likeness rules as the other demo components on this page.
   ========================================================================= */

.acb {
  --acb-canvas: #FAF9F5;
  --acb-card: #FFFFFF;
  --acb-border: #DBDBDE;
  --acb-line: #EAEAEA;
  --acb-head: #F6F6F7;
  --acb-ink: #2B2B2B;
  --acb-ink2: #777777;
  --acb-accent: #6A5BC6;
  --acb-accent-soft: #ECECFF;
}

/* standard product-demo width (matches .btc__stage and .pf-visual-ph —
   the hero demo is the one exception, sized larger). Height is a
   deliberate exception to the shared aspect-ratio/min-height: the
   Customer Success expand row needs real vertical room to show all 11
   accounts, and a taller box only helps on narrow (portrait) phones — the
   "narrower for mobile" goal was about width, not height. */
.acb__stage {
  position: relative; overflow: hidden;
  min-height: 370px; max-width: 640px; margin: 0 auto;
  background: var(--acb-canvas);
  display: flex; flex-direction: column;
  transition: opacity .5s ease;
}
.acb.is-out .acb__stage { opacity: 0; }

/* sticky header — spans the full width of every scene. */
.acb__topBar {
  flex: none; font-size: 11px; font-weight: 600; color: var(--acb-ink);
  padding: 12px 14px 9px; border-bottom: 1px solid var(--acb-line);
  white-space: nowrap;
}

.acb__scene { position: relative; flex: 1; min-height: 0; }
.acb__sceneStack { position: absolute; inset: 0; }

/* each scene fills the whole stage and crossfades in/out — only one is
   opaque at a time, driven by `is-scene-bottomup` on the root (the chat is
   the default, unmarked state). */
.acb__scenePanel {
  position: absolute; inset: 0; overflow: hidden; min-width: 0;
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .5s ease;
}
.acb__scenePanel--chat { opacity: 1; }
.acb.is-scene-bottomup .acb__scenePanel--chat { opacity: 0; }
.acb.is-scene-bottomup .acb__scenePanel--bottomUp { opacity: 1; }

/* ---------- SCENE: AI Co-Builder chat, full width ---------- */
.acb__chatPanelFull {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--acb-card); padding: 20px 0 10px;
}

.acb__chatThread {
  flex: 1; min-height: 0; padding: 0 14px; display: flex; flex-direction: column;
  justify-content: flex-start; gap: 9px; overflow: hidden;
}

.acbMsg {
  margin: 0; background: var(--acb-head); border: 1px solid var(--acb-line); border-radius: 8px;
  padding: 9px 11px; font-size: 11px; line-height: 1.45; color: var(--acb-ink);
  opacity: 0; transform: translateY(6px);
  transition: opacity .35s ease, transform .35s ease;
}
.acb.is-sent .acbMsg { opacity: 1; transform: none; }
.acb__inlineChip {
  display: inline-flex; color: var(--acb-accent); font-weight: 600;
  background: var(--acb-accent-soft); border: 1px solid #CFC7EF; border-radius: 5px;
  padding: 1px 5px;
}

/* AI's acknowledgement — plain text (not a bubble, unlike the user's
   message), same voice as the "Done" line, revealed a beat after the
   message sends and before the build steps start listing. */
.acb__aiReply {
  margin: 0; font-size: 10.5px; line-height: 1.5; color: var(--acb-ink);
  opacity: 0; transform: translateY(4px);
  transition: opacity .3s ease, transform .3s ease;
}
.acb.is-replied .acb__aiReply { opacity: 1; transform: none; }

/* step-by-step build log — Clive's reply */
.acb__steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.acb__step {
  display: flex; align-items: center; gap: 5px;
  font-size: 9px; color: var(--acb-ink);
  opacity: 0; transform: translateY(4px);
  transition: opacity .3s ease, transform .3s ease;
}
.acb__step.is-shown { opacity: 1; transform: none; }
.acb__step__check { flex: none; color: #2C8E45; font-weight: 700; font-size: 9px; }
.acb__step__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* "Done" line + the resulting budget chip */
.acb__doneLine {
  margin: 2px 0 0; font-size: 10.5px; font-weight: 600; color: var(--acb-ink);
  opacity: 0; transform: translateY(4px);
  transition: opacity .3s ease, transform .3s ease;
}
.acb.is-done .acb__doneLine { opacity: 1; transform: none; }

/* inline with the "Done — take a look here" copy (a child of .acb__doneLine
   now, not its own line) — vertical-align keeps it sitting on the text
   baseline instead of the flex item's default alignment. */
.acb__budgetChip {
  display: inline-flex; align-items: center; gap: 5px; vertical-align: -3px;
  margin-left: 4px;
  font-size: 9.5px; font-weight: 600; color: var(--acb-accent);
  background: var(--acb-accent-soft); border: 1px solid #CFC7EF; border-radius: 7px;
  padding: 5px 9px;
  opacity: 0; transform: translateY(4px);
  transition: opacity .3s ease, transform .3s ease, transform .15s ease;
}
.acb.is-done .acb__budgetChip { opacity: 1; transform: none; }
.acb.is-press-chip .acb__budgetChip { transform: scale(.94); }

/* greeting — centered in the panel above the composer's landing spot,
   like an empty chat's welcome state; fades out the moment typing starts. */
.acb__greeting {
  position: absolute; left: 14px; right: 14px; top: 38%; transform: translateY(-50%);
  margin: 0; text-align: center; font-size: 15px; font-weight: 500; color: var(--acb-ink2);
  transition: opacity .3s ease;
}
.acb.is-typing .acb__greeting, .acb.is-sent .acb__greeting { opacity: 0; }

/* composer — lands in the lower third of the panel (under the greeting)
   then docks a little further down once the message sends, so the first
   message visibly travels into the thread instead of quietly appearing in
   a panel that's competing with the table for attention. */
.acbComposer {
  position: absolute; left: 14px; right: 14px; top: 70%; transform: translateY(-50%);
  background: var(--acb-canvas);
  border: 1px solid var(--acb-border); border-radius: 8px; padding: 13px 10px 11px;
  transition: top .8s cubic-bezier(.6, .05, .3, 1), border-color .3s ease, box-shadow .3s ease;
}
.acb.is-sent .acbComposer { top: 84%; }
/* a brief radiating pulse draws the eye to the composer the instant typing
   starts — the first message otherwise lands quietly in a thread competing
   with the table for attention. Settles into the static ring below. */
.acb.is-typing .acbComposer {
  border-color: var(--acb-accent); box-shadow: 0 0 0 2px var(--acb-accent-soft);
  animation: acbComposerPulse .9s ease-out;
}
@keyframes acbComposerPulse {
  0% { box-shadow: 0 0 0 0 rgba(106, 91, 198, .45); }
  60% { box-shadow: 0 0 0 9px rgba(106, 91, 198, 0); }
  100% { box-shadow: 0 0 0 2px var(--acb-accent-soft); }
}
.acbComposer__field { position: relative; min-height: 26px; font-size: 10.5px; line-height: 1.4; color: var(--acb-ink); }
.acbComposer__ph { position: absolute; inset: 0; color: #9b9ba2; transition: opacity .2s ease; }
.acb.is-typing .acbComposer__ph { opacity: 0; }
.acbCaret {
  display: none; width: 1.5px; height: 11px; margin-left: 1px; vertical-align: -2px;
  background: var(--acb-ink);
}
.acb.is-typing .acbCaret { display: inline-block; animation: acbCaret 1s step-end infinite; }
@keyframes acbCaret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
/* standard composer bar (matches the homepage hero demo): paperclip, a
   mode pill pushed right via margin-left:auto, then send. */
.acbComposer__bar {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--acb-line); margin: 5px -9px 0; padding: 5px 9px 0;
}
.acbComposer__clip { color: var(--acb-ink2); }
.acbComposer__mode {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  font-size: 9px; font-weight: 500; color: #fff;
  background: var(--acb-ink2); border-radius: 999px; padding: 3px 9px;
}
.acbComposer__mode i { font-style: normal; font-size: 7px; }
.acbComposer__send {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--acb-ink); background: #D9D9D9;
  transition: transform .18s ease, background .18s ease, color .18s ease;
}
.acb.is-press-send .acbComposer__send { transform: scale(.82); background: var(--acb-ink); color: #fff; }

/* ---------- SCENE: top-down / bottom-up tables, full width ---------- */
.acb__tablePane { flex: 1; min-height: 0; min-width: 0; padding: 12px 14px; display: flex; flex-direction: column; }
.acb__tableTitle { flex: none; margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--acb-ink); }

.acb__chev {
  display: inline-block; width: 12px; color: var(--acb-ink2); font-size: 10px;
  transition: transform .3s ease;
}
/* department rows (and Operating Expense) start pointing right (collapsed);
   rotate to point down when expanded */
.acb__xrow.is-expanded .acb__chev,
[data-el="opexRow"].is-expanded .acb__chev { transform: rotate(90deg); transform-origin: 45% 50%; }

/* ---------- bottom-up monthly grid — card-style like the homepage's
   "Revenue build-up" table: shaded header row, full cell borders, rounded
   card. 12 fixed-width monthly columns; however many fit at the current
   width are shown in full, the next one is cut mid-cell (reads as a table
   that keeps going past the frame), the rest scroll off. CSS grid instead
   of a <table> — table-layout:fixed proved unreliable at this column
   count. */
.acb__monthGrid {
  display: grid; grid-template-columns: 110px repeat(12, 85px);
  background: var(--acb-card); border: 1px solid var(--acb-border); border-radius: 8px;
  overflow: hidden; max-width: 100%;
}
.acb__mgCell {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 7px 8px; font-size: 9.5px; color: var(--acb-ink2);
  border-bottom: 1px solid var(--acb-line); border-right: 1px solid var(--acb-line);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acb__mgCell--head {
  flex-direction: column; align-items: flex-end; gap: 1px;
  background: var(--acb-head); font-weight: 500;
  border-bottom: 1px solid var(--acb-border);
}
.acb__mgCell--head i { font-style: normal; font-weight: 400; }
.acb__mgCell--corner { align-items: flex-start; font-weight: 600; color: var(--acb-ink); }
.acb__mgCell--label {
  justify-content: flex-start; gap: 4px;
  font-weight: 600; color: var(--acb-ink); white-space: nowrap;
}
.acb__mgCell--val { font-variant-numeric: tabular-nums; }
/* the total row now sits at the top of the table (right under the header),
   so it needs its own border on both sides — the header's bottom border
   isn't enough separation from a bold summary row, and the rows below
   need a clear line under it too. */
.acb__mgCell--total { font-weight: 700; color: var(--acb-ink); border-top: 1px solid var(--acb-border); border-bottom: 1px solid var(--acb-border); }

.acb__expandRow { grid-column: 1 / -1; }
.acb__expandInner {
  max-height: 0; overflow: hidden;
  transition: max-height .5s cubic-bezier(.4, 0, .2, 1);
}
/* Two independent nesting levels share these classes (Operating Expense →
   departments, and within that, Customer Success → accounts) — each
   max-height is scoped with a direct-child combinator + data-el so opening
   one level doesn't also force the other level's inner max-height, no
   matter its own open/closed state.
   171px on the Customer Success level = the closed table's total height
   (241px) minus the header row (42px) minus the Customer Success row
   itself (28px) — i.e. exactly what the other departments + total row
   occupy while hidden below. Matching it keeps the table's overall height
   fixed whether that toggle is open or closed, instead of the card
   growing/shrinking. The Operating Expense level's own max-height (220px)
   just needs to be generous enough to fit either of that inner level's
   two states. */
[data-el="expandRow"].is-open > [data-el="expandInner"] { max-height: 171px; }
[data-el="opexExpandRow"].is-open > [data-el="opexExpandInner"] { max-height: 220px; }
/* the "more accounts" row at the end of the list — implies the visible
   accounts are a partial view of a much longer list, without having to
   fake more rows. */
/* left-aligned, not centered: this row still spans the grid's full
   un-clipped 1130px width (matching every other row so columns stay
   aligned), and most of that is off-screen past the visible ~3-5 months —
   centering would put the text in the clipped-off middle, so it's anchored
   to the same left edge as the account labels above it instead. */
.acb__mgCell--loadmore {
  grid-column: 1 / -1; justify-content: flex-start;
  padding: 6px 8px 6px 24px;
  color: var(--acb-accent); font-weight: 600; background: var(--acb-canvas);
}
/* while expanded, the other departments (and the total row) step aside so
   the account list is the sole focus instead of competing with a long
   scroll of unrelated rows underneath; they come back once it re-closes.
   The total row sits above Customer Success, so it can't be reached by
   the "later siblings" rule below — `is-cs-open` (set by the JS driver
   alongside `is-open`) targets it directly instead. */
.acb__expandRow.is-open ~ .acb__mgCell { display: none; }
.acb.is-cs-open .acb__mgCell--total { display: none; }
.acb__mgSubgrid { display: grid; grid-template-columns: 110px repeat(12, 85px); }
/* tighter vertical padding than the main .acb__mgCell rows — this is
   secondary account-level detail, and there are 11 of them to fit in the
   same expand space. */
.acb__mgCell--sublabel, .acb__mgCell--subval {
  padding-top: 4px; padding-bottom: 4px;
}
.acb__mgCell--sublabel { justify-content: flex-start; padding-left: 24px; font-size: 8.5px; font-weight: 400; color: var(--acb-ink2); background: var(--acb-canvas); }
.acb__mgCell--subval { background: var(--acb-canvas); font-size: 9px; }

/* ---------- cursor — travels the full stage, not scoped to one scene ---------- */
.acb__cursor {
  position: absolute; opacity: 0; pointer-events: none; z-index: 6;
  transition: left .6s cubic-bezier(.5, .05, .3, 1), top .6s cubic-bezier(.5, .05, .3, 1), opacity .3s ease;
  left: 50%; top: 50%;
}
.acb[data-cursor="chip"] .acb__cursor { left: 33.9%; top: 53.7%; opacity: 1; }
.acb[data-cursor="expand"] .acb__cursor { left: 4.4%; top: 36.2%; opacity: 1; }
.acb[data-cursor="opex"] .acb__cursor { left: 4.4%; top: 27.7%; opacity: 1; }
.acb.is-press-opex [data-el="opexRow"] { background: var(--acb-head); }
