/* ELEMNT Design System — Cycling Coach */

/* ========== CUSTOM PROPERTIES ========== */
:root {
  --bg: #111113;
  --bg-card: #1a1a1e;
  --bg-sidebar: #0e0e10;
  --bg-input: #222228;
  --border: #2a2a30;
  --border-hover: #3a3a42;
  --text: #ffffff;
  --text-muted: #888892;
  --text-dim: #555560;
  --z1: #8b8b8b; --z2: #4a90d9; --z3: #50b848; --z4: #f5c542; --z5: #f59e42; --z6: #e84545; --z7: #c040c0;
  --good: #50b848; --warn: #f5c542; --alert: #e84545;
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Outfit', sans-serif;
  --sidebar-w: 56px;
}

/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  margin: 0;
}

a { color: inherit; text-decoration: none; }

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0; z-index: 50;
}
.sidebar-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px; color: var(--text-dim);
  cursor: pointer; position: relative; transition: color 0.15s;
}
.sidebar-icon:hover { color: var(--text-muted); }
.sidebar-icon.active { color: var(--text); }
.sidebar-icon.active::before {
  content: ''; position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%); width: 3px; height: 20px;
  background: var(--text);
}
.sidebar-icon svg { width: 20px; height: 20px; }
.sidebar-spacer { flex: 1; }
.sidebar-icon.logout { color: var(--text-dim); margin-top: auto; }
.sidebar-icon.logout:hover { color: var(--alert); }

/* ========== MAIN LAYOUT ========== */
.main {
  margin-left: var(--sidebar-w); flex: 1;
  padding: 24px 32px; max-width: 1200px;
}

/* ========== HEADER ========== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-muted);
}
.user-label {
  font-size: 12px; color: var(--text-dim);
  font-family: var(--font-mono);
}

/* ========== PANELS & CARDS ========== */
.panel {
  background: var(--bg-card); border: 1px solid var(--border);
  margin-bottom: 20px;
}
.panel-padded { padding: 20px 24px; }
.panel-label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 16px;
  font-family: var(--font-sans);
}
.panel-header {
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}

/* ========== FITNESS TREND ========== */
.fitness-panel { background: var(--bg-card); border: 1px solid var(--border); margin-bottom: 20px; padding: 20px 24px; }
.fitness-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.fitness-item { text-align: center; }
.fitness-num { font-family: var(--font-mono); font-weight: 800; font-size: 3.5rem; line-height: 1; }
.fitness-sub { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-muted); margin-top: 6px; }
.fitness-num.negative { color: var(--alert); }
.sparkline { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 24px; margin-top: 10px; }
.spark-bar { width: 6px; border-radius: 1px; min-height: 2px; }

/* ========== WEEK / STAT GRIDS ========== */
.week-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin-bottom: 20px; }
.week-cell {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 16px 12px; text-align: center; transition: border-color 0.15s;
}
.week-cell:hover { border-color: var(--border-hover); }
.week-cell + .week-cell { border-left: none; }
.week-num { font-family: var(--font-mono); font-weight: 800; font-size: 2.5rem; line-height: 1; }
.week-unit { font-family: var(--font-mono); font-weight: 400; font-size: 0.9rem; color: var(--text-muted); }
.week-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.15em; color: var(--text-dim); margin-top: 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-bottom: 20px; }
.stat-cell {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 16px; text-align: center; transition: border-color 0.15s;
}
.stat-cell:hover { border-color: var(--border-hover); }
.stat-cell + .stat-cell { border-left: none; }
.stat-cell:nth-child(n+5) { border-top: none; }
.stat-num { font-family: var(--font-mono); font-weight: 800; font-size: 2.2rem; line-height: 1; }
.stat-unit { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-muted); }
.stat-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); margin-top: 4px; }

/* ========== PROFILE STRIP ========== */
.profile-strip {
  background: var(--bg-card); border: 1px solid var(--border);
  margin-bottom: 20px; padding: 14px 20px;
  display: flex; gap: 32px; align-items: center;
}
.profile-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); }
.profile-val { font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem; }
.profile-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }

/* ========== ACTIVITIES ========== */
.activities-panel { background: var(--bg-card); border: 1px solid var(--border); }
.activity-row {
  display: grid; grid-template-columns: 1fr auto;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
  text-decoration: none; color: inherit;
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: rgba(255,255,255,0.02); }
.activity-name { font-weight: 600; font-size: 14px; color: var(--text); }
.activity-date { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }
.activity-meta { display: flex; gap: 16px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.activity-stat { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.activity-stat strong { color: var(--text); font-weight: 700; }
.activity-right { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; }

/* TSS pills */
.tss-pill { font-family: var(--font-mono); font-size: 11px; font-weight: 700; padding: 2px 8px; display: inline-block; }
.tss-easy { background: rgba(80,184,72,0.15); color: var(--good); }
.tss-moderate { background: rgba(245,197,66,0.15); color: var(--warn); }
.tss-hard { background: rgba(245,158,66,0.15); color: var(--z5); }
.tss-hr-tag { font-weight: 600; opacity: 0.6; letter-spacing: 0.04em; }

/* Type badge */
.type-badge {
  font-size: 10px; padding: 1px 6px;
  border: 1px solid var(--border); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em; margin-left: 8px;
}

/* ========== PEAK POWERS ========== */
.peaks-panel { background: var(--bg-card); border: 1px solid var(--border); margin-bottom: 20px; }
.peaks-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; }
.peak-cell { padding: 16px 8px; text-align: center; border-right: 1px solid var(--border); }
.peak-cell:last-child { border-right: none; }
.peak-duration { font-size: 10px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.08em; margin-bottom: 4px; font-family: var(--font-mono); }
.peak-watts { font-family: var(--font-mono); font-weight: 800; font-size: 1.8rem; line-height: 1; }
.peak-watts span { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.pr-badge { display: inline-block; font-size: 9px; font-weight: 700; color: var(--good); border: 1px solid var(--good); padding: 1px 5px; margin-top: 4px; font-family: var(--font-mono); letter-spacing: 0.05em; }

/* ========== CHART PANELS ========== */
.chart-panel { background: var(--bg-card); border: 1px solid var(--border); margin-bottom: 20px; padding: 20px; }
.chart-legend { display: flex; gap: 16px; margin-bottom: 12px; }
.chart-legend-item { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 1px; }

/* ========== ZONE BARS ========== */
.zones-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.zone-panel { background: var(--bg-card); border: 1px solid var(--border); padding: 16px 20px; }
.zone-bar-row { display: flex; align-items: center; margin-bottom: 6px; }
.zone-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); width: 80px; flex-shrink: 0; }
.zone-bar-bg { flex: 1; height: 14px; background: rgba(255,255,255,0.03); position: relative; }
.zone-bar { height: 100%; transition: width 0.8s ease; }
.zone-pct { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); width: 48px; text-align: right; flex-shrink: 0; margin-left: 8px; }

/* ========== STATS TOGGLE (expandable) ========== */
.stats-toggle { background: var(--bg-card); border: 1px solid var(--border); margin-bottom: 20px; }
.stats-toggle-btn {
  width: 100%; padding: 12px 20px;
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font-sans); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.12em;
  cursor: pointer; text-align: left;
}
.stats-toggle-btn:hover { color: var(--text); }
.stats-content { display: none; padding: 16px 20px; border-top: 1px solid var(--border); }
.stats-content.open { display: block; }
.stats-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.03); }
.stats-row:last-child { border-bottom: none; }
.stats-label { font-size: 12px; color: var(--text-muted); }
.stats-val { font-family: var(--font-mono); font-size: 12px; font-weight: 700; }

/* ========== BREADCRUMB ========== */
.breadcrumb { font-size: 12px; color: var(--text-dim); margin-bottom: 16px; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }

/* ========== ACTIVITY DETAIL HEADER ========== */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.detail-header h1 { font-family: var(--font-sans); font-weight: 700; font-size: 1.5rem; }
.detail-header-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.detail-tss { text-align: right; }
.detail-tss-num { font-family: var(--font-mono); font-weight: 800; font-size: 2.8rem; line-height: 1; color: var(--z5); }
.detail-tss-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }

/* ========== TABS ========== */
.tab-nav { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 10px 16px; background: none; border: none;
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text-muted); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--text); }

/* ========== COACH FAB & PANEL ========== */
.coach-fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 48px; height: 48px; border-radius: 0;
  border: 2px solid var(--text-muted); background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
  z-index: 30;
}
.coach-fab:hover { border-color: var(--text); background: var(--bg-card); }
.coach-fab svg { width: 20px; height: 20px; color: var(--text-muted); }
.coach-fab:hover svg { color: var(--text); }

.chat-panel {
  position: fixed; right: 0; z-index: 50;
  background: var(--bg-card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.3s ease;
}
.chat-panel-desktop {
  top: 0; width: 420px; max-width: 90vw; height: 100%;
  transform: translateX(100%);
}
.chat-panel-desktop.open { transform: translateX(0); }

.chat-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 40;
}
.chat-overlay.open { opacity: 1; visibility: visible; }

/* Chat messages */
.chat-header {
  padding: 16px; border-bottom: 1px solid var(--border);
}
.chat-header h2 { font-size: 16px; font-weight: 600; }
.chat-header p { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.chat-input-area { padding: 16px; border-top: 1px solid var(--border); }

/* Coach chat page layout: chat-list sidebar + conversation area.
   On mobile the sidebar collapses to a slide-in drawer (see media query). */
.chat-layout {
  display: flex; gap: 16px;
  height: calc(100vh - 140px); min-height: 500px;
}
.chat-sidebar {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.chat-main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.chat-mobile-bar { display: none; }
.chat-drawer-overlay { display: none; }

.chat-bubble {
  display: inline-block; max-width: 85%;
  padding: 10px 14px; font-size: 13px;
  white-space: pre-wrap; line-height: 1.5;
}
.chat-bubble-user {
  background: var(--z2); color: var(--text);
}
.chat-bubble-assistant {
  background: var(--bg-input); color: var(--text);
}
.chat-bubble-error {
  background: rgba(232,69,69,0.15); color: var(--alert);
}

.chat-list-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; color: var(--text-muted);
  text-decoration: none; font-size: 13px;
  border-left: 2px solid transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.chat-list-item:hover { background: var(--bg-input); color: var(--text); }
.chat-list-item.active {
  border-left-color: var(--text); color: var(--text); background: var(--bg-input);
}
.chat-list-item-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-list-item-delete {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 2px 4px; font-size: 14px; line-height: 1;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.chat-list-item:hover .chat-list-item-delete { opacity: 1; }
.chat-list-item-delete:hover { color: var(--alert); }
.chat-list-group-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-dim); padding: 12px 12px 4px;
}

.memory-notification {
  margin-top: 6px; font-size: 11px; color: var(--text-dim);
  font-style: italic; line-height: 1.4;
}
.memory-notification-line { padding: 2px 0; }

/* ========== FORMS (dark theme) ========== */
.elemnt-input {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font-sans); font-size: 14px;
  padding: 10px 14px; width: 100%;
  outline: none; transition: border-color 0.15s;
}
.elemnt-input:focus { border-color: var(--text-muted); }
.elemnt-input::placeholder { color: var(--text-dim); }

.elemnt-select {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font-sans); font-size: 14px;
  padding: 10px 14px; width: 100%;
  outline: none; transition: border-color 0.15s;
  appearance: auto;
}
.elemnt-select:focus { border-color: var(--text-muted); }

.elemnt-checkbox {
  accent-color: var(--z2);
}

.elemnt-btn {
  background: var(--text); color: var(--bg);
  font-family: var(--font-sans); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 20px; border: none; cursor: pointer;
  transition: opacity 0.15s;
}
.elemnt-btn:hover { opacity: 0.9; }
.elemnt-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.elemnt-btn-secondary {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  font-family: var(--font-sans); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 20px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.elemnt-btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

.elemnt-btn-danger {
  background: transparent; color: var(--alert);
  border: 1px solid rgba(232,69,69,0.3);
  font-family: var(--font-sans); font-size: 12px;
  padding: 6px 12px; cursor: pointer;
  transition: border-color 0.15s;
}
.elemnt-btn-danger:hover { border-color: var(--alert); }

.elemnt-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); display: block; margin-bottom: 6px;
}

/* ========== TABLES (dark theme) ========== */
.elemnt-table { width: 100%; border-collapse: collapse; }
.elemnt-table thead { border-bottom: 1px solid var(--border); }
.elemnt-table th {
  padding: 10px 16px; text-align: left;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim);
}
.elemnt-table td {
  padding: 12px 16px;
  font-size: 13px; color: var(--text);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.elemnt-table tr:last-child td { border-bottom: none; }
.elemnt-table .text-right { text-align: right; }
.elemnt-table .mono { font-family: var(--font-mono); }

/* ========== BADGES ========== */
.badge {
  font-size: 10px; font-weight: 600; padding: 2px 8px;
  font-family: var(--font-mono); letter-spacing: 0.03em;
  display: inline-block;
}
.badge-green { background: rgba(80,184,72,0.15); color: var(--good); }
.badge-blue { background: rgba(74,144,217,0.15); color: var(--z2); }
.badge-purple { background: rgba(192,64,192,0.15); color: var(--z7); }
.badge-amber { background: rgba(245,197,66,0.15); color: var(--warn); }
.badge-red { background: rgba(232,69,69,0.15); color: var(--alert); }
.badge-gray { background: rgba(255,255,255,0.05); color: var(--text-dim); }

/* Priority badges */
.priority-a { background: rgba(232,69,69,0.15); color: var(--alert); border: 1px solid rgba(232,69,69,0.3); }
.priority-b { background: rgba(245,197,66,0.15); color: var(--warn); border: 1px solid rgba(245,197,66,0.3); }
.priority-c { background: rgba(255,255,255,0.05); color: var(--text-dim); border: 1px solid var(--border); }

/* ========== ALERT PANELS ========== */
.alert-warn {
  background: rgba(245,197,66,0.08); border: 1px solid rgba(245,197,66,0.2);
  padding: 14px 20px; margin-bottom: 20px;
}
.alert-warn p { font-size: 13px; color: var(--warn); }
.alert-warn a { color: var(--text); text-decoration: underline; }

.alert-error {
  background: rgba(232,69,69,0.08); border: 1px solid rgba(232,69,69,0.2);
  padding: 14px 20px; margin-bottom: 20px;
}
.alert-error p { font-size: 13px; color: var(--alert); }

/* ========== SYNC STATUS ========== */
.sync-status { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.sync-badge {
  font-size: 11px; font-weight: 600; padding: 3px 10px;
  font-family: var(--font-mono); letter-spacing: 0.03em;
}
.sync-connected { background: rgba(80,184,72,0.15); color: var(--good); }
.sync-btn {
  font-size: 12px; color: var(--text-muted); background: none; border: none;
  cursor: pointer; font-family: var(--font-sans);
  transition: color 0.15s;
}
.sync-btn:hover { color: var(--text); }

/* ========== FILTER PILLS ========== */
.filter-pills { display: flex; gap: 6px; margin-bottom: 20px; }
.filter-pill {
  font-size: 11px; font-weight: 600; padding: 4px 14px;
  text-transform: uppercase; letter-spacing: 0.08em;
  border: 1px solid var(--border); color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s;
}
.filter-pill:hover { border-color: var(--text-muted); color: var(--text-muted); }
.filter-pill.active { border-color: var(--text); color: var(--text); background: rgba(255,255,255,0.05); }

/* ========== MODAL (dark) ========== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.modal-content {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 24px; max-width: 480px; width: 100%; margin: 16px;
}

/* ========== HTMX INDICATORS ========== */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
[hx-indicator] .htmx-indicator { opacity: 0; }
[hx-indicator].htmx-request .htmx-indicator { opacity: 1; }

/* ========== ANIMATIONS ========== */
.fade-in { opacity: 0; transform: translateY(6px); animation: fadeIn 0.4s ease forwards; }
@keyframes fadeIn { to { opacity: 1; transform: translateY(0); } }
.d1 { animation-delay: 0.05s; } .d2 { animation-delay: 0.1s; } .d3 { animation-delay: 0.15s; }
.d4 { animation-delay: 0.2s; } .d5 { animation-delay: 0.25s; } .d6 { animation-delay: 0.3s; }

.chat-message-animate { animation: messageIn 0.3s ease; }
@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.thinking-dot {
  width: 8px; height: 8px; background: var(--text-dim);
  border-radius: 50%; animation: bounce 1.4s infinite ease-in-out;
}
.thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ========== PAGINATION ========== */
.pagination {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.pagination-info { font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); }
.pagination-links { display: flex; gap: 4px; }
.pagination-link {
  font-size: 12px; padding: 6px 14px;
  border: 1px solid var(--border); color: var(--text-muted);
  font-family: var(--font-mono); transition: border-color 0.15s, color 0.15s;
}
.pagination-link:hover { border-color: var(--text-muted); color: var(--text); }

/* ========== INTERVALS ========== */
.interval-card {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 12px 16px; margin-bottom: 8px;
}
.interval-header { display: flex; justify-content: space-between; align-items: center; }
.interval-title { font-size: 13px; font-weight: 600; }
.interval-time { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.interval-stats { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; }

/* ========== LAP TABLE ========== */
.lap-panel { padding: 0; overflow: hidden; }
.lap-panel .panel-label { padding: 14px 20px 8px; margin: 0; }
.lap-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.lap-table thead th {
  font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); font-weight: 500;
  text-align: left; padding: 10px 12px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.18);
  position: sticky; top: 0;
}
.lap-table thead th.num { text-align: right; }
.lap-table tbody tr.lap-row {
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background 0.12s;
}
.lap-table tbody tr.lap-row:hover { background: rgba(255,255,255,0.04); }
.lap-table tbody tr.lap-row.active { background: rgba(74,144,217,0.10); }
.lap-table tbody tr.lap-row.active td { box-shadow: inset 0 1px 0 rgba(74,144,217,0.4); }
.lap-table td { padding: 11px 12px; font-family: var(--font-mono); vertical-align: middle; }
.lap-table td.num { text-align: right; }
.lap-num {
  display: inline-block; width: 22px; height: 22px; line-height: 22px;
  border-radius: 50%; text-align: center;
  font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,0.06); color: var(--text);
}
.lap-name {
  font-family: var(--font-base, 'Outfit', sans-serif);
  color: var(--text-muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-block; max-width: 100%;
}
.power-pill { display: inline-flex; align-items: baseline; gap: 4px; font-weight: 700; }
.power-pill .unit { font-size: 10px; color: var(--text-dim); font-weight: 400; }
.zone-tag {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 9px; font-weight: 700; color: #000; vertical-align: 1px;
}
.relbar {
  display: block; height: 6px;
  background: rgba(255,255,255,0.04); border-radius: 2px; overflow: hidden;
}
.relbar > span { display: block; height: 100%; }

/* Lap detail (expanded row) */
.lap-detail-row td {
  padding: 0;
  background: rgba(0,0,0,0.22);
  border-bottom: 1px solid var(--border);
}
.lap-detail-content {
  display: grid; grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 28px; padding: 20px 24px;
  border-left: 3px solid var(--border);
}
.lap-detail-stats {
  display: flex; flex-direction: column; gap: 18px;
  align-items: center;
}

/* Time/distance header row at the top of the detail card — centered. */
.lap-time-row {
  display: flex; align-items: baseline; justify-content: center; gap: 36px;
  padding-bottom: 14px; border-bottom: 1px solid var(--border);
  width: 100%;
}
.lap-time-block { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.lap-time-block .v {
  font-family: var(--font-mono); font-size: 32px; font-weight: 700;
  line-height: 1; color: var(--text);
}
.lap-time-block .v .u {
  font-size: 13px; color: var(--text-dim); font-weight: 400; margin-left: 3px;
}
.lap-time-block.moving .v, .lap-time-block.secondary .v {
  font-size: 20px; color: var(--text-muted); font-weight: 600;
}
.lap-time-block .l {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-dim);
}

/* Avg/Max metric grid: row label on the right of the left column,
   then two centered numeric columns. The whole grid is centered in
   its container so the numbers visually balance the chart. */
.lap-stats-table {
  display: grid; grid-template-columns: auto 110px 110px;
  column-gap: 28px; row-gap: 10px;
  align-items: baseline;
}
.lap-stats-table .col-header {
  font-family: var(--font-mono); font-size: 9px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim);
  text-align: center;
}
.lap-stats-table .row-label {
  font-size: 12px; color: var(--text-muted); text-align: right;
  white-space: nowrap;
}
.lap-stats-table .cell {
  font-family: var(--font-mono); font-size: 15px; font-weight: 700;
  text-align: center; color: var(--text);
}
.lap-stats-table .cell .u {
  font-size: 10px; color: var(--text-dim); font-weight: 400; margin-left: 3px;
}
.lap-stats-table .cell.dim, .lap-stats-table .dim { color: var(--text-dim); font-weight: 400; }
.lap-mini-chart-wrap {
  position: relative; min-height: 140px;
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--border);
  padding: 8px;
}
.lap-mini-chart-wrap .panel-label {
  position: absolute; top: 6px; left: 10px;
  margin: 0; font-size: 9px; pointer-events: none; z-index: 1;
}
.lap-mini-chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 52px;
    flex-direction: row; justify-content: space-around;
    z-index: 1000;
    border-top: 1px solid var(--border);
    border-right: none;
  }
  .sidebar-icon { padding: 8px; margin-bottom: 0; }
  .sidebar-icon.active::before {
    left: 25%; right: 25%; top: 0;
    transform: none; width: 50%; height: 2px;
    border-radius: 0 0 2px 2px;
  }
  .sidebar-spacer { display: none; }
  .main { margin-left: 0; padding: 16px 16px 68px; }
  .fitness-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .fitness-num { font-size: 2.5rem; }
  .week-grid { grid-template-columns: repeat(3, 1fr); }
  .week-cell + .week-cell { border-left: 1px solid var(--border); }
  .week-cell:nth-child(n+4) { border-top: none; }
  .week-num { font-size: 1.8rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-cell + .stat-cell { border-left: 1px solid var(--border); }
  .stat-cell:nth-child(odd) + .stat-cell { border-left: none; }
  .stat-cell:nth-child(n+3) { border-top: none; }
  .stat-num { font-size: 1.8rem; }
  .peaks-grid { grid-template-columns: repeat(3, 1fr); }
  .peak-cell:nth-child(3) { border-right: none; }
  .peak-cell:nth-child(n+4) { border-top: 1px solid var(--border); }
  .zones-row { grid-template-columns: 1fr; }
  .activity-meta { gap: 10px; }
  .profile-strip { flex-wrap: wrap; gap: 16px; }

  /* Mobile chat panel: bottom sheet */
  .chat-panel-desktop {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 85vh;
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
  }
  .chat-panel-desktop.open { transform: translateY(0); }

  /* Lift FAB above the bottom nav (52px tall) */
  .coach-fab { bottom: 76px; }

  /* Render chat above the bottom nav (z-index: 1000) so the input isn't covered */
  .chat-panel { z-index: 1010; }
  .chat-overlay { z-index: 1005; }

  /* Coach chat page: chat list becomes a slide-in drawer so the
     conversation + input get the full viewport width.
     transform/animation are cleared because .fade-in leaves a non-none
     transform on this wrapper, which would otherwise make it the
     containing block for the position:fixed drawer (pinning it to the
     layout box instead of the viewport). */
  .chat-layout {
    display: block; height: calc(100vh - 124px); min-height: 0;
    transform: none; animation: none; opacity: 1;
  }
  .chat-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 280px; max-width: 82vw;
    margin: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1010;
  }
  .chat-sidebar.open { transform: translateX(0); }
  .chat-drawer-overlay {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0; visibility: hidden;
    transition: opacity 0.25s ease;
    z-index: 1009;
  }
  .chat-drawer-overlay.open { opacity: 1; visibility: visible; }
  .chat-main { height: 100%; }
  .chat-mobile-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .chat-drawer-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    background: none; border: 1px solid var(--border);
    color: var(--text-muted); font-size: 13px;
    padding: 7px 12px; cursor: pointer;
    font-family: var(--font-sans);
    transition: color 0.15s, border-color 0.15s;
  }
  .chat-drawer-toggle:hover { color: var(--text); border-color: var(--text-muted); }
}

/* ========== EMPTY STATES ========== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-dim); }
.empty-state svg { margin: 0 auto 12px; color: var(--text-dim); }
.empty-state p { font-size: 13px; margin-top: 4px; }

/* ========== LOGIN PAGE ========== */
.login-container {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.login-box {
  width: 100%; max-width: 400px;
}
.login-title {
  font-family: var(--font-mono); font-weight: 800; font-size: 1.8rem;
  text-align: center; margin-bottom: 8px;
}
.login-subtitle {
  font-size: 13px; color: var(--text-dim); text-align: center; margin-bottom: 32px;
}
