/**
 * ToolGrid AI Composer Styles
 * Premium conversational composer: attachments, voice, drag & drop,
 * streaming reveal, rich result cards. Additive only — does not
 * redefine .tg-chat-history / .tg-chat-msg / .tg-workspace-* etc.,
 * which stay owned by ai-mode-styles.css.
 */

.tg-composer-root .tg-chat-history {
  max-height: 460px;
}

/* ---------- message entrance ---------- */
.tg-chat-msg-enter {
  animation: tgMsgIn 220ms ease-out;
}

@keyframes tgMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- typing indicator ---------- */
.tg-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.tg-typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9CA3AF;
  display: inline-block;
  animation: tgTypingBounce 1.1s infinite ease-in-out;
}

.tg-typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.tg-typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes tgTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- composer shell ---------- */
.tg-composer {
  position: relative;
  padding: 14px 20px 20px;
  background: #F9FAFB;
  border-top: 1px solid #E5E7EB;
}

.tg-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #ffffff;
  border: 1.5px solid #E5E7EB;
  border-radius: 20px;
  padding: 8px 8px 8px 10px;
  transition: border-color 150ms ease-in-out, box-shadow 150ms ease-in-out;
}

.tg-composer-row:focus-within {
  border-color: #FF6B00;
  box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.12);
}

.tg-composer-textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--tg-font-family, 'Inter', sans-serif);
  font-size: 14.5px;
  line-height: 1.5;
  color: #0A2540;
  padding: 8px 4px;
  max-height: 220px;
  min-height: 22px;
}

.tg-composer-textarea::placeholder {
  color: #9CA3AF;
}

.tg-composer-icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6B7280;
  font-size: 18px;
  cursor: pointer;
  transition: background 150ms ease-in-out, color 150ms ease-in-out, transform 150ms ease-in-out;
}

.tg-composer-icon-btn:hover {
  background: rgba(10, 37, 64, 0.06);
  color: #0A2540;
}

.tg-composer-icon-btn:active {
  transform: scale(0.94);
}

.tg-composer-icon-btn:focus-visible {
  outline: 2px solid #FF6B00;
  outline-offset: 2px;
}

#tg-mic-btn.is-recording {
  color: #fff;
  background: #EF4444;
  animation: tgPulse 1.4s infinite;
}

@keyframes tgPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.tg-composer-send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: #FF6B00;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  transition: background 150ms ease-in-out, transform 150ms ease-in-out;
}

.tg-composer-send-btn:hover:not(:disabled) {
  background: #E55A00;
  transform: translateY(-1px);
}

.tg-composer-send-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.tg-composer-send-btn:focus-visible {
  outline: 2px solid #0A2540;
  outline-offset: 2px;
}

.tg-composer-hint {
  margin: 8px 2px 0;
  font-size: 11.5px;
  color: #9CA3AF;
}

.tg-composer-error {
  margin: 8px 2px 0;
  padding: 8px 12px;
  background: #FEE2E2;
  color: #B91C1C;
  border-radius: 8px;
  font-size: 12.5px;
  animation: tgMsgIn 180ms ease-out;
}

/* ---------- attachment chip ---------- */
.tg-attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid #E5E7EB;
  border-radius: 12px;
  font-size: 13px;
  color: #0A2540;
  width: fit-content;
  max-width: 100%;
}

.tg-attachment-icon { font-size: 16px; }

.tg-attachment-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.tg-attachment-size { color: #9CA3AF; font-size: 11.5px; }

.tg-attachment-remove {
  border: none;
  background: transparent;
  color: #9CA3AF;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 50%;
}

.tg-attachment-remove:hover {
  color: #EF4444;
  background: rgba(239, 68, 68, 0.08);
}

.tg-chat-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  opacity: 0.85;
  margin-bottom: 4px;
}

/* ---------- persistent "active file" pill (conversation continuity) ---------- */
.tg-active-file-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px 10px;
  background: rgba(255, 107, 0, 0.06);
  border: 1px dashed rgba(255, 107, 0, 0.35);
  border-radius: 12px;
  font-size: 12.5px;
  color: #0A2540;
  width: fit-content;
  max-width: 100%;
}

.tg-active-file-icon { font-size: 14px; }

.tg-active-file-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-active-file-clear {
  border: none;
  background: transparent;
  color: #9CA3AF;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 50%;
}

.tg-active-file-clear:hover {
  color: #EF4444;
  background: rgba(239, 68, 68, 0.08);
}

/* ---------- drag & drop overlay ---------- */
.tg-composer-dropzone-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 107, 0, 0.06);
  border: 2px dashed #FF6B00;
  border-radius: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 150ms ease-in-out, visibility 150ms ease-in-out;
}

.tg-composer-dropzone-overlay.is-active {
  opacity: 1;
  visibility: visible;
}

.tg-dropzone-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: #ffffff;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  font-weight: 600;
  color: #0A2540;
  font-size: 13.5px;
}

.tg-dropzone-icon { font-size: 18px; }

/* ---------- rich result cards ---------- */
.tg-result-card {
  align-self: stretch;
  width: 100%;
  background: #ffffff;
  border: 1px solid #E5E7EB;
  border-left: 4px solid #10B981;
  border-radius: 12px;
  padding: 16px 18px;
  animation: tgMsgIn 220ms ease-out;
}

.tg-result-title {
  margin: 0 0 6px;
  font-size: 15px;
  color: #0A2540;
}

.tg-result-text {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: #4B5563;
  line-height: 1.55;
}

.tg-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tg-result-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #E5E7EB;
  background: #F9FAFB;
  color: #0A2540;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 150ms ease-in-out;
}

.tg-result-action:hover {
  border-color: #FF6B00;
  color: #FF6B00;
  background: rgba(255, 107, 0, 0.05);
}

.tg-result-action[data-action="download"] {
  background: #FF6B00;
  border-color: #FF6B00;
  color: #fff;
}

.tg-result-action[data-action="download"]:hover {
  background: #E55A00;
  color: #fff;
}

/* ---------- responsive (tablet rules untouched elsewhere; this only
   tightens spacing on narrow phones) ---------- */
/* ---------- rendered Markdown content (assistant messages + result cards) ---------- */
.tg-msg-body p,
.tg-result-text p {
  margin: 0 0 8px;
}
.tg-msg-body p:last-child,
.tg-result-text p:last-child {
  margin-bottom: 0;
}
.tg-md-heading {
  margin: 12px 0 6px;
  color: #0A2540;
  font-weight: 700;
  line-height: 1.3;
}
.tg-md-heading:first-child { margin-top: 0; }
.tg-md-list {
  margin: 0 0 8px;
  padding-left: 20px;
}
.tg-md-list li { margin: 2px 0; }
.tg-md-code {
  background: #F3F4F6;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.tg-md-pre {
  background: #0A2540;
  color: #F3F4F6;
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.tg-md-pre code {
  background: transparent;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.tg-md-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 8px;
  font-size: 0.95em;
}
.tg-md-table td {
  border: 1px solid #E5E7EB;
  padding: 6px 10px;
}

@media (max-width: 480px) {
  .tg-composer { padding: 12px 12px 16px; }
  .tg-attachment-name { max-width: 140px; }
}

/* ---------- dark mode ---------- */
@media (prefers-color-scheme: dark) {
  .tg-composer {
    background: #111827;
    border-top-color: rgba(255, 255, 255, 0.08);
  }

  .tg-composer-row {
    background: #1F2937;
    border-color: rgba(255, 255, 255, 0.12);
  }

  .tg-composer-textarea {
    color: #F3F4F6;
  }

  .tg-composer-textarea::placeholder {
    color: #6B7280;
  }

  .tg-composer-icon-btn {
    color: #9CA3AF;
  }

  .tg-composer-icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #F3F4F6;
  }

  .tg-attachment-chip {
    background: #1F2937;
    border-color: rgba(255, 255, 255, 0.12);
    color: #F3F4F6;
  }

  .tg-active-file-pill {
    background: rgba(255, 107, 0, 0.1);
    border-color: rgba(255, 107, 0, 0.4);
    color: #F3F4F6;
  }

  .tg-result-card {
    background: #1F2937;
    border-color: rgba(255, 255, 255, 0.12);
  }

  .tg-result-title { color: #F3F4F6; }
  .tg-result-text { color: #9CA3AF; }

  .tg-md-heading { color: #F3F4F6; }
  .tg-md-code { background: rgba(255, 255, 255, 0.08); color: #F3F4F6; }
  .tg-md-table td { border-color: rgba(255, 255, 255, 0.12); }

  .tg-result-action {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
    color: #F3F4F6;
  }

  .tg-dropzone-msg {
    background: #1F2937;
    color: #F3F4F6;
  }
}
