/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0a0a0a;
  --card:        #141414;
  --card2:       #1c1c1e;
  --border:      #2a2a2a;
  --accent:      #34d399;   /* emerald */
  --accent-dim:  #059669;
  --red:         #f87171;
  --orange:      #fb923c;
  --blue:        #60a5fa;
  --purple:      #c084fc;
  --text:        #f2f2f7;
  --text-dim:    #8e8e93;
  --text-muted:  #48484a;
  --nav-h:       64px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bot:    env(safe-area-inset-bottom, 0px);
  --radius:      16px;
  --radius-sm:   10px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  padding-top: max(14px, var(--safe-top));
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px 12px;
}
.header-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.header-right { display: flex; align-items: center; gap: 4px; }

/* ── Main scrollable area ──────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bot) + 12px);
}

/* ── Bottom nav ────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  background: rgba(14,14,14,0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  padding: 8px 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 24px; height: 24px; stroke-width: 1.8; }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { stroke-width: 2.2; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  padding-top: max(24px, var(--safe-top));
}
.login-wrap {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
.login-logo { text-align: center; }
.login-icon { font-size: 3rem; margin-bottom: 8px; }
.login-logo h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -1px; }
.login-logo p { color: var(--text-dim); font-size: 0.9rem; margin-top: 4px; }
.pin-error {
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.3);
  color: var(--red);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  text-align: center;
  width: 100%;
}
.pin-display {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 4px 0;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}
.pin-key {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--card2);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  min-height: 72px;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:active, .pin-key.tap { background: var(--card); transform: scale(0.92); }
.pin-key--empty { background: transparent; pointer-events: none; }
.pin-key--del { background: var(--card); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.card-link { font-size: 0.8rem; color: var(--accent); font-weight: 500; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
  min-height: 50px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.2px;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn-primary  { background: var(--accent); color: #000; }
.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost    { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-danger   { background: var(--red); color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 8px 14px; font-size: 0.8125rem; min-height: 36px; border-radius: 8px; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  background: transparent;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--card2); }
.icon-btn-sm {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn-sm:active { background: var(--card2); }

/* ── Typography helpers ─────────────────────────────────────────────────────── */
.page-header { margin-bottom: 18px; }
.page-header h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; }
.section-header { margin: 20px 0 10px; }
.section-header h3 { font-size: 1rem; font-weight: 600; }
.text-dim    { color: var(--text-dim); }
.text-muted  { color: var(--text-muted); }
.text-green  { color: var(--accent); }
.text-red    { color: var(--red); }
.text-orange { color: var(--orange); }
.text-sm  { font-size: 0.875rem; }
.text-xs  { font-size: 0.75rem; }

/* ── Stats ─────────────────────────────────────────────────────────────────── */
.stat-row {
  display: flex;
  gap: 8px;
}
.stat-block {
  flex: 1;
  background: var(--card2);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
  min-width: 0;
}
.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.stat-unit  { font-size: 0.65rem; font-weight: 500; color: var(--text-dim); }
.stat-label { font-size: 0.7rem; color: var(--text-dim); margin-top: 3px; }

/* ── Progress ───────────────────────────────────────────────────────────────── */
.progress-bar-wrap { margin-top: 12px; }
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-fill--green  { background: var(--accent); }
.progress-fill--orange { background: var(--orange); }
.progress-fill--red    { background: var(--red); }
.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-green  { background: rgba(52,211,153,0.15); color: var(--accent); }
.badge-orange { background: rgba(251,146,60,0.15); color: var(--orange); }
.badge-red    { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-dim    { background: var(--card2); color: var(--text-dim); }
.badge-blue   { background: rgba(96,165,250,0.15); color: var(--blue); }
.pulse { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Divider ────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ── History rows ───────────────────────────────────────────────────────────── */
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }
.history-info { flex: 1; min-width: 0; }

/* ── Exercise chips ─────────────────────────────────────────────────────────── */
.exercise-preview { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.exercise-chip {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  background: var(--card2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.exercise-chip--cardio { background: rgba(96,165,250,0.1); color: var(--blue); border-color: rgba(96,165,250,0.2); }
.exercise-chip--strength { background: rgba(52,211,153,0.08); color: var(--accent); border-color: rgba(52,211,153,0.15); }
.exercise-chip--resistance { background: rgba(192,132,252,0.1); color: var(--purple); border-color: rgba(192,132,252,0.2); }

/* ── Plan cards ─────────────────────────────────────────────────────────────── */
.plan-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.plan-name { font-size: 1.1rem; font-weight: 700; }
.plan-session-info { margin-top: 12px; }
.plan-quick-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Session progress ───────────────────────────────────────────────────────── */
.session-progress-wrap {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.session-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* ── Exercise cards (session) ───────────────────────────────────────────────── */
.exercise-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  transition: opacity 0.2s, border-color 0.2s;
}
.exercise-card--done {
  opacity: 0.55;
  border-color: rgba(52,211,153,0.2);
}
.ex-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.check-btn {
  width: 28px; height: 28px; min-width: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  margin-top: 2px;
  -webkit-tap-highlight-color: transparent;
}
.check-btn svg { opacity: 0; transition: opacity 0.15s; stroke: #000; }
.check-btn.checked { background: var(--accent); border-color: var(--accent); }
.check-btn.checked svg { opacity: 1; }
.ex-title-wrap { flex: 1; min-width: 0; }
.ex-name { font-size: 0.975rem; font-weight: 600; display: block; }
.ex-category {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
  background: var(--card2);
  padding: 1px 7px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.ex-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-left: 40px;
}
.ex-stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--card2);
  padding: 4px 9px;
  border-radius: 8px;
}
.ex-stat--weight { color: var(--accent); }
.ex-edit-btn {
  margin-left: auto;
  padding: 4px 8px;
  color: var(--text-muted);
  border-radius: 6px;
  display: flex; align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.ex-edit-btn:active { background: var(--card2); }
.ex-note {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-top: 8px;
  padding: 8px 10px;
  padding-left: 40px;
  background: rgba(251,146,60,0.06);
  border-left: 2px solid rgba(251,146,60,0.4);
  border-radius: 0 6px 6px 0;
  font-size: 0.75rem;
  color: var(--orange);
  line-height: 1.4;
}
.ex-note svg { flex-shrink: 0; margin-top: 1px; }

/* ── Exercise edit form ─────────────────────────────────────────────────────── */
.ex-edit-form {
  margin-top: 12px;
  padding: 14px;
  background: var(--card2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.form-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── Exercise manage cards ──────────────────────────────────────────────────── */
.exercise-manage-card { padding: 12px 14px; margin-bottom: 6px; }
.ex-manage-row { display: flex; justify-content: space-between; align-items: center; }
.ex-manage-info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ex-manage-stats { margin-top: 4px; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-row { margin-bottom: 12px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-input {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.9375rem;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
}
.form-input--large { font-size: 1.1rem; font-weight: 600; padding: 14px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238e8e93'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 36px;
}

/* ── Medication styles ──────────────────────────────────────────────────────── */
.med-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.med-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.med-icon--purple { background: rgba(192,132,252,0.15); }
.med-icon--blue   { background: rgba(96,165,250,0.15); }
.med-info { flex: 1; min-width: 0; }
.med-name { font-weight: 600; font-size: 0.9375rem; }
.med-status-card { }
.med-status-card--alert { border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.04); }
.med-status-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.med-icon-lg { font-size: 1.8rem; }
.med-dates { display: flex; flex-direction: column; gap: 6px; }
.med-date-row { display: flex; justify-content: space-between; align-items: center; }
.med-history-icon { font-size: 1.1rem; margin-right: 4px; }

/* ── Session status ─────────────────────────────────────────────────────────── */
.session-status { padding: 10px; background: var(--card2); border-radius: var(--radius-sm); }
.session-complete { border-left: 3px solid var(--accent); }
.session-active { border-left: 3px solid var(--orange); }

/* ── Weight chart ───────────────────────────────────────────────────────────── */
.weight-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  margin-bottom: 16px;
  padding: 0 2px;
}
.weight-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}
.weight-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.7;
  min-height: 4px;
}
.weight-bar-label { font-size: 0.6rem; color: var(--text-muted); }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ── HTMX indicator ─────────────────────────────────────────────────────────── */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ── Scroll snap areas ──────────────────────────────────────────────────────── */
@media (max-width: 430px) {
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
  .form-grid-3 .form-row:last-child { grid-column: 1 / -1; }
}
