/* ════════════════════════════════════════
   AI COACH — coach.css
   Drop into your project, link in index.html
   ════════════════════════════════════════ */

/* ── Floating Action Button ── */
.coach-fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 14px);
  right: 18px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-accent);
  z-index: 150;
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  touch-action: manipulation;
}
.coach-fab:hover  { transform: scale(1.09); box-shadow: 0 6px 28px rgba(255,91,20,0.45); }
.coach-fab:active { transform: scale(0.93); }
.coach-fab.coach-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}
/* Pulse ring when closed & no messages yet */
.coach-fab.coach-pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: coachPulse 2s ease-out infinite;
}
@keyframes coachPulse {
  0%   { opacity: 0.8; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.6); }
}

/* ── Drawer ── */
.coach-drawer {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--content-max);
  height: 62vh;
  max-height: 540px;
  min-height: 320px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  z-index: 145;
  box-shadow: var(--shadow-float);
  animation: coachSlideUp 0.28s var(--ease-spring) both;
  overflow: hidden;
}
.coach-drawer.hidden { display: none; }

@keyframes coachSlideUp {
  from { transform: translateX(-50%) translateY(100%); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);   opacity: 1; }
}

/* ── Header ── */
.coach-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}
.coach-header-left {
  display: flex;
  align-items: center;
  gap: 11px;
}
.coach-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1.5px solid rgba(255,91,20,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.coach-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-primary);
  line-height: 1.1;
}
.coach-model {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}
.coach-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.coach-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  touch-action: manipulation;
}
.coach-icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.coach-icon-btn:active { transform: scale(0.9); }

/* ── Messages ── */
.coach-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.coach-messages::-webkit-scrollbar { width: 3px; }
.coach-messages::-webkit-scrollbar-track { background: transparent; }
.coach-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* Bubbles */
.coach-msg {
  max-width: 84%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.52;
  word-break: break-word;
  animation: bubblePop 0.18s var(--ease-spring) both;
}
@keyframes bubblePop {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)  scale(1); }
}
.coach-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.coach-msg-assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.coach-msg-error {
  align-self: flex-start;
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255,23,68,0.2);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
}

/* Typing dots */
.coach-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 14px;
}
.coach-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  display: block;
  animation: typeDot 1.1s ease-in-out infinite;
}
.coach-typing span:nth-child(2) { animation-delay: 0.18s; }
.coach-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typeDot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Input Row ── */
.coach-input-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}
.coach-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 9px 15px;
  outline: none;
  transition: border-color var(--t-fast);
  min-height: 40px;
}
.coach-input:focus { border-color: var(--border-focus); }
.coach-input::placeholder { color: var(--text-muted); }
.coach-input:disabled { opacity: 0.5; }

.coach-send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--t-fast), background var(--t-fast);
  touch-action: manipulation;
}
.coach-send-btn:hover  { background: var(--accent-secondary); transform: scale(1.07); }
.coach-send-btn:active { transform: scale(0.9); }
.coach-send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* ── API Key Setup Screen ── */
.coach-key-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  text-align: center;
  animation: bubblePop 0.2s var(--ease-spring) both;
}
.coach-key-icon { font-size: 2rem; line-height: 1; margin-bottom: 2px; }
.coach-key-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-primary);
}
.coach-key-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.55;
  max-width: 270px;
}
.coach-key-desc.error { color: var(--danger); }
.coach-key-input {
  width: 100%;
  max-width: 310px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 10px 13px;
  outline: none;
  letter-spacing: 0.5px;
  transition: border-color var(--t-fast);
}
.coach-key-input:focus { border-color: var(--border-focus); }
.coach-key-input.invalid { border-color: var(--danger); }
.coach-key-save {
  width: 100%;
  max-width: 310px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
  touch-action: manipulation;
}
.coach-key-save:hover  { background: var(--accent-secondary); }
.coach-key-save:active { transform: scale(0.97); }
.coach-key-link {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  margin-top: 2px;
}
.coach-key-link:hover { text-decoration: underline; }

/* ── Suggested Prompt Chips ── */
.coach-suggestions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
  align-self: stretch;
}
.coach-suggestions-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 2px;
}
.coach-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  padding: 8px 13px;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  touch-action: manipulation;
  line-height: 1.3;
}
.coach-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255,91,20,0.35);
}
.coach-chip:active { transform: scale(0.97); }

/* ── BUG 14 FIX: Suppress coach animations for users who prefer reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .coach-drawer                 { animation: none; }
  .coach-msg                    { animation: none; }
  .coach-fab.coach-pulse::after { animation: none; }
  .coach-typing span            { animation: none; opacity: 0.5; }
}
