/* Swim Tracker NAS - Shared Styles */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
  color: #333;
  line-height: 1.5;
}

a {
  color: #667eea;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* === Navigation === */
.nav {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 56px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nav-brand {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  margin-right: 32px;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav-links a {
  color: rgba(255, 255, 255, 0.85);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* === Layout === */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

.container-wide {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* === Page Header === */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: #333;
  margin: 0 0 4px 0;
}

.page-header .subtitle {
  color: #666;
  font-size: 14px;
  margin: 0;
}

/* === Cards === */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
}

/* === Tables === */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
}

tbody tr:hover {
  background: #f8f9fa;
}

tbody tr.clickable {
  cursor: pointer;
}

tbody tr.clickable:hover {
  background: #eef2ff;
}

/* Phantom rest highlight */
tbody tr.phantom-rest {
  background: #fff5f5;
}

tbody tr.phantom-rest td {
  color: #c0392b;
}

/* Rest row styling */
tbody tr.rest-row {
  background: #fafafa;
  color: #888;
  font-style: italic;
}

/* === Metrics Grid === */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.metric-item {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.metric-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  color: #333;
}

/* === Pace Drift Colors === */
.drift-positive {
  color: #e74c3c;
  font-weight: 600;
}

.drift-negative {
  color: #27ae60;
  font-weight: 600;
}

.drift-zero {
  color: #888;
}

/* === Best Value Highlight (comparison) === */
.best-value {
  color: #27ae60;
  font-weight: 700;
}

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  text-align: center;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.btn-secondary {
  background: #95a5a6;
  color: #fff;
}

.btn-danger {
  background: #e74c3c;
  color: #fff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
}

/* Export button (fixed position) */
.btn-export {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  color: #333;
}

.form-input,
input[type="text"],
input[type="url"],
input[type="date"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #667eea;
}

textarea {
  min-height: 80px;
  resize: vertical;
  font-family: monospace;
}

/* === Loading State === */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #667eea;
  font-weight: 600;
  font-size: 14px;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid #ddd;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 10px;
}

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

/* === Error State === */
.error-message {
  padding: 14px 16px;
  background: #fff5f5;
  border-left: 4px solid #e74c3c;
  border-radius: 6px;
  color: #c0392b;
  font-size: 14px;
  margin-bottom: 16px;
}

/* === Info Notice === */
.info-notice {
  padding: 14px 16px;
  background: #e8f4f8;
  border-left: 4px solid #3498db;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* === Checkbox === */
.checkbox-cell {
  width: 40px;
  text-align: center;
}

.checkbox-cell input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* === Session Count Badge === */
.badge {
  display: inline-block;
  background: #667eea;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  margin-left: 8px;
  vertical-align: middle;
}

/* === Subset Section === */
.subset-section {
  margin-bottom: 16px;
}

.subset-header {
  font-size: 14px;
  font-weight: 600;
  color: #667eea;
  margin-bottom: 8px;
}

/* === Chart Container === */
.chart-container {
  width: 100%;
  min-height: 300px;
  position: relative;
}

.chart-container svg {
  width: 100%;
  height: 100%;
}

/* === Tooltip (D3 charts) === */
.chart-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
}

/* === HR Zone Colors === */
.zone-1 { color: #3498db; }
.zone-2 { color: #2ecc71; }
.zone-3 { color: #f1c40f; }
.zone-4 { color: #e67e22; }
.zone-5 { color: #e74c3c; }

.zone-bg-1 { background: #3498db; }
.zone-bg-2 { background: #2ecc71; }
.zone-bg-3 { background: #f1c40f; }
.zone-bg-4 { background: #e67e22; }
.zone-bg-5 { background: #e74c3c; }

/* === Compare Columns === */
.compare-grid {
  display: grid;
  gap: 16px;
}

/* === Filter Bar === */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-bar select,
.filter-bar input {
  width: auto;
  min-width: 160px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .nav {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
  }

  .nav-brand {
    margin-right: 0;
    width: 100%;
    margin-bottom: 8px;
  }

  .nav-links {
    width: 100%;
    flex-wrap: wrap;
  }

  .container, .container-wide {
    padding: 16px 12px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  table {
    font-size: 12px;
  }

  thead th, tbody td {
    padding: 8px 6px;
  }

  .btn-export {
    bottom: 16px;
    right: 16px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 20px;
  }
}

/* === Utility === */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #888; }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.hidden { display: none; }
