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

html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  font-family: var(--font-family-body);
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  font-weight: var(--font-weight-regular);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

.container {
  max-width: 768px;
  margin: 0 auto;
  padding: var(--gap-screen);
  width: 100%;
}

@media (max-width: 640px) {
  .container {
    padding: var(--gap-md);
  }
}

/* ─── TYPOGRAPHY ─── */

.display {
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--font-weight-bold);
  font-optical-sizing: auto;
}

.title {
  font-size: var(--font-size-xl);
  line-height: var(--line-height-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--font-weight-semibold);
}

.subtitle {
  font-size: var(--font-size-lg);
  line-height: var(--line-height-tight);
  font-weight: var(--font-weight-semibold);
}

.body {
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  font-weight: var(--font-weight-regular);
}

.caption {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  letter-spacing: var(--tracking-wide);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── MATERIAL SURFACES ─── */

.surface {
  background: var(--surface-bg, var(--material-light));
  border-radius: var(--radius-lg);
  border: 1px solid var(--surface-border, var(--material-border));
  box-shadow: var(--shadow-xs);
  padding: var(--gap-lg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  will-change: transform, opacity;
}

.surface-elevated {
  background: var(--surface-elevated-bg, var(--material-light-strong));
  border-radius: var(--radius-lg);
  border: 1px solid var(--surface-elevated-border, var(--material-border));
  box-shadow: var(--shadow-md);
  padding: var(--gap-lg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  will-change: transform, opacity;
}

.surface-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--material-light);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--material-border);
  box-shadow: 
    0 1px 0 rgba(0, 0, 0, 0.03),
    0 2px 8px rgba(0, 0, 0, 0.03);
}

.surface-floating {
  position: fixed;
  bottom: var(--gap-md);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--material-light-strong);
  border-radius: var(--radius-full);
  border: 1px solid var(--material-border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  padding: var(--gap-sm) var(--gap-md);
  will-change: transform, opacity;
}

/* ─── BUTTONS ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  transition: none;
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97) !important;
}

.btn-primary {
  background: var(--color-blue-bright);
  color: #ffffff;
  padding: var(--gap-sm) var(--gap-md);
}

.btn-primary:hover {
  background: var(--color-blue);
}

.btn-secondary {
  background: var(--material-hover);
  color: var(--color-text-secondary);
  padding: var(--gap-sm) var(--gap-md);
  border: 1px solid var(--material-border);
  border-radius: var(--radius-lg);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: var(--gap-xs) var(--gap-sm);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.25rem;
  will-change: transform;
}

.btn-icon:active {
  transform: scale(0.9) !important;
}

/* ─── DATE NAVIGATION ─── */
.date-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--date-nav-size);
  height: var(--date-nav-size);
  border-radius: var(--radius-full);
  border: 1px solid var(--material-border);
  background: var(--date-nav-bg);
  color: var(--date-nav-color);
  font-size: 1.25rem;
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  padding: 0;
  will-change: transform, background-color;
}

.date-nav:hover {
  background: var(--date-nav-bg-hover);
}

.date-nav:active {
  transform: scale(0.93) !important;
}

/* ─── FORMS ─── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  margin-bottom: var(--gap-md);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  letter-spacing: var(--tracking-wide);
}

.form-input {
  width: 100%;
  padding: var(--gap-sm) var(--gap-md);
  font-family: inherit;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-regular);
  border: 1px solid var(--material-border);
  border-radius: var(--radius-lg);
  background: var(--material-light);
  color: var(--color-text);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  transition: none;
  will-change: border-color;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.6;
}

.form-textarea {
  width: 100%;
  min-height: 100px;
  padding: var(--gap-sm) var(--gap-md);
  font-family: inherit;
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  border: 1px solid var(--material-border);
  border-radius: var(--radius-lg);
  background: var(--material-light);
  color: var(--color-text);
  resize: vertical;
  transition: none;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-textarea::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.5;
}

/* ─── LAYOUT UTILITIES ─── */

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

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid {
  display: grid;
  gap: var(--gap-md);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-cols-7 {
  grid-template-columns: repeat(7, 1fr);
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--color-slate-800); }
.text-secondary { color: var(--color-slate-500); }
.text-success { color: var(--color-green); }
.text-warning { color: var(--color-amber); }
.text-danger { color: var(--color-red); }

.mt-xs { margin-top: var(--gap-xs); }
.mt-sm { margin-top: var(--gap-sm); }
.mt-md { margin-top: var(--gap-md); }
.mt-lg { margin-top: var(--gap-lg); }

.mb-xs { margin-bottom: var(--gap-xs); }
.mb-sm { margin-bottom: var(--gap-sm); }
.mb-md { margin-bottom: var(--gap-md); }
  .mb-lg { margin-bottom: var(--gap-lg); }

/* ─── SECTION SPACING ─── */
.section-spacing {
  margin-top: var(--gap-section);
}

.section-spacing-sm {
  margin-top: var(--gap-md);
}

.section-spacing-inner {
  margin-bottom: var(--gap-md);
}

/* ─── REDUCED MOTION ─── */

@media (prefers-reduced-motion: reduce) {
  .sheet, .snackbar, .sheet-overlay {
    transition: opacity 200ms ease !important;
    transform: none !important;
  }
  
  .timeline-phase, .record-item, .pill {
    transform: none !important;
  }
}

/* ─── SHEET (Bottom Sheet Modal) ─── */
.sheet-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sheet {
  width: 100%;
  max-width: 768px;
  background: var(--material-light-strong);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--material-border);
  border-bottom: none;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  transform: translateY(100%);
  will-change: transform;
}

.sheet-handle {
  width: 32px;
  height: 4px;
  background: var(--material-border);
  border-radius: var(--radius-full);
  margin: 8px auto;
}

.sheet-content {
  padding: var(--gap-lg) var(--gap-md);
  max-height: 70vh;
  overflow-y: auto;
}

/* ─── SNACKBAR ─── */
.snackbar {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: var(--gap-sm) var(--gap-lg);
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.85);
  color: #ffffff;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  will-change: transform, opacity;
}

/* ─── TIMELINE ─── */
.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.timeline-phase {
  display: flex;
  align-items: center;
  padding: var(--gap-sm);
  border-radius: var(--radius-md);
  background: var(--material-hover);
  border: 1px solid var(--material-border);
  will-change: transform, background-color;
}

.timeline-phase:active {
  transform: scale(0.98) !important;
}

.phase-dot {
  font-size: 1.25rem;
  line-height: 1;
}

/* ─── PHASE BADGES ─── */
.phase-badge {
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.phase-loss { background: rgba(245, 158, 11, 0.2); color: var(--color-amber); }
.phase-plateau { background: rgba(148, 163, 184, 0.2); color: var(--color-slate-500); }
.phase-gain { background: rgba(34, 197, 94, 0.2); color: var(--color-green); }

/* ─── PILLS ─── */
.pill {
  height: 44px;
  padding: 0 var(--gap-md);
  border-radius: var(--radius-full);
  border: 2px solid var(--material-border);
  background: var(--material-light-strong);
  color: var(--color-text);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  font-size: var(--font-size-body);
  will-change: transform, border-color, background-color;
  -webkit-tap-highlight-color: transparent;
}

.pill:active {
  transform: scale(0.95) !important;
}

.pill.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--color-blue);
  color: var(--color-blue);
}

/* ─── PROGRESS BAR ─── */
.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  will-change: width;
}

/* ─── HEATMAP ─── */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-xs);
  cursor: pointer;
  will-change: transform;
  min-height: 24px;
}

.heatmap-cell:active {
  transform: scale(0.92) !important;
}

.heatmap-cell.empty {
  background: transparent;
  cursor: default;
}

.heatmap-cell-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  height: 24px;
}

/* ─── RECORD LIST ─── */
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-sm);
  border-radius: var(--radius-md);
  background: var(--material-light);
  border: 1px solid var(--material-border);
  cursor: pointer;
  will-change: transform, background-color;
  -webkit-tap-highlight-color: transparent;
}

.record-item:active {
  transform: scale(0.98) !important;
  background: var(--material-hover);
}

.record-weight {
  font-weight: var(--font-weight-bold);
  font-size: 1.1rem;
}

.record-date {
  color: var(--color-slate-500);
  font-size: var(--font-size-sm);
}

.record-meals {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.1);
  color: var(--color-blue);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

/* ─── BUTTONS ─── */
.btn-small {
  padding: var(--gap-xs) var(--gap-sm);
  font-size: var(--font-size-sm);
  min-height: 36px;
}

.btn-small.active {
  background: var(--color-blue);
  color: #ffffff;
}

/* ─── CHART ─── */
.chart-container {
  position: relative;
  height: 280px;
  margin-top: var(--gap-md);
}

/* ─── DARK MODE ─── */
[data-theme="dark"] {
  .phase-loss { background: rgba(245, 158, 11, 0.15); }
  .phase-plateau { background: rgba(148, 163, 184, 0.15); }
  .phase-gain { background: rgba(34, 197, 94, 0.15); }
}
