/* Workout Tracker - Mobile-first CSS */

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --muted: #888888;
  --accent: #2563eb;
  --danger: #dc2626;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 16px;
  --text-lg: 20px;
  --text-xl: 28px;

  --nav-height: 52px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==================== NAV ==================== */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.nav .app-name {
  font-weight: 600;
  font-size: 18px;
  margin-right: auto;
  color: var(--text);
  text-decoration: none;
}

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

.nav-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  transition: color 80ms ease, background 80ms ease;
}

.nav-links a:hover,
.nav-links a:active {
  color: var(--text);
  background: var(--surface);
}

.nav-links a.active {
  color: var(--accent);
  background: var(--surface);
}

.nav-links svg {
  width: 22px;
  height: 22px;
}

/* ==================== PAGE LAYOUT ==================== */
.page {
  padding-top: 64px;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  margin: 0 auto;
}

.page-header {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: 16px;
  padding-top: 4px;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.log-header .page-header {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

.add-activity-link {
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: white;
  text-decoration: none;
  padding: 8px 14px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.add-activity-link:active {
  opacity: 0.8;
}



.section {
  margin-bottom: 24px;
}

.section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: var(--text-sm);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  font-weight: 500;
}

/* ==================== TODAY'S LOG ==================== */
.log-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.log-row.has-sets {
  border-color: #334155;
}

.log-row.just-logged {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.log-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.log-row-header .activity-name {
  font-weight: 500;
  font-size: var(--text-base);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-row-header .log-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.log-input {
  width: 78px;
  height: 44px;
  font-size: var(--text-base);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  scroll-margin-bottom: 120px;
  -webkit-appearance: none;
}

.log-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.log-btn {
  height: 44px;
  min-width: 60px;
  padding: 0 14px;
  background: var(--accent);
  color: white;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 80ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.log-btn:active {
  opacity: 0.75;
}

/* Chips + undo area when logged */
.sets-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs);
  background: #222;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.undo-btn {
  min-width: 36px;
  height: 32px;
  padding: 0 6px;
  margin-left: 2px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.undo-btn:active {
  opacity: 0.7;
  background: #111;
}

.daily-total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 8px;
  font-family: 'JetBrains Mono', monospace;
}

.daily-total .label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.daily-total .value {
  font-size: var(--text-sm);
  color: var(--accent);
  font-weight: 500;
}

/* ==================== STATS BAR (2x2) ==================== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  font-weight: 500;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xl);
  font-weight: 500;
  line-height: 1.1;
  color: var(--text);
}

/* ==================== CHARTS ==================== */
.charts-section {
  margin-top: 8px;
}

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 8px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.chart-title {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.chart-wrapper {
  position: relative;
  height: 168px;
  width: 100%;
}

/* ==================== HISTORY PAGE ==================== */
.month-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.month-picker button {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  transition: opacity 80ms;
}

.month-picker button:active {
  opacity: 0.75;
}

.month-picker .month-label {
  font-size: var(--text-lg);
  font-weight: 600;
  min-width: 140px;
  text-align: center;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.history-card .date {
  font-weight: 600;
  font-size: var(--text-base);
  margin-bottom: 10px;
}

.history-card .activity-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: var(--text-sm);
}

.history-card .activity-line .name {
  color: var(--text);
}

.history-card .activity-line .total {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
}

.history-card .chips {
  margin-top: 6px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: var(--text-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.empty-state .empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
  line-height: 1;
}

.empty-state .empty-cta {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  text-decoration: none;
  border-radius: 6px;
  font-size: var(--text-sm);
}

.empty-state .empty-cta:active {
  opacity: 0.8;
}

.backup-reminder {
  background: #1f2937;
  border: 1px solid #f59e0b;
  color: #fcd34d;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: var(--text-sm);
}

.backup-reminder a {
  color: #60a5fa;
  font-weight: 500;
  margin-left: 6px;
}

.backup-reminder a:hover {
  text-decoration: underline;
}

.backup-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

#backup-restore {
  scroll-margin-top: 80px;
}

.last-backup-info {
  font-size: var(--text-sm);
  margin-bottom: 12px;
  color: var(--text);
}

.backup-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.backup-note {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.4;
}

.backup-note code {
  background: #222;
  padding: 1px 4px;
  border-radius: 3px;
}

/* ==================== SETTINGS PAGE ==================== */
.activity-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.activity-item {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 8px 0 4px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background 80ms;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-item .drag-handle {
  width: 22px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 16px;
  opacity: 0.7;
  cursor: grab;
  user-select: none;
}

.activity-item .drag-handle:active {
  cursor: grabbing;
  opacity: 1;
}

.activity-item .name {
  flex: 1;
  font-weight: 500;
  padding-left: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-item .type-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-right: 8px;
  white-space: nowrap;
}

.activity-item .delete-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
}

.activity-item .delete-btn:active:not([disabled]) {
  opacity: 0.75;
}

.activity-item .delete-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  color: var(--muted);
}

.reorder-arrows {
  display: flex;
  flex-direction: column;
  margin-right: 2px;
  gap: 1px;
}

.reorder-arrows button {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
  padding: 0;
}

.reorder-arrows button:active {
  background: #111;
  opacity: 0.75;
}

.activity-item.dragging {
  opacity: 0.5;
}

.activity-item.drag-over {
  background: var(--bg);
}

/* Add Activity Form */
.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.add-form .form-row {
  margin-bottom: 12px;
}

.add-form label {
  display: block;
  font-size: var(--text-sm);
  color: var(--muted);
  margin-bottom: 6px;
}

.add-form input[type="text"] {
  width: 100%;
  height: 44px;
  font-size: var(--text-base);
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  scroll-margin-bottom: 120px;
}

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

.type-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.type-toggle button {
  flex: 1;
  height: 44px;
  background: var(--bg);
  border: none;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 80ms;
}

.type-toggle button.active {
  background: var(--accent);
  color: white;
}

.type-toggle button:active {
  opacity: 0.85;
}

.add-form .add-btn {
  width: 100%;
  height: 48px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: var(--text-base);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 4px;
}

.add-form .add-btn:active {
  opacity: 0.8;
}

/* ==================== TOOLTIPS / MESSAGES ==================== */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: var(--text);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms;
  margin-bottom: 6px;
  z-index: 10;
}

.tooltip:hover::after,
.tooltip:focus-within::after {
  opacity: 1;
}

/* ==================== FOCUS RINGS ==================== */
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.log-input:focus-visible {
  box-shadow: none;
}

/* ==================== DESKTOP ENHANCEMENTS ==================== */
@media (min-width: 768px) {
  .page {
    padding-left: 24px;
    padding-right: 24px;
    max-width: 960px;
  }

  .dashboard-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
    margin-bottom: 24px;
  }

  .dashboard-top .section {
    margin-bottom: 0;
  }

  .log-row {
    padding: 14px 16px;
  }

  .sets-area {
    gap: 10px;
  }

  .dashboard-stats .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chart-wrapper {
    height: 200px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .nav-links a,
  .log-btn,
  .month-picker button,
  .type-toggle button,
  .add-form .add-btn,
  .reorder-arrows button,
  .activity-item .delete-btn {
    transition: opacity 80ms ease, background 80ms ease, color 80ms ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Ensure no horizontal scroll */
body, .page, .nav, .log-row, .chips, .history-card {
  overflow-x: hidden;
}
