/* Set default weight for all Google Icons */
.material-symbols-outlined {
  font-weight: 200;
}

/* General Body Styling */

/* Prevent scrolling when a dialog is open */
body.dialog-open {
  overflow: hidden;
}

/* Ensure workout overlay is above other modals (like Manage Templates) */
#workoutViewOverlay {
  z-index: 2200;
}

/* Main Container */
.container {
  max-width: 100%;
  width: 400px;
  margin: 0 auto;
  animation: slide-in-from-right 0.5s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

/* Page Transitions */
@keyframes slide-in-from-right {
  from {
    transform: translateX(100%);
    /* Add a shadow to the leading edge to create depth */
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.3);
    opacity: 1;
  }
  to {
    transform: translateX(0);
    box-shadow: none;
    opacity: 1;
  }
}

@keyframes slide-out-right {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100vw);
    opacity: 1;
  }
}

@keyframes slide-out-left {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(-100vw);
    opacity: 0;
  }
}

body.page-exit-right .container {
  animation: slide-out-right 0.5s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}
body.page-exit-left .container {
  animation: slide-out-left 0.3s cubic-bezier(0.42, 0, 0.58, 1) forwards;
}

.workout-title {
  line-height: 1.2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 20px !important;
}

.workout-title .material-symbols-outlined {
  margin-left: 0;
  color: var(--color-success-base); /* Green for completion checkmark */
  font-size: 40px;
}

.sets-completed-text {
  color: var(--color-text-muted);
  font-size: 12px;
  margin: 0;
  margin-left: 16px;
}

.current-date-display {
  font-size: 14px;
  color: var(--color-text-muted);
  white-space: nowrap;
  /* The parent flexbox with justify-content: space-between handles spacing */
}

.workout-name-edit-input {
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--color-primary-base);
  text-align: center;
  width: 100%;
  min-width: 150px;
  padding: 0;
  margin: 0;
  outline: none;
}

/* Styles specific to template mode, scoped to the workout overlay */
#workoutViewOverlay.template-mode-active.edit-mode #workoutNameDisplay {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}

#workoutViewOverlay.template-mode-active .back-button {
  visibility: hidden;
}

body.template-mode-active .current-date-display, #workoutViewOverlay.template-mode-active .current-date-display {
  display: none;
}

/* Progress Bar Card */
.progress-bar-card {
  background-color: white;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
  /* position: sticky; */
  /* Stick below the notch + 16px gap */
  /* top: calc(env(safe-area-inset-top) + 16px); */
  z-index: 90; /* Ensure it stays above content but below header (z-index 100) */
  display: none; /* Hidden by default to prevent flash in edit mode */
}

/* --- Progress Card: Edit Mode Style --- */
/* In edit mode, the card becomes an invisible sticky container for the menu button */
.progress-bar-card.edit-mode-style {
  display: none !important;
}

/* Hide progress elements when in edit mode */
.progress-bar-card.edit-mode-style .progress-bar-header,
.progress-bar-card.edit-mode-style .progress-track {
  display: none;
}

.progress-bar-card.edit-mode-style .progress-card-left-group {
  
}

.progress-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.progress-title-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.progress-title-group span:first-child {
  color: var(--color-text-primary);
  font-weight: 700;
  font-size: 20px;
  margin: 0;
}

.progress-bar-header span:last-child {
  color: var(--color-text-muted);
  font-size: 14px;
}

.progress-track {
  background-color: var(--color-surface-track);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
}

.progress-fill {
  background-color: var(--color-primary-base); /* Main workout color */
  height: 100%;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 8px;
}

.progress-card-buttons {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.progress-card-left-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* --- Header Actions (Timer & Menu) --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto; /* Push to the right */
}

/* Adjust utility buttons when in header */
.header-actions .utility-button,
.header-actions #optionsMenuButton,
.header-actions #toggleAllCardsButton {
  background-color: transparent !important;
  box-shadow: none !important;
  border: none !important;
  color: var(--color-text-primary);
}

.workout-timer-container {
  display: none; /* Hidden by default, shown by JS */
  align-items: center;
  /* gap: 6px; */
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 24px;
  font-weight: 700;
  color: var(--color-primary-base);
  cursor: pointer; /* Indicate the timer is clickable */
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

/* Sticky Timer State */
.workout-timer-container.sticky-mode {
  position: fixed; /* Relative to workout-overlay because of transform */
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100; /* Higher than header (100) */
  background-color: var(--color-bg-card);
  padding: 4px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border: 1px solid var(--color-border-default);
  width: auto;
  justify-content: center;
  display: flex !important; /* Ensure it stays visible even if parent logic tries to hide it */
}

/* Adjust inner elements for sticky mode */
.workout-timer-container.sticky-mode #workoutTimerDisplay {
  font-size: 18px;
  width: auto;
  text-align: center;
  padding-right: 0;
}

.workout-timer-container.sticky-mode .material-symbols-outlined {
  font-size: 20px;
}

.workout-timer-container.sticky-mode .timer-control-button {
  margin-right: 4px;
}

.workout-timer-container.paused {
  color: var(--color-text-muted);
  animation: none;
}

.workout-timer-container .material-symbols-outlined {
  font-size: 36px;
  font-weight: 300;
}

.timer-control-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

#workoutTimerDisplay {
  font-variant-numeric: tabular-nums;
  width: 120px;
  display: inline-block;
  text-align: right;
  padding-right: 10px;
}

.workout-timer-container.paused .timer-control-button {
  animation: icon-pulse 2s infinite ease-in-out;
  color: var(--color-primary-base);
}

/* Hide header title when timer is sticky */
body.timer-sticky-active .header-title-container {
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.utility-button {
  background-color: white;
  /* box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); */
  border: none;
  color: var(--color-text-muted);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.utility-button.active {
  background-color: var(--color-success-base);
  color: white;
}
.utility-button .material-symbols-outlined {
  font-size: 24px;
}

.utility-buttons-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.menu-container {
  position: relative;
}

.sheet-action-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--color-border-default);
    color: var(--color-text-primary);
    font-size: 16px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}
.sheet-action-button:last-child {
    border-bottom: none;
}
.sheet-action-button .material-symbols-outlined {
    font-size: 24px;
    color: var(--color-text-muted);
}
.sheet-action-button.danger {
    color: var(--color-danger-base);
}
.sheet-action-button.danger .material-symbols-outlined {
    color: var(--color-danger-base);
}

/* When in edit mode, hide the "Edit" and "Save" options from the menu */
/* Note: In the new design, the menu button toggles edit mode directly, so the menu isn't shown */

/* Exercises List */
.exercises-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.loading-spinner .material-symbols-outlined {
  font-size: 72px;
  margin-bottom: 16px;
}

.loading-spinner p {
  font-size: 16px;
  font-weight: 500;
}
/* Instantly hide spinner on subsequent loads to prevent flashing */
html.cache-loaded .loading-spinner {
  display: none;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spin {
  animation: spin 1.5s linear infinite;
}

/* Animation for the paused timer */
@keyframes pulse-animation {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes sticky-slide-down {
  0% {
    transform: translate(-50%, -150%);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes timer-return-pop {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes icon-pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes tada {
  from {
    transform: scale3d(1, 1, 1);
  }
  10%,
  20% {
    transform: scale3d(0.9, 0.9, 0.9) rotate3d(0, 0, 1, -3deg);
  }
  30%,
  50%,
  70%,
  90% {
    transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
  }
  40%,
  60%,
  80% {
    transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
  }
  to {
    transform: scale3d(1, 1, 1);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}
/* ==========================================================================
    Exercise Card Component
    ========================================================================== */

/* --- Base Card Layout --- */
.exercise-card {
  background-color: white;
  border-radius: 16px;
  padding: 20px;
  position: relative;
  box-shadow: var(--card-shadow);
  border: var(--card-border);
  transition:
    border-color 0.3s ease,
    padding-left 0.3s ease,
    padding-top 0.35s ease,
    padding-bottom 0.35s ease;
}
.exercise-card.popping {
  /* Apply the animation when this class is added */
  animation: pop 0.3s ease-out;
}

/* --- Drag & Drop States --- */
.exercise-card::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 20px;
  right: 20px;
  height: 4px;
  background-color: var(--color-primary-base);
  border-radius: 2px;
  transform: scaleX(0);
  transition: transform 0.2s ease-in-out;
  transform-origin: center;
  z-index: -1;
}

.exercise-card.drop-indicator-before::before {
  transform: scaleX(1);
  z-index: 1;
}

.exercise-card.dragging {
  opacity: 0.5;
  background: #eef2ff;
  border: 2px dashed var(--color-primary-base);
  cursor: grabbing;
}

/* --- State: Completed --- */
.exercise-card.completed-exercise {
  border-color: var(--color-success-base);
}

/* --- Card Header (Flex Container) --- */
.exercise-header {
  display: flex;
  align-items: center;
  /* EXPANDED STATE: Allow wrapping */
  flex-wrap: wrap;
  row-gap: 8px;
  column-gap: 12px;
  margin-bottom: 16px;
}

/* --- Header Content: Expanded (Default) --- */
.exercise-name-display {
  order: 1;
  flex-grow: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
  word-break: break-word;
}

.exercise-card-icon {
  /* Size is now controlled by font-size, making it scalable and crisp */
  font-size: 26px;
  /* Better alignment with the exercise name text */
  vertical-align: middle;
}

.exercise-name-display .material-symbols-outlined {
  color: var(--color-success-base);
  font-size: 24px;
}

.substitution-indicator {
  color: var(--color-warning-base);
  font-size: 20px;
  margin-left: 6px;
  vertical-align: middle;
}

.toggle-sets-button {
  order: 2;
  margin-left: auto; /* Push to the far right on the top line */
  background-color: transparent;
  color: var(--color-text-muted);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
}

.toggle-sets-button .material-symbols-outlined {
  font-size: 36px;
}

.delete-exercise-button {
  display: none;
  margin-left: auto;
  background-color: transparent;
  color: #ef4444;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  padding: 0;
  cursor: pointer;
  transition: background-color 0.2s ease;
  align-items: center;
  justify-content: center;
  /* NEW: Positioning logic for the button itself */
  order: 3; /* Default order for expanded view */
  flex-basis: 100%; /* Force to new line in expanded view */
}

.sets-count-tag {
  background-color: var(--color-primary-light);
  color: var(--color-primary-base);
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0; /* Explicitly prevent shrinking */
  display: none; /* Hidden by default, shown when minimized */
}

/* --- State: Minimized --- */
.exercise-card.minimized {
  padding-top: 8px;
  padding-bottom: 8px;
}

.exercise-card.minimized .exercise-header {
  flex-wrap: nowrap; /* THE GOAL: Force single line */
  margin-bottom: 0;
  gap: 8px;
}

.exercise-card.minimized .exercise-name-display {
  order: 1;
  flex-grow: 1; /* Allow it to take up all available space */
  flex-shrink: 1; /* Allow it to shrink if needed */
  min-width: 0; /* CRITICAL: Allows shrinking below its content's width */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exercise-card.minimized .delete-exercise-button {
  order: 2;
  flex-basis: auto; /* Undo the 100% basis */
  margin-left: auto;
  flex-shrink: 0;
}

.exercise-card.minimized .sets-count-tag {
  order: 3;
  flex-shrink: 0; /* Already set, but good to be explicit */
  display: inline-block; /* Show the tag when minimized */
}

.exercise-card.minimized .toggle-sets-button {
  order: 4;
  margin-left: 0; /* Reset the auto margin from expanded state */
  flex-shrink: 0; /* Do not allow the button to shrink */
}

/* --- State: Edit Mode --- */
.reorder-icon {
  display: none;
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 30px;
  cursor: grab;
}

.exercises-list.reorder-mode .reorder-icon {
  display: block;
}

.exercises-list.reorder-mode .exercise-card {
  padding-left: 48px; /* Make space for reorder handle */
}

.exercises-list.delete-mode .delete-exercise-button {
  display: flex;
  flex-basis: auto;
}

/* In edit mode, hide interactive elements to avoid confusion */
.exercises-list.edit-mode .toggle-sets-button,
.exercises-list.edit-mode .sets-count-tag {
  display: none;
}

/* --- Collapsible Section --- */
.exercise-notes-section.minimized,
.sets-container.minimized,
.cardio-stats-container.minimized {
  display: none;
}

/* --- Empty State Message --- */
.empty-state-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
  background-color: white;
  border-radius: 16px;
  margin-top: 20px;
}

.empty-state-message .material-symbols-outlined {
  font-size: 64px;
  margin-bottom: 16px;
  color: var(--color-border-default);
}

.empty-state-message h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: var(--color-text-primary);
}

.exercise-notes-section {
  margin-bottom: 8px;
}

.exercise-notes-section h4 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--color-text-primary);
  font-weight: 700;
}

.exercise-notes-section h4 > span:first-child {
  display: flex;
}

.exercise-notes-section h4 .material-symbols-outlined {
  margin-right: 6px;
  color: var(--color-success-base);
  font-size: 21px;
}

.exercise-notes-textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--color-border-default);
  font-size: 14px;
  resize: none;
  box-sizing: border-box;
  overflow-y: hidden; /* Hide scrollbar during resize */
}

/* Sets Table Header - Mobile Optimized Grid */
.sets-table-header {
  display: grid;
  /* Default grid for live mode (6 columns) */
  grid-template-columns: 25px 70px 1fr 1fr 40px 40px;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  padding: 0 4px;
}

.sets-table-header span {
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sets-container.set-edit-mode .sets-table-header span:nth-child(5) {
  /* Hide the checkmark header '✓' when in set edit mode */
  display: none;
}

.toggle-set-edit-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: color 0.2s ease;
  grid-column: 6; /* Explicitly place this button in the 6th column */
}

.toggle-set-edit-button .material-symbols-outlined {
  font-size: 20px;
  font-weight: 400;
}

/* Individual Set Row - Mobile Optimized Grid */
.set-row {
  display: grid;
  grid-template-columns: 25px 70px 1fr 1fr 40px 40px;
  /* gap: 6px; */
  align-items: center;
  /* margin-bottom: 4px; */
  padding: 8px 4px;
  /* background-color: var(--light-grey-bg); */
  border-radius: 12px;
  border: 2px solid transparent;
  transition:
    background-color 0.2s ease,
    border 0.2s ease;
}

.sets-container.set-edit-mode .set-row {
  /* In edit mode, we use a 6-column grid to maintain consistent widths. */
  grid-template-columns: 25px 70px 1fr 1fr 40px 40px;
}

.set-row.completed {
  background-color: var(--color-success-light);
  /* border-color: var(--color-primary-base); */
}

.set-row span {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
}

/* .set-row span:first-child { */
/* font-size: 16px; */
/* font-weight: 200; */
/* } */

.set-row .prev-info {
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
  white-space: nowrap;
}
.sets-table-header span .material-symbols-outlined {
  font-size: 20px;
  font-weight: 200;
}

/* New style for the value display in the set row to make it look like a button */
.value-display-button {
  width: 100%;
  padding: 6px;
  border-radius: 6px;
  /* border: 1px solid var(--border-grey); */
  border: none;
  text-align: center;
  font-size: 14px;
  min-height: 36px;
  box-sizing: border-box;
  background-color: transparent;
  cursor: pointer;
  font-weight: 400;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.set-complete-button {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background-color: var(--color-surface-track);
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sets-container.set-edit-mode .set-complete-button {
  /* Hide the checkmark button when in set edit mode */
  display: none;
}

.set-complete-button.completed {
  background-color: var(--color-success-base);
  color: white;
}

.delete-set-button {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background-color: transparent; /* The color is set on the icon's span directly */
  cursor: pointer;
  align-items: center;
  justify-content: center;
  display: flex;
  display: none; /* Hidden by default, shown in set-edit-mode */
  transition: background-color 0.2s ease;
}

.sets-container.set-edit-mode .delete-set-button {
  /* This ensures the button is visible and correctly placed in its grid column */
  display: flex;
}

.delete-set-button .material-symbols-outlined {
  color: #ef4444;
  font-size: 24px;
}

.add-set-button {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background-color: #f3f4f6;
  border: none;
  border-radius: 12px;
  color: var(--color-text-muted);
  font-size: 16px;
  cursor: pointer;
  min-height: 48px;
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.add-set-button .material-symbols-outlined {
  margin-right: 8px;
  font-size: 24px;
}

body.loading .add-exercise-card {
  display: none;
}

/* Add Exercise Section */
.add-exercise-card {
  background-color: white;
  font-weight: 400;
  border-radius: 16px;
  padding: 20px;
  margin-top: 20px;
  box-shadow: var(--card-shadow);
  position: relative;
  border: var(--card-border);
}
.workout-actions-container {
  display: flex; /* This remains a flex container */
}
.add-exercise-main-button {
  flex: 8; /* Two-thirds width */
  padding: 12px 16px;
  background-color: var(--color-primary-base);
  border: none;
  border-radius: 1rem;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#showAddExerciseButton {
  display: block;
  opacity: 1;
  visibility: visible;
}

.workout-icon-container {
  border-radius: 12px;
  margin-right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Specific background colors for icon containers */
.icon-bg-pushDay {
  background-color: transparent;
}
.icon-bg-pullDay {
  background-color: transparent;
}
.icon-bg-legsDay {
  background-color: transparent;
}
.icon-bg-upperBody {
  background-color: transparent;
}
.icon-bg-grey {
  background-color: transparent;
}

.workout-icon {
  font-size: 36px;
}

/* Specific icon colors */
.icon-color-pushDay {
  color: var(--color-primary-base);
}
.icon-color-pullDay {
  color: var(--color-success-base);
}
.icon-color-legsDay {
  color: var(--color-warning-base);
}
.icon-color-upperBody {
  color: var(--color-accent-purple-base);
}
.icon-color-grey {
  color: var(--color-text-muted);
}

/* Style for custom image icons on workout cards */
.workout-icon-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  /* filter removed for light mode, icons will be black */
}

/* Footer Styling */
.footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 20px;
  color: var(--color-text-muted);
  font-size: 14px;
  position: relative;
  z-index: 99; /* Sits above the fade-overlay (98) */
}

.finish-workout-button {
  /* Now used inside .progress-card-buttons */
  padding: 10px 16px;
  background-color: transparent; /* Green for finish */
  /* border: 1px solid var(--color-success-base); */
  border: none;
  border-radius: 999px;
  color: var(--color-success-base);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition:
    background-color 0.3s ease,
    opacity 0.3s ease;
  display: none; /* Hidden by default, shown by JS if isLiveMode */
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.finish-workout-button.celebrate-enable {
  /* Apply the animation when this class is added */
  animation: tada 1s ease;
}

.finish-workout-button {
  background-color: var(--color-success-base);
  color: white;
  font-weight: 600;
}

.finish-workout-button:disabled {
  background-color: var(--color-text-muted);
  border-radius: 999px;
  border: none;
  opacity: 0.6;
  cursor: not-allowed;
}

.finish-workout-button .material-symbols-outlined {
  font-size: 24px;
  font-weight: 200;
  /* Prevent layout shift from icon font loading by reserving space */
  width: 1em; /* Use 'em' to be relative to the font-size */
  height: 1em;
  overflow: hidden; /* Hide fallback text that is wider than the icon */
  display: inline-flex; /* Center the icon within the reserved space */
  align-items: center;
  justify-content: center;
  flex-shrink: 0; /* Prevent the icon container from shrinking */
}

.save-template-button {
  background-color: var(--color-success-base);
  color: white;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background-color 0.3s ease, opacity 0.3s ease;
  flex: 1;
  border-radius: 16px;
  /* height: 56px; */
  font-size: 16px;
  padding: 12px 16px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cancel-workout-button {
  background-color: var(--color-surface-track);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-default);
  border-radius: 16px;
  padding: 12px 16px;
  /* height: 56px; */
  font-size: 16px;
  font-weight: 600;
  margin-right: 12px;
  flex: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.template-action-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border-default);
  padding: 16px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: none; /* Hidden by default */
  gap: 12px;
  z-index: 1000;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
}

/* Show the footer when the body has the template-mode-active class */
body.template-mode-active .template-action-footer {
  display: flex;
}

/* Ensure content isn't hidden behind the fixed footer */
body.template-mode-active {
  padding-bottom: 100px !important;
}

@media (hover: hover) and (pointer: fine) {
  .cancel-workout-button:hover {
    background-color: var(--color-surface-track);
    color: var(--color-text-primary);
  }
}

/* ==========================================================================
   Add Exercise Dialog - Independent Styling
   ========================================================================== */

.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2300;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

.dialog-overlay.show {
  opacity: 1;
  visibility: visible;
}

#spinnerDialogOverlay {
  z-index: 2400; /* Ensure spinner appears above summary dialog */
}

.dialog-content {
  background-color: white;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 400px;
  box-sizing: border-box;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transform: scale(0.9);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dialog-overlay.show .dialog-content {
  transform: scale(1);
}

#addExerciseDialogOverlay .dialog-content {
  text-align: left;
  padding: 20px;
  gap: 0; /* Override default dialog gap */
}

#addExerciseDialogOverlay .dialog-content h3 {
  text-align: center;
  margin-bottom: 12px;
}

/* Inputs & Selects */
#addExerciseDialogOverlay .add-exercise-input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--color-border-default);
  font-size: 16px;
  margin-bottom: 8px; /* Controls vertical spacing between rows */
  min-height: 48px;
  box-sizing: border-box;
  background-color: white;
  color: var(--color-text-primary);
  
  /* Custom Dropdown Arrow */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 1rem center;
  background-repeat: no-repeat;
  background-size: 1.5em;
  padding-right: 3rem;
}

/* Search Input Specifics */
#addExerciseDialogOverlay input.add-exercise-input {
  background-image: none; /* No arrow for text input */
  padding-right: 16px;
}

/* Titles above inputs */
#addExerciseDialogOverlay .dropdown-title {
  text-align: left;
  margin: 0 0 2px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
}

/* Clear Filters Button */
#addExerciseDialogOverlay .clear-filters-button {
  background: none;
  border: none;
  color: var(--color-primary-base);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 4px 8px 4px;
  margin-left: auto;
  display: block;
}

/* Container for Exercise Name + Star */
#addExerciseDialogOverlay .input-with-icon-container {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#addExerciseDialogOverlay .input-with-icon-container .add-exercise-input {
  margin-bottom: 8px;
  flex-grow: 1;
}

/* Favorite Star Button */
#addExerciseDialogOverlay .icon-action-button {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--color-border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  transition: transform 0.2s ease, color 0.2s ease;
}

#addExerciseDialogOverlay .icon-action-button.favorited {
  color: var(--color-warning-base);
  font-variation-settings: 'FILL' 1;
}

#addExerciseDialogOverlay .manage-exercises-link {
  display: block;
  text-align: center;
  color: var(--color-primary-base);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-top: 16px;
}

/* Dark Mode Overrides for this dialog */
html.dark-mode #addExerciseDialogOverlay .add-exercise-input {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
  color: var(--color-text-primary);
}

/* --- Workout Summary Dialog --- */

.summary-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2300;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.summary-dialog-overlay.show {
  opacity: 1;
  visibility: visible;
}

.summary-dialog-content {
  background-color: white;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 400px;
  box-sizing: border-box;
  margin: 0;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: scale(0.9);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.summary-dialog-overlay.show .summary-dialog-content {
  transform: scale(1);
}

.summary-dialog-content h3 {
  margin: 0 0 12px 0;
  font-size: 20px;
  color: var(--color-text-primary);
  font-weight: 700;
}

.summary-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  margin: 16px 0;
  text-align: center;
}

.summary-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  background-color: var(--color-surface-track);
  border-radius: 12px;
}

.summary-stat-item .stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.summary-stat-item .stat-value.editable {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}

.summary-stat-item .stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  font-weight: 600;
}

.summary-notes-container {
  width: 100%;
  text-align: left;
  margin-bottom: 16px;
}

.summary-notes-container h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--color-text-muted);
  font-weight: 700;
}

#summaryNotesTextarea {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border-default);
  font-size: 14px;
  resize: vertical;
  box-sizing: border-box;
  background-color: var(--color-surface-track);
  color: var(--color-text-primary);
  font-family: inherit;
}

.summary-device-reminder {
  font-size: 14px;
  color: var(--color-text-muted);
  margin: 0 0 16px 0;
  padding: 8px 12px;
  /* background-color: var(--color-surface-track); */
  border-radius: 8px;
  display: inline-block;
}

/* Specific styles for Watch Reminder Dialog */
#watchReminderDialogContent .material-symbols-outlined {
  color: var(--color-success-base);
}

.nav-button.active .nav-icon-cycle7 {
  background-color: var(--color-primary-base); /* Active color */
  -webkit-mask-image: url("Assets/Cycle7 Logo.svg");
  mask-image: url("Assets/Cycle7 Logo.svg");
}

/* --- Toast Notification --- */
.toast-container {
  position: fixed;
  bottom: 90px; /* Above the bottom nav bar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none; /* Allow clicks to pass through the container */
}

.toast-notification {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  pointer-events: auto; /* Re-enable pointer events for the toast itself */
}

.toast-notification.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-notification.success {
  background-color: var(--color-success-base);
}
.toast-notification.error {
  background-color: #ef4444; /* Red */
}

html.dark-mode .container {
  color: #e2e8f0;
}

html.dark-mode .header .workout-title,
html.dark-mode .header .sets-completed-text,
html.dark-mode .header .current-date-display,
html.dark-mode .workout-title-container .workout-title {
  color: #e2e8f0;
}

html.dark-mode .back-button .material-symbols-outlined {
  /* The background is handled by the general .header .back-button rule in common.css, so we just need to ensure the icon color is correct. */
  color: var(--color-text-primary); /* A dark grey from the theme */
}

html.dark-mode .exercise-card,
html.dark-mode .add-exercise-card {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
}

/* In dark mode, make the progress card transparent and apply the background
   only to the top part to make the buttons area blend with the page background. */
html.dark-mode .progress-bar-card {
  background-color: transparent;
  box-shadow: none;
}

/* Restore card appearance for edit mode in dark mode */
html.dark-mode .progress-bar-card.edit-mode-style {
  display: none !important;
}

html.dark-mode .progress-bar-header span:first-child,
html.dark-mode .exercise-name-display,
html.dark-mode .exercise-notes-section h4, 
html.dark-mode .dialog-content h3,
html.dark-mode .summary-dialog-content h3,
html.dark-mode .summary-notes-container h4 {
  color: var(--color-text-primary);
}

html.dark-mode .progress-bar-header span:last-child,
html.dark-mode .dialog-content p {
  color: var(--color-text-muted);
}

html.dark-mode .sets-table-header span,
html.dark-mode .set-row span {
  color: var(--color-text-primary);
}

html.dark-mode .progress-track {
  background-color: var(--color-surface-track);
}

html.dark-mode .exercise-card.completed-exercise {
  /* Use a success color for consistency with light mode */
  border-color: var(--color-success-dark);
}

html.dark-mode .sets-count-tag {
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
}

html.dark-mode .toggle-sets-button {
  background-color: var(--color-surface-track);
  color: var(--color-text-primary);
  border-color: var(--color-border-default);
}

html.dark-mode .exercise-notes-textarea {
  background-color: #1a202c;
  border-color: #4a5568;
  color: #e2e8f0;
}

html.dark-mode .set-row {
  background-color: var(--color-surface-subtle);
}

html.dark-mode .set-row.completed {
  background-color: var(--color-success-light);
}

/* In dark mode, make the rep/weight buttons transparent when completed to show the green background */
html.dark-mode .set-row.completed .value-display-button {
  background-color: transparent;
  border-color: transparent;
}

html.dark-mode .value-display-button {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
  color: var(--color-text-primary);
}

html.dark-mode .set-complete-button {
  background-color: var(--color-surface-track);
  color: var(--color-text-muted);
}

html.dark-mode .set-complete-button.completed {
  background-color: var(--color-success-base);
  color: white;
}

html.dark-mode .add-set-button {
  background-color: var(--color-surface-track);
  color: white;
}

html.dark-mode .add-exercise-input {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
  color: var(--color-text-primary);
}

html.dark-mode .footer {
  color: var(--neutral-grey-color);
}

html.dark-mode .dialog-overlay {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

html.dark-mode .summary-dialog-overlay {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Dark mode for spinner */
html.dark-mode .dialog-content {
  background-color: var(--color-surface-icon-bg);
}
html.dark-mode .summary-dialog-content {
  background-color: var(--color-surface-icon-bg);
}

html.dark-mode #summaryNotesTextarea {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
  color: var(--color-text-primary);
}

html.dark-mode .utility-button {
  background-color: var(--color-surface-subtle);
  box-shadow: none;
  color: var(--color-text-primary); /* Light icon on dark button */
}

html.dark-mode .utility-button.active {
  color: white; /* Ensure icon is white on green bg */
}

html.dark-mode .summary-stat-item {
  background-color: var(--color-surface-track);
}

html.dark-mode .summary-stat-item .stat-value {
  color: #e2e8f0;
}

html.dark-mode .summary-device-reminder {
  background-color: var(--color-surface-track);
}

html.dark-mode .bottom-sheet-content {
  background-color: var(--color-surface-subtle);
}

html.dark-mode .bottom-sheet-header h3 {
  color: var(--color-text-muted);
}

html.dark-mode .nav-button.active {
  color: var(--color-primary-base);
}

/* In dark mode, make sure the black PNG icons are visible against the dark background */
html.dark-mode .workout-icon-img {
  /* This filter inverts the color, turning the black PNGs white. */
  filter: invert(1);
}

.cardio-stats-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.cardio-labels,
.cardio-values {
  display: grid;
  gap: 8px;
  align-items: center;
}

.cardio-labels {
  padding: 0 4px; /* Align with set rows */
}

.cardio-labels label {
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  text-align: center;
}

.cardio-values {
  border-radius: 12px;
  padding: 8px;
  transition: background-color 0.2s ease;
}

.cardio-values.completed {
  background-color: var(--color-success-light);
}

html.dark-mode .template-action-footer {
  background-color: rgba(30, 41, 59, 0.9);
}

.edit-button .material-symbols-outlined,
.clear-all-sets-button .material-symbols-outlined,
.add-set-button .material-symbols-outlined,
.add-exercise-main-button .material-symbols-outlined {
  vertical-align: middle;
}

/* --- Hover states for devices that support it --- */
@media (hover: hover) and (pointer: fine) {
  .back-button:hover {
    transform: translateY(-2px);
  }

  .utility-button:hover:not(.active) {
    background-color: #f3f4f6;
    transform: translateY(-1px);
  }

  .options-menu a:hover {
    background-color: #f3f4f6;
  }

  .toggle-sets-button:hover {
    background-color: #e5e7eb;
  }

  .delete-exercise-button:hover {
    background-color: #fee2e2;
  }

  .toggle-set-edit-button:hover {
    color: var(--color-primary-base);
  }

  .set-complete-button:hover {
    background-color: var(--color-success-dark); /* Main workout color */
    color: white;
  }

  .delete-set-button:hover {
    background-color: #fee2e2; /* Light red */
  }

  .add-set-button:hover {
    background-color: var(--color-surface-track);
  }

  .add-exercise-main-button:hover {
    background-color: var(--color-primary-dark);
  }

  .finish-workout-button:hover {
    background-color: var(--color-success-dark);
    color: white;
  }

  .save-template-button:hover {
    background-color: var(--color-success-dark);
    color: white;
  }

  .dialog-buttons .green-button:hover {
    background-color: var(--color-success-dark);
  }

  .dialog-buttons .red-button:hover {
    background-color: #dc2626;
  }

  .dialog-buttons .grey-button:hover {
    background-color: var(--color-text-muted-dark);
  }

  html.dark-mode .utility-button:hover:not(.active) {
    background-color: #e5e7eb; /* Slightly darker white for hover */
    transform: translateY(-1px);
  }

  html.dark-mode .toggle-sets-button:hover {
    background-color: var(--color-text-muted);
  }

  html.dark-mode .value-display-button:hover {
    background-color: #2d3748;
  }

  html.dark-mode .add-set-button:hover {
    background-color: var(--color-border-default);
  }
}

/* Hide navbar in live, edit, and template modes */
body.live-mode .bottom-nav,
body.edit-mode .bottom-nav,
body.template-mode-active .bottom-nav {
  transform: translateY(200%) !important;
}

body.live-mode .nav-bar-spacer,
body.edit-mode .nav-bar-spacer,
body.template-mode-active .nav-bar-spacer {
  display: none !important;
}

/* --- Planner Reorder Mode Fixes --- */
.upcoming-workout-item {
  position: relative; /* Ensure absolute children position correctly */
}

.weekly-view-container.reorder-mode .upcoming-workout-item {
  padding-left: 54px !important; /* Ensure space for the reorder handle */
}

.weekly-view-container.reorder-mode .reorder-icon {
  display: block !important; /* Override global display:none from Workout.css */
}

/* --- History Modal Styles (Copied from profile.css for standalone support) --- */
.pb-chart-card {
  background-color: var(--color-bg-card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--card-shadow);
  border: var(--card-border);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pb-exercise-title {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.chart-toggle-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 4px;
  border-radius: 12px;
}

.chart-toggle-btn {
  flex: 1;
  padding: 2px 12px;
  border: none;
  background-color: transparent;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 400;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-toggle-btn.active {
  background-color: var(--color-primary-base);
  color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pr-metric-card {
  background-color: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--card-shadow);
  border: var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.pr-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0;
  font-size: 16px;
  color: var(--color-text-muted);
}

.pr-icon-img {
  width: 24px;
  height: 24px;
  margin-left: 8px;
  object-fit: contain;
}

.pr-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-default);
}

.pr-metric-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

html.dark-mode .pb-chart-card,
html.dark-mode .pr-metric-card {
  background-color: var(--color-surface-subtle);
}

/* Ensure History modal appears above the workout overlay (z-index 2200) */
#pbHistoryModal {
  z-index: 2300;
}

/* Sticky Timer State */
.workout-timer-container.sticky-mode {
  position: fixed; /* Relative to workout-overlay because of transform */
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100; /* Higher than header (100) */
  background-color: var(--color-bg-card);
  padding: 6px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border: 1px solid var(--color-border-default);
  width: auto;
  justify-content: center;
  display: flex !important; /* Ensure it stays visible even if parent logic tries to hide it */
  animation: sticky-slide-down 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.workout-timer-container.timer-returning {
  animation: timer-return-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Adjust inner elements for sticky mode */
.workout-timer-container.sticky-mode #workoutTimerDisplay {
  font-size: 24px;
  width: auto;
  text-align: center;
  padding-right: 0;
}

.workout-timer-container.sticky-mode .material-symbols-outlined {
  font-size: 28px;
}

.workout-timer-container.sticky-mode .timer-control-button {
  margin-right: 4px;
}

/* Hide header title when timer is sticky */
body.timer-sticky-active .header-title-container {
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

html.dark-mode .workout-timer-container.sticky-mode {
  background-color: var(--color-surface-subtle);
  border-color: var(--color-border-default);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
