/* FlowStudio AI web widget — house design system
   Palette and type lifted from flowstudio.app + mcp.flowstudio.app:
   teal/cyan primary, plum secondary, deep navy heroes, coral for errors,
   the signature plum→teal ribbon, Inter type. */

:root {
  --fs-navy: #0a1422;
  --fs-navy-2: #102d4a;
  --fs-ink: #1f1d41;
  --fs-teal: #1a9ba1;
  --fs-cyan: #37c6d0;
  --fs-cyan-light: #5fd4dd;
  --fs-plum: #752876;
  --fs-plum-2: #8e3f8e;
  --fs-plum-light: #d4a8d6;
  --fs-coral: #e87272;
  --fs-coral-deep: #c14f4f;
  --fs-paper: #f7f9fb;
  --fs-line: #e2e7ee;
  --fs-muted: #5f6b7a;
  --fs-faint: #8a94a3;
  --fs-teal-tint: #e7f7f8;
  --fs-plum-tint: #f2def4;
  --fs-coral-tint: #fdeeee;
  --fs-ribbon: linear-gradient(95deg, #d4a8d6, #8e3f8e 35%, #1a9ba1 65%, #37c6d0);
  --fs-btn-gradient: linear-gradient(135deg, #1a9ba1, #37c6d0);
  /* The user bubble rides one step lighter than the buttons: ink on the teal end
     passed the bar but was the darkest surface in the chat (Catherine, 2026-08-05:
     "some part of teal is too dark"). Both stops are existing palette tokens. */
  --fs-bubble-gradient: linear-gradient(135deg, #37c6d0, #5fd4dd);
}

* { box-sizing: border-box; }
/* The hidden attribute must win over the .gate/.chat display rules */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--fs-ink);
  background: var(--fs-paper);
  display: flex;
  flex-direction: column;
}

/* Header — deep navy with the signature ribbon underneath */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(100deg, var(--fs-navy), var(--fs-navy-2));
  border-bottom: 3px solid transparent;
  border-image: var(--fs-ribbon) 1;
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: 0.01em; }
.brand-mark {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
.account { display: flex; align-items: center; gap: 10px; position: relative; }
.user-email { color: rgba(255, 255, 255, 0.65); font-size: 13px; }

/* The email IS the account menu button */
.user-email-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.65);
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  max-width: 320px;
}
.user-email-btn span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email-btn:hover, .user-email-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.1); color: #fff; }
.user-email-btn .caret { font-size: 10px; opacity: 0.7; }
.user-email-btn:focus-visible { outline: 2px solid var(--fs-cyan); outline-offset: 2px; }

/* Account menu — dropdown anchored under the email */
.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 260px;
  max-width: 320px;
  background: #fff;
  color: var(--fs-ink);
  border: 1px solid var(--fs-line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(5, 12, 22, 0.28);
  padding: 6px;
  font-size: 13.5px;
}
.account-menu hr { border: 0; border-top: 1px solid var(--fs-line); margin: 5px 0; }
.menu-plan { padding: 8px 10px 6px; color: var(--fs-muted); font-size: 12.5px; }
.menu-item {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  /* Actions must READ as actions: teal like every other clickable, with a chevron —
     they sat in plain ink and looked like labels (Catherine, 2026-07-31). */
  color: var(--fs-teal);
  background: none;
  border: 0;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
}
.menu-item::after { content: "›"; float: right; color: var(--fs-faint); }
.menu-item:hover { background: var(--fs-teal-tint); }
.menu-item:disabled { color: var(--fs-faint); cursor: default; }
.menu-signout { color: var(--fs-coral-deep); }
.menu-signout:hover { background: var(--fs-coral-tint); }
.menu-toggle { padding: 8px 10px; }
.menu-legal { display: flex; gap: 5px; padding: 4px 10px 8px; align-items: baseline; }
.menu-legal span { color: var(--fs-faint); font-size: 12px; }
.credits {
  background: rgba(255, 255, 255, 0.1);
  color: #5fd4dd;
  border: 1px solid rgba(95, 212, 221, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.credits.low { background: rgba(232, 114, 114, 0.15); color: #f0a3a3; border-color: rgba(232, 114, 114, 0.4); }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}
/* Ink, not white. White on this gradient measures 2.07:1 at the cyan end against a
   4.5:1 accessibility bar; ink clears it at both ends (4.77:1 teal, 7.75:1 cyan). The
   gradient itself is unchanged — same two hexes, same angle (Catherine, 2026-08-02). */
.btn-primary { background: var(--fs-btn-gradient); color: var(--fs-ink); }
.btn-primary:hover { background: linear-gradient(135deg, #158187, #2cb3bd); }
.btn-primary:disabled { background: #a8ccce; cursor: default; }
.btn-primary:focus-visible { outline: 2px solid var(--fs-cyan); outline-offset: 2px; }
.btn-quiet { background: #fff; color: var(--fs-teal); border-color: #bfe3e6; padding: 4px 12px; font-size: 13px; }
.btn-quiet:hover { background: var(--fs-teal-tint); }
/* Quiet buttons that sit on the navy header */
.top .btn-quiet { background: rgba(255, 255, 255, 0.08); color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.top .btn-quiet:hover { background: rgba(255, 255, 255, 0.16); }
.btn-stop { background: var(--fs-coral-deep); }
.btn-stop:hover { background: #a94040; }

/* Gate screens (sign-in / setup) — the flagship's navy hero treatment */
.gate {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 60% at 70% 10%, rgba(117, 40, 118, 0.25), transparent),
    radial-gradient(ellipse 70% 55% at 20% 90%, rgba(26, 155, 161, 0.22), transparent),
    linear-gradient(160deg, var(--fs-navy), var(--fs-navy-2));
}
.gate-card {
  position: relative;
  overflow: hidden; /* clips the ribbon to the rounded corners */
  max-width: 480px;
  background: #fff;
  border: 1px solid var(--fs-line);
  border-radius: 12px;
  padding: 40px 36px 36px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(5, 12, 22, 0.35);
}
/* Ribbon as an inset strip, not border-image — border-image ignores
   border-radius and paints a square frame around the rounded card */
.gate-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--fs-ribbon);
}
.gate-card h1 { font-size: 22px; margin: 0 0 12px; line-height: 1.3; color: var(--fs-ink); letter-spacing: -0.01em; }
.gate-card p { color: var(--fs-muted); margin: 0 0 20px; line-height: 1.55; }
.fine { font-size: 12.5px; color: var(--fs-faint); }
/* Beats .gate-card p (whose shorthand zeroes margin-top at higher specificity)
   so fine print keeps breathing room below the button it follows */
.gate-card p.fine { margin: 14px 0 0; }
.error { color: var(--fs-coral-deep); }

/* Header chip: how this session reaches Power Automate (relay sessions only) */
.conn-chip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: #eef7f4; color: #0d7a5f; border: 1px solid #bfe5da; white-space: nowrap;
}
.conn-chip.offline { background: #fdf0ee; color: var(--fs-coral-deep); border-color: #f2cdc6; }

/* Browser-relay connect pane (setup screen) */
.relay-steps { text-align: left; color: var(--fs-muted); margin: 12px 0 16px; padding-left: 20px; line-height: 1.55; }
.relay-steps li { margin-bottom: 8px; }
.relay-key-row { display: flex; gap: 8px; align-items: center; margin: 0 0 14px; }
.relay-key-row code {
  flex: 1; word-break: break-all; text-align: left;
  background: #eef2f5; border-radius: 6px; padding: 8px 10px; font-size: 13px;
}
#relay-option { margin-top: 18px; border-top: 1px solid #e5e9ee; padding-top: 4px; }
#relay-status { min-height: 1em; }
/* Phone-only warning: extensions can't install on mobile browsers, so the pairing
   steps need a "do this on your computer" pointer there. Desktop never sees it. */
.relay-mobile-hint { display: none; color: var(--fs-coral-deep); }
@media (max-width: 560px) {
  .relay-mobile-hint { display: block; }
}

.spinner {
  width: 28px; height: 28px;
  margin: 8px auto 0;
  border: 3px solid #d9e6e7;
  border-top-color: var(--fs-teal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chat */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* Sit the conversation ON the composer instead of hanging from the top.
   .messages is flex:1, so a short conversation was pinned to the top and ALL the leftover
   height fell between the last message and the input — on a phone with the keyboard up,
   that gap pushed the conversation off screen entirely while the composer stayed put.
   An auto top-margin on the first child pushes the stack down when there is spare room and
   collapses to nothing once the content overflows — unlike justify-content:flex-end, which
   makes the overflowing top unreachable in a scroll container. */
.messages > :first-child { margin-top: auto; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.bot .bubble { background: #fff; border: 1px solid var(--fs-line); border-bottom-left-radius: 4px; }
.msg.user .bubble { background: var(--fs-bubble-gradient); color: var(--fs-ink); border-bottom-right-radius: 4px; }
.msg.error .bubble { background: var(--fs-coral-tint); border: 1px solid #f3cccc; color: #93403a; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble code { background: #eef2f5; border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.msg.user .bubble code { background: rgba(31, 29, 65, 0.12); }

.thinking { color: var(--fs-muted); font-style: italic; }

/* Markdown extras in bot bubbles: clickable links + pipe tables */
.bubble a { color: #0b6bcb; text-decoration: underline; word-break: break-all; }
.md-table-wrap { overflow-x: auto; margin: 8px 0; }
.md-table-wrap table { border-collapse: collapse; font-size: 13px; }
.md-table-wrap th, .md-table-wrap td { border: 1px solid #d7e0e8; padding: 5px 10px; text-align: left; vertical-align: top; }
.md-table-wrap th { background: #f2f6f9; font-weight: 600; }

/* Quiet notice under an answer served by a different model than the user picked */
.downgrade-note {
  font-size: 12px;
  color: var(--fs-muted);
  font-style: italic;
  padding: 2px 6px 0;
  max-width: 720px;
}

/* Model selector — user-chosen upgrade for build/diagnosis turns, lives above the composer */
.composer-bar {
  display: flex;
  justify-content: flex-end;
  padding: 4px 16px 0;
}
.model-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fs-muted);
  cursor: pointer;
}
.model-inline select {
  font: inherit;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid #c6d2dd;
  border-radius: 6px;
  background: #fff;
  color: var(--fs-ink);
  max-width: 280px;
}

/* What the selected model is good at — measured, not marketing (2026-07-20 eval) */
.model-guidance {
  font-size: 11px;
  color: var(--fs-muted);
  text-align: right;
  padding: 2px 16px 0;
  min-height: 14px;
}

/* Phone layout. Vertical space is the scarce resource once the keyboard is up, and the
   chrome around the composer was consuming a lot of it: the model guidance wraps to four
   or five lines beside the picker, and the outer padding adds more. The picker itself
   stays — it changes what a message costs — but its description is desktop nicety and is
   one tap away in the option text anyway. */
@media (max-width: 560px) {
  .model-guidance { display: none; }
  .composer-bar { padding: 2px 12px 0; }
  .composer { padding: 8px 12px 10px; gap: 6px; }
  .messages { padding: 12px 12px 4px; }
  .bubble { max-width: 88%; }
}

/* Report-a-problem overlay (feedback-for-credits) */
.report-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, .25);
  padding: 20px;
  width: min(440px, calc(100vw - 32px));
}
.report-panel h2 { margin: 0 0 6px; font-size: 17px; }
.report-panel textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #c6d2dd;
  border-radius: 8px;
  resize: vertical;
  box-sizing: border-box;
  margin: 8px 0;
}
.report-label { display: block; font-size: 12px; color: var(--fs-muted); margin-top: 8px; }
.report-panel select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid #c6d2dd;
  border-radius: 8px;
  background: #fff;
  color: var(--fs-ink);
  box-sizing: border-box;
  margin-top: 4px;
}
.report-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* One-click switch inside a model hint */
.hint-switch {
  font: inherit;
  font-size: 12px;
  font-style: normal;
  margin-left: 6px;
  padding: 1px 8px;
  border: 1px solid #c6d2dd;
  border-radius: 999px;
  background: #fff;
  color: var(--fs-ink);
  cursor: pointer;
}
.hint-switch:hover:not(:disabled) { background: #f2f6fa; }
.hint-switch:disabled { cursor: default; opacity: .75; border-style: dashed; }

/* Attachment chips — pending files/screenshots shown above the composer, content hidden */
.attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 16px 0;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 3px 6px 3px 8px;
  border: 1px solid #c6d2dd;
  border-radius: 14px;
  background: #fff;
  font-size: 12.5px;
  color: var(--fs-muted);
}
.attach-chip img { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  border: 0;
  background: none;
  color: var(--fs-faint);
  cursor: pointer;
  padding: 0 2px;
}
.chip-remove:hover { color: var(--fs-coral-deep); }
.attach-note { margin-top: 6px; font-size: 12px; opacity: 0.85; }

/* Offer buttons — one concrete action proposed by the reply, click = go */
.offer-card .bubble { background: var(--fs-teal-tint); border: 1px solid #bfe3e6; }
.offer-actions { display: flex; gap: 8px; margin-top: 10px; }
.offer-actions .btn-quiet { background: #fff; }

.history-divider {
  text-align: center;
  color: var(--fs-faint);
  font-size: 12px;
  letter-spacing: 0.04em;
  margin: 6px 0;
}

/* Recents slide-over */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 34, 0.45);
  z-index: 40;
}
.recents-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(340px, 90vw);
  background: #fff;
  border-left: 1px solid var(--fs-line);
  box-shadow: -4px 0 22px rgba(5, 12, 22, 0.25);
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.recents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 3px solid transparent;
  border-image: var(--fs-ribbon) 1;
  font-weight: 600;
  color: var(--fs-ink);
}
.recents-actions { display: flex; align-items: center; gap: 6px; }
.panel-close {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  border: 0;
  background: none;
  color: var(--fs-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.panel-close:hover { color: var(--fs-ink); }
.recents-list { flex: 1; overflow-y: auto; padding: 8px; }
.recents-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: 8px;
}
.recents-row:hover { background: var(--fs-teal-tint); }
.recents-row.current { background: var(--fs-teal-tint); box-shadow: inset 3px 0 0 var(--fs-teal); }
.recents-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.recents-archive {
  flex: 0 0 auto;
  align-self: center;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: #b6bec9;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.recents-archive:hover { color: var(--fs-coral-deep); background: var(--fs-coral-tint); }
.recents-archive:disabled { opacity: 0.5; cursor: default; }
.recents-title {
  font-size: 14px;
  color: var(--fs-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recents-meta { font-size: 12px; color: var(--fs-faint); }
.recents-empty { color: var(--fs-faint); font-size: 13.5px; text-align: center; padding: 24px 12px; }
.recents-foot {
  border-top: 1px solid var(--fs-line);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.improve-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--fs-muted);
  cursor: pointer;
}
.improve-toggle input { margin-top: 2px; accent-color: var(--fs-teal); }
.privacy-link { font-size: 12px; color: var(--fs-faint); }
.privacy-link:hover { color: var(--fs-teal); }
/* Marketing-consent checkbox on the sign-in gate (email program) */
.marketing-optin { display: flex; gap: 6px; align-items: flex-start; text-align: left; cursor: pointer; }
.marketing-optin input { margin-top: 2px; accent-color: var(--fs-teal); }
.improve-prompt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 10px 44px 10px 0;
  padding: 12px 14px;
  border: 1px solid #e5c8e7;
  border-radius: 10px;
  background: var(--fs-plum-tint);
  font-size: 13px;
  color: #5d3160;
}
.improve-prompt span { flex: 1 1 100%; }
.btn-small { font-size: 12.5px; padding: 5px 12px; }

/* Composer */
.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  align-items: flex-end; /* button stays bottom-aligned as the textarea grows */
}
#message-input {
  flex: 1;
  font: inherit;
  line-height: 1.45;
  padding: 10px 14px;
  border: 1px solid #c6d2dd;
  border-radius: 8px;
  outline: none;
  background: #fff;
  resize: none;
  /* Two-line floor. rows="1" made the box one line tall at rest, and autoGrowInput only
     runs on `input` — so nothing sized it until you typed, while the placeholder wraps to
     two lines on a phone and had its second line sliced through the middle. min-height also
     beats the inline height autoGrow sets, so typing a short message cannot shrink it back
     below this. 2.9em = two lines at line-height 1.45; 22px = the 10px padding either side
     plus both borders. */
  min-height: calc(2.9em + 22px);
  max-height: 200px;
  overflow-y: auto;
}
#message-input:focus { border-color: var(--fs-teal); box-shadow: 0 0 0 3px rgba(55, 198, 208, 0.18); }
.attach-btn {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  width: 41px;
  height: 41px;
  flex: none;
  border: 1px solid #c6d2dd;
  border-radius: 8px;
  background: #fff;
  color: var(--fs-muted);
  cursor: pointer;
}
.attach-btn:hover { background: var(--fs-teal-tint); color: var(--fs-teal); border-color: var(--fs-teal); }
