@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

:root {
  --bg-primary: #f9fafb;
  --bg-secondary: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --accent-primary: #4d7c0f;
  --accent-secondary: #65a30d;
  --border-color: #e5e7eb;
  --hover-bg: #f3f4f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --accent-primary: #a3e635;
    --accent-secondary: #65a30d;
    --border-color: #374151;
    --hover-bg: #374151;
  }
}
.theme-default {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --accent-primary: #a3e635;
  --accent-secondary: #65a30d;
  --border-color: #374151;
  --hover-bg: #374151;
}
.theme-light {
  --bg-primary: #f9fafb;
  --bg-secondary: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --accent-primary: #4d7c0f;
  --accent-secondary: #65a30d;
  --border-color: #e5e7eb;
  --hover-bg: #f3f4f6;
}
.theme-dark {
  --bg-primary: #000000;
  --bg-secondary: #111111;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --accent-primary: #00ff00;
  --accent-secondary: #00aa00;
  --border-color: #333333;
  --hover-bg: #222222;
}
.theme-cyber {
  --bg-primary: #0a192f;
  --bg-secondary: #172a45;
  --text-primary: #ccd6f6;
  --text-secondary: #8892b0;
  --accent-primary: #64ffda;
  --accent-secondary: #64ffda;
  --border-color: #233554;
  --hover-bg: #233554;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition:
    background-color 0.3s,
    color 0.3s;
}
.workout-container,
.exercise-row {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
  transition: background-color 0.3s;
}
h1,
h2,
#sidebar h3,
.modal h3 {
  color: var(--accent-primary);
}
.header-subtitle,
.schedule-text,
.manual-schedule-container label {
  color: var(--text-secondary);
}
.exercise-row.completed .exercise-name,
.exercise-row.completed .editable-cell-wrapper::before,
.exercise-row.completed .value-span {
  text-decoration: line-through;
  color: var(--text-secondary);
}
.accent {
  accent-color: var(--accent-primary);
}
table {
  border-collapse: separate;
  border-spacing: 0 0.5rem;
}
td,
th {
  padding: 1rem 1.5rem;
}
td:first-child,
th:first-child {
  border-top-left-radius: 0.5rem;
  border-bottom-left-radius: 0.5rem;
}
td:last-child,
th:last-child {
  border-top-right-radius: 0.5rem;
  border-bottom-right-radius: 0.5rem;
}
.adjust-btn {
  background-color: var(--border-color);
  color: var(--text-primary);
  border-radius: 9999px;
  width: 1.75rem;
  height: 1.75rem;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
}
.adjust-btn:hover {
  background-color: var(--text-secondary);
}
.adjust-btn:active {
  background-color: var(--accent-primary);
  color: var(--bg-secondary);
  transform: scale(0.9);
}
.add-exercise-btn {
  background-color: var(--accent-secondary);
  color: var(--bg-primary);
}
.add-exercise-btn:hover {
  opacity: 0.9;
}

/* Timer Button Styles */
.start-timer-btn {
  background-color: var(--accent-secondary); /* Default green */
  color: white;
}

.start-timer-btn.timer-running {
  background-color: #ef4444; /* Tailwind red-500 */
}

.start-timer-btn.timer-running:hover {
  background-color: #dc2626; /* Tailwind red-600 */
}

/* Custom Checkbox/Toggle Styles */
.completion-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.original-checkbox {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.custom-checkbox {
  display: inline-block;
  transition: all 0.2s;
  width: 1.5rem; /* 24px */
  height: 1.5rem; /* 24px */
  background-color: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 0.375rem; /* 6px */
}
.original-checkbox:checked + .custom-checkbox {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}
.custom-checkbox::after {
  content: '';
  position: absolute;
  display: none;
  left: 50%;
  top: 50%;
  width: 0.5rem;
  height: 1rem;
  border: solid white;
  border-width: 0 3px 3px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}
.original-checkbox:checked + .custom-checkbox::after {
  display: block;
}

/* Edit Mode & Dragging Styles */
#finishEditingButton,
.delete-btn,
.add-exercise-btn,
.add-workout-btn,
.delete-workout-btn,
.manual-schedule-container,
.drag-handle-cell {
  display: none;
}
.editable-cell-wrapper .adjust-btn,
.duration-input {
  display: none;
}
.edit-mode .editable-cell-wrapper .adjust-btn,
.edit-mode .duration-input {
  display: inline-flex;
}
.edit-mode .delete-btn {
  display: inline-flex;
} /* Ensure delete button shows in edit mode */
.edit-mode .drag-handle-cell {
  display: table-cell;
}
.edit-mode .add-exercise-btn,
.edit-mode .add-workout-btn {
  display: block;
}
.edit-mode #saveWorkoutButton {
  display: none;
}
.edit-mode .reset-workout-btn {
  display: none;
}
.edit-mode #finishEditingButton {
  display: inline-block;
}
.edit-mode .exercise-row {
  cursor: grab;
}
.exercise-row.dragging {
  opacity: 0.8;
  background-color: var(--accent-secondary);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  transform: scale(1.02);
}
.drag-handle {
  cursor: grab;
}
.edit-mode .workout-title,
.edit-mode .workout-subtitle {
  cursor: pointer;
  background-color: var(--border-color);
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
}
.edit-mode .delete-workout-btn {
  display: block;
}
.edit-mode.manual-schedule-mode .manual-schedule-container {
  display: flex;
}

/* Hide completion toggle in edit mode */
.edit-mode .completion-control {
  display: none;
}
/* Show delete button only in edit mode */
.delete-btn {
  display: none;
}
.edit-mode .delete-btn {
  display: inline-flex;
}

/* Sidebar, Modal & Confetti Styles */
#sidebar {
  transform: translateX(-100%);
  transition: transform 0.3s ease-in-out;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
}
#sidebar.open {
  transform: translateX(0);
}
#sidebar-overlay,
.modal-overlay {
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  pointer-events: none;
}
#sidebar-overlay.open,
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background-color: var(--bg-secondary);
  transform: scale(0.95);
  opacity: 0;
  transition: all 0.3s ease-in-out;
  pointer-events: none;
}
.modal.open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100;
}

/* *** UPDATED: Theme Preview Styles *** */
/* Grid layout for the theme list */
#theme-list {
  display: grid;
  /* Single column to fill width */
  grid-template-columns: 1fr;
  gap: 1rem; /* Spacing between previews */
}
/* Style the button that contains the preview */
#theme-list .theme-btn {
  border: 2px solid transparent; /* Placeholder for active state */
  display: flex; /* Ensure flex for centering */
  flex-direction: column;
  align-items: center;
  padding: 0.75rem; /* Adjust padding */
}
/* Style the preview container */
.theme-preview {
  background-color: var(--bg-primary); /* Use locally set vars */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow */
  width: 100%; /* Make preview fill the button width */
  max-width: 250px; /* Increase max-width */
  height: 80px; /* Keep height */
  margin-bottom: 0.5rem; /* Space between preview and name */
}
.preview-header {
  height: 15%; /* Adjust header proportion */
}
.preview-body {
  padding: 0.3rem; /* Adjust padding */
}
.preview-card {
  height: 35%; /* Adjust card proportion */
  border: 1px solid var(--border-color); /* Add subtle border */
}
.preview-card:first-child {
  margin-bottom: 0.2rem; /* Space between cards */
}
/* Active state border */
#theme-list .theme-btn.active {
  border-color: var(--accent-primary); /* Use main theme's accent for border */
  background-color: var(--hover-bg);
}
#theme-list .theme-btn:hover {
  background-color: var(--hover-bg); /* Use theme's hover color */
}

@media (max-width: 768px) {
  thead {
    display: none;
  }
  tr.exercise-row {
    display: block;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    padding: 1rem;
  }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border-color);
  }
  tr.exercise-row td:last-child {
    border-bottom: none;
  }
  .drag-handle-cell {
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
    border-bottom: none !important;
  }

  td.exercise-name-cell {
    flex-direction: column;
    border-bottom: none;
    padding: 0;
  }
  .mobile-exercise-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border-color);
  }

  .exercise-name-container {
    /* This class is now used for the desktop delete button placement */
  }
  .exercise-type-toggle-container {
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
  }

  .editable-cell-wrapper::before,
  .weight-cell::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
  }
  .adjust-btn {
    width: 2rem;
    height: 2rem;
  }
  .value-span {
    font-size: 1rem;
  }
  .manual-schedule-container {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }

  /* Mobile Toggle Switch Styles */
  .custom-checkbox {
    width: 50px;
    height: 28px;
    background-color: var(--border-color);
    border: none;
    border-radius: 28px;
    position: relative;
  }
  .original-checkbox:checked + .custom-checkbox {
    background-color: var(--accent-primary);
  }
  .custom-checkbox::after {
    content: '';
    position: absolute;
    display: block; /* always display the nub on mobile */
    left: 3px;
    top: 3px;
    width: 22px;
    height: 22px;
    background-color: white;
    border-radius: 50%;
    border-width: 0;
    transform: rotate(0) translateX(0); /* reset from desktop */
    transition: transform 0.2s;
  }
  .original-checkbox:checked + .custom-checkbox::after {
    transform: translateX(22px);
  }

  /* Ensure mobile delete button is placed correctly */
  .mobile-exercise-header .delete-btn {
    margin-left: 0.5rem; /* Add some space */
  }

  /* Adjust padding for cells in mobile view */
  td.editable-cell-wrapper,
  td.weight-cell {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }

  /* Adjust theme list grid for smaller screens if needed */
  #theme-list {
    /* Single column already set, this confirms it for mobile */
    grid-template-columns: 1fr;
    gap: 0.75rem; /* Slightly reduce gap */
  }
  .theme-preview {
    height: 80px; /* Keep height consistent or adjust if needed */
    max-width: 90%; /* Let it fill most of the button */
  }
}
