/* ============================================================
   SurgMentor — Kinetic Depth Animation System
   Philosophy: movement reveals structure, never decorates it.
   Inspired by: deep-water environments, bioluminescent pulses,
   the unhurried drift of precise systems.
   ============================================================ */

/* ── Animation Tokens ─────────────────────────────────────── */
:root {
  /* Durations — strict hierarchy */
  --dur-micro:  120ms;   /* button press, checkbox, pip */
  --dur-fast:   200ms;   /* hover states */
  --dur-medium: 280ms;   /* panel/modal open */
  --dur-slow:   440ms;   /* page-level entrance */
  --dur-crawl:  650ms;   /* score ring, count-up */

  /* Easing — nothing linear */
  --ease-out-expo:  cubic-bezier(0.16, 1, 0.3, 1);    /* snappy entrance */
  --ease-in-out:    cubic-bezier(0.4, 0, 0.2, 1);     /* hover / reversible */
  --ease-spring:    cubic-bezier(0.34, 1.56, 0.64, 1); /* press rebound */
  --ease-out-soft:  cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Reduce Motion: respect user preference ──────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

/* Entrance — elements rise from depth */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUpSm {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* Modal entrance */
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

@keyframes backdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Slide in from right (toast) */
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0)    scale(1); }
  to   { opacity: 0; transform: translateX(20px) scale(0.94); }
}

/* Typing dots bounce */
@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.5; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* Score ring fill — starts at 0 dash, animates to value */
@keyframes ringFill {
  from { stroke-dashoffset: 188.5; }
  /* "to" value is set inline via JS */
}

/* Pulse — live indicators, status dots */
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46,204,143,0.55); }
  50%      { box-shadow: 0 0 0 5px rgba(46,204,143,0); }
}

/* Shimmer — directional left-to-right (skeleton loader) */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position:  600px 0; }
}

/* Glow pulse — primary actions */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0  8px rgba(46,204,143,0.2), 0 2px 8px rgba(0,0,0,0.3); }
  50%      { box-shadow: 0 0 18px rgba(46,204,143,0.38), 0 4px 16px rgba(0,0,0,0.3); }
}

/* Progress bar fill */
@keyframes barFill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Hero badge pulse dot */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.65); }
}

/* Sidebar item active indicator */
@keyframes navPip {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════
   BUTTONS — press feedback + hover refinements
   ═══════════════════════════════════════════════════════════ */

.btn {
  transition:
    background  var(--dur-fast) var(--ease-in-out),
    color       var(--dur-fast) var(--ease-in-out),
    border-color var(--dur-fast) var(--ease-in-out),
    transform   var(--dur-micro) var(--ease-spring),
    box-shadow  var(--dur-fast) var(--ease-in-out),
    opacity     var(--dur-fast) var(--ease-in-out);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

/* Green button gets a subtle glow bloom on hover */
.btn-green:hover:not(:disabled) {
  box-shadow: 0 0 14px rgba(46,204,143,0.28), 0 2px 8px rgba(0,0,0,0.28);
}

.btn-green:active:not(:disabled) {
  transform: scale(0.95);
  box-shadow: 0 0 6px rgba(46,204,143,0.18);
}

/* Primary button hover lift */
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(30,96,145,0.35);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

/* Icon buttons — micro press */
.btn-icon {
  transition:
    background   var(--dur-fast) var(--ease-in-out),
    color        var(--dur-fast) var(--ease-in-out),
    border-color var(--dur-fast) var(--ease-in-out),
    transform    var(--dur-micro) var(--ease-spring);
}

.btn-icon:active { transform: scale(0.90); }

/* Send button in chat — crisp press */
.chat-send-btn:active:not(:disabled) {
  transform: scale(0.88);
}

/* Hamburger button press */
.hamburger-btn:active { transform: scale(0.90); }

/* ═══════════════════════════════════════════════════════════
   NAV ITEMS — active indicator + hover
   ═══════════════════════════════════════════════════════════ */

.nav-item {
  position: relative;
  transition:
    background var(--dur-fast) var(--ease-in-out),
    color      var(--dur-fast) var(--ease-in-out),
    transform  var(--dur-micro) var(--ease-spring);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  background: var(--green);
  border-radius: 0 2px 2px 0;
  animation: navPip var(--dur-medium) var(--ease-out-expo) forwards;
}

.nav-item:active:not(.active) { transform: scale(0.97); }

/* ═══════════════════════════════════════════════════════════
   CARDS — lift on hover
   ═══════════════════════════════════════════════════════════ */

.stat-card {
  transition:
    transform    var(--dur-fast) var(--ease-out-soft),
    border-color var(--dur-fast) var(--ease-in-out),
    box-shadow   var(--dur-fast) var(--ease-in-out);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.15);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

/* Case selection cards */
.case-select-card {
  transition:
    background   var(--dur-fast) var(--ease-in-out),
    border-color var(--dur-fast) var(--ease-in-out),
    transform    var(--dur-fast) var(--ease-out-soft),
    box-shadow   var(--dur-fast) var(--ease-in-out);
}

.case-select-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
}

.case-select-card:active {
  transform: scale(0.99) translateY(0);
}

/* Feature cards on landing */
.feature-card {
  transition:
    transform    var(--dur-fast) var(--ease-out-soft),
    border-color var(--dur-fast) var(--ease-in-out),
    box-shadow   var(--dur-fast) var(--ease-in-out);
}

/* History items in sidebar */
.history-item {
  transition:
    background   var(--dur-fast) var(--ease-in-out),
    border-color var(--dur-fast) var(--ease-in-out),
    transform    var(--dur-micro) var(--ease-spring);
}

.history-item:active { transform: scale(0.99); }

/* ═══════════════════════════════════════════════════════════
   MODALS — entrance + exit
   ═══════════════════════════════════════════════════════════ */

.modal-backdrop {
  transition: opacity var(--dur-medium) var(--ease-in-out);
  opacity: 0;
  pointer-events: none;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal-backdrop.open .modal {
  animation: modalIn var(--dur-medium) var(--ease-out-expo) forwards;
}

/* Smooth close: when backdrop loses .open, modal falls back */
.modal-backdrop:not(.open) .modal {
  animation: modalOut var(--dur-medium) var(--ease-in-out) forwards;
}

@keyframes modalOut {
  from { opacity: 1; transform: scale(1)    translateY(0); }
  to   { opacity: 0; transform: scale(0.95) translateY(8px); }
}

/* ═══════════════════════════════════════════════════════════
   TOAST — upgraded entrance
   ═══════════════════════════════════════════════════════════ */

.toast {
  animation: toastIn var(--dur-medium) var(--ease-out-expo) forwards;
  transition: box-shadow var(--dur-fast) var(--ease-in-out);
}

.toast.removing {
  animation: toastOut var(--dur-medium) var(--ease-in-out) forwards;
}

.toast:hover {
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

/* ═══════════════════════════════════════════════════════════
   CHAT MESSAGES — surfacing from depth
   ═══════════════════════════════════════════════════════════ */

.msg-row {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) both;
}

/* User messages come from the right side */
.msg-row.user {
  animation: fadeUpSm var(--dur-fast) var(--ease-out-expo) both;
}

/* Streaming cursor blink */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 0.9em;
  background: var(--green);
  margin-left: 2px;
  vertical-align: middle;
  border-radius: 1px;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ── Typing indicator ────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-dimmer);
  border-radius: 50%;
  animation: dotBounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }

/* ═══════════════════════════════════════════════════════════
   OSCE RESULT PANEL — staggered entrance
   ═══════════════════════════════════════════════════════════ */

/* The panel container itself */
.osce-result-panel {
  animation: scaleIn var(--dur-medium) var(--ease-out-expo) both;
}

/* Header enters first */
.osce-result-header {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) calc(var(--dur-micro)) both;
}

/* Feedback boxes stagger in after header */
.feedback-box:nth-child(1) {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) calc(var(--dur-micro) * 2) both;
}
.feedback-box:nth-child(2) {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) calc(var(--dur-micro) * 3) both;
}
.feedback-box:nth-child(3) {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) calc(var(--dur-micro) * 4) both;
}
.feedback-box:nth-child(4) {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) calc(var(--dur-micro) * 5) both;
}

/* Score ring — animated fill */
.ring-fill {
  animation: ringFillAnim var(--dur-crawl) var(--ease-out-expo) var(--dur-medium) both;
}

@keyframes ringFillAnim {
  from { stroke-dashoffset: 188.5; }
  /* target offset is set inline; animation starts from full (empty ring) */
}

/* ── OSCE status dot pulse ───────────────────────────────── */
.osce-status-item .dot.active {
  animation: statusPulse 2.2s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════
   INPUTS — focus glow
   ═══════════════════════════════════════════════════════════ */

.input {
  transition:
    border-color var(--dur-fast) var(--ease-in-out),
    box-shadow   var(--dur-fast) var(--ease-in-out),
    background   var(--dur-fast) var(--ease-in-out);
}

.input:focus {
  box-shadow: 0 0 0 3px rgba(46,204,143,0.12), 0 0 0 1px rgba(46,204,143,0.35);
  outline: none;
}

/* Chat input specific — slightly warmer glow */
.chat-input-field:focus,
textarea.input:focus {
  box-shadow: 0 0 0 3px rgba(30,96,145,0.18), 0 0 0 1px rgba(46,204,143,0.28);
}

/* Code input on student-login page */
input.input:focus {
  box-shadow: 0 0 0 3px rgba(46,204,143,0.14), 0 0 0 1px var(--green);
  border-color: var(--green);
}

/* ═══════════════════════════════════════════════════════════
   SKELETON — directional shimmer (upgraded)
   ═══════════════════════════════════════════════════════════ */

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.09) 40%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 600px 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════
   PROGRESS BARS — animated fill on load
   ═══════════════════════════════════════════════════════════ */

.progress-bar-fill {
  transform-origin: left center;
  animation: barFill var(--dur-crawl) var(--ease-out-expo) var(--dur-medium) both;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR DRAWER — smoother open/close (override base)
   ═══════════════════════════════════════════════════════════ */

.sidebar {
  transition: transform 0.28s var(--ease-out-expo);
}

/* ═══════════════════════════════════════════════════════════
   PAGE ENTRANCE — intersection observer targets
   Components gain .is-visible when they scroll into view
   ═══════════════════════════════════════════════════════════ */

[data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity   var(--dur-slow)  var(--ease-out-expo),
    transform var(--dur-slow)  var(--ease-out-expo);
}

[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger delay utilities — applied by JS */
[data-reveal-delay="1"] { transition-delay: 60ms; }
[data-reveal-delay="2"] { transition-delay: 120ms; }
[data-reveal-delay="3"] { transition-delay: 180ms; }
[data-reveal-delay="4"] { transition-delay: 240ms; }
[data-reveal-delay="5"] { transition-delay: 300ms; }
[data-reveal-delay="6"] { transition-delay: 360ms; }

/* ═══════════════════════════════════════════════════════════
   STATS PAGE — card entrance stagger
   ═══════════════════════════════════════════════════════════ */

.stat-card[data-reveal] {
  /* reset to allow CSS transition form */
  transform: translateY(16px);
}

/* ═══════════════════════════════════════════════════════════
   LANDING PAGE — section & hero polish
   ═══════════════════════════════════════════════════════════ */

/* Hero entrance (immediately when page loads) */
.hero-badge {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) 100ms both;
}

.hero-title {
  animation: fadeUp var(--dur-slow) var(--ease-out-expo) 160ms both;
}

.hero-subtitle {
  animation: fadeUp var(--dur-slow) var(--ease-out-expo) 220ms both;
}

.hero-actions {
  animation: fadeUp var(--dur-slow) var(--ease-out-expo) 280ms both;
}

.hero-note {
  animation: fadeIn var(--dur-slow) var(--ease-out-expo) 400ms both;
}

/* Landing nav */
.landing-nav {
  animation: fadeIn var(--dur-medium) var(--ease-out-expo) both;
}

/* ═══════════════════════════════════════════════════════════
   OSCE CHIP / PILL — hover bounce
   ═══════════════════════════════════════════════════════════ */

.osce-chip,
.pill {
  transition:
    background   var(--dur-fast) var(--ease-in-out),
    color        var(--dur-fast) var(--ease-in-out),
    border-color var(--dur-fast) var(--ease-in-out),
    transform    var(--dur-micro) var(--ease-spring);
}

.osce-chip:active,
.pill:active {
  transform: scale(0.94);
}

/* ═══════════════════════════════════════════════════════════
   ALERT / BANNER — smooth slide-down entrance
   ═══════════════════════════════════════════════════════════ */

.alert {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) both;
}

/* ═══════════════════════════════════════════════════════════
   TABLE ROWS — subtle hover state (for stats / admin tables)
   ═══════════════════════════════════════════════════════════ */

tbody tr {
  transition: background var(--dur-fast) var(--ease-in-out);
}

/* ═══════════════════════════════════════════════════════════
   ADMIN PANEL — detail modal slide
   ═══════════════════════════════════════════════════════════ */

#student-detail-panel .modal {
  animation: modalIn var(--dur-medium) var(--ease-out-expo) both;
}

/* ═══════════════════════════════════════════════════════════
   LOGO ICON — gentle pulse on hover
   ═══════════════════════════════════════════════════════════ */

.sidebar-logo .logo-icon,
.login-logo .logo-icon {
  transition: box-shadow var(--dur-fast) var(--ease-in-out), transform var(--dur-fast) var(--ease-out-soft);
}

.sidebar-logo:hover .logo-icon,
.login-logo .logo-icon {
  animation: glowPulse 3s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════
   SOURCES TOGGLE — smooth reveal
   ═══════════════════════════════════════════════════════════ */

.sources-strip {
  transition:
    opacity   var(--dur-medium) var(--ease-in-out),
    transform var(--dur-medium) var(--ease-out-expo);
}

.sources-strip[style*="none"] {
  opacity: 0;
  transform: translateY(-4px);
}

/* ═══════════════════════════════════════════════════════════
   EMPTY STATES — fade in
   ═══════════════════════════════════════════════════════════ */

.empty-state {
  animation: fadeIn var(--dur-slow) var(--ease-out-expo) 120ms both;
}

/* ═══════════════════════════════════════════════════════════
   PAGE CONTAINER — smooth mount
   ═══════════════════════════════════════════════════════════ */

.page-container {
  animation: fadeUp var(--dur-medium) var(--ease-out-expo) both;
}

/* But don't animate if it's inside an already-animated wrapper */
[data-reveal] .page-container {
  animation: none;
}
