/* Calendar Styles - Mobile First Approach */

/* Calendar Container */
.container-calendar {
  width: 100%;
  padding-right: var(--spacing-unit);
  padding-left: var(--spacing-unit);
  margin-right: auto;
  margin-left: auto;
  max-width: none;
}

/* Command Bar Navigation - Mobile First, Compact */
.calendar-command-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background-color: var(--dark-gray);
  color: white;
  margin-bottom: 1rem;
  border-radius: 0.25rem;
}

.command-bar-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-nav {
  padding: 0.5rem 1rem;
  font-weight: 600;
  background-color: var(--medium-gray-dark);
  color: white;
  text-decoration: none;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
}

.btn-nav:hover {
  background-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.command-bar-date {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.025em;
  color: var(--light-gray);
  flex: 1;
  text-align: center;
}

.command-bar-cycles {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.command-bar-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Desktop: Single row layout */
@media (min-width: 768px) {
  .calendar-command-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    gap: 1.5rem;
  }

  .command-bar-nav {
    flex: 0 0 auto;
  }

  .command-bar-date {
    flex: 0 0 auto;
    margin: 0 0.5rem;
    text-align: left;
  }

  .command-bar-cycles {
    flex: 1 1 auto;
    justify-content: center;
  }

  .command-bar-actions {
    flex: 0 0 auto;
  }
}

/* Calendar Day Expand/Contract */
.calendar-day-toggle {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: none;
  font-size: 0.875rem;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s;
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  margin: 0;
  color: inherit;
  border-radius: 0.25rem;
  background: rgba(255, 255, 255, 0.1);
}

.calendar-day-toggle:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.calendar-month-toggle {
  font-size: 0.875rem;
}

.calendar-workout-occurrence-description {
  margin-top: 0.5rem;
  padding: 0.1rem;
  background: rgba(255, 255, 255, 0.5);
  border-top: 1px solid #e0e0e0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.workout-scoring-info {
  font-size: 0.8125rem;
  color: var(--medium-gray, #666);
}

/* Cycle Filter Pills - Mobile First */
.cycle-filters-label {
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--dark-gray, #333);
  text-align: center;
}

/* Mobile: Full-width stacked pills via button-group */
.cycle-filters {
  /* Inherits button-group mobile styles (vertical stack, full width) */
}

/* Filter button styling */
.btn-filter {
  background: white;
  color: var(--dark-gray, #333);
  border: 2px solid #ddd;
  font-size: 1rem;
}

.btn-filter:hover {
  background: #f8f9fa;
  color: var(--dark-gray, #333);
  border-color: #ccc;
}

.btn-filter-selected {
  background: var(--primary-color, #007bff);
  color: white;
  border-color: var(--primary-color, #007bff);
  font-weight: 600;
}

.btn-filter-selected:hover {
  background: var(--primary-color-dark, #0056b3);
  border-color: var(--primary-color-dark, #0056b3);
  color: white;
}

/* Mobile-First Calendar Structure */
.calendar-container {
  background-color: var(--light-gray);
  color: var(--dark-gray);
  border-radius: 0.25rem;
  overflow: hidden;
  position: relative;
  /* Add subtle hint that the calendar is swipeable */
  touch-action: pan-y;
}

/* Swipe hint for mobile */
@media (max-width: 767px) {
  .calendar-container::after {
    content: "← Swipe to navigate →";
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--medium-gray);
    opacity: 0.5;
    pointer-events: none;
  }
}

.calendar {
  width: 100%;
}

/* Mobile: Hide day headers on small screens */
.calendar-header {
  display: none;
}

.calendar-day-header {
  padding: 0.75rem;
  padding-bottom: 0;
  text-align: center;
  font-weight: bold;
}

.calendar-day-header:last-child {
  border-right: none;
}

/* Mobile: Vertical list layout */
.calendar-body {
  display: flex;
  flex-direction: column;
}

.calendar-week {
  display: flex;
  flex-direction: column;
  min-height: auto;
}

/* Calendar Days - Mobile First */
.calendar-day {
  border: 1px solid var(--medium-gray);
  padding: 0;
  position: relative;
  background-color: white;
  margin-bottom: 0.5rem;
  min-height: 80px;
}

.calendar-day-content {
  padding: 0.75rem;
}

.calendar-day.other-month {
  background-color: var(--light-gray);
  color: var(--medium-gray);
}

.calendar-day-today {
  color: white;
  border: 2px dashed var(--primary-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

  color: var(--dark-gray);
  border-radius: 0.25rem;
  padding: var(--spacing-unit);
  border: 2px dashed var(--primary-color);
  background-color: var(--primary-color-dark);
}

.calendar-day-today.other-month {
  background-color: var(--primary-color);
  color: white;
}

/* Mobile: Day number with day name */
.calendar-day-number {
  font-weight: bold;
  display: block;
  width: 100%;
  padding: 0.5rem 1.5rem 0.5rem 0.75rem; /* Extra right padding for toggle button */
  background-color: var(--dark-gray);
  color: var(--light-gray);
  border-radius: 0;
  margin: 0;
  position: relative; /* For absolutely positioned toggle button */
  min-height: 2rem; /* Ensure enough height for toggle button */
  text-align: center;
  font-size: 1.125rem;
}

.calendar-day-number-today {
  background-color: var(--primary-color);
  color: white;
}

/* Mobile: Day name (added via JS or server-side) */
.calendar-day-name {
  display: inline-block;
  margin-left: 0.5rem;
  font-weight: normal;
  opacity: 0.8;
}

/* Calendar Content */
.calendar-cycle-name {
  background-color: var(--light-gray);
  color: var(--dark-gray);
  font-weight: bold;
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.25rem;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  text-decoration: none;
  transition: opacity 0.2s;
}

.calendar-cycle-name:hover {
  opacity: 0.85;
}

.cycle-progress-indicator {
  font-size: 0.75rem;
  line-height: 1;
  flex-shrink: 0;
  padding: 0.15rem 0.25rem;
  border-radius: 0.25rem;
  color: white;
  font-weight: bold;
}

/* Workout Card - Clean slate styling */
.workout-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--dark-gray);
  border-radius: 0.25rem;
  margin: 0.25rem 0;
  overflow: hidden;
  background-color: transparent;
}

/* Legacy support for old class name */
.calendar-workout-occurrence {
  /* Card container - no padding, children handle their own spacing */
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background-color: var(--light-gray);
  border: 1px solid var(--dark-gray);
  border-radius: 0.25rem;
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.2s ease;
  position: relative;
  overflow: hidden; /* Ensure child elements don't overflow rounded corners */
}

.calendar-workout-occurrence:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.workout-occurrence-primary {
  /* Dark header bar - extends to card edges */
  flex-shrink: 0;
  background-color: var(--dark-gray);
  color: var(--light-gray);
  padding: 0.5rem 0.75rem;
}

.workout-occurrence-name {
  font-weight: bold;
  font-size: 1rem;
  display: block;
  color: var(--light-gray);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s, text-decoration 0.2s;
}

.workout-occurrence-name:hover {
  color: white;
  text-decoration: underline;
}

.workout-occurrence-cycle {
  /* Cycle badge section - slightly less dark than header */
  background-color: oklch(50% 0.02 250);
  padding: 0.375rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.workout-occurrence-content {
  /* Content wrapper - provides padding and background for metadata/actions */
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  background-color: var(--light-gray);
}

.workout-occurrence-meta {
  /* Metadata stack - VERTICAL on mobile */
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  align-items: flex-start;
}

.workout-occurrence-meta-item {
  /* Individual metadata piece */
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.workout-occurrence-scoring {
  /* Scoring type display */
  font-size: 0.75rem;
  color: var(--medium-gray-dark);
  padding: 0.125rem 0.375rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 0.25rem;
}

.workout-occurrence-actions {
  /* Inline with content, aligned to the right */
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.reschedule-link {
  font-size: 0.875rem;
  opacity: 0.7;
  transition: opacity 0.2s;
  cursor: pointer;
  padding: 0 0.25rem;
  background: none;
  border: none;
  margin: 0;
  font-family: inherit;
  color: inherit;
}

.reschedule-link:hover {
  opacity: 1;
}

.reschedule-link:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: 0.25rem;
}

.calendar-day.other-month .workout-occurrence {
  background-color: var(--medium-gray);
}

/* Weather Display in Calendar */
.calendar-weather {
  color: var(--dark-gray);
  font-size: 0.75rem;
  padding-left: 0.25rem;
  /* opacity: 0.9; */
}

/* Stratified Day Sections - Progressive lightening creates visual depth */
.day-section {
  padding: 0.5rem;
  margin: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.day-section:last-child {
  border-bottom: none;
}

/* Section 1: Cycles - Foundation layer (darkest) */
.day-section-cycles {
  background-color: oklch(40% 0.02 250);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.calendar-day-today .day-section-cycles {
  background-color: oklch(35% 0.02 250);
}

.calendar-cycle-badge {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.375rem 0.625rem;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  text-decoration: none;
  transition: all 0.15s ease;
}

.calendar-cycle-badge:hover {
  transform: translateX(2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.cycle-name-text {
  flex: 1;
}

.cycle-progress-text {
  font-weight: 700;
  opacity: 0.9;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* Section 2: Context (weather + intensity) - Planning layer */
.day-section-context {
  background-color: oklch(50% 0.01 250);
  background-image: repeating-linear-gradient(45deg,
    transparent,
    transparent 2px,
    var(--medium-gray) 2px,
    var(--medium-gray) 8px);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-height: 1px; /* Ensure section exists for Turbo Stream even when empty */
}

.calendar-day-today .day-section-context {
  background-color: oklch(45% 0.01 250);
}

/* Hide empty context sections (no children) */
.day-section-context:empty {
  display: none;
  min-height: 0;
}

/* Section 3: Workouts - Main content layer */
.day-section-workouts {
  background-color: oklch(88% 0.01 250);
}

.calendar-day-today .day-section-workouts {
  background-color: oklch(85% 0.01 250);
}

/* Section 4: Stimulus - Adaptation layer */
.day-section-stimulus {
  background-color: oklch(93% 0.005 250);
}

.calendar-day-today .day-section-stimulus {
  background-color: oklch(90% 0.005 250);
}

.stimulus-badges-container {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

/* Section 5: Elements - Detail layer (lightest) */
.day-section-elements {
  background-color: oklch(97% 0.005 250);
}

.calendar-day-today .day-section-elements {
  background-color: oklch(95% 0.005 250);
}

/* Desktop Styles - Applied for larger screens */
@media (min-width: 768px) {
  /* Desktop navigation layout - keep column to separate compact nav from cycle filters */
  .calendar-navigation {
    flex-direction: column;
    gap: 1rem;
  }

  /* Desktop month nav - horizontal with month in center */
  .calendar-month-nav {
    flex-direction: row;
    flex-shrink: 0;
    align-items: center;
    gap: 0;
  }

  .calendar-month-nav.button-group {
    flex-direction: row;
    width: auto;
  }

  .calendar-month-nav.button-group .btn {
    width: auto;
    min-height: auto;
  }

  /* Desktop cycle filters - horizontal row */
  .cycle-filters-section {
    flex-direction: row;
    gap: 1rem;
    align-items: center;
  }

  .current-month,
  .current-week {
    font-size: 1.25rem;
    padding: 0 1rem;
    margin: 0;
    order: 0; /* Reset mobile order */
    flex-grow: 1;
  }

  .cycle-filters-label {
    font-size: 1rem;
    margin-bottom: 0;
    text-align: left;
  }

  /* Desktop cycle filters - horizontal wrapping */
  .cycle-filters {
    /* Inherits button-group desktop styles (horizontal row) */
    justify-content: flex-start;
  }

  /* Desktop header section */
  .calendar-header-section {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    text-align: left;
    margin-bottom: 1.5rem;
  }

  .calendar-actions {
    margin-top: 0;
  }
  
  /* Show calendar header on desktop */
  .calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background-color: var(--secondary-color);
    color: white;
  }
  
  /* Hide mobile day names on desktop */
  .calendar-day-name {
    display: none;
  }
  
  /* Grid layout for desktop */
  .calendar-week {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    min-height: 120px;
  }
  
  /* Reset mobile styles for desktop */
  .calendar-day {
    margin-bottom: 0;
    min-height: 120px;
  }
  
  .calendar-day-content {
    padding: 0.5rem;
  }
  
  /* Desktop day number styling */
  .calendar-day-number {
    float: right;
    padding: 0.25rem 1.25rem 0.25rem 0.25rem; /* Extra right padding for toggle button */
    min-width: 2rem;
    text-align: center;
    margin-bottom: 0;
  }

  .calendar-day-number-today {
    border-color: black;
  }

  /* Desktop: Hide day name */
  .calendar-day-name {
    display: none;
  }

  /* Desktop adjustments for workout occurrence structure */
  .calendar-workout-occurrence {
    padding: 0.375rem;
    gap: 0.25rem;
  }

  .workout-occurrence-name {
    font-size: 0.9rem;
  }

  .workout-occurrence-meta {
    /* HORIZONTAL on desktop with wrapping */
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
}
