/* =============================================================================
   Chat panel (right sidebar) — EasyCabinet chat-first reskin
   Organized by component. Tokens mostly reuse ui/theme.css vars (--bg, --text,
   --accent, etc.) which already match the design-spec hex values in dark mode;
   a few spec-only literals (card cream, green pill) are hardcoded per the spec
   since theme.css has no light-mode-safe equivalent for them.
   ============================================================================= */

#chat-panel {
  position: relative;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  transition: opacity 0.2s ease;
}

/* ---- Resize handle (unchanged behavior, ui/chat-resize.js) ---- */
.chat-resize-handle {
  position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
  cursor: ew-resize; z-index: 20; touch-action: none;
}
.chat-resize-handle::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: transparent; transition: background .15s ease;
}
.chat-resize-handle:hover::after,
body.chat-resizing .chat-resize-handle::after { background: var(--accent); }
body.chat-resizing { cursor: ew-resize; user-select: none; }
#app.chat-collapsed .chat-resize-handle { display: none; }
@media (max-width: 900px) { .chat-resize-handle { display: none; } }

#app.chat-collapsed #chat-panel {
  opacity: 0;
  pointer-events: none;
  border-left-color: transparent;
}

/* ---- Header ---- */
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.chat-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.2px;
  font-weight: 700;
}

.chat-head .subtitle {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.chat-head-title { display: flex; align-items: center; gap: 9px; }
.chat-status-dot {
  width: 8px; height: 8px; flex: none; border-radius: 999px;
  background: var(--green); box-shadow: 0 0 9px var(--green);
}

.chat-collapse-btn {
  flex: none;
  padding: 5px 8px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.chat-collapse-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.chat-head-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-new-btn {
  padding: 5px 9px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
.chat-new-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Expand tab (visible when collapsed) */
#chat-expand-tab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 20;
  padding: 12px 8px 12px 10px;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.5px;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.25);
  display: none;
}
#chat-expand-tab:hover {
  background: var(--panel-2);
}
#app.chat-collapsed #chat-expand-tab {
  display: block;
}

/* ---- Design checklist (Dimensions · Design · Build) ----
   Live, spec-driven strip replacing the old static wizard progress bar.
   Rendered by chat-panel.js renderDesignChecklist(). */
.design-checklist {
  flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.design-checklist.empty {
  display: none;
}

.dc-strip {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
}

.dc-phase {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.dc-phase:hover {
  background: var(--accent-softer);
  color: var(--text);
}
.dc-phase.active {
  color: var(--amber-text);
  border-color: var(--accent-soft);
}
.dc-phase.done {
  color: var(--accent-2);
  border-color: var(--green-chip);
  background: var(--green-chip);
}
.dc-phase.open {
  background: var(--panel-3);
  color: var(--text);
}

.dc-phase-count {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  opacity: 0.9;
}
.dc-phase-count svg {
  width: 11px;
  height: 11px;
}

.dc-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 12px 10px;
}

.dc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}
.dc-item:hover {
  background: var(--accent-softer);
}
.dc-item.done {
  color: var(--muted);
  cursor: default;
}
.dc-item.done:hover {
  background: transparent;
}

.dc-item-box {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-2);
}
.dc-item.done .dc-item-box {
  border-color: var(--accent-2);
  background: var(--green-chip);
}
.dc-item-box svg {
  width: 10px;
  height: 10px;
}

.dc-item-label {
  flex: none;
  font-weight: 600;
}

.dc-item-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}

/* =============================================================================
   Design tab strip — spec: dot (left) + label + × (right); active tab bg
   var(--panel-inset), radius 10px 10px 0 0, amber inset underline; inactive muted.
   Built from JS (ensureTabStrip/renderTabStrip in chat-panel.js).
   ============================================================================= */
.chat-tab-strip {
  flex: none;
  display: flex;
  gap: 2px;
  align-items: flex-end;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}

.chat-tab-strip::-webkit-scrollbar {
  height: 4px;
}

.chat-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 168px;
  padding: 9px 11px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  transition: background 0.14s ease, color 0.14s ease;
}

.chat-tab:hover {
  color: var(--text);
  background: var(--panel-inset-hover);
}

.chat-tab.active {
  color: var(--text);
  background: var(--panel-inset);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.chat-tab-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.18) inset;
}

.chat-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tab-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.chat-tab-close:hover {
  color: var(--text);
  background: var(--panel-3);
}

/* Duplicate — relocated from the retired ui/project-panel.js drawer (docs
   §4.4); same small circular icon-button treatment as the close (×) button. */
.chat-tab-duplicate {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  color: var(--muted);
}

.chat-tab-duplicate svg {
  width: 11px;
  height: 11px;
}

.chat-tab-duplicate:hover {
  color: var(--text);
  background: var(--panel-3);
}

.chat-tab-add {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-bottom: 4px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.chat-tab-add:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-softer);
}

/* Signup-on-save affordance (docs/2026-07-09-STEP3-AUTH-DESIGN.md §2.4) — persistent,
   low-pressure, never an auto-popped modal. Shown only while signed out AND the
   active design has real content; disappears the moment the user signs in. */
.chat-tab-backup-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  margin-bottom: 4px;
  padding: 5px 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-softer);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.chat-tab-backup-chip:hover {
  background: var(--accent-softer);
  border-color: var(--accent);
}

/* Cloud "Last synced" status — relocated from the retired ui/sync-panel.js
   always-on-screen panel (docs §4.4). Signed-in counterpart to the backup
   chip above; the two never render at the same time. */
.chat-tab-sync-status {
  flex: none;
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  margin-bottom: 4px;
  padding: 5px 2px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11.5px;
  white-space: nowrap;
}

/* =============================================================================
   Messages
   ============================================================================= */
.chat-messages {
  flex: 1;
  /* Flex items default to min-height: auto, which can stop this box from
     shrinking to its allotted space (and scrolling internally) when the tab
     strip/checklist above it grow — instead it can spill past its own bounds,
     which is how the oldest message ends up rendered under the tab strip.
     min-height: 0 is the standard fix for a scrollable flex child. */
  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-msg {
  max-width: 94%;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.chat-msg.agent {
  align-self: flex-start;
  max-width: 96%;
}

.chat-msg.user {
  align-self: flex-end;
  text-align: right;
}

/* ---- Assistant messages: Fraunces, no bubble, plain text on bg ---- */
.chat-msg.agent .chat-msg-bubble {
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 0;
  font-family: 'Fraunces', var(--font-ui), serif;
  /* Calmer size/line-height than the old 16.5px/1.62 — that made even a 3-line
     reply dominate the panel. Keeps the serif brand voice, closer to the user
     bubble's scale (16px sans, which sits smaller than serif at the same px). */
  font-size: 14px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  text-align: left;
}
.chat-msg.agent .chat-msg-bubble p { margin: 0 0 0.9em; }
.chat-msg.agent .chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg.agent .chat-msg-bubble strong { font-weight: 600; }
.chat-msg.agent .chat-msg-bubble ul,
.chat-msg.agent .chat-msg-bubble ol {
  margin: 0 0 0.9em;
  padding-left: 1.3em;
}
.chat-msg.agent .chat-msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* Guide cards inside agent messages still want a contained surface even
   though the message text itself is now bubble-less. */
.chat-msg.agent .guide-card {
  font-family: var(--font-ui);
  font-size: 12.5px;
  line-height: 1.4;
}

/* ---- User messages: right-aligned dark rounded bubble ---- */
.chat-msg.user .chat-msg-bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 14px;
  border: none;
  background: var(--panel-inset);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
}

.chat-msg-meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 5px;
  padding: 0 2px;
}
.chat-msg.user .chat-msg-meta { text-align: right; }

/* Comment-mode user turn: captured viewport crop shown above the note text. */
.chat-comment-thumb {
  display: block;
  width: 100%;
  max-width: 200px;
  border-radius: 8px;
  margin: 0 0 8px;
  border: 1px solid var(--line);
}

.chat-msg.typing .chat-msg-bubble {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Three-dot pulse next to the live status line — the wait should read as
   activity, not a frozen label. Static ellipsis under reduced motion. */
.typing-dots {
  display: inline-flex;
  gap: 3px;
  flex: none;
}
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: typingDotPulse 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDotPulse {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
  .typing-dots i { animation: none; }
}
.typing-status {
  min-width: 0;
}

/* ---- "Assumed for now" strip (Claude Design gap item 3) ---- */
.chat-assumed {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed rgba(240, 228, 210, 0.14);
}
.chat-assumed-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.chat-assumed-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chat-assumed-pill {
  padding: 4px 9px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(236, 154, 60, 0.09);
  border: 1px solid rgba(236, 154, 60, 0.3);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-assumed-pill:hover {
  background: rgba(236, 154, 60, 0.18);
  border-color: rgba(236, 154, 60, 0.55);
}

/* Muted transcript line for a Tweaks-panel apply */
.chat-tweak-note {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
}

/* Share chip (gap item 6) — sits after the cloud backup/sync chip, which
   already carries the margin-left:auto push. */
.chat-tab-share-chip {
  flex: none;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(240, 228, 210, 0.16);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.14s ease, background 0.14s ease;
}
.chat-tab-share-chip:hover:not(:disabled) {
  border-color: rgba(236, 154, 60, 0.55);
  background: rgba(236, 154, 60, 0.1);
}
.chat-tab-share-chip:disabled {
  color: var(--ok, #7fc98b);
  cursor: default;
}

/* ---- Assistant message hover actions: Copy / Retry ---- */
.chat-msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  pointer-events: none;
}
.chat-msg.agent:hover .chat-msg-actions,
.chat-msg.agent:focus-within .chat-msg-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.chat-msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(240, 228, 210, 0.09);
  border-radius: 7px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}
.chat-msg-action-btn:hover {
  color: var(--text);
  border-color: var(--accent-soft);
  background: var(--accent-softer);
}
.chat-msg-action-btn svg { width: 12px; height: 12px; flex: none; }
.chat-msg-action-btn.copied { color: var(--green); border-color: rgba(131, 220, 160, 0.3); }

/* =============================================================================
   Change pill — NEW. Rendered under an assistant reply after a Build turn
   that returned specPatches (see summarizeSpecPatches() in chat-panel.js).
   ============================================================================= */
.chat-change-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 12px;
  background: rgba(131, 220, 160, 0.12);
  color: #83dca0;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  max-width: 100%;
}
.chat-change-pill .pill-check { flex: none; }
.chat-change-pill .pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =============================================================================
   Change-intent action — NEW. Rendered under an Ask-mode reply that contained
   a change request (response meta.changeIntent + meta.suggestedPrompt) — a
   one-tap "switch to Build and apply it" affordance (chat-panel.js
   renderChangeIntentAction / the 'apply-change-intent' click handler).
   ============================================================================= */
.chat-change-intent {
  margin-top: 8px;
}
.chat-change-intent-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: rgba(236, 154, 60, 0.14);
  color: #ec9a3c;
  border: 1px solid rgba(236, 154, 60, 0.35);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chat-change-intent-btn:hover:not(:disabled) {
  background: rgba(236, 154, 60, 0.22);
  border-color: rgba(236, 154, 60, 0.5);
}
.chat-change-intent-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

/* =============================================================================
   Deliverable card — NEW ("Shop Plan" / cut list summary), rendered once
   after a build turn that changed the design. Cream card on dark bg.
   ============================================================================= */
.chat-deliverable-card {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  padding: 12px;
  background: #f7f2e8;
  color: #251d12;
  border: 1px solid rgba(40, 30, 18, 0.13);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  font-family: var(--font-ui);
  text-align: left;
}

.chat-deliverable-thumb {
  flex: none;
  width: 72px;
  height: 58px;
  border-radius: 8px;
  overflow: hidden;
  background: #efe7d6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-deliverable-thumb svg { width: 100%; height: 100%; display: block; }

.chat-deliverable-body {
  flex: 1;
  min-width: 0;
}

.chat-deliverable-tag {
  display: inline-block;
  padding: 2px 7px;
  margin-bottom: 5px;
  background: rgba(236, 154, 60, 0.16);
  color: #a15b12;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.chat-deliverable-title {
  margin: 0 0 3px;
  font-size: 13.5px;
  font-weight: 700;
  color: #251d12;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-deliverable-sub {
  margin: 0 0 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #6c6253;
  line-height: 1.4;
}

.chat-deliverable-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  color: #c0700f;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.chat-deliverable-link:hover { color: #a15b12; text-decoration: underline; }

/* =============================================================================
   Guided step UI (inline in agent messages) — unchanged, still a contained
   surface since it's an interactive form, not prose.
   ============================================================================= */
.guide-card {
  margin-top: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.guide-card label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.guide-dim-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.guide-dim-row input {
  width: 100%;
  padding: 7px 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.guide-dim-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.guide-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-option {
  display: block;
  width: 100%;
  padding: 9px 11px;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
  transition: border-color 0.15s, background 0.15s;
}
.guide-option:hover {
  border-color: var(--accent);
  background: var(--accent-softer);
}
.guide-option strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}
.guide-option span {
  color: var(--muted);
  font-size: 11px;
}

.guide-submit {
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--accent);
  color: var(--amber-ink);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.guide-submit:hover {
  filter: brightness(1.08);
}
.guide-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* =============================================================================
   Scroll-to-bottom floating arrow — NEW. Appears when transcript is scrolled
   up; jumps to latest message on click.
   ============================================================================= */
.chat-scroll-bottom-btn {
  position: absolute;
  right: 18px;
  bottom: 0;
  transform: translateY(0);
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-inset);
  color: var(--amber-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.16s ease, transform 0.16s ease, width 0.16s ease, padding 0.16s ease;
  z-index: 5;
}
.chat-scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-14px);
}
.chat-scroll-bottom-btn:hover { color: var(--accent); border-color: var(--accent-soft); }
.chat-scroll-bottom-btn svg { width: 15px; height: 15px; flex: none; }
.chat-scroll-bottom-label {
  display: none;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
}
/* A message arrived while scrolled away — grow the compact arrow into an
   icon+label pill so it reads as "New reply", not just a generic jump-to-end. */
.chat-scroll-bottom-btn.has-unseen {
  width: auto;
  padding: 0 14px 0 12px;
}
.chat-scroll-bottom-btn.has-unseen .chat-scroll-bottom-label {
  display: inline;
}

/* =============================================================================
   Suggested Next Steps — a tiny always-visible pill above the composer that
   toggles a card of chips. The expanded card is a NORMAL flex child (not
   absolutely positioned) so it pushes the transcript viewport up instead of
   floating over it — it must never cover the conversation, a shop-plan card,
   or a wizard card's buttons underneath. Collapsed state reserves no space;
   expansion is a sticky user choice (chat-panel.js quickStepsExpanded) that
   never auto-triggers from scrolling or sending a message.
   ============================================================================= */
.chat-quick-steps-wrap {
  flex: none;
  position: relative;
  padding: 6px 16px 2px;
}
.chat-quick-steps-wrap.empty { display: none; }

.chat-quick-steps-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.027);
  border: 1px solid rgba(240, 228, 210, 0.09);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .14s ease, color .14s ease;
}
.chat-quick-steps-pill:hover { border-color: var(--accent-soft); color: var(--text); }
.chat-quick-steps-pill svg { width: 12px; height: 12px; flex: none; }
.chat-quick-steps-pill span { display: inline-flex; align-items: center; }
.chat-quick-steps-wrap.expanded .chat-quick-steps-pill { color: var(--text); border-color: var(--accent-soft); }
.chat-quick-steps-ico-collapse { display: none; }
.chat-quick-steps-wrap.expanded .chat-quick-steps-ico-expand { display: none; }
.chat-quick-steps-wrap.expanded .chat-quick-steps-ico-collapse { display: inline-flex; }

.chat-quick-steps-card {
  display: none;
  max-height: 240px;
  overflow-y: auto;
}
.chat-quick-steps-wrap.expanded .chat-quick-steps-card {
  display: block;
  padding: 9px 11px 10px;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid rgba(240, 228, 210, 0.14);
  border-radius: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: quickStepsIn 0.16s ease;
}
@keyframes quickStepsIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-quick-steps-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 7px;
}
.chat-quick-steps-label {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
}
.chat-quick-steps-collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.chat-quick-steps-collapse:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.chat-quick-steps-collapse svg { width: 12px; height: 12px; }

.chat-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 0; }
.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.027);
  border: 1px solid rgba(240, 228, 210, 0.09);
  border-radius: 11px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  transition: border-color .14s ease, background .14s ease;
}
.chat-chip::before {
  content: '';
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
}
.chat-chip:hover { border-color: var(--accent-soft); background: var(--accent-softer); }

/* =============================================================================
   Composer — roomy rounded container with bottom toolbar.
   ============================================================================= */
.chat-input-area {
  flex: none;
  padding: 10px 16px 16px;
  /* Keep the composer clear of the iOS home-indicator zone. */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.chat-composer {
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 10px 8px;
}

#chatInput {
  width: 100%;
  min-height: 44px;
  max-height: 200px;
  padding: 6px 4px;
  background: transparent;
  color: var(--text);
  border: none;
  resize: none;
  font-family: var(--font-ui);
  /* ≥16px kills iOS Safari's focus auto-zoom (matches the hero textarea,
     trial-prompt.css). */
  font-size: 16px;
  line-height: 1.5;
}
#chatInput:focus {
  outline: none;
}
#chatInput::placeholder {
  color: var(--muted);
}

/* ---- Composer bottom toolbar ---- */
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.chat-toolbar-spacer { flex: 1; }

.chat-tool-btn {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}
.chat-tool-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}
.chat-tool-btn svg { width: 17px; height: 17px; }

.chat-attach { /* alias kept for existing #chatAttach id */ }

.chat-tool-btn.chat-mic-btn.listening {
  color: #e0654f;
  border-color: rgba(224, 101, 79, 0.35);
  background: rgba(224, 101, 79, 0.1);
}

/* ---- Mode pill dropdown: "⬡ Build ⌄" ---- */
.chat-mode-pill-wrap { position: relative; flex: none; }

.chat-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  background: rgba(236, 154, 60, 0.12);
  border: 1px solid rgba(236, 154, 60, 0.22);
  border-radius: 11px;
  color: #f4b45f;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s ease;
}
.chat-mode-pill:hover { background: rgba(236, 154, 60, 0.18); }
.chat-mode-pill svg { width: 13px; height: 13px; flex: none; }
.chat-mode-pill .mode-caret {
  font-size: 9px;
  transition: transform 0.15s ease;
}
.chat-mode-pill-wrap.open .mode-caret { transform: rotate(180deg); }

.chat-mode-menu {
  position: absolute;
  /* Right-aligned to the pill (opens leftward), not left-aligned (opens
     rightward) — the pill sits toward the right of the composer toolbar, so a
     rightward-opening 220px-wide menu ran past the panel/viewport edge and got
     clipped mid-word. */
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 220px;
  max-width: calc(100vw - 32px);
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  padding: 6px;
  display: none;
  z-index: 10;
}
.chat-mode-pill-wrap.open .chat-mode-menu { display: block; }

.chat-mode-menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-ui);
}
.chat-mode-menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.chat-mode-menu-item.active { background: var(--accent-softer); }
.chat-mode-menu-item .mode-menu-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-mode-menu-item.active .mode-menu-title { color: var(--amber-2); }
.chat-mode-menu-item .mode-menu-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

/* ---- Send button: 36×36 amber square ---- */
#chatSend {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ec9a3c;
  color: #1c1304;
  border: none;
  border-radius: 11px;
  cursor: pointer;
  transition: filter 0.14s ease;
}
#chatSend:hover:not(:disabled) {
  filter: brightness(1.06);
}
#chatSend:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Mid-turn the Send button morphs into Stop (ui/chat-panel.js
   setTurnInFlight) — quieter than the amber send so it reads as a control,
   not a call to action, but still obviously live/clickable. */
#chatSend.chat-send-stop {
  background: rgba(240, 228, 210, 0.12);
  color: var(--text);
  border: 1px solid rgba(240, 228, 210, 0.22);
}
#chatSend.chat-send-stop:hover {
  filter: none;
  background: rgba(240, 228, 210, 0.18);
}

.chat-usage {
  margin: 8px 0 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.chat-input-hint {
  margin: 4px 0 0;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.4;
}

@media (pointer: coarse) {
  /* Send button: 36px square is under Apple's 44px guideline. */
  #chatSend {
    width: 44px;
    height: 44px;
  }

  /* Tab duplicate/close icons: grow the visible box a little and give each an
     invisible 44px-tall hit zone. The two sit 8px apart, so a naive centered
     44px square on each would overlap — a tap on "duplicate" could land on
     "delete". Bias each zone outward so they stop at the shared midpoint. */
  .chat-tab-duplicate,
  .chat-tab-close {
    position: relative;
    width: 22px;
    height: 22px;
  }
  .chat-tab-duplicate::after,
  .chat-tab-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 37px;
    height: 44px;
  }
  .chat-tab-duplicate::after { transform: translate(-65%, -50%); }
  .chat-tab-close::after { transform: translate(-35%, -50%); }
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 280px 1fr var(--chat-w, 33.33vw) !important;
  }
}

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr !important;
    /* THREE in-flow children stack here: icon rail (auto) · 3D stage (1fr) ·
       chat (44vh). The rail is in flow (shell.css #ec-iconrail), so a 2-row
       template handed it the 1fr row and pushed the chat panel — composer
       included — into an implicit row clipped by body{overflow:hidden}. */
    grid-template-rows: auto 1fr 44vh !important;
  }
  #app.chat-collapsed {
    /* Stage keeps the flexible row; the collapsed (display:none) chat panel
       lets the auto row collapse to zero. */
    grid-template-rows: auto 1fr auto !important;
  }
  /* Explicit placement — auto-placement must never decide these again. */
  #ec-iconrail { grid-row: 1; grid-column: 1; }
  #viewport { grid-row: 2; grid-column: 1; }
  #chat-panel {
    grid-row: 3;
    grid-column: 1;
    order: 3;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 44vh;
  }
  #app.chat-collapsed #chat-panel {
    display: none;
  }
  #chat-expand-tab {
    top: auto;
    bottom: 0;
    right: 16px;
    transform: none;
    writing-mode: horizontal-tb;
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--line);
    border-bottom: none;
    padding: 8px 14px;
    /* Keep the tab tappable above the iOS home indicator. */
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
}
