* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fafafa;
  --text: #222;
  --text-muted: #888;
  --border: #ddd;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --active-bg: #e0f2fe;
  --completed-bg: #f0f0f0;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
}

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

/* Tab Bar */
#tab-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

#tab-bar.hidden {
  display: none;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 48px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover {
  background: #f5f5f5;
}

.view {
  padding: 1rem;
  padding-top: calc(48px + 1rem);
  padding-bottom: 5rem;
}

.view.no-tab-padding {
  padding-top: 1rem;
}

.hidden {
  display: none !important;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 0.5rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  min-height: 44px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover, .btn-primary:active {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e5e7eb;
  color: var(--text);
}

.btn-secondary:hover, .btn-secondary:active {
  background: #d1d5db;
}

.btn-back {
  background: transparent;
  color: var(--primary);
  padding: 0.5rem;
  font-size: 1rem;
}

.btn-full {
  width: 100%;
  margin-top: 1rem;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover, .btn-danger:active {
  background: var(--danger-hover);
}

/* Library View */
#workout-list {
  list-style: none;
}

.workout-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 0.5rem;
}

.workout-item:hover {
  background: #f5f5f5;
}

.workout-item .workout-name {
  flex: 1;
  font-weight: 500;
}

/* Day picker list */
#day-picker-list {
  list-style: none;
}

.day-pick {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.day-pick:hover {
  background: #f5f5f5;
}

.day-pick-label {
  font-weight: 600;
  color: var(--text);
}

.day-pick-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.workout-actions button {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  min-height: 36px;
}

.btn-edit {
  background: #e5e7eb;
  color: var(--text);
}

.btn-delete {
  background: transparent;
  color: var(--danger);
}

.empty-message {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* Import/Export buttons */
.import-export-buttons {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Edit View */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}

.form-group textarea {
  min-height: 300px;
  resize: vertical;
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Workout View */
.section {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.section-description {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.exercise-list {
  list-style: none;
}

.exercise {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.exercise.active {
  background: var(--active-bg);
  border-left: 3px solid var(--primary);
  padding-left: calc(1rem - 3px);
}

.exercise.completed {
  background: var(--completed-bg);
  opacity: 0.7;
}

.exercise.completed .exercise-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.exercise-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.exercise-name {
  font-weight: 500;
  flex: 1;
}

.timer-display {
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  min-width: 4rem;
  text-align: right;
}

.exercise-description {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.exercise-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.exercise-controls .btn-done {
  margin-left: auto;
}

.exercise-controls button {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  min-height: 40px;
}

.btn-start {
  background: var(--primary);
  color: white;
  min-width: 5rem;
}

.btn-start:hover, .btn-start:active {
  background: var(--primary-hover);
}

.btn-start.running {
  background: #f59e0b;
}

.btn-start.running:hover, .btn-start.running:active {
  background: #d97706;
}

.btn-reset {
  background: #e5e7eb;
  color: var(--text);
}

.btn-done {
  background: var(--primary);
  color: white;
}

.exercise.completed .btn-start,
.exercise.completed .btn-done {
  background: #9ca3af;
  cursor: default;
}

/* Sets info display */
.sets-info {
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 4rem;
  text-align: right;
}

/* Set buttons */
.btn-set {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: #e5e7eb;
  color: var(--text);
  font-weight: 600;
}

.btn-set:hover, .btn-set:active {
  background: #d1d5db;
}

.btn-set.done {
  background: var(--primary);
  color: white;
}

.btn-set.done:hover, .btn-set.done:active {
  background: var(--primary-hover);
}

.btn-set.running {
  background: #f59e0b;
  color: white;
  width: auto;
  min-width: 44px;
  padding: 0 0.5rem;
  border-radius: 22px;
}

.btn-set.running:hover, .btn-set.running:active {
  background: #d97706;
}

/* Weight display in exercise header */
.weight-display {
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

/* Weight button in exercise controls */
.btn-weight {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  min-height: 40px;
}

.btn-weight:hover, .btn-weight:active {
  border-color: var(--primary);
  color: var(--primary);
}

/* Status Bar */
#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  font-weight: 500;
  z-index: 100;
}

.btn-rest {
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-weight: 600;
  min-height: 36px;
  padding: 0.5rem 1rem;
}

.btn-rest:hover, .btn-rest:active {
  background: var(--primary-hover);
}

.btn-rest.active {
  background: #f59e0b;
}

.btn-rest.active:hover, .btn-rest.active:active {
  background: #d97706;
}

#rest-display {
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
}

/* Responsive */
@media (min-width: 600px) {
  .view {
    max-width: 600px;
    margin: 0 auto;
  }

  #status-bar {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 8px 8px 0 0;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111;
    --text: #eee;
    --text-muted: #888;
    --border: #333;
    --active-bg: #1e3a5f;
    --completed-bg: #222;
  }

  #tab-bar {
    background: #111;
  }

  .tab-btn:hover {
    background: #1a1a1a;
  }

  .workout-item:hover {
    background: #1a1a1a;
  }

  .btn-secondary,
  .btn-reset,
  .btn-edit,
  .btn-set {
    background: #333;
    color: var(--text);
  }

  .btn-secondary:hover,
  .btn-reset:hover,
  .btn-edit:hover,
  .btn-set:hover {
    background: #444;
  }

  .btn-set.done {
    background: var(--primary);
    color: white;
  }

  .btn-weight {
    border-color: #555;
  }

  #status-bar {
    background: #111;
  }

  .form-group input,
  .form-group textarea {
    background: #1a1a1a;
    color: var(--text);
    border-color: var(--border);
  }
}
