/* ── App Chat Bubble ─────────────────────────────────────────────────────── */
/* Phase 12: In-app AI chat — onboarding + assistant + Tether Me modes       */

#at-chat {
  position: fixed;
  bottom: calc(var(--at-nav-height, 58px) + var(--at-safe-bottom, 0px) + 80px);
  right: 16px;
  z-index: var(--at-z-modal, 900);
  font-family: var(--at-font-family, -apple-system, BlinkMacSystemFont, sans-serif);
}

/* On desktop, anchor inside the #app container (max-width: 1055px, centered) */
@media (min-width: 1056px) {
  #at-chat {
    right: calc(50% - 1055px / 2 + 16px);
    padding-right: 10px;
  }
}

/* ── Badge ───────────────────────────────────────────────────────────────── */

#at-chat-badge {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  background: var(--at-color-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: transform 0.2s;
  overflow: visible;
  position: relative;
}

#at-chat-badge:active {
  transform: scale(0.92);
}

.at-chat-badge-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Unread notification dot */
.at-chat-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e53e3e;
  border: 2px solid var(--at-surface-card, #fff);
  animation: at-chat-dot-pulse 2s ease-in-out infinite;
}

@keyframes at-chat-dot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── Panel ───────────────────────────────────────────────────────────────── */

#at-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 160px));
  background: var(--at-surface-card, #fff);
  border-radius: var(--at-radius-xl, 16px);
  border: 1px solid var(--at-border, rgba(0,0,0,0.1));
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

#at-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--at-color-brand);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.3s ease;
}

#at-chat-header span {
  flex: 1;
}

/* Tether Me mode header */
#at-chat-header.at-chat-header-tether {
  background: linear-gradient(135deg, var(--at-color-brand), #8B5CF6);
}

/* ── Messages ────────────────────────────────────────────────────────────── */

#at-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 140px;
  -webkit-overflow-scrolling: touch;
}

.at-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}

.at-chat-msg-assistant {
  align-self: flex-start;
  background: var(--at-gray-100, #f1f1f1);
  color: var(--at-text-primary, #1a1a1a);
  border-bottom-left-radius: 4px;
}

.at-chat-msg-user {
  align-self: flex-end;
  background: var(--at-color-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.at-chat-msg em {
  font-style: italic;
}

/* Typing indicator */
.at-chat-typing {
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.at-chat-dot-anim {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--at-text-muted, #999);
  animation: at-chat-bounce 1.2s ease-in-out infinite;
}

.at-chat-dot-anim:nth-child(2) { animation-delay: 0.15s; }
.at-chat-dot-anim:nth-child(3) { animation-delay: 0.3s; }

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

/* ── Buttons ─────────────────────────────────────────────────────────────── */

#at-chat-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--at-border, rgba(0,0,0,0.08));
}

.at-chat-option-btn {
  flex: 1;
  min-width: 80px;
  padding: 8px 12px;
  border: 1.5px solid var(--at-color-brand);
  border-radius: var(--at-radius-md, 8px);
  background: transparent;
  color: var(--at-color-brand);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.at-chat-option-btn:active {
  background: var(--at-color-brand);
  color: #fff;
}

/* ── Input row ───────────────────────────────────────────────────────────── */

#at-chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--at-border, rgba(0,0,0,0.08));
  flex-shrink: 0;
}

#at-chat-input {
  flex: 1;
  border: 1.5px solid var(--at-border-medium, rgba(0,0,0,0.15));
  border-radius: var(--at-radius-md, 8px);
  padding: 8px 12px;
  font-size: 14px;
  background: var(--at-surface-card, #fff);
  color: var(--at-text-primary, #1a1a1a);
  outline: none;
  min-height: 36px;
}

#at-chat-input:focus {
  border-color: var(--at-color-brand);
}

#at-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--at-color-brand);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 36px;
  min-height: 36px;
}

#at-chat-send:disabled {
  opacity: 0.5;
}

/* ── Dismiss row (onboarding only) ───────────────────────────────────────── */

#at-chat-dismiss-row {
  text-align: center;
  padding: 2px 12px 10px;
  flex-shrink: 0;
}

#at-chat-dismiss-row a {
  font-size: 11px;
  color: var(--at-text-muted, #999);
  text-decoration: none;
}

#at-chat-dismiss-row a:hover {
  text-decoration: underline;
}

/* ── Dark mode ───────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  .at-chat-msg-assistant {
    background: var(--at-gray-800, #2c2c2a);
  }
  #at-chat-input {
    background: #2c2c2e;
    color: #f0eee8;
    border-color: rgba(255,255,255,0.15);
  }
  .at-chat-dot {
    border-color: var(--at-gray-800, #2c2c2a);
  }
}

[data-theme="dark"] .at-chat-msg-assistant {
  background: var(--at-gray-800, #2c2c2a);
}
[data-theme="dark"] #at-chat-input {
  background: #2c2c2e;
  color: #f0eee8;
  border-color: rgba(255,255,255,0.15);
}
[data-theme="dark"] .at-chat-dot {
  border-color: var(--at-gray-800, #2c2c2a);
}
