:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-2: #0e9f6e;
  --border: #d1d5db;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(1200px 600px at 0% -10%, #e5f6f2 0%, rgba(229, 246, 242, 0) 60%),
    radial-gradient(900px 420px at 100% 0%, #eef4ff 0%, rgba(238, 244, 255, 0) 58%),
    linear-gradient(180deg, #edf2f9 0%, var(--bg) 100%);
  color: var(--text);
  overflow-x: hidden;
  width: 100%;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
}

header h1 {
  margin-bottom: 0.25rem;
}

header p {
  margin-top: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.05);
}

.ribbon-card {
  background: linear-gradient(135deg, #f8fcfb 0%, #f5f9ff 100%);
  border: 1px solid #d5e4ea;
  border-radius: 12px;
  height: 76px;
  overflow: hidden;
  position: relative;
}

.ribbon-title {
  position: absolute;
  left: 0.85rem;
  top: 0.6rem;
  z-index: 2;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1f2937;
}

.ribbon-wave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.ribbon-wave path {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.6;
}

.ribbon-wave path:nth-child(1) {
  stroke: rgba(15, 118, 110, 0.5);
}

.ribbon-wave path:nth-child(2) {
  stroke: rgba(37, 99, 235, 0.44);
}

.ribbon-wave path:nth-child(3) {
  stroke: rgba(14, 159, 110, 0.34);
}

h2 {
  margin-top: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.95rem;
  min-width: 0;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

optgroup {
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  padding-top: 0.5rem;
}

optgroup option {
  font-weight: normal;
  color: var(--text);
  background: var(--surface);
}

.language-switcher {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.language-switcher label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.language-switcher select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 0.95rem;
  cursor: pointer;
}

.actions,
.timer-row {
  margin-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
}

button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

#syncBtn {
  background: var(--accent-2);
}

.video-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.video-link.disabled {
  color: var(--muted);
  pointer-events: none;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.time {
  font-size: 1.4rem;
  font-weight: 700;
}

.label,
.muted {
  color: var(--muted);
}

/* Weekly Workout Summary */
.weekly-workout-summary {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.weekly-workout-summary h3 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 600;
}

.weekly-boxes {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.day-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.day-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.workout-box {
  width: 2.5rem;
  height: 2.5rem;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  background: white;
  transition: all 0.2s ease;
}

.workout-box.completed {
  background: #22c55e;
  border-color: #16a34a;
  box-shadow: 0 2px 4px rgba(34, 197, 94, 0.2);
}

.workout-box.completed::after {
  content: '✓';
  color: white;
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.weekly-summary-text {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

.weekly-summary-text span {
  font-weight: 700;
  color: var(--accent);
}

.history-list {
  display: grid;
  gap: 0.75rem;
}

.history-footer-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.history-footer-language-switcher {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.language-switcher label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.language-switcher select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 0.95rem;
  cursor: pointer;
}

.deployment-info {
  padding: 1rem;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.03) 0%, rgba(14, 159, 110, 0.03) 100%);
}

.deploy-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  font-family: monospace;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.badge-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-label {
  color: var(--muted, #666);
  font-weight: 600;
}

#commit-badge {
  color: #0369a1;
  text-decoration: none;
  padding: 1px 5px;
  background: #e0f2fe;
  border-radius: 3px;
}

#commit-badge:hover { background: #bae6fd; }

.badge-status {
  padding: 1px 5px;
  border-radius: 3px;
}

.status-success { color: #166534; background: #dcfce7; }
.status-failed  { color: #991b1b; background: #fee2e2; }
.status-running { color: #854d0e; background: #fef9c3; }
.status-unknown { color: #374151; background: #f3f4f6; }

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: #fcfdfd;
}

.history-item h3 {
  margin: 0 0 0.45rem;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.45rem;
}

.delete-history-btn {
  background: #b91c1c;
}

ul {
  margin: 0;
  padding-left: 1.15rem;
}

.remove-btn {
  background: #b91c1c;
}

/* Pull to Refresh Styles */
.pull-to-refresh {
  position: fixed;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease-out;
  z-index: 100;
}

.pull-to-refresh.visible {
  transform: translateY(60px);
}

.pull-to-refresh-spinner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Video Library Styles */
.video-input-group {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.video-input-group label {
  flex: 1;
  margin-bottom: 0;
}

.video-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

/* Workout Library Styles */
.workout-library-actions {
  margin-bottom: 1rem;
}

.workout-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.workout-template-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.workout-template-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.template-thumbnail {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 3rem;
}

.template-thumbnail.no-video {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.template-info {
  padding: 1rem;
}

.template-info h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
  color: var(--text);
}

.template-info p {
  margin: 0 0 0.75rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.template-meta {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.template-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.template-tag {
  background: #e0f2fe;
  color: #0369a1;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.template-actions {
  display: flex;
  gap: 0.5rem;
}

.template-actions button {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.85rem;
}

.template-actions .load-btn {
  background: var(--accent);
  color: white;
}

.template-actions .edit-btn {
  background: #f3f4f6;
  color: var(--text);
}

.template-actions .delete-btn {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.5rem 0.75rem;
  flex: 0;
}

.video-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  position: relative;
}

.video-thumbnail {
  width: 100%;
  height: 180px;
  object-fit: cover;
  cursor: pointer;
}

.video-info {
  padding: 0.75rem;
}

.video-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
  line-height: 1.3;
}

.video-description {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-url {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

.video-delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(185, 28, 28, 0.9);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.video-item:hover .video-delete-btn {
  opacity: 1;
}

.video-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.video-modal.active {
  display: flex;
}

/* Template Modal Styles */
.template-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
}

.template-modal.active {
  display: flex;
}

.template-modal-content {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  margin: 2rem auto;
}

.template-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0;
  width: 2rem;
  height: 2rem;
}

.template-modal-close:hover {
  color: var(--text);
}

.template-modal-content h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.template-modal-content label {
  display: block;
  margin-bottom: 1rem;
}

.template-modal-content textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  resize: vertical;
}

.template-exercises-preview {
  margin: 1.5rem 0;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.template-exercises-preview h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  color: var(--text);
}

.template-exercises-preview ul {
  margin: 0;
  padding-left: 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.template-exercises-preview li {
  margin-bottom: 0.25rem;
}

.template-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.template-modal-actions button {
  padding: 0.6rem 1.25rem;
}

.video-modal-content {
  background: black;
  border-radius: 8px;
  overflow: hidden;
  max-width: 90%;
  max-height: 90%;
  position: relative;
}

.video-modal iframe {
  width: 560px;
  height: 315px;
  border: none;
  display: block;
}

.video-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: white;
  border: none;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 720px) {
  .container {
    padding: 0.5rem;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .card {
    padding: 0.5rem;
  }

  .history-footer-actions {
    justify-content: center;
  }

  .deploy-badges {
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
  }

  #exportCsvBtn {
    order: 1;
  }

  /* Fix table width on mobile */
  table {
    min-width: 0;
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.35rem;
  }

  /* Adjust grid for mobile */
  .grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  /* Adjust buttons for mobile */
  .actions, .timer-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .timer-actions {
    display: flex;
    gap: 0.5rem;
  }

  .timer-actions button {
    flex: 1;
  }

  /* Adjust ribbon card for mobile */
  .ribbon-card {
    height: 60px;
  }

  .ribbon-title {
    font-size: 0.85rem;
    top: 0.4rem;
    left: 0.5rem;
  }
}

/* Extra small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
  .container {
    padding: 0.4rem;
  }

  .card {
    padding: 0.4rem;
  }

  table {
    font-size: 0.75rem;
  }

  th, td {
    padding: 0.25rem;
  }

  .ribbon-title {
    font-size: 0.75rem;
  }

  h2 {
    font-size: 1.1rem;
  }

  button {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Video library mobile styles */
  .video-input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .video-library-grid {
    grid-template-columns: 1fr;
  }

  .video-modal iframe {
    width: 100%;
    height: 200px;
  }
}

/* iPhone Pro and similar devices in portrait mode (393px - 430px) */
@media (max-width: 430px) and (orientation: portrait) {
  .grid {
    grid-template-columns: 1fr;
  }
  
  .video-library-grid {
    grid-template-columns: 1fr;
  }
  
  .workout-library-grid {
    grid-template-columns: 1fr;
  }
  
  .container {
    padding: 0.4rem;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  .card {
    padding: 0.4rem;
  }
  
  table {
    font-size: 0.75rem;
  }
  
  th, td {
    padding: 0.25rem;
  }
  
  .ribbon-title {
    font-size: 0.75rem;
  }
  
  h2 {
    font-size: 1.1rem;
  }
  
  button {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
  
  .video-input-group {
    flex-direction: column;
    align-items: stretch;
  }
  
  .video-modal iframe {
    width: 100%;
    height: 200px;
  }
}
