/* Train Track - Health Dashboard
   Design System: "Precision Vitals"
   A premium health tracking interface with clinical precision and warmth
*/

/* ============================================
   DESIGN TOKENS
   ============================================ */

:root {
  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* Light Theme */
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border: #e2e8f0;
  --border-subtle: #f1f5f9;

  /* Semantic Colors - Vitals */
  --vitals-primary: #0ea5e9;
  --vitals-positive: #10b981;
  --vitals-warning: #f59e0b;
  --vitals-alert: #ef4444;
  --vitals-sleep: #8b5cf6;
  --vitals-activity: #f97316;
  --vitals-heart: #ec4899;

  /* Accent */
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --accent-glow: rgba(14, 165, 233, 0.12);
  --accent-glow-strong: rgba(14, 165, 233, 0.2);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 0 24px var(--accent-glow);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 100px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Dark Theme */
body.dark {
  --bg: #0c1222;
  --bg-elevated: #162032;
  --bg-subtle: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --border: #2d3a4f;
  --border-subtle: #1e293b;

  --accent-glow: rgba(14, 165, 233, 0.15);
  --accent-glow-strong: rgba(14, 165, 233, 0.25);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ============================================
   BASE STYLES
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-width: 320px;
}

/* Subtle background texture */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  opacity: 0.15;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.5' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

body.dark::before {
  opacity: 0.08;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-subtle);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
  border: 2px solid var(--bg-subtle);
  transition: background var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-subtle);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg-subtle);
}

/* ============================================
   FOCUS STATES - Accessibility
   ============================================ */

/* Remove default outline, we'll add our own */
*:focus {
  outline: none;
}

/* Visible focus ring for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Links */
a:focus-visible {
  outline-offset: 3px;
  border-radius: 2px;
}

/* Buttons get a glow effect */
button:focus-visible,
.btn:focus-visible,
input[type="submit"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--accent-glow);
}

/* Form inputs */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Cards and panels */
.trend-card:focus-visible,
.card:focus-visible,
.insight-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--shadow-glow);
}

/* Details/summary elements */
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

/* Table rows */
tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-glow);
}

/* Nav links */
.nav-link:focus-visible,
.header-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Tag items in journal */
.tag-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--accent-glow);
}

/* Time range selector */
.time-range a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

/* Skip link for screen readers */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-md);
  background: var(--accent);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 1000;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-md);
}

main {
  padding: var(--space-lg);
  max-width: 1400px;
  margin: 0 auto;
}

/* Typography */
h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  color: var(--text);
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

/* Data Numbers - Monospace for alignment */
.data-value, .trend-value, .card .value, .glucose-stats strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ============================================
   APP HEADER
   ============================================ */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem var(--space-lg);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.85);
}

body.dark .app-header {
  background: rgba(22, 32, 50, 0.9);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header-logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
}

.header-title:hover {
  text-decoration: none;
  color: var(--text);
}

.header-title:hover .header-logo {
  transform: scale(1.05);
  transition: transform var(--transition-fast);
}

.nav-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.nav-link:hover {
  color: var(--text);
  background: var(--accent-glow);
  text-decoration: none;
}

.header-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.header-actions form {
  margin: 0;
}

.last-sync {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-right: var(--space-sm);
}

.theme-toggle {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: var(--space-sm) 0.75rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1;
}

.theme-toggle:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.logout-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.logout-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

/* ============================================
   TIME RANGE SELECTOR
   ============================================ */

.time-range {
  display: inline-flex;
  gap: 2px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xl);
}

.time-range a {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.time-range a:hover {
  color: var(--text);
  text-decoration: none;
}

.time-range a.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   TRENDS SECTION
   ============================================ */

.trends-section {
  margin-bottom: var(--space-2xl);
}

.trends-section > h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.trends-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 45%), 1fr));
  gap: var(--space-md);
}

/* ============================================
   TREND CARDS - Hero Element
   ============================================ */

.trend-card {
  position: relative;
  background: var(--bg-elevated);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all var(--transition-base);
  animation: fadeSlideIn 0.4s ease-out backwards;
}

.trend-card:nth-child(1) { animation-delay: 0.02s; }
.trend-card:nth-child(2) { animation-delay: 0.04s; }
.trend-card:nth-child(3) { animation-delay: 0.06s; }
.trend-card:nth-child(4) { animation-delay: 0.08s; }
.trend-card:nth-child(5) { animation-delay: 0.10s; }
.trend-card:nth-child(6) { animation-delay: 0.12s; }

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.trend-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border);
}

/* Colored top bar indicator */
.trend-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-indicator, var(--text-subtle));
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.trend-card:hover::before {
  opacity: 1;
}

.trend-card.trend-positive { --card-indicator: var(--vitals-positive); }
.trend-card.trend-negative { --card-indicator: var(--vitals-alert); }
.trend-card.trend-neutral { --card-indicator: var(--text-subtle); }

.trend-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-sm);
}

.trend-header h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.trend-arrow {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
}

.trend-up-color { color: var(--vitals-positive); }
.trend-down-color { color: var(--vitals-alert); }
.trend-flat-color { color: var(--text-subtle); }

.trend-value {
  font-family: var(--font-mono);
  font-size: 1.875rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: var(--space-xs);
}

.trend-value .unit {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.125rem;
}

.trend-delta {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: var(--space-xs);
}

.trend-delta.positive { color: var(--vitals-positive); }
.trend-delta.negative { color: var(--vitals-alert); }
.trend-delta.neutral { color: var(--text-muted); }

.trend-delta .delta-value {
  font-family: var(--font-mono);
  font-weight: 500;
}

.trend-delta .delta-pct {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-left: 0.25rem;
}

.trend-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-xs);
}

.trend-avg {
  font-size: 0.7rem;
  color: var(--text-subtle);
}

.sparkline {
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

.trend-card:hover .sparkline {
  opacity: 1;
}

/* ============================================
   INSIGHTS SECTION
   ============================================ */

.insights-section {
  margin-bottom: var(--space-2xl);
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
  gap: var(--space-md);
}

.insight-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: fadeSlideIn 0.4s ease-out backwards;
  animation-delay: 0.15s;
}

.insight-panel:nth-child(2) {
  animation-delay: 0.2s;
}

.insight-panel summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  transition: background var(--transition-fast);
}

.insight-panel summary:hover {
  background: var(--bg-subtle);
}

.insight-panel summary::-webkit-details-marker {
  display: none;
}

.insight-panel summary::before {
  content: "›";
  font-size: 1.1rem;
  font-weight: 400;
  margin-right: var(--space-sm);
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.insight-panel[open] summary::before {
  transform: rotate(90deg);
}

.insight-panel summary .regen-btn {
  font-size: 0.75rem;
  font-weight: 500;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.insight-panel summary .regen-btn:hover {
  background: var(--accent);
  color: white;
  text-decoration: none;
}

.insight-panel turbo-frame,
.insight-panel > div:not(:first-child) {
  display: block;
  padding: var(--space-lg) var(--space-xl) var(--space-xl);
  border-top: 1px solid var(--border-subtle);
}

.insight-text {
  line-height: 1.7;
  font-size: 0.9rem;
  color: var(--text);
}

.insight-text p {
  margin: 0 0 var(--space-md) 0;
}

.insight-text strong {
  color: var(--accent);
  font-weight: 600;
}

.insight-text h1, .insight-text h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: var(--space-lg) 0 var(--space-sm) 0;
  color: var(--text);
}

.insight-text h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: var(--space-md) 0 var(--space-xs) 0;
  color: var(--text);
}

.insight-text ul, .insight-text ol {
  margin: var(--space-sm) 0;
  padding-left: var(--space-lg);
}

.insight-text li {
  margin-bottom: var(--space-xs);
}

.cache-info {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-bottom: var(--space-sm);
}

.loading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: var(--space-md);
}

.loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Skeleton Loading */
.skeleton {
  padding: var(--space-lg);
}

.skeleton-line {
  height: 1rem;
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 25%,
    var(--border) 50%,
    var(--bg-subtle) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-line.short {
  width: 40%;
}

.skeleton-line.medium {
  width: 70%;
}

.skeleton-line.heading {
  height: 1.25rem;
  width: 50%;
  margin-bottom: var(--space-md);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   CHARTS
   ============================================ */

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.chart-container {
  background: var(--bg-elevated);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  animation: fadeSlideIn 0.4s ease-out backwards;
  animation-delay: 0.25s;
  overflow: hidden;
}

/* Constrain Chartkick canvas */
.chart-container > div {
  max-width: 100%;
  overflow: hidden;
}

/* Standardize all chart heights */
.chart-container canvas,
.chart-container > div {
  height: 350px !important;
  max-height: 350px;
}

.chart-container h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-md);
}

.chart-container.chart-tall {
  grid-column: 1 / -1;
}

.chart-container.chart-tall canvas {
  height: 320px !important;
}

.no-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  color: var(--text-subtle);
  text-align: center;
  font-size: 0.9rem;
}

.no-data::before {
  content: '○';
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
  opacity: 0.4;
}

/* ============================================
   SUMMARY CARDS
   ============================================ */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.card {
  background: var(--bg-elevated);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  text-align: center;
}

.card h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  font-weight: 600;
}

.card .value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.02em;
}

.card .value .subvalue {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ============================================
   TABLES
   ============================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-md);
  font-size: 0.9rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elevated);
}

thead::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--border);
}

th, td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

th {
  color: var(--text-subtle);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-elevated);
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:nth-child(even) {
  background: var(--bg-subtle);
}

tbody tr:hover {
  background: var(--accent-glow);
}

/* Numeric columns - right align and monospace */
td.numeric, th.numeric {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ============================================
   NAVIGATION
   ============================================ */

.main-nav {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--border);
  margin-top: var(--space-xl);
}

.main-nav a {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.main-nav a:hover {
  background: var(--accent-glow);
  color: var(--text);
  text-decoration: none;
}

/* ============================================
   JOURNAL PAGE
   ============================================ */

.journal-nav {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.journal-nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.journal-nav a:hover {
  background: var(--accent-glow);
  color: var(--text);
  text-decoration: none;
}

.journal-nav .date {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.journal-nav .today-link {
  width: auto;
  padding: 0 var(--space-md);
  font-size: 0.8rem;
  margin-left: auto;
}

.tag-section {
  margin-bottom: var(--space-xl);
}

.tag-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.tag-section h3 .date-hint {
  font-weight: 500;
  font-size: 0.75rem;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
}

.tags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.tag-form {
  margin: 0;
}

.tag-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.tag-item:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text);
}

.tag-item:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tag-item input[type="checkbox"] {
  display: none;
}

.tag-item:has(input:checked)::before {
  content: '✓';
  font-size: 0.7rem;
  margin-right: -0.25rem;
}

/* Tag Timeline */
.tag-timeline-section {
  margin: var(--space-xl) 0;
}

.tag-timeline-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.tag-timeline {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow-x: auto;
}

.timeline-header {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.timeline-header .timeline-label {
  width: 100px;
  flex-shrink: 0;
}

.timeline-header .timeline-dates {
  flex: 1;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0 2px;
}

.timeline-row {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.timeline-row .timeline-label {
  width: 100px;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: var(--space-sm);
}

.timeline-cells {
  flex: 1;
  display: flex;
  gap: 2px;
}

.timeline-cell {
  flex: 1;
  height: 12px;
  min-width: 8px;
  background: var(--bg-subtle);
  border-radius: 2px;
  transition: transform var(--transition-fast);
}

.timeline-cell:hover {
  transform: scaleY(1.3);
}

.timeline-cell.active {
  opacity: 0.9;
}

.timeline-cell.active:hover {
  opacity: 1;
}

.timeline-cell.today {
  box-shadow: inset 0 0 0 1px var(--text-muted);
}

/* Manage Tags */
.manage-tags {
  margin: var(--space-xl) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}

.manage-tags summary {
  padding: var(--space-md);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.manage-tags summary:hover {
  color: var(--text);
}

.manage-tags-content {
  padding: var(--space-md);
  border-top: 1px solid var(--border);
}

.add-tag-form {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.tag-input {
  flex: 1;
  min-width: 150px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast);
}

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

.tag-category {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.custom-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

.custom-tags-list .list-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0;
  margin-right: var(--space-sm);
}

.custom-tag-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.custom-tag-item small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.custom-tag-item .btn-delete {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0 var(--space-xs);
  font-size: 1rem;
  line-height: 1;
  transition: color var(--transition-fast);
}

.custom-tag-item .btn-delete:hover {
  color: var(--vitals-alert);
}

/* ============================================
   WORKOUT PAGES
   ============================================ */

.workout-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.workout-actions {
  display: flex;
  gap: var(--space-sm);
}

.workout-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.workout-extension {
  background: var(--bg-elevated);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-bottom: var(--space-xl);
}

.workout-extension h2 {
  margin-bottom: var(--space-md);
  font-size: 1rem;
}

.exercises-list .exercise-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.exercises-list .exercise-row:last-child {
  border-bottom: none;
}

.exercise-name {
  font-weight: 600;
}

.exercise-sets {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.extension-meta {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: var(--space-md);
}

/* Workouts Summary Section */
.workouts-summary {
  margin-bottom: var(--space-xl);
}

.workouts-summary h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-md);
}

.workouts-summary h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin: var(--space-lg) 0 var(--space-sm) 0;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
}

.btn-small {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.8rem;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  text-decoration: none;
}

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

.btn-danger:hover {
  background: #dc2626;
  text-decoration: none;
}

.btn-link {
  color: var(--text-muted);
  background: transparent;
  padding: var(--space-xs);
}

.btn-link:hover {
  color: var(--accent);
}

button {
  font-family: var(--font-sans);
}

input, select, button {
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

/* ============================================
   LOGIN PAGE
   ============================================ */

.login-container {
  max-width: 340px;
  margin: 80px auto;
  text-align: center;
  animation: fadeSlideIn 0.5s ease-out;
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-lg);
}

.login-container h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.03em;
}

.login-container .subtitle {
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
  font-size: 0.95rem;
}

.login-form {
  background: var(--bg-elevated);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.login-form .field {
  margin-bottom: var(--space-md);
}

.login-form input[type="password"] {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  transition: border-color var(--transition-fast);
}

.login-form input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-form .btn {
  width: 100%;
  padding: var(--space-md);
  font-size: 1rem;
}

.login-form .error {
  color: var(--vitals-alert);
  margin-bottom: var(--space-md);
  font-size: 0.9rem;
}

/* ============================================
   FLASH MESSAGES
   ============================================ */

.notice {
  background: var(--vitals-positive);
  color: white;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-weight: 500;
  font-size: 0.9rem;
}

.alert {
  background: var(--vitals-alert);
  color: white;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-weight: 500;
  font-size: 0.9rem;
}

/* ============================================
   PAGE HEADER
   ============================================ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.page-header h1 {
  margin: 0;
}

/* ============================================
   CALENDAR HEATMAP
   ============================================ */

.heatmap-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  overflow-x: auto;
  animation: fadeSlideIn 0.4s ease-out backwards;
  animation-delay: 0.3s;
}

.heatmap-container h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-md);
}

.heatmap-wrapper {
  display: flex;
  gap: var(--space-xs);
}

.heatmap-days {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 22px;
  font-size: 0.65rem;
  color: var(--text-subtle);
}

.heatmap-days span {
  height: 12px;
  line-height: 12px;
}

.heatmap-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.heatmap-months {
  display: flex;
  font-size: 0.65rem;
  color: var(--text-subtle);
  margin-bottom: 4px;
  height: 14px;
}

.heatmap-month {
  text-align: left;
}

.heatmap-weeks {
  display: flex;
  gap: 3px;
}

.heatmap-week {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.heatmap-day {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--heatmap-empty, var(--bg-subtle));
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.heatmap-day:hover {
  transform: scale(1.3);
  z-index: 10;
  box-shadow: var(--shadow-md);
}

/* Intensity levels */
.heatmap-day[data-level="0"] { background: var(--bg-subtle); }
.heatmap-day[data-level="1"] { background: rgba(16, 185, 129, 0.25); }
.heatmap-day[data-level="2"] { background: rgba(16, 185, 129, 0.5); }
.heatmap-day[data-level="3"] { background: rgba(16, 185, 129, 0.75); }
.heatmap-day[data-level="4"] { background: rgb(16, 185, 129); }

/* Dark mode adjustments */
body.dark .heatmap-day[data-level="1"] { background: rgba(16, 185, 129, 0.2); }
body.dark .heatmap-day[data-level="2"] { background: rgba(16, 185, 129, 0.4); }
body.dark .heatmap-day[data-level="3"] { background: rgba(16, 185, 129, 0.6); }
body.dark .heatmap-day[data-level="4"] { background: rgba(16, 185, 129, 0.85); }

/* Tooltip */
.heatmap-day::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  pointer-events: none;
  z-index: 100;
  margin-bottom: 4px;
}

.heatmap-day:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Empty future days */
.heatmap-day.future {
  background: transparent;
  border: 1px dashed var(--border-subtle);
}

.heatmap-day.future:hover {
  transform: none;
  box-shadow: none;
  cursor: default;
}

.heatmap-day.future::after {
  display: none;
}

/* Legend */
.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  font-size: 0.7rem;
  color: var(--text-subtle);
}

.heatmap-legend-scale {
  display: flex;
  gap: 3px;
}

.heatmap-legend-scale span {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.heatmap-legend-scale span[data-level="0"] { background: var(--bg-subtle); }
.heatmap-legend-scale span[data-level="1"] { background: rgba(16, 185, 129, 0.25); }
.heatmap-legend-scale span[data-level="2"] { background: rgba(16, 185, 129, 0.5); }
.heatmap-legend-scale span[data-level="3"] { background: rgba(16, 185, 129, 0.75); }
.heatmap-legend-scale span[data-level="4"] { background: rgb(16, 185, 129); }

body.dark .heatmap-legend-scale span[data-level="1"] { background: rgba(16, 185, 129, 0.2); }
body.dark .heatmap-legend-scale span[data-level="2"] { background: rgba(16, 185, 129, 0.4); }
body.dark .heatmap-legend-scale span[data-level="3"] { background: rgba(16, 185, 129, 0.6); }
body.dark .heatmap-legend-scale span[data-level="4"] { background: rgba(16, 185, 129, 0.85); }

.heatmap-section {
  margin-bottom: var(--space-2xl);
}

/* ============================================
   JOURNAL SEARCH PAGE
   ============================================ */

.search-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  animation: fadeSlideIn 0.4s ease-out backwards;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.search-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.filter-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-xs);
}

.filter-section h3 .optional {
  font-weight: 400;
  color: var(--text-subtle);
  font-size: 0.75rem;
}

.filter-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.tags-filter-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.filter-category {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.category-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.filter-tag:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text);
}

.filter-tag.active,
.filter-tag:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.filter-tag input[type="checkbox"] {
  display: none;
}

.filter-dates {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-lg);
}

.date-inputs {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.date-field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.date-field input[type="date"] {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast);
}

.date-field input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-actions {
  display: flex;
  gap: var(--space-sm);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-subtle);
}

/* Search Results */
.search-results {
  animation: fadeSlideIn 0.4s ease-out backwards;
  animation-delay: 0.1s;
}

.search-results h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-lg);
}

.search-results h2 .results-range {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.result-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.result-card:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: translateX(4px);
}

.result-date {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.result-day {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.result-full-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  justify-content: flex-end;
}

.result-tag {
  font-size: 0.7rem;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.result-tag.highlighted {
  background: var(--accent);
  color: white;
}

.no-results, .search-empty {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.no-results .hint, .search-empty p {
  font-size: 0.9rem;
}

.no-results p:first-child {
  font-size: 1rem;
  margin-bottom: var(--space-sm);
}

/* ============================================
   GLUCOSE PAGE
   ============================================ */

.glucose-days {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.glucose-day-panel {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-lg);
  animation: fadeSlideIn 0.4s ease-out backwards;
}

.glucose-day-panel:nth-child(1) { animation-delay: 0.05s; }
.glucose-day-panel:nth-child(2) { animation-delay: 0.1s; }
.glucose-day-panel:nth-child(3) { animation-delay: 0.15s; }

.glucose-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.glucose-day-header h2 {
  font-size: 1rem;
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

.glucose-stats {
  display: flex;
  gap: var(--space-md);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.glucose-stats .stat strong {
  font-family: var(--font-mono);
  color: var(--text);
}

.glucose-chart-container {
  height: 200px;
  position: relative;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  main {
    padding: var(--space-md);
    overflow-x: hidden;
  }

  h1 {
    font-size: 1.5rem;
  }

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

  .trend-card {
    padding: var(--space-md);
  }

  .trend-value {
    font-size: 1.5rem;
  }

  .insights-grid {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .insight-panel {
    min-width: 0;
  }

  .charts {
    grid-template-columns: 1fr;
  }

  /* Header - stack on small screens */
  .app-header {
    padding: var(--space-sm) var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .header-nav {
    gap: var(--space-sm);
    flex-wrap: wrap;
  }

  .nav-link {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
  }

  .header-logo {
    width: 24px;
    height: 24px;
  }

  .header-title {
    font-size: 1rem;
  }

  .header-title span {
    display: none;
  }

  .header-actions {
    margin-left: auto;
  }

  /* Heatmap - allow horizontal scroll */
  .heatmap-container {
    padding: var(--space-md);
  }

  .heatmap-wrapper {
    overflow-x: auto;
    padding-bottom: var(--space-sm);
    -webkit-overflow-scrolling: touch;
  }

  /* Glucose charts */
  .glucose-day-panel {
    padding: var(--space-md);
  }

  .glucose-day-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }

  .glucose-stats {
    font-size: 0.75rem;
    gap: var(--space-sm);
  }

  /* Tables */
  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: var(--space-sm);
  }

  /* Journal */
  .journal-nav .date {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  main {
    padding: var(--space-sm);
  }

  h1 {
    font-size: 1.25rem;
  }

  .trends-section > h2 {
    font-size: 0.7rem;
  }

  .trends-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
  }

  .trend-card {
    padding: var(--space-sm) var(--space-md);
  }

  .trend-header h3 {
    font-size: 0.65rem;
  }

  .trend-value {
    font-size: 1.25rem;
  }

  .trend-delta {
    font-size: 0.7rem;
  }

  .trend-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }

  .sparkline {
    align-self: flex-end;
  }

  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .card {
    padding: var(--space-md);
  }

  .card .value {
    font-size: 1.25rem;
  }

  .time-range {
    width: 100%;
  }

  .time-range a {
    flex: 1;
    text-align: center;
    padding: var(--space-sm);
    font-size: 0.8rem;
  }

  /* Insights */
  .insight-panel summary {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.85rem;
  }

  .insight-panel turbo-frame,
  .insight-panel > div:not(:first-child) {
    padding: var(--space-md);
  }

  .insight-text {
    font-size: 0.85rem;
  }

  /* Chart containers */
  .chart-container {
    padding: var(--space-md);
  }

  .chart-container h2 {
    font-size: 0.8rem;
  }

  /* Heatmap legend */
  .heatmap-legend {
    font-size: 0.6rem;
  }

  /* Workout tables - horizontal scroll */
  .workouts-summary {
    overflow-x: auto;
  }

  /* Login page */
  .login-container {
    margin: 40px var(--space-md);
  }

  .login-logo {
    width: 64px;
    height: 64px;
  }

  .login-container h1 {
    font-size: 1.5rem;
  }
}

/* ============================================
   WORKOUT EXTENSION FORMS
   ============================================ */

.copy-notice {
  background: var(--accent);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-md);
  font-size: 0.9rem;
}

.workout-extension-form {
  background: var(--bg-elevated);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: var(--space-md);
}

.form-actions {
  margin-top: var(--space-lg);
  display: flex;
  gap: var(--space-sm);
}

/* Exercises Editor (Strength) */
.exercises-editor h2,
.cardio-editor h2 {
  font-size: 1rem;
  margin-bottom: var(--space-md);
}

.exercises-list {
  margin-bottom: var(--space-md);
}

.exercise-entry {
  background: var(--bg);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  border: 1px solid var(--border-subtle);
}

.exercise-header {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.exercise-name-input {
  flex: 1;
  padding: var(--space-sm);
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-sans);
}

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

.sets-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.set-entry {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: var(--bg-elevated);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.set-reps {
  width: 50px;
  padding: var(--space-xs);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  text-align: center;
  font-family: var(--font-mono);
}

.set-weight {
  width: 80px;
  padding: var(--space-xs);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  text-align: center;
  font-family: var(--font-mono);
}

.set-reps:focus,
.set-weight:focus {
  outline: none;
  border-color: var(--accent);
}

.set-separator {
  color: var(--text-muted);
  font-weight: 600;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 var(--space-xs);
  transition: color var(--transition-fast);
}

.btn-icon:hover {
  color: var(--vitals-alert);
}

.btn-small {
  font-size: 0.8rem;
  padding: var(--space-xs) var(--space-sm);
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

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

.add-exercise {
  width: 100%;
  padding: var(--space-sm);
  margin-top: var(--space-sm);
}

.no-exercises {
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-md);
  text-align: center;
}

/* Cardio Editor */
.form-group {
  margin-bottom: var(--space-md);
}

.form-row {
  display: flex;
  gap: var(--space-md);
}

.form-row .form-group {
  flex: 1;
}

.form-group label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 500;
  color: var(--text);
  font-size: 0.875rem;
}

.form-input,
.form-textarea {
  width: 100%;
  padding: var(--space-sm);
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* ============================================
   SYSTEM PAGES - Import Logs
   ============================================ */

.import-stats {
  margin-bottom: var(--space-xl);
}

.import-stats .summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
}

.import-stats .card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
}

.import-stats .card h3 {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--space-sm) 0;
}

.import-stats .card .value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
  margin: 0;
}

.import-history h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
}

.import-history table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.import-history th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.import-history td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.import-history tr:hover {
  background: var(--bg-subtle);
}

.import-history tr.error-row {
  background: rgba(239, 68, 68, 0.05);
}

.import-history tr.error-row:hover {
  background: rgba(239, 68, 68, 0.1);
}

.status-ok {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.1);
  color: var(--vitals-positive);
}

.status-error {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: rgba(239, 68, 68, 0.1);
  color: var(--vitals-alert);
  cursor: help;
}

.import-history .no-data {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
}

/* ============================================
   SYSTEM CONFIG
   ============================================ */

.config-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.config-item h3 {
  margin: 0 0 var(--space-xs) 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.config-description {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: var(--space-md);
}

.config-textarea {
  width: 100%;
  min-height: 200px;
  padding: var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
}

.config-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.config-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.config-actions {
  margin-top: var(--space-lg);
}

.weight-goal-inputs {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-md);
}

.goal-field {
  flex: 1;
}

.goal-field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.checkbox-option {
  margin-top: var(--space-md);
}

.checkbox-option label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.checkbox-option input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.ai-provider-inputs {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-md);
}

.api-key-field {
  flex: 2;
}

.config-select,
.config-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
}

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

.config-warning {
  color: var(--vitals-alert);
  font-size: 0.85rem;
  margin-top: var(--space-sm);
}

.flash-notice {
  background: var(--success-bg);
  color: var(--success-text);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

.data-status {
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
}

.silence-controls {
  margin-bottom: var(--space-lg);
}

.silence-status {
  margin-bottom: var(--space-sm);
  color: var(--text-muted);
}

.silence-form {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.days-input {
  width: 60px;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-align: center;
}

.inline-form {
  display: inline-block;
}

.log-weight-section {
  margin-bottom: var(--space-lg);
}

.weight-log-form {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.weight-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: flex-end;
}

.weight-form-field {
  flex: 1;
  min-width: 100px;
}

.weight-form-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.weight-form-field.checkbox {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.weight-form-field.checkbox label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: 0;
}

.weight-form-actions {
  display: flex;
  gap: var(--space-sm);
}

.data-table {
  width: 100%;
  margin-top: var(--space-md);
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.85rem;
}

/* ============================================
   MOOD SURVEY MODAL
   ============================================ */

.mood-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mood-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.mood-modal h2 {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  margin: 0 0 var(--space-xs) 0;
}

.mood-modal .mood-date {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0 0 var(--space-lg) 0;
}

.mood-slider {
  margin-bottom: var(--space-lg);
}

.mood-slider label {
  display: block;
  font-weight: 500;
  margin-bottom: var(--space-sm);
  color: var(--text);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.slider-label-left,
.slider-label-right {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 60px;
}

.slider-label-left {
  text-align: right;
}

.slider-label-right {
  text-align: left;
}

.mood-range {
  flex: 1;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}

.mood-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-fast);
}

.mood-range::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.mood-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.mood-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-xl);
}

.mood-actions .btn {
  min-width: 100px;
}

/* Weight modal */
.weight-modal {
  max-width: 350px;
}

.weight-field {
  margin-bottom: var(--space-md);
}

.weight-field label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.weight-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
}

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

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn-tertiary {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.85rem;
}

.btn-tertiary:hover {
  color: var(--text-primary);
}

#silence-options {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.silence-prompt {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.silence-buttons {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.btn-small {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.85rem;
}

/* Mood display on journal page */
.mood-display {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.mood-display h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 var(--space-md) 0;
  color: var(--text);
}

.mood-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.mood-bar-row:last-child {
  margin-bottom: 0;
}

.mood-bar-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 60px;
}

.mood-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.mood-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.mood-bar-fill.energy {
  background: var(--vitals-activity);
}

.mood-bar-fill.mood {
  background: var(--vitals-positive);
}

.mood-bar-fill.stress {
  background: var(--vitals-primary);
}

.mood-bar-value {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 35px;
  text-align: right;
}

.mood-display .no-mood {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-style: italic;
}
