/* F&B Codex — /try chat (clean light, Gemini-style app shell)
 * Depends on assets/site.css for tokens (--ink, --gold, --bg-surface, etc.)
 */

/* Exact viewport column: nav takes its natural height (it varies on mobile),
 * .try-app fills the remainder. No hard-coded nav heights — that's what broke
 * mobile (nav taller than the assumed 56px pushed the composer off-screen
 * with no way to scroll to it). */
.try-body {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.try-body nav.top { flex: 0 0 auto; }

.try-app {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ---------------- agent rail ---------------- */
.try-agents {
  width: 248px; flex: 0 0 248px;
  background: var(--bg-surface);
  border-right: 1px solid var(--rule);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
}
.rail-head {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 600; padding: 6px 10px 8px;
}
.agent-card {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: 10px;
  padding: 9px 10px; cursor: pointer; color: var(--ink-2);
  font-family: inherit; transition: background .12s;
}
.agent-card:hover { background: rgba(22,20,40,0.05); }
.agent-card.active { background: var(--gold-soft); }
.agent-card.active .ag-name { color: var(--gold-hi); }
.ag-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.ag-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.ag-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.ag-role { font-size: 11.5px; color: var(--ink-4); }
.try-note {
  margin-top: auto; font-size: 12px; color: var(--ink-3);
  padding: 14px 10px 4px; border-top: 1px solid var(--rule); line-height: 1.55;
}

/* ---------------- chat column ---------------- */
.try-chat {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; background: #fff;
}
.chat-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; border-bottom: 1px solid var(--rule);
}
.chat-head-l { display: flex; align-items: center; gap: 11px; }
.chat-head-l .ag-dot { width: 12px; height: 12px; }
.chat-name { font-weight: 600; font-size: 15px; color: var(--ink); }
.chat-role { font-size: 12.5px; color: var(--ink-3); }
.btn-ghost {
  background: none; border: 1px solid var(--rule-2); border-radius: 8px;
  padding: 6px 13px; font-size: 13px; color: var(--ink-2); cursor: pointer; font-family: inherit;
  transition: background .12s, color .12s;
}
.btn-ghost:hover { background: var(--bg-surface); color: var(--ink); }

/* ---------------- thread ---------------- */
.chat-thread {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 26px max(22px, calc((100% - 800px) / 2));
  display: flex; flex-direction: column; gap: 22px;
}
.msg { max-width: 100%; }
.msg-user {
  align-self: flex-end; max-width: 80%;
  background: var(--bg-elevated); border: 1px solid var(--rule);
  border-radius: 16px 16px 4px 16px; padding: 10px 15px;
}
.msg-user .msg-body p { margin: 0; color: var(--ink); font-size: 15px; line-height: 1.55; }
.msg-user .msg-atts { color: var(--ink-3); }
.msg-agent { align-self: stretch; }
.msg-meta {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-4); margin-bottom: 7px;
}
.msg-body { color: var(--ink-2); font-size: 15px; line-height: 1.7; }
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: var(--ink); font-weight: 600; }
.msg-body h3 { font-size: 17px; color: var(--ink); margin: 16px 0 8px; letter-spacing: -0.01em; }
.msg-body h4 { font-size: 15px; color: var(--ink); margin: 14px 0 6px; }
.msg-body ul, .msg-body ol { margin: 8px 0; padding-left: 20px; }
.msg-body li { margin: 4px 0; }
.msg-body code {
  background: var(--bg-elevated); border: 1px solid var(--rule);
  padding: 1px 6px; border-radius: 5px; font-size: 0.88em; color: var(--gold-hi); font-family: var(--mono);
}
.msg-body pre {
  background: var(--bg-surface); border: 1px solid var(--rule); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.6; font-family: var(--mono);
}
.msg-body pre code { background: none; border: none; padding: 0; color: var(--ink-2); }
.msg-body a { color: var(--gold); }

.cursor {
  display: inline-block; width: 7px; height: 15px;
  background: var(--gold); border-radius: 1px; vertical-align: -2px; margin-left: 1px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* feedback bar under a completed agent answer */
.msg-fb { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--ink-3); }
.msg-fb-q { margin-right: 2px; }
.fb-btn {
  background: none; border: 1px solid var(--rule-2); border-radius: 7px;
  padding: 3px 10px; cursor: pointer; color: var(--ink-3); font: inherit; font-size: 12px; line-height: 1.4;
}
.fb-btn:hover { border-color: var(--rule-strong); color: var(--ink-2); }
.fb-btn.on { border-color: var(--gold); color: var(--gold-hi); background: var(--gold-soft); }
.fb-fix { background: none; border: none; color: var(--gold); cursor: pointer; font: inherit; font-size: 12px; padding: 0; margin-left: 2px; }
.fb-fix:hover { text-decoration: underline; }
.fb-done { color: var(--green); }
.fb-panel { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-width: 560px; }
.fb-text {
  width: 100%; border: 1px solid var(--rule-2); border-radius: 9px; padding: 9px 11px;
  font: inherit; font-size: 13px; color: var(--ink); background: var(--bg-card); resize: vertical;
}
.fb-text:focus { outline: none; border-color: var(--gold); }
.fb-submit {
  align-self: flex-start; background: var(--gold); color: #fff; border: none;
  border-radius: 8px; padding: 6px 13px; font: inherit; font-size: 12px; cursor: pointer;
}
.fb-submit:hover { background: var(--gold-hi); }

/* greeting (empty state) */
.greeting { margin: auto; text-align: center; max-width: 520px; padding: 24px; }
.greeting-title {
  font-size: clamp(26px, 4vw, 34px); font-weight: 600; line-height: 1.2;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.greeting-sub { margin-top: 12px; font-size: 15px; color: var(--ink-3); line-height: 1.6; }

/* empty state — lift the composer up and center it with the greeting (Gemini-style) */
.try-chat.empty .chat-thread { flex: 0 0 auto; margin-top: auto; padding-bottom: 6px; }
.try-chat.empty .composer { margin-bottom: auto; border-top: none; }
.try-chat.empty .greeting { margin: 0 auto; padding-bottom: 12px; }

/* ---------------- composer ---------------- */
.composer { flex: 0 0 auto; border-top: 1px solid var(--rule); padding: 14px 22px 16px; background: #fff; }
.composer > * { max-width: 800px; margin-left: auto; margin-right: auto; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sample-chip {
  background: #fff; border: 1px solid var(--rule-2); border-radius: 999px;
  padding: 7px 13px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s;
}
.sample-chip:hover { background: var(--bg-surface); border-color: var(--rule-strong); }
.attach-tray { display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-hint { display: none; font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }

.chat-input {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--rule-2); border-radius: 28px;
  padding: 10px 10px 10px 18px; background: #fff;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.chat-input:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
#msg {
  flex: 1; border: none; outline: none; resize: none;
  font-family: inherit; font-size: 16px; line-height: 1.55;
  padding: 12px 6px; min-height: 34px; max-height: 220px; background: transparent; color: var(--ink);
}
.icon-btn {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  border: none; background: none; color: var(--ink-3); font-size: 21px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: inherit; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--ink); }
.icon-btn.send { background: var(--gold); color: #fff; }
.icon-btn.send:hover { background: var(--gold-hi); color: #fff; }
.icon-btn.send:disabled { opacity: .45; cursor: default; }

.chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 9px; }
.demo-link {
  background: var(--gold-soft); border: 1px solid rgba(107,91,214,0.25);
  color: var(--gold-hi); border-radius: 999px; padding: 5px 12px; font-size: 12px;
  cursor: pointer; font-family: inherit; transition: background .12s;
}
.demo-link:hover { background: rgba(107,91,214,0.16); }
#status { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
#status.ok { color: var(--green); }
#status.err { color: var(--red); }

/* ---------------- mobile ---------------- */
@media (max-width: 820px) {
  .try-app { flex-direction: column; }
  .try-agents {
    flex: 0 0 auto; width: auto; flex-direction: row; gap: 8px;
    overflow-x: auto; overflow-y: hidden;
    border-right: none; border-bottom: 1px solid var(--rule); padding: 10px 12px;
  }
  .rail-head, .try-note { display: none; }
  .agent-card {
    flex: 0 0 auto; width: auto; padding: 7px 12px;
    border: 1px solid var(--rule-2); border-radius: 999px;
  }
  .agent-card.active { border-color: var(--gold); }
  .ag-role { display: none; }
  .chat-thread { padding: 20px 16px; gap: 18px; }
  /* Sample chips: one horizontally-scrollable row so they never stack and
   * shove the input below the fold on small screens. */
  .samples {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px; scrollbar-width: none;
  }
  .samples::-webkit-scrollbar { display: none; }
  .sample-chip { flex: 0 0 auto; white-space: nowrap; }
  /* Respect the iPhone home-indicator area so the input isn't tucked under it. */
  .composer { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
  .greeting { padding: 16px; }
  .msg-user { max-width: 88%; }
}

/* ---------------- richer agent responses (2026-08-12) ----------------
 * Tables, blockquotes, citation chips, hr — paired with the markdown()
 * upgrades in try.js. Goal: answers read like a briefing, not a printout. */
.msg-body { font-size: 15.5px; letter-spacing: -0.006em; }
.msg-body .md-tablewrap { margin: 12px 0; overflow-x: auto; border: 1px solid var(--rule-2);
  border-radius: 10px; background: var(--bg-card); }
.msg-body table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.45; }
.msg-body th { text-align: left; font-weight: 700; color: var(--ink); background: var(--bg-elevated);
  padding: 8px 12px; border-bottom: 1px solid var(--rule-2); white-space: nowrap; }
.msg-body td { padding: 7px 12px; border-bottom: 1px solid var(--rule); color: var(--ink-2);
  vertical-align: top; }
.msg-body tr:last-child td { border-bottom: none; }
.msg-body tbody tr:nth-child(even) td { background: var(--bg-card-hi); }
.msg-body blockquote { margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--gold);
  background: var(--gold-faint); border-radius: 0 8px 8px 0; color: var(--ink-2); font-size: 14.5px; }
.msg-body hr { border: none; border-top: 1px solid var(--rule-2); margin: 16px 0; }
.msg-body .cite { background: var(--gold-soft); color: var(--gold-lo); border-radius: 5px;
  padding: 0 5px; font-size: 0.94em; font-weight: 600; white-space: nowrap; }
.msg-body h3 { font-size: 18px; font-weight: 700; margin: 18px 0 8px; }
.msg-body h3:first-child, .msg-body h4:first-child { margin-top: 2px; }
.msg-body ul, .msg-body ol { margin: 10px 0; padding-left: 22px; }
.msg-body li { margin: 5px 0; line-height: 1.6; }
.msg-body li::marker { color: var(--gold); font-weight: 700; }

/* ---------------- Supplement Facts inline panel (compute_sfp) ---------------- */
.sfpx-wrap { margin: 14px 0 4px; }
.sfpx { width: 320px; max-width: 100%; border: 2px solid #000; padding: 6px 9px; background: #fff;
  color: #000; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
.sfpx-t { font-size: 28px; font-weight: 900; letter-spacing: -0.5px; line-height: 1.02; }
.sfpx-serv { font-size: 12px; border-top: 1px solid #000; padding: 3px 0 2px; line-height: 1.4; }
.sfpx-hdr { display: flex; justify-content: space-between; border-top: 7px solid #000;
  font-size: 10.5px; font-weight: 800; padding: 2px 0; }
.sfpx-row { display: grid; grid-template-columns: 1fr 74px 46px; border-top: 1px solid #000;
  padding: 3px 0; font-size: 11.5px; align-items: baseline; line-height: 1.35; }
.sfpx-a { text-align: left; }
.sfpx-d { text-align: right; font-weight: 700; }
.sfpx-thick { border-top: 5px solid #000; }
.sfpx-comp { font-size: 10.5px; font-style: italic; padding: 0 0 3px 10px; line-height: 1.35; }
.sfpx-foot { border-top: 7px solid #000; font-size: 9.5px; line-height: 1.35; padding-top: 4px; margin-top: 2px; }
.sfpx-note { font-size: 11px; color: var(--ink-3); margin-top: 6px; }

/* SFP panel export actions */
.sfpx-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.sfpx-btn { font: 600 12px/1 inherit; color: var(--gold-hi); background: var(--gold-faint);
  border: 1px solid rgba(107,91,214,.3); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.sfpx-btn:hover { background: var(--gold-soft); }
.sfpx-btn:disabled { opacity: .55; cursor: default; }
.sfpx-actnote { font-size: 11.5px; color: var(--ink-3); }

/* ---------------- conversation history panel ---------------- */
.convo-panel { position: fixed; z-index: 1000; width: 320px; max-height: 420px; overflow-y: auto;
  background: var(--bg-card, #fff); border: 1px solid var(--rule-2); border-radius: 12px;
  box-shadow: 0 10px 34px rgba(22,20,40,.14); padding: 6px; }
.convo-row { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.convo-row:hover { background: var(--bg-elevated); }
.convo-main { flex: 1; min-width: 0; }
.convo-title { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; }
.convo-del { border: none; background: none; color: var(--ink-4); font-size: 16px; cursor: pointer;
  padding: 2px 6px; border-radius: 6px; flex: none; }
.convo-del:hover { color: #CC4B2C; background: var(--red-soft, rgba(204,75,44,.12)); }
.convo-empty { padding: 14px 12px; font-size: 12.5px; color: var(--ink-3); }

/* history panel: search + rename */
.convo-search { width: calc(100% - 12px); margin: 4px 6px 6px; padding: 8px 11px; font: 13px/1.3 inherit;
  color: var(--ink); background: var(--bg-surface); border: 1px solid var(--rule-2); border-radius: 8px; outline: none; }
.convo-search:focus { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }
.convo-ren { border: none; background: none; color: var(--ink-4); font-size: 13px; cursor: pointer;
  padding: 2px 5px; border-radius: 6px; flex: none; }
.convo-ren:hover { color: var(--gold-hi); background: var(--gold-soft); }
.convo-rename-input { width: 100%; font: 13px/1.3 inherit; color: var(--ink); border: 1px solid var(--gold);
  border-radius: 6px; padding: 3px 7px; outline: none; }

/* topic bar: named threads per agent (Richard 2026-08-14) */
.topic-bar { display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 8px 22px; border-bottom: 1px solid var(--rule-2); background: var(--bg-surface); }
.topic-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 260px;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--rule-2);
  background: var(--bg-elevated); color: var(--ink-2); font: 12.5px/1.4 inherit;
  cursor: pointer; white-space: nowrap; overflow: hidden; }
.topic-chip:hover { border-color: var(--gold); color: var(--ink); }
.topic-chip.active { background: var(--gold-soft); border-color: var(--gold);
  color: var(--gold-hi); font-weight: 600; cursor: default; }
.topic-chip .topic-ren { color: inherit; opacity: 0.55; cursor: pointer; }
.topic-chip .topic-ren:hover { opacity: 1; }
.convo-del-arm { font-size: 11.5px !important; font-weight: 600; color: #b3261e !important;
  background: rgba(179, 38, 30, 0.08) !important; border-radius: 6px; padding: 2px 7px !important;
  white-space: nowrap; }
.topic-chip .topic-x { color: inherit; opacity: 0; font-size: 14px; line-height: 1;
  padding: 0 1px; cursor: pointer; transition: opacity 0.12s; }
.topic-chip:hover .topic-x { opacity: 0.55; }
.topic-chip .topic-x:hover { opacity: 1; color: var(--gold-hi); }
.topic-chip.topic-new { border-style: dashed; color: var(--ink-4); }
.topic-chip.topic-new:hover { color: var(--gold-hi); border-color: var(--gold); }
.topic-chip .convo-rename-input { width: 150px; font-size: 12.5px; padding: 1px 6px; }
@media (max-width: 820px) { .topic-bar { padding: 7px 14px; } }
