/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-card: #f0f0f2;
  --bg-card-hover: #e8e8ea;
  --bg-today: #fafafa;
  --border: #e0e0e2;
  --border-today: #b89840;
  --text-primary: #1a1a1c;
  --text-secondary: #4a4a50;
  --text-muted: #8a8a92;
  --accent: #b89840;
  --accent-light: #d4b05a;
  --tag-load: #b89840;
  --tag-checkbox: #8a8a8a;
  --tag-notscored: #525252;
  --tag-default: #b89840;
  --video-accent: #b89840;
  --workout-accent: #b89840;
  --radius: 8px;
  --radius-sm: 4px;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== Toolbar (merged header + nav) ===== */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid #2a2c30;
  background: #181a1c;
}

.toolbar-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.title {
  font-size: 20px;
  font-weight: 700;
  color: #d4b05a;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.date-range {
  font-size: 13px;
  color: #6b7080;
  white-space: nowrap;
}

.toolbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
}

.week-label {
  font-size: 16px;
  font-weight: 600;
  min-width: 220px;
  text-align: center;
  color: #e8eaec;
}

.toolbar-right {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  justify-self: end;
}

.toolbar .btn {
  color: #c8ccd2;
}

.toolbar .btn:hover {
  color: #e8eaec;
  background: #262830;
}

.toolbar .btn-outline {
  border-color: #2a2c30;
  color: #c8ccd2;
}

.toolbar .btn-outline:hover {
  border-color: #b89840;
  color: #d4b05a;
}

/* ===== Buttons ===== */
.btn {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.btn-text {
  font-weight: 500;
}

.btn-outline {
  border: 1px solid var(--border);
  background: transparent;
  font-weight: 500;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.btn-icon:hover {
  background: var(--bg-card);
}

/* ===== Week Grid ===== */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 50px);
}

.day-column {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.day-column.today {
  background: #e8f0fa;
}

.day-header {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}

.day-column.today .day-header {
  border-bottom: 2px solid var(--border-today);
}

.day-name {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.day-column.today .day-name {
  color: var(--accent-light);
}

.day-date {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

.day-column.today .day-date {
  color: var(--accent-light);
}

.day-content {
  flex: 1;
  padding: 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.no-data {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 24px 8px;
  font-style: italic;
}

/* ===== Workout Card ===== */
.workout-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.workout-card:hover {
  border-color: var(--accent);
}

.workout-card.today-card {
}

.workout-card.type-video {
}

.workout-card.type-workout {
}

.workout-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  cursor: pointer;
  user-select: none;
}

.workout-header:hover {
  background: var(--bg-card-hover);
}

.workout-index {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 50%;
}

.workout-title-area {
  flex: 1;
  min-width: 0;
}

.workout-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.workout-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.result-tag {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-tag.load {
  background: rgba(184, 152, 64, 0.15);
  color: var(--tag-load);
}

.result-tag.checkbox {
  background: rgba(138, 138, 138, 0.15);
  color: var(--tag-checkbox);
}

.result-tag.notscored {
  background: rgba(82, 82, 82, 0.15);
  color: var(--tag-notscored);
}

.result-tag.default {
  background: rgba(184, 152, 64, 0.15);
  color: var(--tag-default);
}

.level-tag {
  font-size: 0.55rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.expand-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  margin-top: 1px;
}

/* ===== Workout Detail ===== */
.workout-detail {
  display: none;
  padding: 8px;
  background: #ffffff;
  border-top: 1px solid var(--border);
}

.workout-card.expanded .workout-detail {
  display: block;
}

.workout-card.expanded .expand-arrow {
  transform: rotate(90deg);
}

.detail-section {
  margin-top: 6px;
}

.detail-section:first-child {
  margin-top: 8px;
}

.detail-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.detail-content {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.detail-content p {
  margin-bottom: 5px;
}

.detail-content p:last-child {
  margin-bottom: 0;
}

.detail-content a {
  color: var(--accent-light);
  text-decoration: none;
}

.detail-content a:hover {
  text-decoration: underline;
}

.detail-content ul, .detail-content ol {
  padding-left: 16px;
  margin-bottom: 5px;
}

.detail-content li {
  margin-bottom: 2px;
}

.detail-content strong {
  color: var(--text-primary);
}

.detail-content code {
  background: var(--bg-primary);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.75rem;
}

.video-thumbnail {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 5px;
  cursor: pointer;
}

.video-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--accent-light);
  text-decoration: none;
  margin-top: 3px;
}

.video-link:hover {
  text-decoration: underline;
}

/* ===== Loading & Error ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

/* ===== Scrollbar ===== */
.day-content::-webkit-scrollbar {
  width: 3px;
}

.day-content::-webkit-scrollbar-track {
  background: transparent;
}

.day-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.day-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Day Selector (Mobile) ===== */
.day-selector {
  display: none;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  html {
    font-size: 15px;
  }
}

@media (max-width: 768px) {
  .week-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 0;
    align-items: center;
  }

  .toolbar-left {
    width: 100%;
    padding: 6px 10px;
    gap: 6px;
  }

  .title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .date-range {
    display: none;
  }

  .toolbar-center {
    width: 100%;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px 6px;
    border-top: 1px solid #2a2c30;
  }

  .toolbar-right {
    display: none;
  }

  .week-label {
    min-width: auto;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  /* Day Selector */
  .day-selector {
    display: flex;
    background: #181a1c;
    border-bottom: 1px solid #2a2c30;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .day-selector::-webkit-scrollbar {
    display: none;
  }

  .day-tab {
    flex: 1;
    min-width: 0;
    padding: 8px 4px 6px;
    text-align: center;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .day-tab:active {
    background: #262830;
  }

  .day-tab-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: #6b7080;
    letter-spacing: 0.5px;
  }

  .day-tab-date {
    font-size: 0.75rem;
    font-weight: 700;
    color: #8a8a92;
    margin-top: 1px;
  }

  .day-tab.active {
    border-bottom-color: var(--accent);
  }

  .day-tab.active .day-tab-name,
  .day-tab.active .day-tab-date {
    color: #d4b05a;
  }

  .day-tab.is-today .day-tab-date {
    color: #c8ccd2;
  }

  .day-tab.active.is-today .day-tab-date {
    color: #d4b05a;
  }

  /* Single day view: hide non-selected days */
  .day-column {
    border-bottom: none;
    display: none;
  }

  .day-column.mobile-selected {
    display: flex;
  }

  .day-header {
    display: none;
  }

  .day-content {
    padding: 8px 10px;
  }

  /* Touch-friendly cards */
  .workout-header {
    padding: 10px 10px;
    gap: 8px;
  }

  .workout-index {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
  }

  .workout-title {
    font-size: 0.85rem;
  }

  .expand-arrow {
    width: 20px;
    height: 20px;
  }

  .btn {
    min-height: 36px;
    padding: 4px 12px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
  }

  .detail-content {
    font-size: 0.82rem;
  }

  .video-thumbnail {
    border-radius: var(--radius);
  }
}

@media (max-width: 480px) {
  .title {
    font-size: 14px;
  }

  .week-label {
    font-size: 0.75rem;
  }

  .day-tab {
    padding: 6px 2px 5px;
  }

  .day-tab-name {
    font-size: 0.65rem;
  }

  .day-tab-date {
    font-size: 0.7rem;
  }

  .workout-header {
    padding: 8px 8px;
  }

  .workout-title {
    font-size: 0.8rem;
  }
}
