/* ============================================================================
   Component Library — RunCoach Refined Athletic Design
   ========================================================================= */

/* ============================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  text-align: center;
  white-space: nowrap;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  min-width: 44px;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

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

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Primary — cobalt blue */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  box-shadow: var(--shadow-sm), 0 2px 8px rgba(29, 78, 216, 0.15);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-md), 0 4px 16px rgba(29, 78, 216, 0.25);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-xs);
}

/* Accent — warm coral */
.btn-accent {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  box-shadow: var(--shadow-sm), 0 2px 8px rgba(255, 98, 70, 0.15);
}

.btn-accent:hover:not(:disabled) {
  background: var(--color-accent-dark);
  box-shadow: var(--shadow-md), 0 4px 16px rgba(255, 98, 70, 0.25);
  transform: translateY(-1px);
}

.btn-accent:active:not(:disabled) {
  transform: translateY(0);
}

/* Secondary */
.btn-secondary {
  background: var(--color-secondary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-secondary-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Danger */
.btn-danger {
  background: var(--color-error);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: #CC2222;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Ghost — transparent with border */
.btn-ghost {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-bg-sunken);
  border-color: var(--color-text-muted);
}

/* Outline — primary color border */
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--color-primary-subtle);
}

/* Subtle — soft background */
.btn-subtle {
  background: var(--color-primary-subtle);
  color: var(--color-primary);
  border: none;
}

.btn-subtle:hover:not(:disabled) {
  background: rgba(29, 78, 216, 0.12);
}

/* Button sizes */
.btn-sm {
  padding: 6px 14px;
  font-size: var(--text-sm);
  min-height: 36px;
  border-radius: var(--radius-md);
}

.btn-lg {
  padding: 14px 28px;
  font-size: var(--text-lg);
  min-height: 52px;
  border-radius: var(--radius-xl);
}

.btn-full {
  width: 100%;
}

/* Icon button */
.btn-icon {
  padding: 10px;
  min-width: 44px;
}

/* ============================================================================
   Cards
   ========================================================================= */

.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition:
    box-shadow var(--duration-base) var(--ease-out),
    transform var(--duration-base) var(--ease-out),
    border-color var(--duration-base) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}

.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin: 0;
}

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

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-bg-sunken);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

/* ============================================================================
   Form Inputs
   ========================================================================= */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  letter-spacing: var(--tracking-wide);
}

.form-label-required::after {
  content: ' *';
  color: var(--color-accent);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg-elevated);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: all var(--duration-fast) var(--ease-out);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  touch-action: manipulation;
  min-height: 46px;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: var(--color-text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-muted);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background: var(--color-bg-sunken);
  cursor: not-allowed;
  opacity: 0.5;
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-error {
  font-size: var(--text-sm);
  color: var(--color-error);
}

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

/* Checkbox and Radio */
.form-checkbox,
.form-radio {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

.form-checkbox input[type="checkbox"],
.form-radio input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ============================================================================
   Badges / Tags
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
  border-radius: var(--radius-full);
  white-space: nowrap;
  letter-spacing: var(--tracking-wide);
}

.badge-primary {
  background: var(--color-primary-subtle);
  color: var(--color-primary);
}

.badge-secondary {
  background: rgba(13, 148, 136, 0.08);
  color: var(--color-secondary);
}

.badge-success {
  background: var(--color-success-subtle);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-subtle);
  color: var(--color-warning);
}

.badge-error {
  background: var(--color-error-subtle);
  color: var(--color-error);
}

.badge-info {
  background: var(--color-info-subtle);
  color: var(--color-info);
}

.badge-neutral {
  background: var(--color-surface);
  color: var(--color-text-secondary);
}

.badge-accent {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

/* ============================================================================
   Alerts / Notifications
   ========================================================================= */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
}

.alert-icon {
  flex-shrink: 0;
  font-size: var(--text-lg);
  margin-top: 1px;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.alert-message {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  opacity: 0.85;
}

.alert-success {
  background: var(--color-success-subtle);
  border-color: var(--color-success-border);
  color: var(--color-success);
}

.alert-warning {
  background: var(--color-warning-subtle);
  border-color: var(--color-warning-border);
  color: var(--color-warning);
}

.alert-error {
  background: var(--color-error-subtle);
  border-color: var(--color-error-border);
  color: var(--color-error);
}

.alert-info {
  background: var(--color-info-subtle);
  border-color: var(--color-info-border);
  color: var(--color-info);
}

/* ============================================================================
   Modal / Dialog
   ========================================================================= */

.modal {
  display: none;
  position: fixed;
  z-index: var(--z-modal);
  inset: 0;
  overflow: auto;
  padding: var(--space-4);
}

.modal.is-open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-bg-overlay);
  backdrop-filter: blur(6px);
  z-index: var(--z-modal-backdrop);
  animation: fadeIn var(--duration-base) var(--ease-out);
}

.modal-content {
  position: relative;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  z-index: var(--z-modal);
  animation: scaleIn var(--duration-slow) var(--ease-out);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.modal-close:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

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

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-bg-sunken);
  border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
}

/* ============================================================================
   Loading Spinner
   ========================================================================= */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface) 0%,
    var(--color-border-subtle) 50%,
    var(--color-surface) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-md);
}

.skeleton-text { height: 1em; margin-bottom: var(--space-2); }
.skeleton-title { height: 1.5em; width: 60%; margin-bottom: var(--space-4); }
.skeleton-rect { height: 100px; width: 100%; }

/* ============================================================================
   Toast Notifications
   ========================================================================= */

.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 320px;
  max-width: 480px;
  padding: var(--space-4) var(--space-5);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-subtle);
  border-left: 3px solid var(--color-border);
  border-radius: var(--radius-md) var(--radius-lg) var(--radius-lg) var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  overflow: hidden;
  animation: toastSlideIn var(--duration-slow) var(--ease-out);
}

.toast.toast-exit {
  animation: toastSlideOut var(--duration-base) var(--ease-out) forwards;
}

/* Type-specific left border accents */
.toast-success { border-left-color: var(--color-success); }
.toast-error   { border-left-color: var(--color-error); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-info    { border-left-color: var(--color-info); }

/* Icon badge — small colored circle */
.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  line-height: 1;
  margin-top: 1px;
}

.toast-success .toast-icon {
  background: var(--color-success-subtle);
  color: var(--color-success);
}
.toast-error .toast-icon {
  background: var(--color-error-subtle);
  color: var(--color-error);
}
.toast-warning .toast-icon {
  background: var(--color-warning-subtle);
  color: var(--color-warning);
}
.toast-info .toast-icon {
  background: var(--color-info-subtle);
  color: var(--color-info);
}

.toast-content {
  flex: 1;
  min-width: 0;
  padding-top: 3px;
}

.toast-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  margin-bottom: 2px;
  color: var(--color-text);
}

.toast-message {
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  color: var(--color-text);
  line-height: var(--leading-normal);
  word-break: break-word;
}

.toast-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: -2px -4px 0 0;
  background: none;
  border: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out);
}

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

/* Auto-dismiss progress bar */
.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--color-border);
  border-radius: 0 0 0 var(--radius-md);
  animation: toastProgress 8s linear forwards;
}

.toast-success .toast-progress { background: var(--color-success); opacity: 0.35; }
.toast-error   .toast-progress { background: var(--color-error);   opacity: 0.35; }
.toast-warning .toast-progress { background: var(--color-warning); opacity: 0.35; }
.toast-info    .toast-progress { background: var(--color-info);    opacity: 0.35; }

@keyframes toastProgress {
  from { width: 100%; }
  to   { width: 0%; }
}

@keyframes toastSlideIn {
  from { transform: translateX(calc(100% + 20px)); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes toastSlideOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(calc(100% + 20px)); opacity: 0; }
}

/* ============================================================================
   Divider
   ========================================================================= */

.divider {
  height: 1px;
  background: var(--color-border);
  border: none;
  margin: var(--space-6) 0;
}

/* ============================================================================
   Stat Block
   ========================================================================= */

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

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

.stat-unit {
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  color: var(--color-text-secondary);
  margin-left: var(--space-1);
}

/* ============================================================================
   Responsive — Mobile
   ========================================================================= */

@media (max-width: 768px) {
  .modal-content {
    margin: var(--space-3);
    max-height: calc(100vh - var(--space-6));
    border-radius: var(--radius-xl);
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-4);
  }

  .modal-close {
    min-width: 44px;
    min-height: 44px;
  }

  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px;
    min-height: 48px;
  }

  .btn {
    min-height: 48px;
  }

  .toast-container {
    top: auto;
    bottom: var(--space-4);
    left: var(--space-4);
    right: var(--space-4);
  }

  .toast {
    min-width: auto;
    max-width: 100%;
  }

  .toast-close {
    min-width: 36px;
    min-height: 36px;
  }
}

@media (max-width: 480px) {
  .modal-content {
    margin: var(--space-2);
    max-height: calc(100vh - var(--space-4));
  }
}
