/* AI Assistant chat widget */

#chat-modal .sheet-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: calc(20px + var(--safe-bottom, 0px));
}
.chat-messages {
  flex: 1;
  min-height: 220px;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: none;
}
.chat-messages::-webkit-scrollbar { display: none; }
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; font-size: 0.9rem; line-height: 1.45; word-break: break-word; color: var(--text); }
.chat-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 6px; }
.chat-msg.bot { align-self: flex-start; background: rgba(0,0,0,0.06); border-bottom-left-radius: 6px; }

/* Markdown formatting in bot replies */
.chat-msg.bot p { margin: 0 0 6px; }
.chat-msg.bot p:last-child { margin-bottom: 0; }
.chat-msg.bot ul, .chat-msg.bot ol { margin: 6px 0; padding-left: 20px; }
.chat-msg.bot li { margin: 2px 0; }
.chat-msg.bot code { background: rgba(0,0,0,0.08); padding: 1px 5px; border-radius: 6px; font-size: 0.85em; }
.chat-msg.bot strong { font-weight: 800; }

.chat-typing { display: none; align-self: flex-start; gap: 4px; padding: 12px 16px; border-radius: 18px; background: rgba(0,0,0,0.06); }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: rgba(0,0,0,0.3); animation: chat-blink 1.2s infinite; }
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.chat-stop-btn {
  margin-left: 6px;
  padding: 2px 10px;
  border: none;
  border-radius: 12px;
  background: rgba(0,0,0,0.08);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-signin { display: none; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 32px 12px; }
.chat-signin-title { font-weight: 800; font-size: 1.05rem; color: var(--text); }
.chat-signin-sub { font-size: 0.82rem; opacity: 0.7; color: var(--text); margin: 0; }
.chat-signin-btn { margin-top: 8px; }

.chat-input-row { display: none; align-items: center; gap: 8px; }
#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 0.9rem;
  background: rgba(255,255,255,0.6);
  color: var(--text);
  outline: none;
}
#chat-input:focus { border-color: var(--primary); }
.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.5; }
.chat-send-btn svg { width: 18px; height: 18px; }

/* Canvas layout diagrams */
.chat-diagram { width: 100%; aspect-ratio: 1; display: block; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-top: 6px; overflow: hidden; }
.chat-dg-box rect { stroke-width: 1; }
.chat-dg-box text { fill: var(--text); font-size: 4px; font-weight: 600; pointer-events: none; }
.chat-dg-box:hover rect { filter: brightness(1.1); }
.chat-dg-blue rect { fill: rgba(0,122,255,0.12); stroke: #007aff; }
.chat-dg-green rect { fill: rgba(52,199,89,0.14); stroke: #34c759; }
.chat-dg-orange rect { fill: rgba(255,149,0,0.15); stroke: #ff9500; }
.chat-dg-red rect { fill: rgba(255,59,48,0.13); stroke: #ff3b30; }
.chat-dg-white rect { fill: #ffffff; stroke: #c7c7cc; }
.chat-dg-arrow { stroke: var(--text); stroke-width: 1; opacity: 0.7; }
.chat-dg-arrow-label { fill: var(--text); font-size: 3.2px; opacity: 0.8; }
