/* ============================================
   F1 PREDICTION LEAGUE — COMPONENTS
   Cards · Buttons · Badges · Toasts · Forms
   Driver Cards · Modals · Skeletons · Empty States
   ============================================ */

/* --- Card (Glassmorphism) --- */
.card {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  border-color: var(--glass-border-hover);
}

.card-header {
  position: relative;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--glass-border);
  overflow: hidden;
}

.card-header .telemetry-svg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  pointer-events: none;
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--glass-border);
}

/* Card variants */
.card-accent {
  border-left: 3px solid var(--accent);
}

.card-cta {
  border-left: 4px solid var(--accent);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.card-cta:hover {
  background: var(--glass-bg-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hover);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-body);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1.4;
  min-height: 36px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-primary);
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px rgba(232, 0, 45, 0.4);
}

.btn-secondary {
  background: var(--glass-bg);
  color: var(--text-primary);
  border-color: var(--glass-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--glass-bg);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-md);
  min-height: 44px;
  border-radius: var(--radius-lg);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  min-height: 28px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

/* Spinner inside button */
.btn .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  line-height: 1.4;
  white-space: nowrap;
}

.badge-sprint {
  background: rgba(245, 158, 11, 0.15);
  color: var(--sprint-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-standard {
  background: rgba(107, 114, 128, 0.15);
  color: var(--status-upcoming);
  border: 1px solid rgba(107, 114, 128, 0.3);
}

/* Status badges */
.badge-upcoming {
  background: rgba(107, 114, 128, 0.15);
  color: var(--status-upcoming);
  border: 1px solid rgba(107, 114, 128, 0.3);
}

.badge-active {
  background: rgba(34, 197, 94, 0.15);
  color: var(--status-active);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-locked {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-locked);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-completed {
  background: rgba(59, 130, 246, 0.15);
  color: var(--status-completed);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Round badge */
.badge-round {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}

/* Score badge */
.badge-score {
  font-family: var(--font-data);
  font-weight: var(--weight-semibold);
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(232, 0, 45, 0.3);
  padding: var(--space-1) var(--space-2);
}

/* --- Toasts --- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  pointer-events: none;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: slideUp var(--transition-slow) ease forwards;
  min-width: 280px;
}

.toast.dismissing {
  animation: slideDown var(--transition-slow) ease forwards;
}

.toast-icon {
  flex-shrink: 0;
  font-size: var(--text-md);
  line-height: 1;
  margin-top: 2px;
}

.toast-message {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast-close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast.toast-success {
  border-left: 3px solid var(--success);
}

.toast.toast-error {
  border-left: 3px solid var(--error);
}

.toast.toast-warning {
  border-left: 3px solid var(--warning);
}

.toast.toast-info {
  border-left: 3px solid var(--status-completed);
}

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  animation: backdropIn var(--transition-base) ease;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modalIn var(--transition-slow) ease;
}

.modal-header {
  padding: var(--space-5) var(--space-5) var(--space-3);
}

.modal-title {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
}

.modal-body {
  padding: 0 var(--space-5) var(--space-5);
}

.modal-message {
  font-size: var(--text-base);
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--glass-border);
}

/* --- Form Fields --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-base);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-input.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--error);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.form-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: var(--space-4) 0;
  position: relative;
}

.form-divider::before,
.form-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 1.5em);
  height: 1px;
  background: var(--glass-border);
}

.form-divider::before { left: 0; }
.form-divider::after { right: 0; }

/* --- Skeleton Loading --- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--glass-bg);
  border-radius: var(--radius-md);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.04) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
}

.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 65%; }
.skeleton-text.long { width: 90%; }

.skeleton-title {
  height: 24px;
  width: 50%;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-sm);
}

.skeleton-card {
  height: 160px;
  border-radius: var(--radius-lg);
}

.skeleton-row {
  height: 56px;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-md);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* --- Driver Card --- */
.driver-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-4) 0 0;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.driver-card:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hover);
}

.driver-card.selected {
  box-shadow: 0 0 0 2px var(--accent);
  border-color: var(--accent);
}

.driver-card.dragging {
  opacity: 0.5;
  box-shadow: var(--shadow-lg);
}

.driver-card.drag-over {
  box-shadow: 0 0 0 2px var(--accent);
  animation: slotGlow 1s ease infinite;
}

.driver-card-color-bar {
  width: 4px;
  height: 100%;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  flex-shrink: 0;
}

.driver-card-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  color: var(--text-primary);
  flex-shrink: 0;
}

.driver-card-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  font-family: var(--font-data);
  font-weight: var(--weight-bold);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.driver-card-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.driver-card-code {
  font-family: var(--font-data);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  color: var(--text-primary);
  letter-spacing: 0.05em;
}

.driver-card-name {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.driver-card-team {
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.7;
}

/* --- Order Slot --- */
.order-slot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  border: 1px dashed var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0 var(--space-4);
  transition: all var(--transition-drag);
}

.order-slot.filled {
  border-style: solid;
  padding: 0;
}

.order-slot.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 2px var(--accent);
}

.order-slot-position {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  color: var(--text-muted);
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.order-slot-position.top3 {
  color: var(--accent);
}

.order-slot-placeholder {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.15);
}

/* --- Empty State --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
}

.empty-state-icon {
  width: 120px;
  height: 80px;
  margin-bottom: var(--space-6);
  opacity: 0.3;
}

.empty-state-title {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  font-size: var(--text-base);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  max-width: 360px;
}

/* --- Countdown --- */
.countdown {
  display: flex;
  gap: var(--space-3);
}

.countdown-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.countdown-value {
  font-family: var(--font-data);
  font-weight: var(--weight-bold);
  font-size: var(--text-2xl);
  color: var(--text-primary);
  line-height: 1;
}

.countdown-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-1);
}

/* --- Save Indicator --- */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.save-indicator.saved {
  color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.save-indicator.saving {
  color: var(--text-muted);
}

.save-indicator.failed {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  cursor: pointer;
}

/* --- Stat Card (Dashboard) --- */
.stat-value {
  font-family: var(--font-data);
  font-weight: var(--weight-bold);
  font-size: var(--text-3xl);
  color: var(--text-primary);
  line-height: 1;
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-data);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.stat-delta.positive {
  color: var(--success);
}

.stat-delta.negative {
  color: var(--error);
}

/* --- Spinner (standalone) --- */
.spinner-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-12);
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border: 3px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.spinner-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* --- Toggle --- */
.toggle-group {
  display: inline-flex;
  background: var(--bg-base);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.toggle-option {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
}

.toggle-option:hover {
  color: var(--text-primary);
}

.toggle-option.active {
  background: var(--accent);
  color: var(--text-primary);
}

/* --- Pill --- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Status Dot --- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.active {
  background: var(--status-active);
  box-shadow: 0 0 6px var(--status-active);
}

.status-dot.locked {
  background: var(--status-locked);
}

.status-dot.completed {
  background: var(--status-completed);
}

/* --- Score Result Grid --- */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-4);
}

.result-player-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.result-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--glass-border);
}

.result-player-name {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
}

.result-player-score {
  font-family: var(--font-data);
  font-weight: var(--weight-bold);
  font-size: var(--text-xl);
  color: var(--accent);
}

/* --- Your Result Card (Highlighted) --- */
.result-player-card.is-current-user {
  border: 2px solid var(--accent);
  box-shadow: 0 0 20px rgba(232, 0, 45, 0.22);
  background: var(--bg-surface);
}

.result-hero-card {
  background: linear-gradient(135deg, rgba(232, 0, 45, 0.08) 0%, rgba(20, 21, 22, 0.95) 100%);
  border: 2px solid var(--accent);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 20px rgba(232, 0, 45, 0.15);
}

.official-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

.official-table th {
  padding: 10px 14px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
}

.official-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--glass-border);
  vertical-align: middle;
}

.official-table tr:hover td {
  background: var(--glass-bg-hover);
}

/* ============================================
   GLOBAL CHAT
   ============================================ */

.global-chat-wrapper {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: none;
}

.global-chat-wrapper:not(.hidden) {
  pointer-events: auto;
}

.chat-fab {
  background: linear-gradient(135deg, var(--accent), #ff1a1a);
  color: white;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(225, 6, 0, 0.4);
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
  pointer-events: auto;
  position: relative;
  z-index: 2;
}

.chat-fab:hover {
  transform: scale(1.1) rotate(-5deg);
  box-shadow: 0 12px 32px rgba(225, 6, 0, 0.5);
}

.chat-fab-avatar {
  font-size: 1.5rem;
}

/* Chat Popup Base (Centered with sweeping animation) */
.chat-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 90vw;
  max-width: 400px;
  height: 75vh;
  max-height: 600px;
  /* Final centered position */
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  /* Premium glass effect */
  background: rgba(15, 15, 15, 0.75);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  overflow: hidden;
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
  pointer-events: auto;
  z-index: 1001;
}

.chat-popup.hidden {
  opacity: 0;
  pointer-events: none;
  display: flex !important; /* Keep it in DOM for animation */
  /* Hidden state: scale down and move towards the FAB at the bottom left */
  transform: translate(calc(-50vw + 52px), calc(50vh - 52px)) scale(0.1);
}

.chat-header {
  padding: var(--space-3) var(--space-4);
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #fff, #aaa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#btn-close-chat {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

#btn-close-chat:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  transform: scale(1.1);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: slideInUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

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

.chat-message-wrapper.own {
  align-self: flex-end;
}

.chat-message-wrapper.other {
  align-self: flex-start;
}

.chat-sender-name {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-left: 4px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.chat-message-wrapper.own .chat-sender-name {
  display: none;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chat-message-wrapper.own .chat-bubble {
  background: linear-gradient(135deg, var(--accent), #e00500);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message-wrapper.other .chat-bubble {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-input-form {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  gap: var(--space-2);
  background: rgba(0, 0, 0, 0.2);
}

#chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 0 16px;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s;
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.chat-send-btn {
  background: linear-gradient(135deg, var(--accent), #ff1a1a);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(225, 6, 0, 0.3);
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(225, 6, 0, 0.4);
}

.chat-send-btn i {
  font-size: 1rem;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .chat-popup {
    /* Use inset for positioning — leaves 8px breathing room on all sides */
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-width: none;
    /* dvh shrinks when the virtual keyboard opens */
    height: calc(100dvh - 16px);
    max-height: none;
    transform: none;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Safe-area for notched devices */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .chat-popup.hidden {
    /* Shrink towards FAB at bottom-left */
    transform: translate(calc(-50vw + 52px), calc(50vh - 52px)) scale(0.1);
  }

  /* Ensure input form stays visible above keyboard */
  .chat-input-form {
    flex-shrink: 0;
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }

  /* Messages area fills remaining space and stays scrollable */
  .chat-messages {
    flex: 1;
    min-height: 0; /* allows flex child to shrink below content size */
    overflow-y: auto;
  }

  /* Slightly smaller FAB on small screens so it doesn't crowd the corner */
  .chat-fab {
    width: 48px;
    height: 48px;
  }
  .chat-fab-avatar {
    font-size: 1.25rem;
  }
}

/* --- Results & Breakdown Components --- */
.result-hero-card {
  background: linear-gradient(135deg, rgba(232, 0, 45, 0.08) 0%, rgba(20, 21, 22, 0.95) 100%);
  border: 1px solid rgba(232, 0, 45, 0.35);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
}

.result-hero-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
}

.result-player-card.is-current-user {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(232, 0, 45, 0.25);
  background: linear-gradient(180deg, rgba(232, 0, 45, 0.06) 0%, var(--bg-surface) 100%);
}

.official-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-body);
}

.official-table th {
  font-family: var(--font-body);
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.02);
}

.official-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: var(--text-sm);
  vertical-align: middle;
}

.official-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.results-weekend-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
  background: var(--bg-surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
}

@media (max-width: 768px) {
  .results-weekend-bar {
    flex-direction: column;
    align-items: stretch;
  }
  #results-race-select {
    width: 100%;
    max-width: none !important;
  }
}
