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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-muted: #8b8d97;
  --accent: #3b82f6;
  --accent-dim: #1e40af;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
}

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

header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  white-space: nowrap;
}

nav {
  display: flex;
  gap: 0.25rem;
}

.nav-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.nav-btn:hover:not(.active) {
  background: var(--border);
  color: var(--text);
}

.status {
  margin-left: auto;
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-weight: 500;
}

.status.connected {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.status.disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

main {
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* Gauges */
.gauges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.gauge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
}

.gauge-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--accent);
}

.gauge-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Derived metrics panel */
.metrics-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.chart-container h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.chart-container canvas {
  width: 100% !important;
  max-height: 220px;
}

/* Session list */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Session filter tabs */
.session-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  width: 100%;
}

.filter-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-btn:hover:not(.active) {
  background: var(--border);
  color: var(--text);
}

/* C2 group header */
.c2-group-header {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* C2 badge */
.c2-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.c2-badge.unassigned {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  transition: border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.session-card-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  cursor: pointer;
}

.session-card .session-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.session-card .session-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.session-notes-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.session-card .session-stats {
  text-align: right;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.session-card-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-left: 0.5rem;
}

.session-card-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-session-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.delete-session-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.session-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.summary-item {
  text-align: center;
}

.summary-item .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.summary-item .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.back-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  transition: all 0.15s;
}

.back-btn:hover {
  background: var(--border);
  color: var(--text);
}

.export-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.export-btn:hover {
  background: var(--accent);
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem;
  text-align: center;
}

/* ===== Setup View ===== */

body.setup-mode header { display: none; }
body.setup-mode main {
  padding: 0;
  max-width: 100%;
  height: 100vh;
}
body.setup-mode #view-setup {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  width: 100%;
  max-width: 600px;
}

.setup-heading {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.setup-rower-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
}

.setup-workout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  width: 100%;
}

.setup-rower-btn,
.setup-workout-btn {
  min-height: 80px;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.setup-rower-btn:hover,
.setup-workout-btn:hover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.setup-rower-btn.selected,
.setup-workout-btn.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.setup-start-btn {
  margin-top: 1rem;
  width: 100%;
  min-height: 60px;
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
}

.setup-start-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.setup-start-btn:not(:disabled):hover {
  background: #2563eb;
}

/* ===== Activity Selection View ===== */

body.activity-select-mode header { display: none; }
body.activity-select-mode main {
  padding: 0;
  max-width: 100%;
  height: 100vh;
}
body.activity-select-mode #view-activity-select {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.activity-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  width: 100%;
}

.activity-select-btn {
  min-height: 120px;
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.activity-select-btn:hover,
.activity-select-btn:focus {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
  outline: none;
}

.activity-select-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.45);
}

.activity-select-btn:active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
}

/* ===== Stroke Length Test View ===== */

body.slt-mode header { display: none; }
body.slt-mode main {
  padding: 0;
  max-width: 100%;
  height: 100vh;
}
body.slt-mode #view-slt {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slt-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.slt-phase-label {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.slt-instruction {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.slt-progress {
  font-size: 4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.slt-live {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.slt-current-dl {
  font-size: 7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--green);
  line-height: 1;
}

.slt-avg-dl {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.slt-dl-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.slt-summary { width: 100%; }

.slt-summary-heading {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.slt-results {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.slt-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
}

.slt-result-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.slt-result-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 0.25rem;
}

.slt-result-pct {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.slt-exit-btn {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 100;
}

/* ===== Rowing View ===== */

/* Hide header in rowing mode */
body.rowing-mode header { display: none; }
body.rowing-mode main {
  padding: 0;
  max-width: 100%;
  height: 100vh;
}
body.rowing-mode #view-rowing {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Hero row — drive length + watts */
.rv-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex: 0 0 auto;
}

.rv-hero-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rv-drive-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  transition: border-color 0.3s, background 0.3s;
}

.rv-drive-value {
  font-size: 7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--accent);
  transition: color 0.3s;
}

.rv-drive-unit {
  font-size: 1.5rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.rv-drive-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.25rem;
}

/* Target threshold coloring (applied to individual values) */
[data-target="good"] {
  color: var(--green) !important;
}

[data-target="short"] {
  color: var(--orange) !important;
}

/* Background shading on cards containing target-colored values */
.rv-drive-card:has([data-target="good"]) {
  background: rgba(34, 197, 94, 0.08);
  border-color: var(--green);
}

.rv-drive-card:has([data-target="short"]) {
  background: rgba(249, 115, 22, 0.08);
  border-color: var(--orange);
}

.rv-force-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  position: relative;
}

.rv-force-card canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Secondary row — pace, power, spm */
.rv-secondary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  flex: 0 0 auto;
}

.rv-gauge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
}

.rv-gauge-value {
  font-size: 4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--accent);
  transition: color 0.3s;
}

.rv-gauge-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

.rv-gauge-avg {
  font-size: 1rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 0.25rem;
}

/* Tertiary row — compact cells */
.rv-tertiary {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  padding: 0.5rem 1.5rem;
  flex: 0 0 auto;
}

.rv-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
}

.rv-cell-value {
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--text);
  transition: color 0.3s;
}

.rv-cell-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.1rem;
}

/* Force curve section — fills remaining space */
.rv-force-section {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.5rem 1.5rem 1rem;
}

.rv-force-section .rv-force-card {
  height: calc(100% - 1.5rem);
}

.rv-target-info {
  font-size: 0.7rem;
  color: #71717a;
  text-align: center;
  padding-top: 0.25rem;
  font-style: italic;
}

/* Drift coloring */
[data-drift="neutral"] {
  border-color: var(--border);
}

[data-drift="ok"] {
  border-color: var(--green);
}
[data-drift="ok"] .rv-drive-value,
[data-drift="ok"] .rv-gauge-value,
[data-drift="ok"] .rv-cell-value {
  color: var(--green);
}

[data-drift="warn"] {
  border-color: var(--yellow);
  background: rgba(234, 179, 8, 0.05);
}
[data-drift="warn"] .rv-drive-value,
[data-drift="warn"] .rv-gauge-value,
[data-drift="warn"] .rv-cell-value {
  color: var(--yellow);
}

[data-drift="alert"] {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.08);
}
[data-drift="alert"] .rv-drive-value,
[data-drift="alert"] .rv-gauge-value,
[data-drift="alert"] .rv-cell-value {
  color: var(--red);
}

/* Setup info badge (top-left of rowing view) */
.rv-setup-info {
  position: fixed;
  top: 0.75rem;
  left: 1rem;
  z-index: 100;
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
}

.rv-setup-info:empty {
  display: none;
}

/* Session recording indicator */
.rv-session-indicator {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
}

.rv-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.rv-session-indicator.recording .rv-rec-dot {
  background: var(--red);
  animation: rv-pulse 1.2s ease-in-out infinite;
}

.rv-session-indicator.recording #rv-session-label {
  color: var(--text);
}

@keyframes rv-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Exit button */
.rv-exit-btn {
  position: fixed;
  top: 2.75rem;
  right: 1rem;
  z-index: 100;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.15s;
}

.rv-exit-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

/* Responsive: shorter screens */
@media (max-height: 800px) {
  .rv-hero { height: 35vh; padding: 0.5rem 1rem; }
  .rv-drive-value { font-size: 5rem; }
  .rv-secondary { padding: 0.25rem 1rem; }
  .rv-gauge-value { font-size: 3rem; }
  .rv-tertiary { padding: 0.25rem 1rem; }
  .rv-cell-value { font-size: 1.4rem; }
}

/* Summary full-width items */
.summary-item.full-width {
  grid-column: 1 / -1;
}

.notes-text {
  font-size: 0.95rem !important;
  font-weight: 400 !important;
  color: var(--text) !important;
  white-space: pre-wrap;
}

/* Edit session modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 90%;
  max-width: 420px;
}

.modal h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.modal-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.modal-input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.modal-btn {
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.modal-btn.cancel {
  background: transparent;
  color: var(--text-muted);
}

.modal-btn.cancel:hover {
  background: var(--border);
  color: var(--text);
}

.modal-btn.save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.modal-btn.save:hover {
  opacity: 0.85;
}

@media (max-width: 768px) {
  header { flex-wrap: wrap; gap: 0.75rem; }
  .gauges { grid-template-columns: repeat(3, 1fr); }
  .gauge-value { font-size: 1.5rem; }
  .charts-grid { grid-template-columns: 1fr; }
}
