/* ═══════════════════════════════════════════════════════════════════════
   Ahura AI Coach — Design System v2.0
   Dual-theme (dark default + light) with CSS custom properties
   ═══════════════════════════════════════════════════════════════════════ */

/* ── DARK THEME (default) ──────────────────────────────────────────────── */
:root {
  /* Background levels */
  --bg-base: #0B0F14;
  --bg-surface: #131720;
  --bg-elevated: #1A1F2B;
  --bg-overlay: #242936;

  /* Text hierarchy */
  --text-primary: #E8ECF1;
  --text-secondary: #8B92A0;
  --text-tertiary: #5A6170;
  --text-disabled: #3D4350;

  /* Brand primary — Emerald Green */
  --brand-primary: #2AD47A;
  --brand-primary-hover: #24B968;
  --brand-primary-active: #1FA55D;
  --brand-primary-muted: rgba(42, 212, 122, 0.12);

  /* Brand secondary — Warm Gold */
  --brand-secondary: #FFC526;
  --brand-secondary-hover: #E6B020;
  --brand-secondary-muted: rgba(255, 197, 38, 0.12);

  /* Borders */
  --border-default: rgba(255, 255, 255, 0.06);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-emphasis: rgba(255, 255, 255, 0.12);

  /* Semantic colors */
  --success: #2AD47A;
  --success-bg: rgba(42, 212, 122, 0.10);
  --warning: #FFC526;
  --warning-bg: rgba(255, 197, 38, 0.10);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.10);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.10);

  /* Shadows */
  --shadow-sm: 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-md: 0 0 0 1px rgba(255,255,255,0.06), 0 0 20px rgba(0,0,0,0.3);
  --shadow-lg: 0 0 0 1px rgba(255,255,255,0.08), 0 0 40px rgba(0,0,0,0.4);

  /* Coaching states */
  --state-idle: #2AD47A;
  --state-listening: #EF4444;
  --state-thinking: #FFC526;
  --state-speaking: #FFC526;

  /* Chat bubbles */
  --chat-ai-bg: var(--bg-surface);
  --chat-ai-border: var(--border-default);
  --chat-user-bg: rgba(42, 212, 122, 0.08);
  --chat-user-border: rgba(42, 212, 122, 0.15);

  /* Scrollbar */
  --scrollbar-thumb: rgba(255,255,255,0.12);
  --scrollbar-thumb-hover: rgba(255,255,255,0.2);

  /* Typography */
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;

  /* Transition defaults */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ── LIGHT THEME ───────────────────────────────────────────────────────── */
.light {
  --bg-base: #F7F5F0;
  --bg-surface: #FFFFFF;
  --bg-elevated: #F0EDE8;
  --bg-overlay: #FFFFFF;

  --text-primary: #1A1A1A;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-disabled: #D1D5DB;

  --brand-primary: #1EB866;
  --brand-primary-hover: #17A359;
  --brand-primary-active: #128F4D;
  --brand-primary-muted: rgba(30, 184, 102, 0.10);

  --brand-secondary: #D4A017;
  --brand-secondary-hover: #BF9015;
  --brand-secondary-muted: rgba(212, 160, 23, 0.10);

  --border-default: #E5E2DC;
  --border-subtle: #EDEBE6;
  --border-emphasis: #D5D1CA;

  --success: #16A34A;
  --success-bg: rgba(22, 163, 74, 0.08);
  --warning: #D97706;
  --warning-bg: rgba(217, 119, 6, 0.08);
  --error: #DC2626;
  --error-bg: rgba(220, 38, 38, 0.08);
  --info: #2563EB;
  --info-bg: rgba(37, 99, 235, 0.08);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.05);

  --state-idle: #16A34A;
  --state-listening: #DC2626;
  --state-thinking: #D97706;
  --state-speaking: #D97706;

  --chat-ai-bg: var(--bg-elevated);
  --chat-ai-border: var(--border-default);
  --chat-user-bg: rgba(30, 184, 102, 0.08);
  --chat-user-border: rgba(30, 184, 102, 0.15);

  --scrollbar-thumb: rgba(0,0,0,0.15);
  --scrollbar-thumb-hover: rgba(0,0,0,0.25);
}


/* ═══════════════════════════════════════════════════════════════════════
   BASE STYLES
   ═══════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  transition-property: color, background-color, border-color, box-shadow;
  transition-duration: 200ms;
  transition-timing-function: ease;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-base);
  color: var(--text-primary);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
}

/* Focus indicators — accessible */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: var(--brand-primary-muted);
  color: var(--text-primary);
}


/* ═══════════════════════════════════════════════════════════════════════
   SCROLLBARS
   ═══════════════════════════════════════════════════════════════════════ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

#messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
}


/* ═══════════════════════════════════════════════════════════════════════
   COMPONENT UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════ */

/* Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card:hover {
  box-shadow: var(--shadow-md);
}

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.75rem;
  background: var(--brand-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
}
.btn-primary:hover {
  background: var(--brand-primary-hover);
  box-shadow: var(--shadow-md);
}
.btn-primary:active {
  background: var(--brand-primary-active);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.75rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all var(--transition-base);
}
.btn-secondary:hover {
  background: var(--bg-overlay);
  border-color: var(--border-emphasis);
}
.btn-secondary:active {
  background: var(--bg-elevated);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Input fields */
.input-field {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: 0.75rem;
  transition: all var(--transition-base);
}
.light .input-field {
  background: var(--bg-surface);
}
.input-field::placeholder {
  color: var(--text-tertiary);
}
.input-field:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-muted);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  line-height: 1.5;
}
.badge-success {
  background: var(--success-bg);
  color: var(--success);
}
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.badge-error {
  background: var(--error-bg);
  color: var(--error);
}
.badge-info {
  background: var(--info-bg);
  color: var(--info);
}
.badge-brand {
  background: var(--brand-primary-muted);
  color: var(--brand-primary);
}
.badge-gold {
  background: var(--brand-secondary-muted);
  color: var(--brand-secondary);
}

/* Toast notifications */
.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid transparent;
}
.toast-success {
  background: var(--bg-surface);
  color: var(--success);
  border-left-color: var(--success);
}
.toast-warning {
  background: var(--bg-surface);
  color: var(--warning);
  border-left-color: var(--warning);
}
.toast-error {
  background: var(--bg-surface);
  color: var(--error);
  border-left-color: var(--error);
}
.toast-info {
  background: var(--bg-surface);
  color: var(--info);
  border-left-color: var(--info);
}


/* ═══════════════════════════════════════════════════════════════════════
   ANIMATION KEYFRAMES
   ═══════════════════════════════════════════════════════════════════════ */

/* Bounce (typing indicator) */
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}
.animate-bounce-dot {
  animation: bounce 1.4s ease-in-out infinite;
}

/* Pulse ring (mic recording) */
@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 0; }
  100% { transform: scale(0.8); opacity: 0; }
}
.pulse-ring::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid currentColor;
  animation: pulse-ring 1.5s ease-out infinite;
}

/* Thinking dots */
@keyframes thinking-dots {
  0%, 20% { opacity: 0.3; }
  50% { opacity: 1; }
  80%, 100% { opacity: 0.3; }
}
.thinking-dot:nth-child(1) { animation: thinking-dots 1.4s ease-in-out infinite 0s; }
.thinking-dot:nth-child(2) { animation: thinking-dots 1.4s ease-in-out infinite 0.2s; }
.thinking-dot:nth-child(3) { animation: thinking-dots 1.4s ease-in-out infinite 0.4s; }

/* Speaking wave */
@keyframes speaking-wave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.2); }
}
.speaking-wave-bar:nth-child(1) { animation: speaking-wave 0.8s ease-in-out infinite 0s; }
.speaking-wave-bar:nth-child(2) { animation: speaking-wave 0.8s ease-in-out infinite 0.1s; }
.speaking-wave-bar:nth-child(3) { animation: speaking-wave 0.8s ease-in-out infinite 0.2s; }
.speaking-wave-bar:nth-child(4) { animation: speaking-wave 0.8s ease-in-out infinite 0.3s; }
.speaking-wave-bar:nth-child(5) { animation: speaking-wave 0.8s ease-in-out infinite 0.15s; }

/* Streak fire */
@keyframes streak-fire {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.1) rotate(-3deg); }
  75% { transform: scale(1.1) rotate(3deg); }
}
.streak-fire {
  animation: streak-fire 1.5s ease-in-out infinite;
}

/* Skeleton shimmer */
@keyframes skeleton-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-overlay) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 0.5rem;
}

/* Confetti burst — uses --drift-x and --rotation custom properties set by JS */
@keyframes confetti-burst {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(-200px) translateX(var(--drift-x, 0)) rotate(var(--rotation, 720deg)) scale(0);
    opacity: 0;
  }
}
.confetti-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: confetti-burst 2s ease-out forwards;
}

/* Float (logo on auth pages) */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Glow effect */
@keyframes glow {
  0%, 100% { box-shadow: 0 0 8px var(--brand-secondary-muted); }
  50% { box-shadow: 0 0 24px var(--brand-secondary-muted); }
}
.glow-gold {
  animation: glow 2s ease-in-out infinite;
}

/* Slide up entrance */
@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up {
  animation: slide-up 0.3s ease-out;
}


/* ═══════════════════════════════════════════════════════════════════════
   COACHING STATE CLASSES
   ═══════════════════════════════════════════════════════════════════════ */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.state-idle,
.status-dot.idle {
  background: var(--state-idle);
}

.state-listening,
.status-dot.listening {
  background: var(--state-listening);
  position: relative;
}
.state-listening::before,
.status-dot.listening::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--state-listening);
  animation: pulse-ring 1.5s ease-out infinite;
}

.state-thinking,
.status-dot.thinking {
  background: var(--state-thinking);
  animation: thinking-dots 1.4s ease-in-out infinite;
}

.state-speaking,
.status-dot.speaking {
  background: var(--state-speaking);
}


/* ═══════════════════════════════════════════════════════════════════════
   HTMX & TRANSITIONS
   ═══════════════════════════════════════════════════════════════════════ */

.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator {
  display: inline-block;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}


/* ═══════════════════════════════════════════════════════════════════════
   AVATAR CONTAINER
   ═══════════════════════════════════════════════════════════════════════ */

#avatar-container canvas,
#avatar-container video {
  width: 100% !important;
  height: 100% !important;
  border-radius: 0.75rem;
  object-fit: cover;
}


/* ═══════════════════════════════════════════════════════════════════════
   MOOD SLIDER
   ═══════════════════════════════════════════════════════════════════════ */

input[type="range"].mood-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, #EF4444, #FFC526, #2AD47A);
  outline: none;
}
input[type="range"].mood-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--bg-surface), 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
}
input[type="range"].mood-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--bg-surface), 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
  border: none;
}


/* ═══════════════════════════════════════════════════════════════════════
   THEME TOGGLE VISIBILITY HELPERS
   ═══════════════════════════════════════════════════════════════════════ */

/* Show in dark mode only */
.dark .show-dark { display: block; }
.dark .show-light { display: none; }
.light .show-dark { display: none; }
.light .show-light { display: block; }

/* Inline variants */
.dark .show-dark-inline { display: inline; }
.dark .show-light-inline { display: none; }
.light .show-dark-inline { display: none; }
.light .show-light-inline { display: inline; }


/* ═══════════════════════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════════════════════ */

@media print {
  nav, aside, .no-print, #alert-container { display: none !important; }
  main { padding: 0 !important; }
  body {
    background: white !important;
    color: black !important;
  }
  .card {
    border: 1px solid #ddd !important;
    box-shadow: none !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   MOBILE COACHING PAGE
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .coaching-fullscreen {
    height: calc(100dvh - 56px);
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   PHOSPHOR ICON SIZING
   ═══════════════════════════════════════════════════════════════════════ */

/* Default icon sizing for sidebar and nav */
i[class*="ph-"] {
  font-size: 1.25rem;
  line-height: 1;
}


/* ═══════════════════════════════════════════════════════════════════════
   ACCESSIBILITY — Screen Reader Only
   ═══════════════════════════════════════════════════════════════════════ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
