/* Consensus Edge Chat — the floating button, the panel, the /chat page (spec §10).
   Type floor 16px. Colours come from main.css's tokens. */

.chat-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The entry button (spec 2026-09-19-chat-entry-button): a labeled pill in the
   .top-nav-pill style — bg-card, an accent border, the sigma-bubble mark and
   "Ask Consensus Edge" — bottom-right; above the search FAB where that shows
   (<=1024px), above the bottom nav where that shows (<=799px). It replaced a
   bare-emoji circle Bill read as "poorly done and not obvious" (2026-09-19). */
.ce-chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 95;
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px 8px 12px;
  border-radius: var(--radius-sm, 6px); border: 1px solid var(--accent); cursor: pointer;
  background: var(--bg-card); color: var(--text-primary);
  font-family: 'IBM Plex Sans', system-ui, sans-serif; font-size: 17px; font-weight: 500; line-height: 1.2; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.ce-chat-fab[hidden] { display: none; }   /* the kill switch (chat_panel.js hideEverything) */
.ce-chat-mark { flex: 0 0 auto; color: var(--accent); }
.ce-chat-fab-label-short { display: none; }
.ce-chat-fab:hover, .ce-chat-fab:focus-visible, .ce-chat-fab[aria-expanded="true"] { background: var(--accent); color: #0d1117; }
.ce-chat-fab:hover .ce-chat-mark, .ce-chat-fab:focus-visible .ce-chat-mark, .ce-chat-fab[aria-expanded="true"] .ce-chat-mark { color: #0d1117; }
.ce-chat-fab:focus-visible { outline: 3px solid var(--text-primary); outline-offset: 2px; }
@media (max-width: 1024px) {
  .ce-chat-fab { right: 12px; bottom: calc(20px + 44px + 12px + var(--parlay-slip-h, 0px)); }
}
@media (max-width: 799px) {
  .ce-chat-fab { bottom: calc(65px + env(safe-area-inset-bottom) + 12px + 44px + 12px + var(--parlay-slip-h, 0px)); }
  /* a ~240px pill fixed over a phone's cards is an occluder: the mark and "Ask" */
  .ce-chat-fab-label { display: none; }
  .ce-chat-fab-label-short { display: inline; }
}

/* The panel */
.ce-chat-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 9000;
  width: min(420px, 100vw); display: flex; flex-direction: column;
  background: var(--bg-card); border-left: 1px solid var(--border-default);
  box-shadow: -8px 0 32px rgba(0,0,0,0.45); color: var(--text-primary); font-size: 16px;
}
.ce-chat-panel[hidden] { display: none; }
@media (max-width: 767px) {
  .ce-chat-panel { width: 100vw; left: 0; border-left: none; }
}
.ce-chat-header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; border-bottom: 1px solid var(--border-default); flex-wrap: wrap; }
.ce-chat-title { font-size: 18px; margin: 0; flex: 1 1 auto; }
.ce-chat-close { font-size: 22px; line-height: 1; }

.chat-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 14px;
  border-radius: var(--radius-sm, 6px); border: 1px solid var(--border-default); background: var(--bg-raised, var(--bg-card));
  color: var(--text-primary); font-size: 16px; cursor: pointer; text-decoration: none;
}
.chat-btn[hidden] { display: none; }   /* Past chats, for a locked reader (showLocked) */
.chat-btn-primary { background: var(--accent); color: #0d1117; border-color: var(--accent); font-weight: 600; }
.chat-btn:focus-visible { outline: 3px solid var(--text-primary); outline-offset: 2px; }
/* a closed composer (signed out, pool used, a turn in flight) looks closed — same recipe as .auth-btn:disabled */
.chat-btn:disabled, .chat-input:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-cap { font-size: 16px; color: var(--text-dim, var(--text-primary)); }

.chat-messages { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-streaming { padding: 0 12px; display: flex; flex-direction: column; }
.chat-streaming:empty { display: none; }
.chat-example-inert { display: block; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-default); font-size: 16px; color: var(--text-dim, var(--text-primary)); }
.chat-thread-time { font-size: 16px; color: var(--text-dim, var(--text-primary)); font-weight: 400; margin-left: 6px; }
.chat-msg { max-width: 92%; padding: 10px 12px; border-radius: 12px; line-height: 1.45; font-size: 16px; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 8px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg-user { align-self: flex-end; background: var(--accent); color: #0d1117; }
.chat-msg-assistant { align-self: flex-start; background: var(--bg-raised, var(--bg-hover)); border: 1px solid var(--border-default); }
.chat-msg-failed { opacity: 0.6; }
/* A failed question is dimmed, but its resend line is not: it has to read as an action. */
.chat-msg-user.chat-msg-failed { opacity: 1; background: transparent; border: 1px dashed var(--accent); color: var(--text-primary); }
.chat-resend { display: block; min-height: 44px; margin: 6px 0 0 auto; padding: 8px 0; background: none; border: 0; color: var(--accent); font: inherit; font-size: 16px; font-weight: 600; text-align: right; cursor: pointer; }
.chat-resend:focus-visible { outline: 3px solid var(--text-primary); outline-offset: 2px; }
.chat-note { font-style: italic; color: var(--text-dim, var(--text-primary)); }
.chat-table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 16px; }
.chat-table th, .chat-table td { border: 1px solid var(--border-default); padding: 6px 8px; text-align: left; }
.chat-table td:last-child, .chat-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.chat-cite { font-size: 16px; text-decoration: none; color: var(--accent); }
.chat-sources { margin: 8px 0 0; padding-left: 20px; font-size: 16px; color: var(--text-dim, var(--text-primary)); }
.chat-h { font-size: 16px; }
.chat-msg code { font-family: var(--font-mono, monospace); font-size: 16px; }

.chat-status { min-height: 20px; padding: 0 12px 6px; font-size: 16px; color: var(--text-dim, var(--text-primary)); }
.chat-error { margin: 0 12px 8px; padding: 10px 12px; border-radius: 8px; background: rgba(220, 60, 60, 0.15); border: 1px solid var(--accent-red, #c33); font-size: 16px; }
.chat-error[hidden] { display: none; }
.chat-link { margin-left: 4px; color: var(--accent); text-decoration: underline; font-weight: 600; font-size: 16px; }
.chat-error .chat-link { color: inherit; }
.chat-gl-more summary { display: list-item; min-height: 44px; padding-block: 10px; box-sizing: border-box; cursor: pointer; }  /* list-item keeps the disclosure marker; flex would drop it */
.chat-retry { margin-left: 8px; min-height: 36px; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border-default); background: var(--bg-card); color: var(--text-primary); font-size: 16px; cursor: pointer; }

.chat-composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border-default); }
.chat-input { flex: 1 1 auto; min-height: 44px; resize: vertical; padding: 10px; border-radius: 8px; border: 1px solid var(--border-default); background: var(--bg-base, var(--bg-card)); color: var(--text-primary); font-size: 16px; font-family: inherit; }
.chat-input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.chat-empty, .chat-locked { padding: 16px 12px; }
.chat-empty[hidden], .chat-locked[hidden] { display: none; }
/* In the panel the descriptor and examples scroll; the composer and any refusal
   box never leave the viewport. Measured 2026-09-19 at 1280x720: header 117 +
   empty state 518 + status + error + form = 834px in a 720px panel put the
   composer at 759px, fully hidden. While the empty state shows, the (empty)
   message list must not take the free space, or a blank band sits above the composer. */
.ce-chat-panel .chat-empty, .ce-chat-panel .chat-locked { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.ce-chat-panel .chat-empty:not([hidden]) ~ .chat-messages, .ce-chat-panel .chat-locked:not([hidden]) ~ .chat-messages { flex: 0 0 auto; }
.ce-chat-panel .chat-messages { min-height: 0; }
/* Past chats in the panel (beta feedback 2026-09-25: a phone had no way back to
   an earlier question). While the list shows, it takes the panel's free space and
   everything below the header steps aside — the composer included. */
.ce-chat-panel[data-view="past"] > :not(.ce-chat-header):not(.chat-past) { display: none; }
.chat-past { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }
.chat-past[hidden] { display: none; }
.chat-past-title { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.chat-past-title:focus { outline: none; }
.chat-past-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chat-past-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px; width: 100%; min-height: 44px;
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border-default); background: var(--bg-raised, var(--bg-hover));
  color: var(--text-primary); font-size: 16px; font-family: inherit; text-align: left; cursor: pointer;
}
.chat-past-item[aria-current="true"] { border-color: var(--accent); }
.chat-past-item:focus-visible { outline: 3px solid var(--text-primary); outline-offset: 2px; }
.chat-past-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.chat-past-item .chat-thread-time { flex: 0 0 auto; margin-left: 0; white-space: nowrap; }
.chat-past-none { font-size: 16px; color: var(--text-dim, var(--text-primary)); padding: 8px 0; }
.chat-descriptor { font-size: 16px; line-height: 1.5; color: var(--text-primary); margin: 0 0 12px; }
.chat-locked-headline { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.chat-examples { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.chat-example { display: block; width: 100%; text-align: left; min-height: 44px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-default); background: var(--bg-raised, var(--bg-hover)); color: var(--text-primary); font-size: 16px; cursor: pointer; }
.chat-example:focus-visible { outline: 3px solid var(--text-primary); outline-offset: 2px; }

/* The /chat page */
.chat-page-body { background: var(--bg-base, #0d1117); color: var(--text-primary); margin: 0; font-family: 'IBM Plex Sans', system-ui, sans-serif; }
.chat-page { max-width: 1100px; margin: 0 auto; padding: 16px; font-size: 16px; }
.chat-page-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.chat-page-title { font-size: 20px; margin: 0; flex: 1 1 auto; }
.chat-back { color: var(--accent); text-decoration: none; font-size: 16px; min-height: 44px; display: inline-flex; align-items: center; }
.chat-page-columns { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 768px) {
  .chat-page-columns { grid-template-columns: 260px 1fr; }
  .chat-threads-toggle { display: none; }
  .chat-threads { display: block !important; }
}
.chat-threads-pane { display: flex; flex-direction: column; gap: 8px; }
.chat-threads { list-style: none; margin: 0; padding: 0; display: none; }
.chat-threads.open { display: block; }
.chat-thread-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.chat-thread-item.active .chat-thread-title { font-weight: 700; color: var(--accent); }
.chat-thread-title { flex: 1 1 auto; text-align: left; background: none; border: none; color: var(--text-primary); font-size: 16px; min-height: 44px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.chat-thread-title:hover, .chat-thread-title:focus-visible { background: var(--bg-hover, rgba(255,255,255,0.06)); outline: none; }
.chat-thread-tool { min-width: 44px; min-height: 44px; background: none; border: none; color: var(--text-dim, var(--text-primary)); font-size: 16px; cursor: pointer; }
.chat-conversation { display: flex; flex-direction: column; min-height: 60vh; border: 1px solid var(--border-default); border-radius: 12px; background: var(--bg-card); }
.chat-conversation .chat-messages { min-height: 40vh; }

@media (prefers-reduced-motion: no-preference) {
  .ce-chat-panel { transition: transform 160ms ease-out; }
}

/* A wide outcome table (the analyst adds the split that never loses on a win
   beside Net, 2026-09-25: five columns) scrolls sideways inside its bubble on
   a phone instead of running past it. The desktop table is unchanged. */
@media (max-width: 640px) {
  .chat-table { display: block; overflow-x: auto; }
  .chat-table th, .chat-table td { overflow-wrap: normal; }
}
/* The floating panel is at most 420px at every width, so a desktop reader
   meets the phone's problem there: a six-column table of your bets (442px)
   ran past its 350px bubble and the Result column sat off to the right
   (Bill's own thread, 2026-09-26). In the panel a table always scrolls inside
   its bubble; the wide /chat page keeps the plain table.
   A scrolling table keeps its words whole: .chat-msg breaks anywhere, and in a
   cell that squeezed "New England" to "Engl / and" instead of scrolling. */
.ce-chat-panel .chat-table { display: block; overflow-x: auto; }
.ce-chat-panel .chat-table th, .ce-chat-panel .chat-table td { overflow-wrap: normal; }
