/* ─── CSS Variables ──────────────────────────────────────────── */
:root {
  --bg:        #13131e;
  --surface:   #1c1c2e;
  --surface2:  #252540;
  --border:    #2a2a45;
  --accent:    #7c6fff;
  --accent-d:  #6355e0;
  --teal:      #2dd4bf;
  --green:     #22c55e;
  --red:       #ef4444;
  --orange:    #f97316;
  --yellow:    #f59e0b;
  --blue:      #60a5fa;
  --text:      #f0f0f8;
  --muted:     #8585a8;
  --sidebar-w: 240px;
  --sidebar-collapsed-w: 76px;
  --nav-h:     64px;
  --radius:    16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --shadow:    0 8px 32px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
ul { list-style: none; }

/* ─── Heading font ───────────────────────────────────────────── */
h1, h2, h3, h4, .greeting-heading, .brand-name, .metric-value,
.day-name, .month-title, .exercise-name, .history-day {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.2px;
}

/* ─── Layout ─────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dvh adjusts when mobile browser chrome appears/disappears */
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 28px 0 24px;
  transition: width 0.28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

/* Collapsed state */
#sidebar.collapsed { width: var(--sidebar-collapsed-w); }
#sidebar.collapsed .brand-name,
#sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; pointer-events: none; }
#sidebar.collapsed .nav-brand { padding: 0 0 28px; justify-content: center; }
#sidebar.collapsed .nav-link { padding: 0; justify-content: center; }
#sidebar.collapsed .nav-links { padding: 0; }
#sidebar.collapsed #sidebar-toggle { left: 50%; transform: translateX(-50%); }
#sidebar.collapsed .nav-logo-img { display: none; }
#sidebar.collapsed .nav-brand { border-bottom: none; padding-bottom: 8px; }

.nav-logo-img {
  width: 130px; height: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px 20px;
  width: 100%;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
}
.brand-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  border-radius: 10px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  transition: opacity 0.2s, width 0.28s;
}

/* Toggle button */
#sidebar-toggle {
  position: absolute;
  bottom: 24px;
  left: 20px;
  width: 36px; height: 36px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  transition: background var(--transition), color var(--transition), left 0.28s;
}
#sidebar-toggle svg { width: 18px; height: 18px; }
#sidebar-toggle:hover { background: var(--surface2); color: var(--text); }

.nav-links { padding: 0 14px; display: flex; flex-direction: column; gap: 6px; width: 100%; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: all var(--transition);
  overflow: hidden;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); }
.nav-link:hover .nav-icon-wrap { background: var(--surface2); }
.nav-link.active { color: var(--text); }
.nav-link.active .nav-icon-wrap {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  box-shadow: 0 4px 14px rgba(124,111,255,0.4);
}
.nav-link.active .nav-icon-wrap svg { stroke: #fff; }

.nav-icon {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
/* Wrap icon in a circle */
.nav-icon-wrap {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  transition: background var(--transition), box-shadow var(--transition);
  flex-shrink: 0;
}
.nav-icon-wrap svg { width: 19px; height: 19px; }
.nav-label { white-space: nowrap; transition: opacity 0.2s, width 0.28s; letter-spacing: 0.01em; }


/* ─── Main content ───────────────────────────────────────────── */
#main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  height: 100vh;
  overflow: hidden;
  transition: margin-left 0.28s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
}
#sidebar.collapsed ~ #main-content,
body.sidebar-collapsed #main-content {
  margin-left: var(--sidebar-collapsed-w);
}
#views-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#views-wrapper::-webkit-scrollbar { width: 5px; }
#views-wrapper::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9px; }
#views-wrapper::-webkit-scrollbar-track { background: transparent; }

/* Views */
.view {
  display: none;
  padding: 32px 40px;
  max-width: 960px;
  margin: 0 auto;
  animation: fadeIn 0.22s ease;
}
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ─── View Header ────────────────────────────────────────────── */
.view-header { margin-bottom: 28px; }
.view-header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
  background: linear-gradient(90deg, #ffffff 0%, #c4b5fd 60%, #7c6fff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.greeting-heading {
  font-size: 1.75rem;
  font-weight: 700;
}
.subtitle { color: var(--muted); font-size: 0.875rem; margin-top: 4px; font-weight: 400; }

/* ─── Metric Cards ───────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.metric-card {
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.metric-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.06;
  background: radial-gradient(circle at top right, #fff, transparent 70%);
  pointer-events: none;
}
.metric-card:hover { transform: translateY(-3px); box-shadow: 0 12px 36px rgba(0,0,0,0.4); }
.metric-card:nth-child(1) { background: linear-gradient(145deg, #1a0d45 0%, #2e1b70 60%, #1e1040 100%); border-color: rgba(167,139,250,0.35); }
.metric-card:nth-child(2) { background: linear-gradient(145deg, #0a2525 0%, #0e3d38 60%, #092929 100%); border-color: rgba(45,212,191,0.3); }
.metric-card:nth-child(3) { background: linear-gradient(145deg, #181828 0%, #20202e 100%); border-color: rgba(255,255,255,0.07); }
.metric-card:nth-child(4) { background: linear-gradient(145deg, #1e0e06 0%, #3a2010 60%, #1e0e06 100%); border-color: rgba(249,115,22,0.3); }
.metric-card.accent { background: linear-gradient(145deg, #1a0d45 0%, #2e1b70 60%, #1e1040 100%); border-color: rgba(167,139,250,0.35); }
.metric-value {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -1px;
  margin-bottom: 8px;
  color: var(--text);
}
.metric-card:nth-child(1) .metric-value { color: #c4b5fd; }
.metric-card:nth-child(2) .metric-value { color: #5eead4; }
.metric-card:nth-child(4) .metric-value { color: #fb923c; }
.metric-card.accent .metric-value { color: #c4b5fd; }
.metric-label { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.metric-icon { margin-bottom: 10px; opacity: 0.5; }
.metric-icon svg { width: 22px; height: 22px; stroke: currentColor; }
.metric-card.accent .metric-icon { opacity: 0.7; color: #c4b5fd; }
.metric-card:nth-child(2) .metric-icon { color: #5eead4; }
.metric-card:nth-child(4) .metric-icon { color: #fb923c; }

/* ─── Plan Badge ─────────────────────────────────────────────── */
.plan-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 500;
  width: fit-content;
  margin-bottom: 24px;
  color: var(--muted);
}
.plan-badge .plan-icon { font-size: 1rem; }
.plan-badge strong { color: var(--text); font-weight: 600; }
.plan-switch-link { color: var(--accent); font-weight: 600; margin-left: 8px; font-size: 0.8rem; padding: 2px 10px; background: rgba(124,111,255,0.12); border-radius: 100px; }
.plan-switch-link:hover { background: rgba(124,111,255,0.22); }

/* ─── CTA Section ────────────────────────────────────────────── */
.cta-section {
  margin-bottom: 32px;
}
.logged-today {
  color: var(--green);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.cta-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.edit-log-picker {
  display: none;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.edit-log-picker.open {
  display: flex;
}

/* ─── Activity Grid ──────────────────────────────────────────── */
.section { margin-bottom: 32px; }
.section-title { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }

/* ─── Monthly Calendar ───────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.month-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.btn-month-nav {
  font-size: 1.4rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-month-nav:hover:not(:disabled) { background: var(--surface2); }
.btn-month-nav:disabled { opacity: 0.3; cursor: default; }
.month-dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.month-dow {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 0;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.month-cell {
  background: var(--surface);
  border-radius: 8px;
  padding: 8px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  border: 1px solid transparent;
}
.month-cell.month-empty { background: transparent; border: none; }
.month-cell.cal-active { background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.3); }
.month-cell.cal-planned { background: rgba(108,99,255,0.1); border-color: rgba(108,99,255,0.25); }
.month-cell.cal-missed { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.35); }
.month-cell.cal-today { border-color: var(--green) !important; box-shadow: 0 0 0 1px var(--green); }
.month-missed-label { font-size: 0.6rem; color: rgba(239,68,68,0.8); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.month-day-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}
.month-day-num.today-num { color: var(--green); }
.month-session {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--green);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-planned {
  font-size: 0.62rem;
  color: var(--accent);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-cell .cal-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  padding: 3px 7px;
  background: rgba(255,255,255,0.09);
  border-radius: 5px;
  color: var(--muted);
  margin-top: auto;
  align-self: flex-start;
  line-height: 1.4;
  white-space: nowrap;
}
.month-cell .cal-edit-btn:hover { color: var(--text); background: rgba(255,255,255,0.18); }

/* ── Mobile week day-list ──────────────────────────────────── */
.wday-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wday-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 14px;
  border: 1.5px solid transparent;
  min-height: 62px;
}
.wday-row.wday-active    { background: rgba(34,197,94,0.10);  border-color: rgba(34,197,94,0.28); }
.wday-row.wday-is-missed { background: rgba(239,68,68,0.09);  border-color: rgba(239,68,68,0.32); }
.wday-row.wday-is-planned{ background: rgba(108,99,255,0.09); border-color: rgba(108,99,255,0.22); }
.wday-row.wday-today     { border-color: var(--green) !important; box-shadow: 0 0 0 1px var(--green); }
.wday-date-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.wday-dow {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.wday-num {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.wday-num.today-num { color: var(--green); }
.wday-content { flex: 1; }
.wday-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.wday-logged  { background: rgba(34,197,94,0.15);  color: #4ade80; }
.wday-missed  { background: rgba(239,68,68,0.15);  color: #f87171; }
.wday-planned { background: rgba(108,99,255,0.18); color: #a78bfa; }
.wday-rest    { background: rgba(255,255,255,0.05); color: var(--muted); font-weight: 400; }
.wday-action  { display: flex; align-items: center; }
.wday-edit-btn, .wday-log-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  white-space: nowrap;
  line-height: 1;
}
.wday-edit-btn {
  background: rgba(255,255,255,0.1);
  color: var(--muted);
  border: none;
}
.wday-edit-btn:hover { background: rgba(255,255,255,0.18); color: var(--text); }
.wday-log-btn {
  background: rgba(108,99,255,0.18);
  color: var(--accent);
  text-decoration: none;
}
.wday-log-btn:hover { background: rgba(108,99,255,0.3); }

.activity-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.activity-cell {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.activity-cell.active { background: rgba(34,197,94,0.2); border-color: rgba(34,197,94,0.5); }
.activity-day { font-size: 0.7rem; color: var(--muted); font-weight: 600; }
.activity-cell.active .activity-day { color: var(--green); }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, #7c6fff, #a78bfa); color: #fff; box-shadow: 0 4px 18px rgba(124,111,255,0.35); }
.btn-primary:hover { background: linear-gradient(135deg, #6c5eff, #9575f5); transform: translateY(-1px); box-shadow: 0 6px 22px rgba(108,99,255,0.5); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: rgba(108,99,255,0.1); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-danger { background: rgba(239,68,68,0.12); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--radius); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-back { color: var(--muted); font-size: 0.875rem; font-weight: 500; display: flex; align-items: center; gap: 4px; margin-bottom: 8px; transition: color var(--transition); }
.btn-back:hover { color: var(--accent); }

/* ─── Log Workout View ───────────────────────────────────────── */
.section-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; display: block; }

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all var(--transition);
  cursor: pointer;
  height: 110px;
  justify-content: flex-end;
}
.day-card:hover { border-color: var(--accent); background: rgba(108,99,255,0.08); transform: translateY(-2px); box-shadow: var(--shadow); }
.day-card-today {
  border-color: var(--green) !important;
  background: rgba(34,197,94,0.08) !important;
  box-shadow: 0 0 0 1px var(--green), 0 0 18px rgba(34,197,94,0.25);
  animation: day-glow 2s ease-in-out infinite alternate;
}
@keyframes day-glow {
  from { box-shadow: 0 0 0 1px var(--green), 0 0 12px rgba(34,197,94,0.2); }
  to   { box-shadow: 0 0 0 1px var(--green), 0 0 28px rgba(34,197,94,0.45); }
}
.day-today-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--green);
  background: rgba(34,197,94,0.15);
  border-radius: 4px;
  padding: 2px 7px;
  align-self: flex-start;
  margin-bottom: auto;
}
.day-name { font-weight: 700; font-size: 1rem; }
.day-exercises { font-size: 0.8rem; color: var(--muted); }

/* Gym time row */
.gym-time-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}
.gym-time-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.gym-time-duration {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface2);
  border-radius: 10px;
  padding: 8px 14px;
  margin-bottom: 12px;
  white-space: nowrap;
}
.gym-time-error {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  color: #f87171;
  text-align: center;
  margin-bottom: 8px;
  display: none;
}
.gym-time-error.visible { display: block; }

/* Log date picker */
.log-date-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.log-date-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.log-date-input {
  width: auto;
  min-width: 160px;
  color-scheme: dark;
}

/* Exercise Logger */
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 14px;
}
.exercise-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.exercise-name {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-add-set {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(108,99,255,0.3);
  background: rgba(108,99,255,0.08);
  transition: all var(--transition);
}
.btn-add-set:hover { background: rgba(108,99,255,0.18); }

.exercise-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.btn-del-exercise {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.btn-del-exercise:hover { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.3); }

/* Add exercise row */
.add-exercise-row {
  display: flex;
  gap: 10px;
  margin: 12px 0 20px;
  align-items: center;
}
.add-exercise-row .input {
  flex: 1;
  min-width: 0;
}
@media (max-width: 768px) {
  .add-exercise-row {
    flex-direction: column;
    gap: 8px;
  }
  .add-exercise-row .btn { width: 100%; }
}

.sets-table { display: flex; flex-direction: column; gap: 8px; }
.sets-header {
  display: grid;
  grid-template-columns: 18px 32px 1fr 1fr 28px 28px;
  gap: 8px;
  padding: 0 4px;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.set-row {
  display: grid;
  grid-template-columns: 18px 32px 1fr 1fr 28px 28px;
  gap: 8px;
  align-items: center;
  animation: slideIn 0.15s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

.set-num { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-align: center; }
.set-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.9rem;
  width: 100%;
  color: var(--text);
  transition: border-color var(--transition);
}
.set-input:focus { outline: none; border-color: var(--accent); }
.set-input::placeholder { color: var(--border); }
.btn-remove-set {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  transition: all var(--transition);
}
.btn-remove-set:hover { color: var(--red); background: rgba(239,68,68,0.1); }
.btn-dup-set {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  transition: all var(--transition);
}
.btn-dup-set:hover { color: var(--accent); background: rgba(108,99,255,0.12); }

.log-actions {
  padding: 8px 0 32px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ─── Progress View ──────────────────────────────────────────── */
.progress-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.progress-controls label { color: var(--muted); font-size: 0.85rem; font-weight: 600; flex-shrink: 0; }
.ex-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.ex-select-row .select { flex: 1; min-width: 0; }
#pr-badge { flex-shrink: 0; white-space: nowrap; }
.select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color var(--transition);
}
.select:focus { outline: none; border-color: var(--accent); }

.pr-badge {
  background: linear-gradient(135deg, rgba(245,158,11,0.15), rgba(245,158,11,0.05));
  border: 1px solid rgba(245,158,11,0.3);
  color: var(--yellow);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 100px;
}
.pr-badge.hidden { display: none; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
  transition: border-color var(--transition);
}
.chart-card:hover { border-color: var(--surface2); }
.chart-card h3 { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 22px; display: flex; align-items: center; gap: 6px; }
.chart-wrapper { position: relative; height: 240px; }

/* ─── Plans View ─────────────────────────────────────────────── */
.plans-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  transition: border-color var(--transition), transform var(--transition);
}
.plan-card:hover { border-color: var(--surface2); transform: translateY(-1px); }
.plan-card.plan-active { border-color: rgba(124,111,255,0.5); background: rgba(124,111,255,0.04); }
.plan-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.plan-card h3 { font-size: 1rem; font-weight: 700; }
.plan-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.plan-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.badge-active {
  background: rgba(34,197,94,0.15);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.3);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 100px;
  white-space: nowrap;
}
.plan-days { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Create Plan Form */
.create-plan-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 16px;
}
.create-plan-form h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.hidden { display: none !important; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.label-hint { font-size: 0.72rem; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.weekday-conflict { font-size: 0.72rem; color: #f87171; font-weight: 600; margin-left: 8px; }
.weekday-conflict.hidden { display: none; }
.input-error { border-color: #f87171 !important; }
.input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color var(--transition);
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: #4a5270; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* Drag handles */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  flex-shrink: 0;
  font-size: 1rem;
  color: var(--text-muted, #888);
  cursor: grab;
  user-select: none;
  opacity: 0.45;
  transition: opacity 0.15s;
}
.drag-handle:hover { opacity: 1; }
.drag-handle:active { cursor: grabbing; }
.dragging { opacity: 0.35; }
.custom-day.drag-over { outline: 2px dashed var(--accent, #7c6fff); outline-offset: 2px; }
.custom-exercise-row.drag-over { outline: 2px dashed var(--accent, #7c6fff); border-radius: 4px; }

/* Custom Day Builder */
.custom-day {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 10px;
}
.custom-day-header { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.custom-day-header .input { flex: 1; }
.custom-exercise-row { display: grid; grid-template-columns: 18px 1fr 56px 56px 28px 28px; gap: 6px; margin-bottom: 6px; align-items: center; }
.custom-exercise-row .input { padding: 7px 8px; font-size: 0.82rem; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-content h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

/* ─── Rest Day Banner ────────────────────────────────────────── */
.rest-day-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 4px;
}
.rest-day-icon { font-size: 1.8rem; flex-shrink: 0; }
.rest-day-title { font-size: 1rem; font-weight: 700; color: var(--text); margin: 0 0 2px; }
.rest-day-sub { font-size: 0.82rem; color: var(--muted); margin: 0; }
.rest-day-banner .btn { margin-left: auto; white-space: nowrap; }

/* ─── History Filter ─────────────────────────────────────────── */
.history-filter { margin-bottom: 20px; }
.history-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  flex-wrap: wrap;
}
.history-filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.history-filter-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.hist-date-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
  padding: 6px 10px;
  flex: 1;
  min-width: 130px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.hist-date-input:focus { outline: none; border-color: var(--accent); }
.hist-date-input::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }
.history-filter-arrow {
  color: var(--muted);
  font-size: 1rem;
  flex-shrink: 0;
}
.hist-clear-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
.hist-clear-btn:hover { border-color: var(--accent); color: var(--accent); }
.hist-clear-btn.hidden { display: none; }

/* ─── History View ───────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 14px; }
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  transition: border-color var(--transition), transform var(--transition);
}
.history-card:hover { border-color: rgba(124,111,255,0.3); transform: translateY(-1px); }
.history-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.history-date { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.history-day { font-size: 1rem; font-weight: 700; margin-top: 2px; }
.history-actions { display: flex; gap: 6px; }
.history-stats { display: flex; gap: 16px; font-size: 0.8rem; color: var(--muted); margin-bottom: 0; }
.history-stats span::before { content: '·'; margin-right: 6px; opacity: 0.4; }
.history-stats span:first-child::before { display: none; }
.history-detail { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.history-exercise strong { font-size: 0.9rem; display: block; margin-bottom: 6px; }
.history-sets { display: flex; flex-wrap: wrap; gap: 6px; }
.set-chip { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 0.75rem; color: var(--muted); }

/* ─── Empty State ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { font-size: 1rem; margin-bottom: 20px; }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: all 0.25s ease;
  pointer-events: auto;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: none; }
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--accent); }

/* ─── Calendar Grid ──────────────────────────────────────────── */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.cal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color var(--transition);
}
.cal-card.cal-active {
  border-color: rgba(34,197,94,0.4);
  background: rgba(34,197,94,0.05);
}
.cal-card.cal-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(108,99,255,0.3);
}
.cal-card.cal-today.cal-active {
  border-color: var(--green);
  box-shadow: 0 0 0 1px rgba(34,197,94,0.3);
}
.cal-header {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 2px;
}
.cal-dow {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.cal-card.cal-today .cal-dow { color: var(--accent); }
.cal-card.cal-active .cal-dow { color: var(--green); }
.cal-date {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
}
.cal-session {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--green);
  background: rgba(34,197,94,0.1);
  border-radius: 4px;
  padding: 2px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-exercises {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.cal-exercises li {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-more {
  font-size: 0.65rem !important;
  color: var(--accent) !important;
  font-weight: 600;
}
.cal-edit-btn {
  margin-top: auto;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(108,99,255,0.3);
  background: rgba(108,99,255,0.08);
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: background var(--transition);
}
.cal-edit-btn:hover { background: rgba(108,99,255,0.18); }

.cal-rest {
  font-size: 0.68rem;
  color: var(--border);
  font-style: italic;
  margin-top: auto;
}
.cal-card.cal-planned {
  border-color: rgba(108,99,255,0.3);
  background: rgba(108,99,255,0.04);
}
.cal-planned-label {
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Day schedule picker in plan editor */
.day-schedule-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.schedule-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.day-schedule-row .select {
  font-size: 0.82rem;
  padding: 5px 10px;
  flex: 1;
  min-width: 120px;
}

/* ─── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Hide sidebar footer on mobile (not part of bottom nav) ── */
  .sidebar-footer { display: none !important; }

  /* ── Bottom tab bar ─────────────────────────────── */
  #sidebar,
  #sidebar.collapsed {
    width: 100% !important;
    height: auto !important;
    top: auto; bottom: 0; left: 0; right: 0;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-right: none;
    border-top: 1px solid var(--border);
    background: rgba(18, 18, 30, 0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    z-index: 200;
    overflow: visible;
  }
  #sidebar-toggle { display: none !important; }
  .nav-brand      { display: none !important; }

  /* Reset ALL collapsed overrides on mobile */
  #sidebar.collapsed .nav-label {
    opacity: 1 !important;
    width: auto !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }
  #sidebar.collapsed .nav-link {
    padding: 10px 4px !important;
    justify-content: center !important;
  }
  #sidebar.collapsed .nav-links {
    padding: 0 !important;
  }

  .nav-links {
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch;
    width: 100%;
    padding: 0 !important;
    gap: 0;
  }
  .nav-links li { flex: 1; display: flex; min-width: 0; }

  .nav-link {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 10px 2px !important;
    border-radius: 0;
    color: var(--muted);
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
  }
  .nav-label {
    opacity: 1 !important;
    width: auto !important;
    overflow: hidden !important;
    text-overflow: ellipsis;
    max-width: 60px;
    font-size: 0.56rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: block;
  }
  .nav-icon-wrap {
    width: 36px !important;
    height: 32px !important;
    border-radius: 10px;
    flex-shrink: 0;
  }
  .nav-icon-wrap svg { width: 17px; height: 17px; }

  /* Active tab */
  .nav-link.active {
    color: var(--accent) !important;
    background: transparent !important;
  }
  .nav-link.active .nav-icon-wrap {
    background: rgba(124, 111, 255, 0.16) !important;
    box-shadow: none !important;
  }
  .nav-link.active .nav-icon-wrap svg { stroke: var(--accent) !important; }

  /* ── Layout ─────────────────────────────────────── */
  html { overflow: hidden; height: 100%; }
  body { overflow: hidden; height: 100%; height: 100dvh; }

  #app {
    height: 100vh;
    height: 100dvh; /* dynamic — shrinks when iOS browser chrome shows */
  }

  #main-content {
    margin-left: 0 !important;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
  }

  /* Let flex do the height math — no calc, no 100vh */
  #views-wrapper {
    flex: 1;
    min-height: 0;
    height: auto !important;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch; /* iOS momentum scroll */
  }

  /* ── View padding ───────────────────────────────── */
  /* top: 58px clears profile avatar                                         */
  /* bottom: 180px clears tab bar + browser nav bar + safe area on all phones */
  .view { padding: 64px 20px 180px; }
  .view-header { margin-bottom: 24px; padding-right: 54px; }
  .view-header h1, .greeting-heading { font-size: 1.55rem; }
  .subtitle { font-size: 0.8rem; }

  /* ── Profile widget on mobile (inside topbar, not fixed) ── */
  #profile-widget { position: static; top: auto; right: auto; }
  .profile-btn { width: 38px; height: 38px; }
  .profile-dropdown { position: fixed; top: 60px; right: 16px; left: 16px; width: auto; max-width: 320px; margin-left: auto; }

  /* ── Metric cards ───────────────────────────────── */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
  }
  .metric-card { padding: 18px 14px; border-radius: 18px; }
  .metric-value { font-size: 1.9rem; }
  .metric-label { font-size: 0.65rem; }

  /* ── Plan badge ─────────────────────────────────── */
  .plan-badge { font-size: 0.8rem; padding: 7px 14px; margin-bottom: 18px; }

  /* ── CTA buttons ────────────────────────────────── */
  .cta-row { gap: 10px; }
  .cta-row .btn { flex: 1; justify-content: center; }
  .btn-lg { padding: 13px 18px; font-size: 0.92rem; }

  /* ── Day cards ──────────────────────────────────── */
  .day-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .day-card { height: 100px; padding: 14px; }
  .day-name { font-size: 0.92rem; }

  /* ── Exercise log ───────────────────────────────── */
  .exercise-card { padding: 16px; border-radius: 16px; }
  .sets-header, .set-row { grid-template-columns: 14px 28px 1fr 1fr 26px 26px; gap: 6px; }
  .set-input { padding: 7px 6px; font-size: 0.85rem; }
  .gym-time-row { gap: 10px; }

  /* ── Plans ──────────────────────────────────────── */
  .plan-card { padding: 16px; border-radius: 16px; }
  .plan-card-header { flex-direction: column; gap: 10px; }
  .plan-card-actions { justify-content: flex-start; flex-wrap: wrap; }

  /* ── History ────────────────────────────────────── */
  .history-card { padding: 16px; border-radius: 16px; }
  .history-card-header { flex-wrap: wrap; gap: 8px; }

  /* ── Progress / Charts ──────────────────────────── */
  .chart-card { padding: 18px 16px; border-radius: 16px; }
  .chart-wrapper { height: 180px; }
  .progress-controls { gap: 8px; flex-wrap: wrap; }

  /* ── Calendar (month hidden on mobile, week view used) ───────── */
  .month-grid { display: none; }
  .month-dow-row { display: none; }

  /* ── Forms ──────────────────────────────────────── */
  .custom-exercise-row { grid-template-columns: 14px 1fr 40px 48px 22px 22px; gap: 4px; }
  .drag-handle { width: 14px; font-size: 0.85rem; }
  .form-actions { flex-direction: column; }
  .input { padding: 10px 12px; }
  .create-plan-form, .modal-content { padding: 18px; border-radius: 16px; }

  /* ── Modal ──────────────────────────────────────── */
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    width: 100%;
    padding: 24px 20px;
  }

  /* ── Toast ──────────────────────────────────────── */
  #toast-container {
    left: 12px; right: 12px;
    bottom: calc(66px + env(safe-area-inset-bottom, 0px) + 8px);
  }
  .toast { max-width: none; }

  /* ── Log actions ────────────────────────────────── */
  .log-actions { flex-direction: column; }
  .log-actions .btn { width: 100%; justify-content: center; }
}

/* ─── Profile Widget ─────────────────────────────────────────── */
#profile-widget {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 1000;
}

.profile-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  cursor: pointer; padding: 0;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.profile-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,111,255,0.2); }

.profile-avatar-img, .profile-dd-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.profile-avatar-initials {
  font-family: 'Montserrat', sans-serif; font-weight: 700;
  font-size: 0.85rem; color: var(--text);
}

.profile-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  overflow: hidden;
}
.profile-dropdown[hidden] { display: none; }

.profile-dropdown-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
}
.profile-dd-img { width: 40px; height: 40px; flex-shrink: 0; }
.profile-dd-initials {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-family: 'Montserrat', sans-serif; font-weight: 700; font-size: 0.9rem; color: #fff;
}
.profile-dd-name  { font-weight: 600; font-size: 0.9rem; color: var(--text); word-break: break-word; }
.profile-dd-email { font-size: 0.75rem; color: var(--muted); margin-top: 2px; word-break: break-all; overflow-wrap: anywhere; }
.profile-dropdown-divider { height: 1px; background: var(--border); }

.profile-dd-signout {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 13px 16px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.875rem;
  transition: background var(--transition), color var(--transition);
  text-align: left;
}
.profile-dd-signout:hover { background: rgba(239,68,68,0.1); color: var(--red); }

/* ─── Mobile Top Nav Bar ─────────────────────────────────────── */
#mobile-topbar {
  display: none; /* hidden on desktop */
}
@media (max-width: 768px) {
  #mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 300;
    height: 64px;
    padding: 0 16px;
    background: rgba(18, 18, 30, 0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .mobile-topbar-logo {
    height: 52px; width: auto;
    object-fit: contain;
  }
  /* On mobile, profile-widget sits inside topbar — remove fixed positioning */
  #mobile-topbar #profile-widget {
    position: static;
    top: auto; right: auto;
  }
  /* Adjust view padding to clear mobile topbar (64px) and bottom tab bar (~68px) */
  .view { padding-top: 80px; padding-bottom: 88px; }
  /* Smaller sign-in button in topbar */
  #mobile-topbar .guest-signin-btn {
    padding: 7px 13px;
    font-size: 0.78rem;
    gap: 6px;
  }
  #mobile-topbar .guest-signin-btn svg { width: 13px; height: 13px; }
}

/* ─── Login Screen ───────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.login-logo {
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px;
}
.login-logo-img {
  width: 200px; height: auto;
  border-radius: 16px;
}
.login-brand-icon { font-size: 2rem; }
.login-brand-name {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 1.8rem; font-weight: 800;
  background: linear-gradient(90deg, #fff 0%, #c4b5fd 60%, #7c6fff 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.login-title {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 1.5rem; font-weight: 700;
  color: var(--text); line-height: 1.3;
  margin-bottom: 12px;
}

.login-sub {
  font-size: 0.9rem; color: var(--muted);
  line-height: 1.6; margin-bottom: 32px;
}

.btn-google-signin {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 20px;
  background: #fff; color: #1f1f1f;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer; justify-content: center;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-google-signin:hover { background: #f5f5f5; box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.btn-google-signin:active { background: #eee; }

.login-privacy {
  margin-top: 16px; font-size: 0.78rem; color: var(--muted);
}

/* ─── Guest Sign-In Button (top-right) ───────────────────────── */
.guest-signin-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 18px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 0.88rem; font-weight: 700;
  cursor: pointer; letter-spacing: 0.02em;
  transition: background var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 12px rgba(124,111,255,0.35);
}
.guest-signin-btn:hover { background: var(--accent-d); box-shadow: 0 4px 20px rgba(124,111,255,0.5); }
.guest-signin-btn:active { background: var(--accent-d); }

/* ─── Sign-In Modal ──────────────────────────────────────────── */
#signin-modal {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#signin-modal[hidden] { display: none; }

.signin-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.signin-modal-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
}

.signin-modal-x {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 4px;
  border-radius: 6px; transition: color var(--transition), background var(--transition);
}
.signin-modal-x:hover { color: var(--text); background: var(--surface2); }

.signin-modal-logo { margin-bottom: 20px; }
.signin-modal-logo-img { width: 120px; height: auto; display: block; margin: 0 auto; }

.signin-modal-title {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 1.25rem; font-weight: 700;
  color: var(--text); line-height: 1.35;
  margin-bottom: 10px;
}

.signin-modal-sub {
  font-size: 0.88rem; color: var(--muted);
  line-height: 1.6; margin-bottom: 28px;
}

.signin-modal-privacy {
  margin-top: 14px; font-size: 0.76rem; color: var(--muted);
}

/* ─── Weight change metric colours ──────────────────────────── */
.metric-gain { color: #34d399 !important; } /* green = gained weight */
.metric-loss { color: #f87171 !important; } /* red = lost weight */

/* ─── Sidebar LinkedIn footer (desktop) ─────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding: 16px 12px 72px;
  border-top: 1px solid var(--border);
}
.sidebar-linkedin {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-linkedin:hover { background: var(--surface2); color: #0a66c2; }
.sidebar-linkedin svg { flex-shrink: 0; }
.sidebar.collapsed .sidebar-footer .nav-label { display: none; }
.sidebar.collapsed .sidebar-linkedin { justify-content: center; }

/* ─── Mobile dev credit (dashboard only) ────────────────────── */
.mobile-dev-credit {
  display: none;
}
@media (max-width: 768px) {
  .mobile-dev-credit {
    display: flex;
    justify-content: center;
    padding: 20px 0 8px;
  }
  .mobile-dev-credit a {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.75rem;
    transition: color 0.15s;
  }
  .mobile-dev-credit a:hover { color: #0a66c2; }
}

