/* ─────────────────────────────────────────────────────────────────────────────
   ai.css — Thanzi AI Assistant Panel
   Uses the same CSS vars as style.css (--bg-surface, --accent, --text-*, etc.)
   ──────────────────────────────────────────────────────────────────────────── */

/* ── Panel wrapper (fills space between dash-header and bottom-nav) ────────── */
.ai-panel-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 58px - 65px); /* dash-header ≈ 58px, bottom-nav ≈ 65px */
  overflow: hidden;
}

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

.ai-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(var(--accent-rgb), .15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.ai-avatar-img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
}

.ai-msg-logo {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: cover;
}

.ai-header-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ai-name {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text-1);
}

.ai-subtitle {
  font-size: .75rem;
  color: var(--text-3);
}

.ai-online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .25);
  flex-shrink: 0;
}

.ai-clear-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-3);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ai-clear-btn svg { width: 17px; height: 17px; }
.ai-clear-btn:hover  { background: rgba(var(--accent-rgb), 0.1); color: var(--text-1); }
.ai-clear-btn:active { transform: scale(0.94); }

/* ── Messages area ──────────────────────────────────────────────────────────── */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ── Message bubbles ─────────────────────────────────────────────────────────  */
.ai-msg {
  display: flex;
  gap: 8px;
  max-width: 92%;
  animation: aiMsgIn .22s ease;
}

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

.ai-msg.ai-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), .15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.ai-msg--user .ai-msg-icon {
  background: rgba(var(--accent-rgb), .25);
}

.ai-msg-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ai-msg-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 13px;
  font-size: .88rem;
  line-height: 1.5;
  color: var(--text-1);
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg-bubble strong {
  font-weight: 700;
  color: var(--text-1);
}

.ai-msg-bubble em {
  font-style: italic;
}

.ai-msg-bubble code {
  background: rgba(var(--accent-rgb), 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.ai-msg-bubble .ai-md-h {
  display: block;
  margin: 2px 0 4px;
  font-size: 1.02em;
}

.ai-msg--user .ai-msg-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  border-radius: 16px 16px 4px 16px;
}

.ai-msg-time {
  font-size: .68rem;
  color: var(--text-4);
  padding: 0 4px;
}

.ai-msg--user .ai-msg-time {
  text-align: right;
}

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

.ai-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: aiTypingPulse 1.2s ease infinite;
}

.ai-typing-dot:nth-child(2) { animation-delay: .2s; }
.ai-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes aiTypingPulse {
  0%, 60%, 100% { transform: scale(1); opacity: .5; }
  30%            { transform: scale(1.3); opacity: 1; }
}

/* ── Quick actions ──────────────────────────────────────────────────────────── */
.ai-quick-section {
  padding: 6px 16px 10px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-soft);
}

.ai-quick-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.ai-quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.ai-quick-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .8rem;
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-quick-btn:hover  { border-color: var(--accent); color: var(--accent); }
.ai-quick-btn:active { background: rgba(var(--accent-rgb), .08); transform: scale(0.97); }

.ai-quick-btn span.qi { font-size: 1rem; flex-shrink: 0; }

/* ── Composer (input row) ───────────────────────────────────────────────────── */
.ai-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 16px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-page);
}

#ai-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: .88rem;
  background: var(--bg-surface);
  color: var(--text-1);
  line-height: 1.45;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color .15s;
  font-family: inherit;
  outline: none;
  /* Reset margin set by global input rule */
  margin-bottom: 0;
  width: auto;
}

#ai-input:focus { border-color: var(--accent); }
#ai-input::placeholder { color: var(--text-5); }

.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.ai-send-btn:active { transform: scale(0.92); }
.ai-send-btn:disabled { background: var(--text-5); cursor: default; }

.ai-send-btn svg { width: 18px; height: 18px; }

/* ── Error toast ────────────────────────────────────────────────────────────── */
.ai-error-bubble .ai-msg-bubble {
  background: rgba(231, 76, 60, .1);
  border-color: rgba(231, 76, 60, .35);
  color: var(--danger);
}

/* ── Empty / welcome state ──────────────────────────────────────────────────── */
.ai-welcome {
  text-align: center;
  padding: 12px 0 4px;
}

.ai-welcome-emoji {
  font-size: 2.4rem;
  margin-bottom: 8px;
}

.ai-welcome-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 4px;
}

.ai-welcome-sub {
  font-size: .82rem;
  color: var(--text-3);
}
