/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.9375rem;
  --font-size-md: 1.0625rem;
  --font-size-lg: 1.375rem;
  --font-size-xl: 1.75rem;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;

  /* Colors */
  --color-bg: #F2F2F7;
  --color-surface: #FFFFFF;
  --color-text: #1C1C1E;
  --color-text-secondary: #8E8E93;
  --color-border: #E5E5EA;
  --color-accent: #007AFF;
  --color-accent-hover: #0056CC;
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-danger: #FF3B30;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

/* ============================================
   AUTH / LOGIN SCREEN
   ============================================ */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

body:not(.auth-pending) .login-screen {
  display: none;
}

body.auth-pending .topbar,
body.auth-pending .tabs,
body.auth-pending .content {
  display: none;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-10) var(--space-8);
  text-align: center;
  max-width: 380px;
  width: 90%;
}

.login-card__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.login-card__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-8);
}

.btn--google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn--google:hover {
  background: var(--color-bg);
  box-shadow: var(--shadow-sm);
}

.google-icon {
  flex-shrink: 0;
}

.login-card__error {
  margin-top: var(--space-4);
  padding: var(--space-3);
  background: rgba(255, 59, 48, 0.08);
  border-radius: var(--radius-sm);
  color: var(--color-danger);
  font-size: var(--font-size-sm);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   TOP BAR
   ============================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.02em;
}

.topbar__actions {
  display: flex;
  gap: var(--space-2);
}

/* ============================================
   TAB NAVIGATION
   ============================================ */
.tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  position: sticky;
  top: 60px;
  z-index: 99;
}

.tabs__btn {
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tabs__btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.tabs__btn--active {
  background: var(--color-accent);
  color: #fff;
}

.tabs__btn--active:hover {
  background: var(--color-accent-hover);
  color: #fff;
}

/* ============================================
   PANELS
   ============================================ */
.panel {
  display: none;
  padding: var(--space-6);
  max-width: 960px;
  margin: 0 auto;
}

.panel--active {
  display: block;
}

/* ============================================
   CARD
   ============================================ */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
}

/* ============================================
   DATE NAVIGATION
   ============================================ */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.date-nav__label {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  min-width: 220px;
  text-align: center;
}

.date-nav__btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  font-size: var(--font-size-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  font-family: var(--font-family);
  color: var(--color-text);
}

.date-nav__btn:hover {
  background: var(--color-border);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  padding: var(--space-2) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

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

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

.btn--ghost {
  background: transparent;
  color: var(--color-accent);
}

.btn--ghost:hover {
  background: rgba(0, 122, 255, 0.08);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
}

.btn--danger:hover {
  background: #E0332B;
}

.btn--small {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
}

.btn--outline {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.btn--outline:hover {
  background: var(--color-bg);
}

.btn--outline.active {
  border-color: var(--color-accent);
  background: rgba(0, 122, 255, 0.08);
  color: var(--color-accent);
}

/* ============================================
   FORM INPUTS
   ============================================ */
input, select, textarea {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition-fast);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
}

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

/* ============================================
   HABITS
   ============================================ */
.habits-summary {
  text-align: center;
  margin-bottom: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.habits-summary strong {
  color: var(--color-success);
  font-weight: var(--font-weight-semibold);
}

.habit-list {
  list-style: none;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.habit-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition-fast);
}

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

.habit-item:hover {
  background: var(--color-bg);
}

.habit-item__checkbox {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border: 2px solid var(--color-border);
  border-radius: 7px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.habit-item__checkbox:checked {
  background: var(--color-success);
  border-color: var(--color-success);
}

.habit-item__checkbox:checked::after {
  content: "\2713";
  color: #fff;
  font-size: 15px;
  font-weight: bold;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.habit-item__checkbox:hover {
  border-color: var(--color-success);
}

.habit-item__label {
  flex: 1;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
}

.habit-item__streak {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.habit-item__streak--active {
  color: var(--color-warning);
  background: rgba(255, 149, 0, 0.1);
}

.habit-item--notes {
  padding: 0 var(--space-5) var(--space-4) calc(26px + var(--space-5) + var(--space-3));
  border-bottom: 1px solid var(--color-border);
}

.habit-notes-input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  background: var(--color-bg);
}

.habit-notes-input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
}

/* ============================================
   WORKOUTS
   ============================================ */
.weighin-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.weighin-row label {
  margin-bottom: 0;
  white-space: nowrap;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.weighin-row input {
  width: 120px;
}

.weighin-row .unit {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.workout-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-3);
}

.workout-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.workout-card__type {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: capitalize;
  color: #fff;
}

.workout-card__type--cardio { background: #FF2D55; }
.workout-card__type--lifting { background: #007AFF; }
.workout-card__type--calisthenics { background: #34C759; }
.workout-card__type--stretching { background: #AF52DE; }

.workout-card__duration {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.workout-card__notes {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
}

.exercise-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  margin-top: var(--space-2);
}

.exercise-table th {
  text-align: left;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.exercise-table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.exercise-table tr:last-child td {
  border-bottom: none;
}

.exercise-name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  padding: var(--space-2) 0 var(--space-1);
}

/* Workout form */
.workout-form {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-top: var(--space-4);
}

.exercise-builder {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.exercise-entry {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.exercise-entry__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.exercise-entry__header input {
  flex: 1;
}

.set-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--font-size-sm);
}

.set-row__label {
  width: 50px;
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
}

.set-row input {
  width: 64px;
  text-align: center;
}

/* Stepper +/- buttons */
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper input {
  border: none;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  border-radius: 0;
  width: 56px;
  text-align: center;
  padding: var(--space-1) var(--space-1);
  font-size: var(--font-size-sm);
}

.stepper input:focus {
  box-shadow: none;
}

.stepper__btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  font-family: var(--font-family);
}

.stepper__btn:hover {
  background: var(--color-border);
}

/* Cardio builder */
.cardio-builder {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ============================================
   FOOD & MACROS
   ============================================ */
.food-summary__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
  text-align: center;
}

.food-summary__item {
  padding: var(--space-2);
}

.food-summary__value {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.food-summary__label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.food-summary__value--calories { color: var(--color-accent); }
.food-summary__value--protein { color: var(--color-success); }
.food-summary__value--carbs { color: var(--color-warning); }
.food-summary__value--fat { color: var(--color-danger); }

.meal-group {
  margin-bottom: var(--space-4);
}

.meal-group__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  text-transform: capitalize;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
  padding-left: var(--space-2);
}

.food-entry {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.food-entry__desc {
  font-weight: var(--font-weight-medium);
  flex: 1;
}

.food-entry__macros {
  display: flex;
  gap: var(--space-3);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin-right: var(--space-3);
}

.food-form {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-top: var(--space-4);
}

/* ============================================
   SCHEDULE
   ============================================ */
.panel--wide {
  max-width: 1100px;
}

.schedule-layout {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
}

.schedule-sidebar {
  width: 180px;
  flex-shrink: 0;
  position: sticky;
  top: 120px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

.schedule-main {
  flex: 1;
  min-width: 0;
}

.schedule-toolbar__row {
  margin-bottom: var(--space-3);
}

.schedule-toolbar__label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.increment-toggle {
  display: flex;
  gap: var(--space-1);
  width: 100%;
}

.increment-toggle .btn {
  flex: 1;
}

.activity-palette {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.activity-pill {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: #fff;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  user-select: none;
}

.activity-pill:hover {
  opacity: 0.85;
}

.activity-pill--selected {
  border-color: var(--color-text);
  box-shadow: var(--shadow-md);
  transform: scale(1.05);
}

.activity-pill--eraser {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.activity-pill--eraser.activity-pill--selected {
  border-color: var(--color-text);
}

.schedule-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 1px;
  background: var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.schedule-grid__time {
  background: var(--color-surface);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
}

.schedule-grid__slot {
  background: var(--color-surface);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: background var(--transition-fast);
  user-select: none;
}

.schedule-grid__slot:hover {
  background: var(--color-bg);
}

.schedule-grid__slot--filled {
  color: #fff;
}

.schedule-grid__slot--filled:hover {
  opacity: 0.9;
}

/* ============================================
   REPORTS
   ============================================ */
.reports-toolbar {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: var(--space-4);
}

.report-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.report-card__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-4);
}

.report-card canvas {
  width: 100% !important;
  max-height: 280px;
}

.streak-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background: var(--color-bg);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.streak-badge__count {
  font-weight: var(--font-weight-semibold);
  color: var(--color-warning);
}

.report-stat {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.report-stat:last-child {
  border-bottom: none;
}

.report-stat__label {
  color: var(--color-text-secondary);
}

.report-stat__value {
  font-weight: var(--font-weight-semibold);
}

/* ============================================
   UTILITIES
   ============================================ */
.text-center { text-align: center; }
.text-secondary { color: var(--color-text-secondary); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }

.empty-state {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

/* Fade-in animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel--active {
  animation: fadeIn 0.2s ease;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .panel {
    padding: var(--space-4);
  }

  .topbar {
    padding: var(--space-3) var(--space-4);
  }

  .tabs {
    padding: var(--space-2) var(--space-4);
  }

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

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

  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .schedule-grid {
    grid-template-columns: 60px 1fr;
  }
}
