/**
 * Schedule Builder V2 - Persistent Sidebar + Floating Cart Pattern
 * Desktop: Right sidebar always visible
 * Mobile: Floating cart icon → Full modal
 * UPDATED: Daily repeating schedule with exercise-level goals
 */

:root {
  --schedule-primary: #667eea;
  --schedule-primary-dark: #5a67d8;
  --schedule-success: #10b981;
  --schedule-danger: #ef4444;
  --schedule-bg: #1a1f2e;
  --schedule-card: #2d3748;
  --schedule-border: #4a5568;
  --schedule-text: #e2e8f0;
  --schedule-text-muted: #a0aec0;
}

/* Desktop: Schedule Sidebar */
.schedule-sidebar {
  position: fixed;
  top: var(--header-height, 96px);
  right: 0;
  width: 380px;
  height: calc(100vh - var(--header-height, 96px));
  background: var(--schedule-bg);
  border-left: 2px solid var(--schedule-border);
  z-index: var(--z-layer-system, 120);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}

.schedule-sidebar.active {
  transform: translateX(0);
}

.schedule-sidebar-header {
  padding: 1.5rem;
  border-bottom: 2px solid var(--schedule-border);
  background: linear-gradient(135deg, var(--schedule-primary) 0%, var(--schedule-primary-dark) 100%);
  color: white;
}

.schedule-sidebar-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.schedule-close-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s;
}

.schedule-close-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.1);
}

.schedule-counter {
  font-size: 0.875rem;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.schedule-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

/* Exercise List in Sidebar */
.schedule-exercises-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Exercise Item - Refactored for Inline Goals */
.schedule-exercise-item {
  background: var(--schedule-card);
  border: 1px solid var(--schedule-border);
  border-radius: 8px;
  padding: 0;
  transition: all 0.3s ease;
  overflow: hidden;
  margin-bottom: 0.75rem;
  cursor: grab;
}

.schedule-exercise-item:hover {
  border-color: var(--schedule-primary);
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.15);
}

.schedule-exercise-item.dragging {
  cursor: grabbing;
}

.schedule-exercise-item.expanded {
  border-color: var(--schedule-primary);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
}

/* Exercise Header (always visible) */
.schedule-exercise-header {
  padding: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
}

.schedule-exercise-header:hover {
  background: rgba(102, 126, 234, 0.05);
}

.schedule-exercise-info {
  flex: 1;
}

.schedule-exercise-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.schedule-exercise-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--schedule-text);
  margin: 0;
}

.schedule-goal-badge {
  font-size: 0.75rem;
  line-height: 1;
}

.schedule-goal-badge.goal-set {
  color: #16a34a;
}

.schedule-goal-badge.goal-empty {
  color: #ea580c;
}

.schedule-exercise-meta {
  font-size: 0.7rem;
  color: var(--schedule-text-muted);
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.schedule-goal-summary {
  font-size: 0.7rem;
  color: var(--schedule-primary);
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

.schedule-exercise-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.schedule-expand-btn {
  background: transparent;
  border: 1px solid var(--schedule-border);
  color: var(--schedule-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.schedule-expand-btn:hover {
  background: var(--schedule-primary);
  border-color: var(--schedule-primary);
  color: white;
}

.schedule-exercise-item.expanded .expand-icon {
  transform: rotate(180deg);
}

.expand-icon {
  transition: transform 0.3s ease;
}

.schedule-remove-btn {
  background: var(--schedule-danger);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.2s;
}

.schedule-remove-btn:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* Inline Goal Form (hidden by default) */
.schedule-inline-goal-form {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  background: rgba(102, 126, 234, 0.03);
  border-top: 1px solid transparent;
}

.schedule-exercise-item.expanded .schedule-inline-goal-form {
  max-height: 500px;
  padding: 1rem 0.75rem;
  border-top-color: var(--schedule-border);
}

/* Single Row Layout for Reps, Sets, Accuracy */
.schedule-goal-single-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  align-items: flex-end;
}

.schedule-goal-compact-input {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0; /* Allow flexbox shrinking */
}

.schedule-goal-compact-input label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--schedule-text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Notes Row (Full Width) */
.schedule-goal-notes-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.schedule-goal-notes-row label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--schedule-text);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Input Fields */
.inline-goal-input {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--schedule-border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--schedule-card);
  color: var(--schedule-text);
  transition: all 0.2s;
  width: 100%;
}

.inline-goal-input:focus {
  outline: none;
  border-color: var(--schedule-primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.inline-goal-input::placeholder {
  color: var(--schedule-text-muted);
  opacity: 0.6;
  font-size: 0.8rem;
}

.inline-goal-input[type="number"] {
  appearance: textfield;
  text-align: center;
  font-weight: 600;
}

.inline-goal-input[type="number"]::-webkit-inner-spin-button,
.inline-goal-input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
}

textarea.inline-goal-input {
  resize: vertical;
  min-height: 50px;
  font-family: inherit;
  text-align: left;
  font-weight: normal;
}

/* Responsive: Stack on mobile */
@media (max-width: 480px) {
  .schedule-goal-single-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .schedule-goal-compact-input {
    min-width: 100%;
  }
  
  .inline-goal-input[type="number"] {
    text-align: left;
  }
}

/* OLD STYLES - Remove after migration */
.schedule-goal-inputs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.schedule-goal-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.schedule-goal-input-group.full-width {
  grid-column: 1 / -1;
}

.schedule-goal-input-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--schedule-text);
}

/* Radar Chart Section */
.schedule-overall-radar-section {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
  border: 1px solid var(--schedule-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.schedule-radar-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--schedule-text);
  margin: 0 0 0.25rem 0;
  text-align: center;
}

.schedule-radar-desc {
  font-size: 0.7rem;
  color: var(--schedule-text-muted);
  text-align: center;
  margin: 0 0 1rem 0;
}

.schedule-radar-chart-container {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.schedule-radar-legend {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.schedule-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: var(--schedule-text-muted);
}

.schedule-legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.schedule-section-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--schedule-text);
  margin: 0 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--schedule-border);
}

/* OLD STYLES - Keep for backward compatibility, will be removed */
.schedule-goal-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  width: fit-content;
}

.schedule-goal-status.goal-set {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.schedule-goal-status.goal-empty {
  background: rgba(251, 146, 60, 0.1);
  color: #ea580c;
  border: 1px solid rgba(251, 146, 60, 0.2);
}

.schedule-goal-preview {
  font-size: 0.7rem;
  color: var(--schedule-text-muted);
  margin-top: 0.25rem;
  font-family: 'Courier New', monospace;
}

/* Empty State */
.schedule-empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--schedule-text-muted);
}

.schedule-empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.schedule-empty-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  color: var(--schedule-text);
}

.schedule-empty-text {
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Setup Form */
.schedule-setup-form {
  padding: 1rem;
  border-top: 2px solid var(--schedule-border);
  background: var(--schedule-card);
}

.schedule-form-group {
  margin-bottom: 1rem;
}

.schedule-form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--schedule-text);
  margin-bottom: 0.5rem;
}

.schedule-form-input,
.schedule-form-textarea {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid var(--schedule-border);
  border-radius: 6px;
  background: var(--schedule-bg);
  color: var(--schedule-text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.schedule-form-input:focus,
.schedule-form-textarea:focus {
  outline: none;
  border-color: var(--schedule-primary);
}

.schedule-form-textarea {
  resize: vertical;
  min-height: 60px;
}

.schedule-save-btn {
  width: 100%;
  padding: 0.875rem;
  background: linear-gradient(135deg, var(--schedule-success) 0%, #059669 100%);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.schedule-save-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.schedule-save-btn:disabled {
  background: var(--schedule-border);
  cursor: not-allowed;
  transform: none;
}

/* Mobile: Floating Cart Icon - Only show when schedule is active */
.schedule-floating-cart {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--schedule-primary) 0%, var(--schedule-primary-dark) 100%);
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
  cursor: pointer;
  display: none; /* Hidden by default on all screens */
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.75rem;
  z-index: var(--z-layer-overlay, 100);
  transition: all 0.3s ease;
}

/* Show floating cart on mobile when schedule is active */
@media (max-width: 768px) {
  body.schedule-active .schedule-floating-cart {
    display: flex;
  }
}

.schedule-floating-cart:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.schedule-cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--schedule-danger);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--schedule-bg);
  animation: cartBadgePulse 2s infinite;
}

@keyframes cartBadgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Mobile: Full Modal */
.schedule-mobile-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--schedule-bg);
  z-index: var(--z-layer-system, 120);
  display: none;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.schedule-mobile-modal.active {
  transform: translateY(0);
}

/* Add to Schedule Button (in content cards) */
.add-to-schedule-btn {
  background: linear-gradient(135deg, var(--schedule-primary) 0%, var(--schedule-primary-dark) 100%);
  border: none;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: none; /* Hidden by default */
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

/* Show buttons only when schedule builder is active */
body.schedule-active .add-to-schedule-btn {
  display: inline-flex;
}

.add-to-schedule-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.add-to-schedule-btn.added {
  background: var(--schedule-success);
  pointer-events: none;
}

.add-to-schedule-btn.added::before {
  content: '✓';
  margin-right: 0.25rem;
}

/* Week Planner */
.schedule-week-planner {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.schedule-day-column {
  background: var(--schedule-card);
  border: 1px solid var(--schedule-border);
  border-radius: 6px;
  padding: 0.5rem;
  min-height: 120px;
}

.schedule-day-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--schedule-text);
  text-align: center;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--schedule-border);
}

.schedule-day-exercises {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.schedule-day-exercise-chip {
  background: var(--schedule-primary);
  color: white;
  font-size: 0.625rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  text-align: center;
  cursor: move;
  transition: all 0.2s;
}

.schedule-day-exercise-chip:hover {
  transform: translateX(2px);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

/* Responsive */
@media (max-width: 768px) {
  .schedule-sidebar {
    display: none;
  }
  
  /* Floating cart visibility controlled by body.schedule-active class above */
  
  .schedule-mobile-modal {
    display: flex;
  }
  
  .schedule-week-planner {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .schedule-day-column {
    min-height: auto;
  }
}

@media (min-width: 769px) {
  .schedule-sidebar {
    display: flex;
  }
  
  /* Desktop: Never show floating cart */
  .schedule-floating-cart {
    display: none !important;
  }
}

/* Animations */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Loading State */
.schedule-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--schedule-text-muted);
}

.schedule-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--schedule-border);
  border-top-color: var(--schedule-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast Notifications */
.schedule-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--schedule-card);
  border: 1px solid var(--schedule-border);
  color: var(--schedule-text);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: var(--z-layer-toast, 160);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.schedule-toast.show {
  opacity: 1;
}

.schedule-toast.success {
  border-color: var(--schedule-success);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.1) 100%);
}

.schedule-toast.error {
  border-color: var(--schedule-danger);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
}
/* Goal Setting Modal */
.schedule-goal-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-layer-modal, 140);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.schedule-goal-modal.active {
  opacity: 1;
}

.schedule-goal-modal-content {
  background: var(--schedule-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.schedule-goal-exercise-info {
  background: var(--schedule-card);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.schedule-goal-exercise-info h4 {
  margin: 0 0 0.5rem 0;
  color: var(--schedule-text);
  font-size: 1.125rem;
}

.schedule-goal-exercise-info p {
  margin: 0;
  color: var(--schedule-text-muted);
  font-size: 0.875rem;
}

.schedule-modal-footer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--schedule-border);
}

.schedule-cancel-btn {
  flex: 1;
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--schedule-border);
  background: transparent;
  color: var(--schedule-text);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.schedule-cancel-btn:hover {
  background: var(--schedule-card);
}

/* Radar Chart in Goal Modal */
.schedule-goal-radar-section {
  background: var(--schedule-card);
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  text-align: center;
}

.schedule-goal-radar-title {
  margin: 0 0 0.5rem 0;
  color: var(--schedule-text);
  font-size: 1rem;
  font-weight: 600;
}

.schedule-goal-radar-desc {
  margin: 0 0 1rem 0;
  color: var(--schedule-text-muted);
  font-size: 0.875rem;
}

.schedule-goal-radar-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 1rem;
}

#goal-radar-chart {
  max-width: 100%;
  height: auto;
}

.schedule-goal-legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
}

.schedule-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--schedule-text-muted);
}

.schedule-legend-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.2);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .schedule-goal-radar-container {
    max-width: 280px;
  }
  
  #goal-radar-chart {
    width: 280px;
    height: 280px;
  }
  
  .schedule-goal-legend {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }
}
/* Drag and Drop Styles */
.schedule-exercise-item {
  transition: opacity 0.2s ease, background-color 0.2s ease;
  cursor: grab;
  user-select: none;
}

.schedule-exercise-item:active {
  cursor: grabbing;
}

.schedule-exercise-item.dragging {
  opacity: 0.88;
  background-color: rgba(102, 126, 234, 0.1);
  position: relative;
  z-index: 6;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

.schedule-exercise-item.drag-over {
  background-color: rgba(102, 126, 234, 0.2);
}

.schedule-exercise-item.drag-over-before {
  border-top: 3px solid var(--schedule-primary);
}

.schedule-exercise-item.drag-over-after {
  border-bottom: 3px solid var(--schedule-primary);
}

/* Disable selection during drag */
.schedule-exercise-item.dragging * {
  pointer-events: none;
}