/* ═══════════════════════════════════════════
   META AI — Chat UI
   prefix: mai-
   ═══════════════════════════════════════════ */

.mai-page { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* ── Header ── */
.mai-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px 12px; flex-shrink: 0;
}
.mai-header-icon {
  width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0084ff, #00c6ff); color: #fff; font-size: 18px; flex-shrink: 0;
}
.mai-header-text { flex: 1; min-width: 0; }
.mai-header-text h2 { margin: 0; font-size: 16px; font-weight: 700; color: var(--fx-text, #1a1a1a); line-height: 1.3; }
.mai-header-text p { margin: 0; font-size: 12px; color: var(--fx-muted, #888); line-height: 1.3; }
.mai-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.mai-hdr-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--fx-border, #e5e7eb);
  background: var(--fx-card, #fff); color: var(--fx-muted, #888); font-size: 15px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all .15s;
}
.mai-hdr-btn:hover { color: var(--fx-text, #1a1a1a); border-color: var(--fx-border-hover, #ccc); }
.mai-status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #aaa; margin-right: 4px; flex-shrink: 0;
}
.mai-status-dot.connected { background: #10b981; }

/* ── Connect card ── */
.mai-connect {
  margin: 0 20px 12px; padding: 16px; border-radius: 12px;
  background: var(--fx-card, #fff); border: 1px solid var(--fx-border, #e5e7eb);
}
.mai-connect-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--fx-text, #1a1a1a); }
.mai-connect-head i { color: #0084ff; font-size: 16px; }
.mai-connect-row { display: flex; gap: 8px; align-items: stretch; }
.mai-connect-input {
  flex: 1; min-width: 0; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--fx-border, #e5e7eb); background: var(--fx-input-bg, #f9fafb); color: var(--fx-text, #1a1a1a);
  font-family: monospace; transition: border-color .15s;
}
.mai-connect-input:focus { outline: none; border-color: #0084ff; }
.mai-connect-input::placeholder { color: var(--fx-muted, #aaa); font-family: inherit; }
.mai-connect-btn {
  padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600;
  background: linear-gradient(135deg, #0084ff, #00c6ff); color: #fff; white-space: nowrap; transition: opacity .15s;
}
.mai-connect-btn:hover { opacity: .9; }
.mai-connect-btn:disabled { opacity: .5; cursor: not-allowed; }
.mai-connect-hint { margin-top: 8px; font-size: 11px; color: var(--fx-muted, #999); line-height: 1.4; }
.mai-connect-hint code { background: var(--fx-code-bg, #f3f4f6); padding: 1px 4px; border-radius: 3px; font-size: 11px; }
.mai-connect-status {
  margin-top: 8px; padding: 6px 10px; border-radius: 6px; font-size: 12px; display: none;
}
.mai-connect-status.ok { display: block; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.mai-connect-status.err { display: block; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Chat area ── */
.mai-chat {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  margin: 0 20px; border-radius: 12px; overflow: hidden;
  background: var(--fx-card, #fff); border: 1px solid var(--fx-border, #e5e7eb);
}
.mai-messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px;
}

/* ── Welcome (empty state) ── */
.mai-welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 20px; gap: 12px; color: var(--fx-muted, #999);
}
.mai-welcome-icon { font-size: 48px; color: #0084ff; opacity: .6; }
.mai-welcome h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--fx-text, #1a1a1a); }
.mai-welcome p { margin: 0; font-size: 13px; max-width: 340px; line-height: 1.5; }
.mai-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.mai-sug-btn {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--fx-border, #e5e7eb);
  background: var(--fx-card, #fff); color: var(--fx-text, #555); font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.mai-sug-btn:hover { border-color: #0084ff; color: #0084ff; background: rgba(0,132,255,.04); }

/* ── Messages ── */
.mai-msg { display: flex; gap: 10px; max-width: 85%; animation: maiFadeIn .2s ease; }
.mai-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.mai-msg-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.mai-msg.ai .mai-msg-avatar { background: linear-gradient(135deg, #0084ff, #00c6ff); color: #fff; }
.mai-msg.user .mai-msg-avatar { background: var(--fx-accent-bg, #f0f0ff); color: var(--fx-accent, #6366f1); }
.mai-msg-body {
  padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.6;
  word-break: break-word; white-space: pre-wrap;
}
.mai-msg.ai .mai-msg-body {
  background: var(--fx-input-bg, #f3f4f6); color: var(--fx-text, #1a1a1a);
  border-bottom-left-radius: 4px;
}
.mai-msg.user .mai-msg-body {
  background: #0084ff; color: #fff;
  border-bottom-right-radius: 4px;
}
.mai-msg-body p { margin: 0 0 8px; }
.mai-msg-body p:last-child { margin-bottom: 0; }
.mai-msg-body code {
  background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 12px;
}
.mai-msg.user .mai-msg-body code { background: rgba(255,255,255,.2); }
.mai-msg-body pre {
  background: var(--fx-code-bg, #1e1e2e); color: #cdd6f4; padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 12px; line-height: 1.5; margin: 8px 0;
}
.mai-msg-body pre code { background: none; padding: 0; color: inherit; }

/* Thinking block */
.mai-thinking {
  margin-bottom: 8px; padding: 8px 12px; border-radius: 8px; font-size: 12px;
  background: rgba(99,102,241,.06); border-left: 3px solid #6366f1; color: var(--fx-muted, #888);
  line-height: 1.5; white-space: pre-wrap;
}
.mai-thinking-label { font-weight: 600; color: #6366f1; margin-bottom: 2px; font-size: 11px; }

/* Streaming cursor */
.mai-cursor {
  display: inline-block; width: 2px; height: 14px; background: #0084ff;
  margin-left: 1px; vertical-align: text-bottom;
  animation: maiBlink .8s steps(2) infinite;
}

@keyframes maiBlink { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes maiFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Input area ── */
.mai-input-wrap {
  padding: 12px 16px; border-top: 1px solid var(--fx-border, #e5e7eb);
  display: flex; gap: 8px; align-items: flex-end; flex-shrink: 0;
}
.mai-textarea {
  flex: 1; min-height: 38px; max-height: 120px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--fx-border, #e5e7eb); background: var(--fx-input-bg, #f9fafb);
  color: var(--fx-text, #1a1a1a); font-size: 13px; line-height: 1.5; resize: none;
  font-family: inherit; transition: border-color .15s;
}
.mai-textarea:focus { outline: none; border-color: #0084ff; }
.mai-textarea::placeholder { color: var(--fx-muted, #aaa); }
.mai-send-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #0084ff, #00c6ff); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center; transition: opacity .15s; flex-shrink: 0;
}
.mai-send-btn:hover { opacity: .9; }
.mai-send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Thinking mode toggle ── */
.mai-think-toggle {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fx-muted, #888);
  cursor: pointer; user-select: none; padding: 4px 0;
}
.mai-think-toggle input { display: none; }
.mai-think-sw {
  width: 28px; height: 16px; border-radius: 8px; background: var(--fx-border, #d1d5db);
  position: relative; transition: background .2s; flex-shrink: 0;
}
.mai-think-sw::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: transform .2s;
}
.mai-think-toggle input:checked + .mai-think-sw { background: #6366f1; }
.mai-think-toggle input:checked + .mai-think-sw::after { transform: translateX(12px); }

/* ── Typing indicator ── */
.mai-typing { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.mai-typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #0084ff; opacity: .4;
  animation: maiTyping 1.2s infinite;
}
.mai-typing-dot:nth-child(2) { animation-delay: .2s; }
.mai-typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes maiTyping { 0%, 60%, 100% { opacity: .4; transform: scale(1); } 30% { opacity: 1; transform: scale(1.2); } }

/* ── Dark mode ── */
[data-bs-theme="dark"] .mai-connect { background: var(--fx-card-dark, #1e1e2e); border-color: var(--fx-border-dark, #333); }
[data-bs-theme="dark"] .mai-chat { background: var(--fx-card-dark, #1e1e2e); border-color: var(--fx-border-dark, #333); }
[data-bs-theme="dark"] .mai-msg.ai .mai-msg-body { background: rgba(255,255,255,.06); }
[data-bs-theme="dark"] .mai-msg-body pre { background: #0d0d1a; }
[data-bs-theme="dark"] .mai-textarea { background: rgba(255,255,255,.04); border-color: var(--fx-border-dark, #333); }
[data-bs-theme="dark"] .mai-connect-input { background: rgba(255,255,255,.04); border-color: var(--fx-border-dark, #333); }
[data-bs-theme="dark"] .mai-connect-status.ok { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.3); color: #6ee7b7; }
[data-bs-theme="dark"] .mai-connect-status.err { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.3); color: #fca5a5; }
[data-bs-theme="dark"] .mai-hdr-btn { background: transparent; border-color: var(--fx-border-dark, #333); }
[data-bs-theme="dark"] .mai-sug-btn { background: transparent; border-color: var(--fx-border-dark, #444); }
