/* =====================================================================
   8. CHAT PANEL
   Expands from FAB chat button. Glassmorphism panel.
   ===================================================================== */

.m-chat-panel {
  position: fixed;
  z-index: 8999;
  bottom: calc(16px + var(--m-safe-bottom));
  right: 16px;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(var(--m-vvh, 100dvh) - 100px));
  background: var(--m-panel-bg);
  border: 1px solid var(--m-panel-border);
  border-radius: 16px;
  box-shadow: var(--m-panel-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--ease-spring), opacity 0.25s var(--ease),
              height 0.3s var(--ease-spring);
  will-change: transform, opacity;
}

.m-chat-panel.open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Specular highlight at top */
.m-chat-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 10%, var(--specular) 50%, transparent 90%);
  z-index: 1;
  pointer-events: none;
}

/* Chat header */
.m-chat-header {
  display: flex;
  align-items: center;
  padding: 14px 16px 12px;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.m-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0071e3 0%, #2997ff 100%);
  box-shadow:
    0 2px 8px rgba(0, 113, 227, 0.22),
    inset 0 1px 1px rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.m-chat-avatar svg { display: none; }

.m-chat-title-group {
  flex: 1;
  min-width: 0;
}

.m-chat-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-0);
  line-height: 1.2;
}

.m-chat-subtitle {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.3;
}

.m-chat-close-btn {
  width: 32px;
  height: 32px;
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: none;
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.m-chat-close-btn:hover {
  background: var(--bg-input);
  color: var(--text-0);
}

.m-chat-close-btn:active {
  background: var(--bg-input-hover);
}

/* Chat messages area */
.m-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  overscroll-behavior: contain;
}

.m-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.m-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.m-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Individual messages */
.m-chat-msg {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: m-fab-msg-in 0.3s var(--ease-spring);
}

@keyframes m-fab-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* User message */
.m-chat-msg.user {
  background: var(--m-msg-user-bg);
  color: var(--text-0);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border);
}

/* AI message */
.m-chat-msg.ai {
  background: var(--m-msg-ai-bg);
  color: var(--text-0);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--m-msg-ai-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.m-chat-msg.ai p {
  margin: 0 0 4px 0;
}

.m-chat-msg.ai p:last-child {
  margin-bottom: 0;
}

.m-chat-msg.ai strong {
  font-weight: 600;
}

/* File chip inside sent message */
.m-msg-file-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 4px;
  margin-bottom: 4px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.2;
}
[data-theme="dark"] .m-msg-file-chip {
  background: rgba(255, 255, 255, 0.08);
}
.m-msg-file-chip.downloadable { cursor: pointer; transition: background 0.15s ease, transform 0.1s ease; }
.m-msg-file-chip.downloadable:hover {
  background: rgba(0, 0, 0, 0.10);
}
[data-theme="dark"] .m-msg-file-chip.downloadable:hover {
  background: rgba(255, 255, 255, 0.14);
}
.m-msg-file-chip.downloadable:active {
  background: rgba(0, 0, 0, 0.14);
  transform: scale(0.97);
}
[data-theme="dark"] .m-msg-file-chip.downloadable:active {
  background: rgba(255, 255, 255, 0.18);
}
.m-msg-file-icon { font-size: 14px; flex-shrink: 0; }
.m-msg-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  color: var(--text-1);
}
/* .m-msg-file-ext removed — format shown on icon label */
.m-msg-file-ext {
  display: none;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
/* Light theme ext colors */
.m-msg-file-ext.ext-pdf { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
.m-msg-file-ext.ext-docx, .m-msg-file-ext.ext-doc { background: rgba(59, 130, 246, 0.15); color: #2563eb; }
.m-msg-file-ext.ext-xlsx, .m-msg-file-ext.ext-xls, .m-msg-file-ext.ext-csv { background: rgba(34, 197, 94, 0.15); color: #16a34a; }
.m-msg-file-ext.ext-pptx, .m-msg-file-ext.ext-ppt { background: rgba(249, 115, 22, 0.15); color: #ea580c; }
.m-msg-file-ext.ext-png, .m-msg-file-ext.ext-jpg, .m-msg-file-ext.ext-jpeg, .m-msg-file-ext.ext-gif, .m-msg-file-ext.ext-webp { background: rgba(168, 85, 247, 0.15); color: #9333ea; }
.m-msg-file-ext.ext-txt, .m-msg-file-ext.ext-md, .m-msg-file-ext.ext-json { background: rgba(0, 0, 0, 0.08); color: rgba(0, 0, 0, 0.55); }
/* Dark theme ext colors */
[data-theme="dark"] .m-msg-file-ext.ext-pdf { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
[data-theme="dark"] .m-msg-file-ext.ext-docx, [data-theme="dark"] .m-msg-file-ext.ext-doc { background: rgba(59, 130, 246, 0.25); color: #93c5fd; }
[data-theme="dark"] .m-msg-file-ext.ext-xlsx, [data-theme="dark"] .m-msg-file-ext.ext-xls, [data-theme="dark"] .m-msg-file-ext.ext-csv { background: rgba(34, 197, 94, 0.25); color: #86efac; }
[data-theme="dark"] .m-msg-file-ext.ext-pptx, [data-theme="dark"] .m-msg-file-ext.ext-ppt { background: rgba(249, 115, 22, 0.25); color: #fdba74; }
[data-theme="dark"] .m-msg-file-ext.ext-png, [data-theme="dark"] .m-msg-file-ext.ext-jpg, [data-theme="dark"] .m-msg-file-ext.ext-jpeg, [data-theme="dark"] .m-msg-file-ext.ext-gif, [data-theme="dark"] .m-msg-file-ext.ext-webp { background: rgba(168, 85, 247, 0.25); color: #d8b4fe; }
[data-theme="dark"] .m-msg-file-ext.ext-txt, [data-theme="dark"] .m-msg-file-ext.ext-md, [data-theme="dark"] .m-msg-file-ext.ext-json { background: rgba(255, 255, 255, 0.10); color: rgba(255, 255, 255, 0.55); }
/* Fallback — no matching ext class */
.m-msg-file-ext:not([class*="ext-"]) { background: rgba(0, 0, 0, 0.08); color: rgba(0, 0, 0, 0.6); }
[data-theme="dark"] .m-msg-file-ext:not([class*="ext-"]) { background: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.6); }

.m-msg-file-size {
  color: rgba(0, 0, 0, 0.4);
  font-size: 10px;
  flex-shrink: 0;
}
[data-theme="dark"] .m-msg-file-size {
  color: rgba(255, 255, 255, 0.55);
}
/* download icon removed — whole chip is clickable */

/* Typing indicator */
.m-chat-typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  align-self: flex-start;
}

.m-typing-dots {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.m-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-2);
  animation: m-typing-bounce 1.4s infinite;
}

.m-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.m-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

.m-typing-status {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

@keyframes m-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* In-chat stop button (above composer, visible during generation) */
.m-chat-stop-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 16px 8px;
  padding: 8px 16px;
  border: 1.5px solid #ef4444;
  border-radius: 999px;
  background: transparent;
  color: #ef4444;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m-chat-stop-btn.visible {
  display: flex;
}
.m-chat-stop-btn:active {
  background: rgba(239, 68, 68, 0.1);
}
.m-chat-stop-btn svg {
  flex-shrink: 0;
}

/* Recording indicator — styles moved to _visual-chat.css */

/* Keyboard-open adjustments */
.m-chat-panel.keyboard-open {
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  border-radius: 16px 16px 0 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  height: calc(var(--m-vvh, 100dvh) - 20px);
  max-height: calc(var(--m-vvh, 100dvh) - 20px);
}

.m-chat-panel.keyboard-open .m-chat-composer {
  padding-bottom: 10px;
}


/* =====================================================================
   9. SCRIM
   Subtle background overlay when chat panel is open.
   ===================================================================== */

.m-scrim {
  position: fixed;
  inset: 0;
  z-index: 8998;
  background: transparent;
  pointer-events: none;
  transition: background 0.3s var(--ease);
}

.m-scrim.active {
  background: rgba(0, 0, 0, 0.01);
  pointer-events: auto;
}

[data-theme="dark"] .m-scrim.active {
  background: rgba(0, 0, 0, 0.15);
}


/* =====================================================================
   10. DRAG HANDLE
   Centered bar visible on touch devices for chat panel dragging.
   ===================================================================== */

.m-drag-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-3);
  margin: 0 auto;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  position: relative;
}

/* Expand hit target for touch */
.m-drag-handle::before {
  content: '';
  position: absolute;
  inset: -10px -20px;
}

/* Show on touch devices */
@media (hover: none) and (pointer: coarse) {
  .m-drag-handle {
    opacity: 1;
    margin-top: 8px;
    margin-bottom: -4px;
  }
}


