/* =========================================================
   CHATROOM — "The Tape"
   Wick AI copilot for CandlEntry. Trading-terminal identity:
   hairline structure, flat tinted surfaces, tabular numerals.
   Scope: 3-pane app shell (rail · chat · inspector).
   Dark mode: token overrides live in theme_preferences.css.
   ========================================================= */

.chat-shell {
  /* ---- palette (light) ---- */
  --bg:          #eef1f7;
  --surface:     #ffffff;
  --surface-2:   #f6f8fb;
  --surface-3:   #e9edf4;

  --line:        #dde3ed;
  --line-2:      #e9edf4;

  --ink:         #0b1426;
  --ink-2:       #2c3a55;
  --muted:       #5d6b86;
  --soft:        #8e9bb2;
  --faint:       #cdd7e5;

  --green:       #0e9c68;
  --green-2:     #077a4e;
  --green-soft:  #e7f6ef;
  --green-line:  #bfe6d3;

  --amber:       #a35a00;
  --amber-soft:  #fdf5e7;
  --amber-line:  #efdcb2;

  --red:         #c53d32;
  --red-soft:    #fcf0ee;
  --red-line:    #f2d2cd;

  --user-bg:     #16223b;   /* user bubble — never flips in dark mode */
  --user-fg:     #f2f5fa;

  --r-sm: 6px;  --r-md: 10px;  --r-lg: 14px;  --r-xl: 18px;
  --r-pill: 999px;

  --shadow-1:  0 0 0 0.5px var(--line);
  --shadow-2:  0 8px 24px -16px rgba(11, 20, 38, .25);
  --shadow-pop: 0 12px 32px -16px rgba(11, 20, 38, .28);

  --mono: "SF Mono", ui-monospace, "Monaco", "Menlo", monospace;

  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 304px;
  height: calc(100vh - 64px);
  min-height: 560px;
  background: var(--surface);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.chat-shell-main { display: flex; flex-direction: column; min-width: 0; }

/* Shared data accents — pnl-positive/pnl-negative come from the global
   helper (calendar_helper#pnl_class); re-scope them to chat tokens so
   they follow the shell into dark mode. */
.chat-shell .pnl-positive { color: var(--green-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.chat-shell .pnl-negative { color: var(--red);     font-weight: 600; font-variant-numeric: tabular-nums; }

/* =========================================================
   LEFT RAIL — chatrooms
   ========================================================= */
.chat-rail {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 18px 10px 10px;
}
.chat-rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 12px;
}
.chat-rail-head span {
  font-size: 12px; font-weight: 600; letter-spacing: -.01em;
  color: var(--muted);
}
.chat-rail-foot {
  font-size: 11px; color: var(--soft); line-height: 1.55;
  padding: 12px 8px 4px; margin-top: 8px;
  border-top: 1px solid var(--line-2);
}

.chat-room-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding-right: 2px; margin-right: -4px;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.chat-room-list::-webkit-scrollbar { width: 6px; }
.chat-room-list::-webkit-scrollbar-track { background: transparent; }
.chat-room-list::-webkit-scrollbar-thumb { background: var(--faint); border-radius: var(--r-pill); }

.chat-room-item-wrap { position: relative; }
.chat-room-link-cover { position: absolute; inset: 0; z-index: 1; border-radius: var(--r-md); }

.chat-room-item {
  position: relative;
  display: flex; flex-direction: column; gap: 3px;
  border-radius: var(--r-md);
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.chat-room-item-wrap:hover .chat-room-item { background: var(--surface-3); }
.chat-room-item.is-active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-2);
}
.chat-room-item.is-active::before {
  content: "";
  position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--green);
}

.chat-room-top { display: flex; align-items: center; gap: 6px; }
.chat-room-account {
  font-size: 10px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  color: var(--muted); background: var(--surface-3);
  border-radius: var(--r-pill); padding: 2px 8px;
  max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-room-item.is-active .chat-room-account {
  background: var(--green-soft); color: var(--green-2);
}
.chat-room-badge {
  margin-left: auto;
  font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--amber-soft); color: var(--amber);
  border: 1px solid var(--amber-line);
  border-radius: var(--r-pill); padding: 1px 7px;
}
.chat-room-delete {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); font-size: 14px; line-height: 1;
  color: var(--soft); text-decoration: none;
  background: transparent; border: none;
  opacity: 0; transition: opacity .15s, background .15s, color .15s;
}
.chat-room-item-wrap:hover .chat-room-delete { opacity: 1; }
.chat-room-delete:hover { color: var(--red); background: var(--red-soft); }

.chat-room-title {
  font-size: 13px; font-weight: 600; letter-spacing: -.005em;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: calc(100% - 28px);
}
.chat-room-preview {
  font-size: 12px; color: var(--muted); line-height: 1.45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-room-time { font-size: 10.5px; color: var(--soft); margin-top: 1px; }
.chat-rail-empty {
  font-size: 12px; color: var(--soft);
  text-align: center; padding: 24px 12px;
}

/* Multi-account initials stack */
.chat-room-account.is-multi {
  display: inline-flex; align-items: center; gap: 6px; padding-left: 4px;
}
.chat-room-account-stack { display: inline-flex; }
.chat-room-account-stack i {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-2);
  font-style: normal;
  font-size: 8.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--bg);
  margin-left: -5px;
}
.chat-room-account-stack i:first-child { margin-left: 0; }
.chat-room-account-stack i:nth-child(1) { background: #dbeafe; color: #1e40af; }
.chat-room-account-stack i:nth-child(2) { background: var(--green-soft); color: var(--green-2); }
.chat-room-account-stack i:nth-child(3) { background: #fdf5e7; color: var(--amber); }
.chat-room-item.is-active .chat-room-account-stack i { border-color: var(--green-soft); }

/* =========================================================
   CENTER — CHAT
   ========================================================= */
.chat-page {
  display: flex; flex-direction: column;
  height: 100%; min-width: 0;
  background: var(--surface);
}
.chat-header {
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.chat-header .dash-heading { flex: 1; min-width: 0; }

.chat-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-title-row h1 {
  font-size: 20px; font-weight: 700; letter-spacing: -.02em;
  line-height: 1.2; color: var(--ink); margin: 0;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header p {
  font-size: 12.5px; color: var(--muted); margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}

/* icon buttons */
.chat-icon-btn {
  width: 32px; height: 32px; padding: 0; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink-2); cursor: pointer; text-decoration: none;
  font-family: inherit; font-size: 13px;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.chat-icon-btn svg { width: 15px; height: 15px; }
.chat-icon-btn:hover { background: var(--surface-2); border-color: var(--faint); color: var(--ink); }
.chat-icon-btn:active { transform: translateY(1px); }

/* rename form */
.chat-rename {
  display: flex; gap: 8px;
  padding: 12px 28px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.chat-rename.hidden { display: none; }
.chat-rename input[type=text] {
  flex: 1;
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 9px 12px; font-size: 13px; font-family: inherit;
  background: var(--surface); color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.chat-rename input[type=text]:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent);
}

/* pending pill */
.chat-pending-pill {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--amber-soft); border: 1px solid var(--amber-line);
  color: var(--amber); font-weight: 600;
  border-radius: var(--r-md); padding: 9px 14px;
  font-size: 12.5px; font-variant-numeric: tabular-nums;
  margin: 14px auto 0; width: min(780px, calc(100% - 56px));
  flex-wrap: wrap;
}
.chat-pending-pill button {
  background: var(--amber); color: #fff;
  border: none; border-radius: var(--r-sm);
  padding: 4px 12px; font-size: 11.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.chat-pending-pill button:hover { background: color-mix(in srgb, var(--amber) 82%, black); }

/* =========================================================
   MESSAGES — single 780px reading column, flat hairlines
   ========================================================= */
.chat-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 26px 28px 22px;
  display: flex; flex-direction: column; gap: 18px;
  align-items: center;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--faint); border-radius: var(--r-pill); }
/* FIX: flex-shrink: 0 — the transcript is a fixed-height column flex
   box; children default to flex-shrink: 1, and items with overflow:
   hidden (.chat-think, .chat-activity, .chat-tool-card) have NO
   automatic minimum size, so any new turn that pushed the transcript
   past the viewport squashed earlier turns' panels to a 2px sliver.
   Bubbles survived only by accident (overflow: visible ⇒ content-sized
   min height). The container must GROW, never shrink — it scrolls. */
.chat-scroll > * { width: 100%; max-width: 780px; flex-shrink: 0; }

/* ---- empty state ---- */
.chat-empty {
  margin: auto; text-align: center; max-width: 560px; padding: 40px 20px 30px;
}
.chat-empty h2 {
  font-size: 26px; font-weight: 700; letter-spacing: -.025em;
  color: var(--ink); margin: 18px 0 8px;
}
.chat-empty p { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 24px; }

.chat-candles {
  width: 148px; height: 64px; margin: 0 auto;
  display: block;
}
/* Presentation attributes can't use var() — candle colors are class-driven
   so they follow the theme tokens in light and dark. */
.chat-candles .cc-wick    { stroke: var(--faint); }
.chat-candles .cc-up      { fill: var(--green); }
.chat-candles .cc-up-wick { stroke: var(--green); }
.chat-candles .cc-down    { fill: var(--red); }
.chat-candles .cc-down-wick { stroke: var(--red); }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chat-suggestion {
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: var(--r-lg);
  padding: 8px 15px; font-size: 12.5px; color: var(--ink-2);
  cursor: pointer; font-family: inherit;
  transition: border-color .15s, background .15s, color .15s, transform .1s;
}
.chat-suggestion:hover {
  border-color: var(--green-line); color: var(--green-2); background: var(--green-soft);
}
.chat-suggestion:active { transform: translateY(1px); }

/* ---- message rows ---- */
.chat-msg { display: flex; gap: 12px; animation: chatFade .25s ease; min-width: 0; }
@keyframes chatFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg--user { justify-content: flex-end; }
.chat-msg--assistant { justify-content: flex-start; }

/* Wick's avatar: a candle, drawn in markup — square tile, no gradient */
.chat-avatar {
  flex: 0 0 34px; width: 34px; height: 34px;
  border-radius: var(--r-md);
  background: var(--green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.chat-avatar svg { width: 16px; height: 16px; display: block; }

.chat-bubble {
  max-width: 76%;
  padding: 12px 16px;
  border-radius: var(--r-xl);
  font-size: 14.5px; line-height: 1.6;
  color: var(--ink);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.chat-msg--user .chat-bubble {
  background: var(--user-bg); color: var(--user-fg);
  border-bottom-right-radius: var(--r-sm);
}
.chat-msg--assistant .chat-bubble {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--r-sm);
  color: var(--ink-2);
}
.chat-msg--assistant .chat-bubble :is(strong, b) { color: var(--ink); font-weight: 650; }
.chat-bubble p { margin: 0 0 8px; }
.chat-bubble p:last-child { margin: 0; }
.chat-bubble a { color: var(--green-2); text-underline-offset: 2px; }
.chat-bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.chat-bubble th, .chat-bubble td { border: 1px solid var(--line); padding: 6px 10px; }
.chat-bubble th { background: var(--surface-3); font-size: 11px; }
.chat-bubble code {
  background: var(--surface-3); padding: 1px 6px; border-radius: var(--r-sm);
  font-size: 12.5px; font-family: var(--mono);
}

/* =========================================================
   STREAMING STATES
   ========================================================= */
.chat-bubble--thinking {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 12px 16px;
  border-radius: var(--r-xl); border-bottom-left-radius: var(--r-sm);
}
.chat-bubble--thinking-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint);
  animation: chatBlink 1.2s infinite;
}
.chat-bubble--thinking-dot:nth-child(2) { animation-delay: .2s; }
.chat-bubble--thinking-dot:nth-child(3) { animation-delay: .4s; }
.chat-bubble--thinking-label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  margin-right: 6px; font-variant-numeric: tabular-nums;
}

@keyframes chatBlink {
  0%, 80%, 100% { opacity: .35; transform: scale(.85); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* Streaming caret */
.chat-bubble--streaming { position: relative; }
.chat-bubble--streaming::after {
  content: '▍';
  display: inline-block; margin-left: 2px;
  color: var(--green);
  animation: chatCaret 1.1s steps(2, start) infinite;
  vertical-align: -1px;
}
@keyframes chatCaret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .chat-bubble--streaming::after,
  .chat-bubble--thinking-dot,
  .chat-msg,
  .chat-think,
  .chat-scope-event { animation: none !important; }
  .chat-scroll { scroll-behavior: auto !important; }
}

/* ---- reasoning panel ---- */
.chat-think {
  margin-left: 46px;
  width: calc(100% - 46px);
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r-md);
  overflow: hidden;
  font-size: 12.5px;
  align-self: flex-start;
  animation: chatFade .25s ease;
}
.chat-think-head {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px;
  background: transparent; border: 0;
  cursor: pointer; color: var(--muted);
  font-size: 11.5px; font-weight: 600; font-family: inherit;
  text-align: left;
  transition: color .15s, background .15s;
}
.chat-think-head:hover { color: var(--ink-2); background: var(--surface-3); }
.chat-think-head:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chat-think-chev {
  width: 12px; height: 12px; flex-shrink: 0;
  transition: transform .2s cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-think.is-open .chat-think-chev { transform: rotate(90deg); }
.chat-think-label { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.chat-think-body {
  display: none;
  padding: 10px 14px 12px;
  font-size: 11.5px; line-height: 1.65;
  color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
  max-height: 240px; overflow-y: auto;
  font-family: var(--mono);
  border-top: 1px solid var(--line-2);
}
.chat-think.is-open .chat-think-body { display: block; }
.chat-think-body::-webkit-scrollbar { width: 5px; }
.chat-think-body::-webkit-scrollbar-thumb { background: var(--faint); border-radius: var(--r-pill); }

/* =========================================================
   TOOL RESULT CARDS
   ========================================================= */
.chat-tool-card {
  margin-left: 46px;
  width: calc(100% - 46px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
  align-self: flex-start;
  width: 100%;
}
.chat-tool-card .chat-tool-chip {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: none; border: none;
  padding: 10px 14px;
  font-size: 12.5px; color: var(--ink-2);
  cursor: pointer; text-align: left; font-family: inherit;
  transition: background .15s;
}
.chat-tool-chip:hover { background: var(--surface-2); }
.chat-tool-chip.is-error { color: var(--red); cursor: default; }
.chat-tool-chip .chat-tool-emoji { flex-shrink: 0; }
.chat-tool-chip strong { font-weight: 650; color: var(--ink); }
.chat-tool-caret { margin-left: auto; color: var(--soft); font-size: 10px; transition: transform .15s; }
.chat-tool-card.is-open .chat-tool-caret { transform: rotate(180deg); }
.chat-tool-body { display: none; border-top: 1px solid var(--line-2); padding-bottom: 8px; }
.chat-tool-card.is-open .chat-tool-body { display: block; }
.chat-tool-body .dash-table-wrap { padding: 8px 10px 0; }

/* =========================================================
   ACTIVITY — one collapsed card per turn holding the tool
   calls Wick made on the way to its answer. The streamed
   client and the reload path both produce this same markup.
   ========================================================= */
.chat-activity {
  margin-left: 46px;
  width: calc(100% - 46px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
  align-self: flex-start;
}
.chat-activity-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 12.5px;
  font-family: inherit;
  text-align: left;
  transition: background .15s;
}
.chat-activity-head:hover { background: var(--surface-2); }
.chat-activity-head:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chat-activity-chev {
  width: 12px; height: 12px; flex-shrink: 0;
  color: var(--soft);
  transition: transform .2s cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-activity.is-open .chat-activity-chev { transform: rotate(90deg); }
.chat-activity-label { font-weight: 600; }
.chat-activity-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-3);
  padding: 2px 9px;
  border-radius: var(--r-pill);
}
.chat-activity-body { display: none; border-top: 1px solid var(--line-2); }
.chat-activity.is-open .chat-activity-body { display: block; }
/* Cards inside the group become quiet rows — no nested borders. */
.chat-activity-body .chat-tool-card {
  margin: 0;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-2);
  border-radius: 0;
}
.chat-activity-body .chat-tool-card:last-child { border-bottom: 0; }

/* =========================================================
   PROCESS — one collapsed card per turn holding ALL process
   elements: reasoning steps (one per LLM round) and the tool
   activity group. The streamed client and the reload path
   both produce this same markup (2026-11-19: replaced the
   three stacked bars thinking / activity / reasoning).
   ========================================================= */
.chat-process {
  margin-left: 46px;
  width: calc(100% - 46px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
  align-self: flex-start;
}
.chat-process-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 12.5px;
  font-family: inherit;
  text-align: left;
  transition: background .15s;
}
.chat-process-head:hover { background: var(--surface-2); }
.chat-process-head:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chat-process-chev {
  width: 12px; height: 12px; flex-shrink: 0;
  color: var(--soft);
  transition: transform .2s cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-process.is-open .chat-process-chev { transform: rotate(90deg); }
.chat-process-label { font-weight: 600; }
.chat-process-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-3);
  padding: 2px 9px;
  border-radius: var(--r-pill);
}
.chat-process-body { display: none; border-top: 1px solid var(--line-2); }
.chat-process.is-open .chat-process-body { display: block; }

/* Steps inside become quiet rows — collapsed by default (2026-11-19);
   they open via their own toggles. */
.chat-process-body .chat-think,
.chat-process-body .chat-activity {
  margin: 0;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-2);
  border-radius: 0;
}
.chat-process-body .chat-think:last-child,
.chat-process-body .chat-activity:last-child { border-bottom: 0; }
/* The activity group inside keeps its quiet tool rows; strip its own
   top border — the step border above already separates it. */
.chat-process-body .chat-activity .chat-activity-body { border-top: 0; }

/* =========================================================
   CONFIRM CARDS
   ========================================================= */
.chat-confirm {
  margin-left: 46px;
  width: calc(100% - 46px);
  border: 1px solid var(--amber-line);
  background: var(--amber-soft);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.chat-confirm.executed  { border-color: var(--green-line); background: var(--green-soft); }
.chat-confirm.cancelled { border-color: var(--line); background: var(--surface-2); }

.chat-confirm-head { display: flex; gap: 10px; align-items: flex-start; }
.chat-confirm-icon { flex-shrink: 0; font-size: 16px; line-height: 1.3; }
.chat-confirm-head strong { font-size: 14px; color: var(--ink); }
.chat-confirm-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.chat-confirm-list {
  margin: 10px 0 0; padding-left: 18px;
  font-size: 13px; color: var(--ink-2);
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
.chat-confirm-list strong { color: var(--ink); }
.chat-confirm-more { font-size: 12px; color: var(--soft); margin: 4px 0 0 18px; }
.chat-confirm-actions { display: flex; gap: 8px; margin-top: 12px; }
.chat-confirm-state-msg {
  margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--green-2);
  font-variant-numeric: tabular-nums;
}
.chat-confirm.cancelled .chat-confirm-state-msg { color: var(--muted); }
.chat-confirm-open { color: var(--soft); font-style: italic; }

/* =========================================================
   KEY / VALUE GRIDS
   ========================================================= */.chat-kv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px; padding: 10px 12px 0;
}
.chat-kv-row {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 9px 12px;
}
.chat-kv-row span {
  display: block;
  font-size: 10.5px; letter-spacing: .3px;
  color: var(--soft); margin-bottom: 3px;
}
.chat-kv-row strong {
  font-size: 14.5px; font-weight: 650; letter-spacing: -.01em;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.chat-notes { margin: 8px 14px 0; font-size: 13px; color: var(--ink-2); }
/* review_checklist card — the checks Wick must judge */
.chat-check-list {
  list-style: none;
  margin: 10px 14px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.chat-check-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.chat-check-list li::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--green);
  flex-shrink: 0;
  transform: translateY(-1px);
}
.chat-check-list li.muted { color: var(--muted); font-style: italic; }
.chat-check-list li.muted::before { background: var(--faint); }
.chat-raw {
  margin: 10px 14px 0; font-size: 11.5px; color: var(--muted);
  overflow-x: auto; font-family: var(--mono);
  white-space: pre;
}

/* =========================================================
   COMPOSER
   ========================================================= */
.chat-composer {
  padding: 14px 28px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chat-form { display: block; max-width: 780px; margin: 0 auto; }
.chat-input-shell {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 6px 6px 6px 16px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.chat-input-shell:focus-within {
  background: var(--surface);
  border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 12%, transparent);
}
.chat-input-shell textarea {
  flex: 1;
  resize: none; border: none; outline: none;
  background: transparent;
  font-size: 14.5px; font-family: inherit; line-height: 1.5;
  padding: 10px 0;
  min-height: 24px; max-height: 160px;
  color: var(--ink);
}
.chat-input-shell textarea::placeholder { color: var(--soft); }
.chat-send {
  flex: 0 0 auto;
  width: 38px; height: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--r-lg);
  background: var(--green); color: #fff;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s, box-shadow .15s;
}
.chat-send svg { width: 16px; height: 16px; }
.chat-send:hover:not(:disabled) {
  background: var(--green-2);
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--green) 60%, transparent);
}
.chat-send:active:not(:disabled) { transform: scale(.96); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }

.chat-disclaimer {
  font-size: 11px; color: var(--soft);
  margin: 8px 0 0; text-align: center;
}

/* =========================================================
   SCOPE BAR
   ========================================================= */
.chat-scope-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12.5px;
  flex-wrap: wrap;
}
.chat-scope-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
}
.chat-scope-label svg { color: var(--soft); }

.chat-scope-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  flex: 1; min-width: 0;
}
.chat-scope-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 11px 4px 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  text-decoration: none;
  font-family: inherit;
  font-size: 12px; font-weight: 500; line-height: 1.2;
  transition: border-color .15s, background .15s, color .15s, transform .1s;
  max-width: 180px;
}
.chat-scope-chip:hover { border-color: var(--faint); background: var(--surface-3); }
.chat-scope-chip:active { transform: translateY(1px); }
.chat-scope-chip:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.chat-scope-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The scope dot: a candle — body + wick ticks */
.chat-scope-chip-dot {
  width: 8px; height: 10px; border-radius: 2px;
  background: var(--faint);
  box-shadow: 0 -3px 0 -2px var(--faint), 0 3px 0 -2px var(--faint);
  transition: background .15s, box-shadow .15s;
  flex-shrink: 0;
}
.chat-scope-chip.is-on {
  background: var(--green-soft);
  border-color: var(--green-line);
  color: var(--green-2);
  font-weight: 600;
}
.chat-scope-chip.is-on .chat-scope-chip-dot {
  background: var(--green);
  box-shadow: 0 -3px 0 -2px var(--green), 0 3px 0 -2px var(--green);
}
.chat-scope-chip.is-all {
  padding: 4px 12px;
  color: var(--muted);
  border-style: dashed;
}
.chat-scope-chip.is-all:hover { border-style: solid; color: var(--ink-2); }

.chat-scope-count {
  font-size: 11px; font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  flex-shrink: 0;
}
.chat-scope-count-slash { color: var(--soft); margin: 0 1px; font-weight: 400; }

/* =========================================================
   SCOPE EVENT — transcript divider
   ========================================================= */
.chat-scope-event {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 6px;
  animation: scopeFade .35s ease;
}
@keyframes scopeFade {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: none; }
}
.chat-scope-event-line {
  flex: 1; height: 1px;
  background: linear-gradient(to right, transparent, var(--line), transparent);
}
.chat-scope-event-body {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  padding: 3px 12px;
  flex-wrap: wrap; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.chat-scope-event-label {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--soft);
}
.chat-scope-event-arrow { color: var(--soft); }
.chat-scope-event-target { color: var(--ink-2); font-weight: 600; }
.chat-scope-event-tag {
  font-size: 11px; font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  margin-left: 2px;
}
.chat-scope-event-tag.is-added   { background: var(--green-soft); color: var(--green-2); }
.chat-scope-event-tag.is-removed { background: var(--red-soft);   color: var(--red); }

/* =========================================================
   PROVENANCE
   ========================================================= */
.chat-provenance {
  display: inline-flex; align-items: center; gap: 5px;
  margin: 4px 0 0 46px;
  font-size: 11px; color: var(--soft);
  align-self: flex-start;
}
.chat-provenance strong { color: var(--muted); font-weight: 600; }
.chat-provenance svg { color: var(--faint); flex-shrink: 0; }

/* =========================================================
   RIGHT PANE — INSPECTOR (account tape)
   ========================================================= */
.chat-inspector {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 18px 14px 14px;
  gap: 12px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

.chat-inspect-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
}
.chat-inspect-card h3 {
  font-size: 12.5px; font-weight: 650; letter-spacing: -.01em;
  color: var(--ink);
  margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}

.inspect-account-head { display: flex; align-items: center; gap: 10px; }
.inspect-avatar {
  flex: 0 0 36px; width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .02em;
}
.inspect-account-meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.inspect-account-meta strong {
  font-size: 13.5px; font-weight: 650; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inspect-account-meta span { font-size: 11.5px; color: var(--muted); }

.inspect-stat-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 12px;
}
.inspect-stat {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 9px 11px;
  min-width: 0;
}
.inspect-stat-label {
  display: block;
  font-size: 10.5px; letter-spacing: .2px;
  color: var(--soft); margin-bottom: 3px;
}
.inspect-stat-value {
  font-size: 15px; font-weight: 700; letter-spacing: -.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}
.inspect-stat--accent {
  background: var(--green-soft);
  border-color: var(--green-line);
}
.inspect-stat--accent .inspect-stat-label { color: var(--green-2); }
.inspect-stat--accent .inspect-stat-value { color: var(--green-2); }
.inspect-stat--accent .pnl-negative { color: var(--red); }

.inspect-meter {
  height: 3px; border-radius: var(--r-pill);
  background: var(--line-2); margin-top: 7px;
  overflow: hidden;
}
.inspect-meter-fill {
  height: 100%; border-radius: inherit;
  background: var(--green);
  transition: width .3s ease;
}
.inspect-spark { width: 100%; height: 18px; margin-top: 6px; display: block; color: var(--green-2); }
.inspect-spark path { stroke: currentColor; }

.inspect-action {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 12.5px; font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  background: var(--surface-2);
  transition: border-color .15s, background .15s, color .15s;
}
.inspect-action:hover { border-color: var(--faint); background: var(--surface-3); color: var(--ink); }

.inspect-badge {
  font-size: 10.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--muted);
}
.inspect-badge.has { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber-line); }
.inspect-cap { font-size: 10.5px; color: var(--soft); font-weight: 500; margin-left: auto; }

.chat-inspect-empty { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }

.chat-activity-row {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-2);
}
.chat-activity-row:last-child { border-bottom: none; }
.chat-activity-row > div { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-activity-row strong {
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-activity-row span { font-size: 10.5px; color: var(--soft); }
.chat-activity-dot {
  flex-shrink: 0;
  width: 8px; height: 8px; border-radius: 2px;
  margin-top: 4px;
  background: var(--faint);
}
.chat-activity-row.executed  .chat-activity-dot { background: var(--green); }
.chat-activity-row.pending   .chat-activity-dot { background: var(--amber); }
.chat-activity-row.cancelled .chat-activity-dot,
.chat-activity-row.failed    .chat-activity-dot { background: var(--red); }

/* =========================================================
   TABLES inside tool bodies + bubbles — horizontal scroll
   ========================================================= */
.chat-table-wrap { padding: 4px 4px 0; }
.chat-table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.chat-table::-webkit-scrollbar { height: 6px; }
.chat-table::-webkit-scrollbar-track { background: transparent; }
.chat-table::-webkit-scrollbar-thumb { background: var(--faint); border-radius: var(--r-pill); }

.chat-table thead th {
  text-align: left;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--soft);
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
}
.chat-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
  vertical-align: middle;
  white-space: nowrap;
}
.chat-table tbody tr:last-child td { border-bottom: none; }
.chat-table tbody tr.is-in-scope td { background: color-mix(in srgb, var(--green) 4%, transparent); }
.chat-table td.is-name { color: var(--ink); font-weight: 600; }
.chat-table td.is-muted { color: var(--muted); }
.chat-table td.is-num, .chat-table th.is-num {
  text-align: right; font-family: var(--mono); font-size: 12.5px;
}
.chat-table td.is-center, .chat-table th.is-center { text-align: center; }
.chat-table .is-win  { color: var(--green-2); font-weight: 650; }
.chat-table .is-loss { color: var(--red);     font-weight: 650; }

.chat-table-pill {
  display: inline-block;
  font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
}
.chat-table-pill.is-on { background: var(--green-soft); color: var(--green-2); }
.chat-table-pill.is-off { opacity: .45; }

.chat-table-foot {
  font-size: 11.5px; color: var(--muted);
  margin: 6px 12px 8px;
  font-variant-numeric: tabular-nums;
}
.chat-table-foot em { font-style: normal; color: var(--ink-2); font-weight: 600; }

/* Markdown tables the model writes inside bubbles scroll too. */
.chat-bubble table {
  display: block;
  width: 100%; max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.chat-bubble table::-webkit-scrollbar { height: 6px; }
.chat-bubble table::-webkit-scrollbar-thumb { background: var(--faint); border-radius: var(--r-pill); }
.chat-bubble th, .chat-bubble td { white-space: nowrap; }

/* Markdown lists align with the bubble's text edge */
.chat-bubble ul, .chat-bubble ol {
  margin: 0.6em 0;
  padding-left: 1.5em;
  list-style-position: outside;
}
.chat-bubble li { margin: 0.35em 0; }
.chat-bubble li > p { margin: 0; }

/* =========================================================
   KEYBOARD FOCUS
   ========================================================= */
.chat-shell :is(.chat-icon-btn, .chat-suggestion, .chat-send, .chat-room-link-cover, .inspect-action, .chat-tool-chip):focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}
.chat-shell :is(button, a, input):focus-visible { outline-color: var(--green); }

/* =========================================================
   RESPONSIVE
   ========================================================= */
.chat-panel-toggle { display: none; }

@media (max-width: 1180px) {
  .chat-shell { grid-template-columns: 264px minmax(0, 1fr); }
  .chat-inspector { display: none; }
}

@media (max-width: 920px) {
  .chat-shell { grid-template-columns: minmax(0, 1fr); }
  .chat-rail { display: none; }
  .chat-shell.show-rail .chat-rail {
    display: flex; position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; z-index: 60;
    background: var(--bg);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
  }
  .chat-shell.show-rail::after {
    content: ""; position: fixed; inset: 0; z-index: 55;
    background: rgba(11, 20, 38, .35);
  }
  .chat-panel-toggle { display: inline-flex; }
  .chat-bubble { max-width: 88%; }
  .chat-scroll { padding: 18px 16px; }
  .chat-scroll > * { max-width: 100%; }
  .chat-header { padding: 14px 16px 12px; }
  .chat-composer { padding: 12px 16px 16px; }
  .chat-scope-bar { padding: 9px 16px; }
  .chat-rename { padding: 12px 16px; }
  .chat-pending-pill { width: calc(100% - 32px); margin-top: 12px; }
  .chat-scope-count { display: none; }
  .chat-scope-chip { max-width: 140px; }
  .chat-provenance { margin-left: 46px; }
  .chat-think { max-width: calc(100% - 46px); }
}

/* =========================================================
   FULL-HEIGHT LOCK — page owns 100dvh; inner regions scroll
   ========================================================= */
html:has(.chat-shell),
body:has(.chat-shell) {
  height: 100dvh;
  overflow: hidden;
}
body:has(.chat-shell) .main-content,
.main-content:has(> .chat-shell) {
  padding: 0;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.chat-shell {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr);
}
.chat-page,
.chat-shell-main {
  min-height: 0;
  overflow: visible;
}
.chat-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}
