/* ============================================
   AI CHAT — Phase 7
   Relies on tokens defined in css/variables.css
   ============================================ */

.ai-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-base);
}

/* ---------- Top bar ---------- */
.ai-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.ai-topbar__back {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
}

.ai-topbar__back svg { width: 16px; height: 16px; }

.ai-topbar__title {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 1;
}

.ai-topbar__title h1 {
  font-size: var(--text-md);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}

.ai-topbar__title svg {
  width: 18px;
  height: 18px;
  color: var(--info);
}

.ai-topbar__status {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-topbar__status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--success);
  display: inline-block;
}

/* ---------- Messages ---------- */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) 16px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.ai-empty {
  margin: auto 0;
  text-align: center;
  color: var(--text-secondary);
  padding: var(--space-xl) var(--space-md);
}

.ai-empty svg {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  margin: 0 auto var(--space-sm);
}

.ai-empty h2 {
  font-size: var(--text-base);
  color: var(--text-primary);
  font-weight: var(--font-semi);
  margin-bottom: 4px;
}

.ai-empty p {
  font-size: var(--text-sm);
  max-width: 280px;
  margin: 0 auto;
}

/* ---------- Suggestion chips ---------- */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  justify-content: center;
  margin-top: var(--space-lg);
}

.ai-chip {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-full);
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ai-chip:hover,
.ai-chip:active {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

/* ---------- Message rows ---------- */
.ai-msg {
  display: flex;
  gap: var(--space-sm);
  max-width: 100%;
}

.ai-msg--user {
  justify-content: flex-end;
}

.ai-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.ai-msg__avatar svg { width: 15px; height: 15px; }

.ai-bubble {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.5;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg--assistant .ai-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.ai-msg--user .ai-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-top-right-radius: 4px;
}

/* ---------- Typing indicator ---------- */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  width: fit-content;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  animation: ai-typing-bounce 1.1s infinite ease-in-out;
}

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

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

/* ---------- Action cards (proposals from AI) ---------- */
.ai-action-card {
  margin-left: 36px;
  max-width: 78%;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.ai-action-card__head {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.ai-action-card__head svg {
  width: 16px;
  height: 16px;
  color: var(--info);
  flex-shrink: 0;
}

.ai-action-card--savings .ai-action-card__head svg { color: var(--success); }
.ai-action-card--reminder .ai-action-card__head svg { color: var(--pending); }
.ai-action-card--security .ai-action-card__head svg { color: var(--danger); }

.ai-action-card__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}

.ai-action-card__body {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

.ai-action-card__meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-sm);
}

.ai-action-card__meta b { font-weight: var(--font-semi); }

.ai-action-card__actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: 2px;
}

.ai-action-card__btn {
  flex: 1;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  text-align: center;
}

.ai-action-card__btn--primary {
  background: var(--text-primary);
  color: var(--bg-base);
  border-color: var(--text-primary);
}

/* ---------- Input bar ---------- */
.ai-inputbar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-sm) 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-base);
  flex-shrink: 0;
}

.ai-inputbar__field {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-xs) var(--space-md);
  min-height: 44px;
  max-height: 120px;
}

.ai-inputbar__field:focus-within {
  border-color: var(--border-active);
}

.ai-inputbar textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--text-primary);
  line-height: 1.4;
  max-height: 100px;
}

.ai-inputbar textarea::placeholder { color: var(--text-muted); }

.ai-iconbtn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

.ai-iconbtn--send {
  background: var(--text-primary);
  color: var(--bg-base);
  border-color: var(--text-primary);
}

.ai-iconbtn--send:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  border-color: var(--border-soft);
  cursor: not-allowed;
}

.ai-iconbtn--mic.is-listening {
  background: var(--danger);
  color: var(--text-primary);
  border-color: var(--danger);
  animation: ai-mic-pulse 1.4s infinite;
}

@keyframes ai-mic-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.35); }
  70%  { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.ai-voice-banner {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  color: var(--danger);
  padding: 0 16px var(--space-xs);
}

.ai-voice-banner svg { width: 14px; height: 14px; }

/* ---------- Insight / cost-saver widget (used on dashboard / rewards) ---------- */
.ai-insight {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  padding: var(--space-md);
  display: flex;
  gap: var(--space-sm);
}

.ai-insight__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-insight__icon svg { width: 18px; height: 18px; color: var(--success); }

.ai-insight__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semi);
  color: var(--text-primary);
  margin-bottom: 2px;
}

.ai-insight__body {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---------- Low-data banner (Data Balance Alerts deep link) ---------- */
.low-data-banner {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin: 0 16px var(--space-sm);
}

.low-data-banner svg {
  width: 18px;
  height: 18px;
  color: var(--danger);
  flex-shrink: 0;
}

.low-data-banner__text {
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.low-data-banner__text b { color: var(--danger); }

/* ---------- Responsive ---------- */
@media (min-width: 768px) {
  .ai-page { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border-subtle); border-right: 1px solid var(--border-subtle); }
}
