*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; background: none; -webkit-tap-highlight-color: transparent; }
input, textarea, select { font-family: inherit; outline: none; border: none; font-size: 16px; }
textarea { resize: none; }
::-webkit-scrollbar { display: none; }
.hidden { display: none !important; }

/* ── Palette (light) ──────────────────────────────────────── */
:root {
  --bg:      #f0f0f5;
  --card:    #ffffff;
  --card2:   #f5f5fa;
  --input:   #e8e8ed;
  --line:    rgba(0,0,0,0.08);
  --shadow:  0 1px 4px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
  --accent:  #22a74f;
  --accent-d:rgba(34,167,79,0.1);
  --text:    #1c1c1e;
  --sub:     #6b7280;
  --dim:     #b0b8c4;
  --danger:  #ef4444;
  --orange:  #f97316;
  --orange-d:rgba(249,115,22,0.1);
  --r:  16px;
  --rs: 10px;
}

/* ── Auth ─────────────────────────────────────────────────── */
#auth-page {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) 20px 28px;
  background: var(--bg);
}
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-icon  { font-size: 52px; line-height: 1; }
.auth-name  { font-size: 26px; font-weight: 800; margin-top: 10px; letter-spacing: -.5px; }
.auth-sub   { font-size: 13px; color: var(--sub); margin-top: 4px; }
.auth-card  {
  width: 100%; max-width: 360px; background: var(--card);
  border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden;
}
.tabs       { display: flex; border-bottom: 1px solid var(--line); }
.tab        { flex: 1; padding: 15px; color: var(--sub); font-size: 14px; font-weight: 600; position: relative; transition: color .2s; }
.tab.active { color: var(--accent); }
.tab.active::after { content:''; position:absolute; bottom:-1px; left:0; right:0; height:2px; background:var(--accent); }
.tab-body   { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

/* ── Forms ───────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .6px; }
.field input, .field textarea, .field select {
  background: var(--input); border-radius: var(--rs); padding: 12px 14px;
  color: var(--text); width: 100%; border: 1.5px solid transparent; transition: border-color .15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); background: var(--card); }
.field select { -webkit-appearance: none; }
.form-error { font-size: 13px; color: var(--danger); min-height: 16px; }
.row-btns   { display: flex; gap: 10px; }
.row-btns .btn-outline { flex: 1; }
.row-btns .btn-primary { flex: 2; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 14px; background: var(--accent); border-radius: var(--rs);
  color: #fff; font-size: 15px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  min-height: 50px; transition: opacity .15s;
}
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .4; }

.btn-outline {
  padding: 13px 20px; border-radius: var(--rs); border: 1.5px solid var(--line);
  color: var(--sub); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; min-height: 48px;
  background: var(--card2); transition: border-color .15s;
}
.btn-outline.full { width: 100%; }
.btn-outline:active { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  padding: 13px 20px; border-radius: var(--rs); color: var(--danger); font-size: 14px;
  font-weight: 600; display: flex; align-items: center; justify-content: center; min-height: 48px;
}
.btn-danger.full { width: 100%; }

.btn-add-workout {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 15px; margin-top: 12px;
  background: none; border: 1.5px dashed rgba(34,167,79,.3);
  border-radius: var(--r); color: var(--accent); font-size: 15px; font-weight: 600;
  min-height: 52px; transition: background .15s;
}
.btn-add-workout:active { background: var(--accent-d); }
.btn-add-small {
  padding: 6px 14px; background: var(--accent-d); color: var(--accent);
  border-radius: 20px; font-size: 13px; font-weight: 600;
}

/* ── App shell ───────────────────────────────────────────── */
#app-page { display: flex; flex-direction: column; min-height: 100dvh; background: var(--bg); }

/* ── Top header ──────────────────────────────────────────── */
.top-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  padding-top: calc(max(14px, env(safe-area-inset-top)));
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.top-header-left { display: flex; align-items: center; gap: 8px; }
.top-logo  { font-size: 22px; }
.top-title { font-size: 17px; font-weight: 800; color: var(--text); }
.btn-menu {
  display: flex; align-items: center; gap: 4px;
  font-size: 14px; font-weight: 500; color: var(--sub);
  padding: 6px 12px; border-radius: 20px; background: var(--input);
}
.btn-menu:active { background: var(--line); }

/* ── Calendar ─────────────────────────────────────────────── */
.calendar-wrapper {
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: calc(max(14px, env(safe-area-inset-top)) + 48px); z-index: 20;
}
.cal-month-label {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--sub); padding: 8px 0 2px; letter-spacing: .3px;
}
.cal-scroll {
  display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden;
  padding: 4px 14px 10px; -webkit-overflow-scrolling: touch;
}
.cal-day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex-shrink: 0; width: 48px; padding: 4px 0 6px;
  border-radius: 12px; cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.cal-day-name { font-size: 10px; font-weight: 600; color: var(--dim); }
.cal-day.is-weekend .cal-day-name { color: var(--accent); opacity: .6; }
.cal-day-num {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600; color: var(--sub); border-radius: 50%; transition: all .15s;
}
.cal-day:not(.is-today) .cal-day-num { color: var(--text); }
.cal-day.is-today .cal-day-num  { background: var(--accent); color: #fff; font-weight: 800; }
.cal-day.is-selected:not(.is-today) .cal-day-num { background: var(--accent-d); color: var(--accent); font-weight: 700; }
.cal-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); opacity: 0; position: absolute; bottom: 2px; transition: opacity .15s; }
.cal-dot.visible { opacity: .7; }

/* ── Journal ─────────────────────────────────────────────── */
.journal-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 14px calc(32px + env(safe-area-inset-bottom));
}
.date-label { font-size: 18px; font-weight: 700; color: var(--text); padding: 16px 2px 10px; }

/* ── Workout card ─────────────────────────────────────────── */
.workout-card {
  background: var(--card); border-radius: var(--r); margin-bottom: 10px;
  box-shadow: var(--shadow); overflow: hidden;
}
.workout-card.is-active   { box-shadow: 0 0 0 1.5px var(--orange), var(--shadow); }
.workout-card.is-completed{ box-shadow: 0 0 0 1.5px rgba(34,167,79,.3), var(--shadow); }

.wcard-header {
  display: flex; align-items: center; padding: 14px 16px; gap: 12px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.wcard-bar { width: 3px; align-self: stretch; border-radius: 2px; flex-shrink: 0; }
.wcard-bar.planned   { background: var(--dim); }
.wcard-bar.active    { background: var(--orange); }
.wcard-bar.completed { background: var(--accent); }
.wcard-info { flex: 1; min-width: 0; }
.wcard-name { font-size: 16px; font-weight: 700; color: var(--text); }
.wcard-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.status-pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; }
.status-pill.planned   { background: var(--input); color: var(--sub); }
.status-pill.active    { background: var(--orange-d); color: var(--orange); }
.status-pill.completed { background: var(--accent-d); color: var(--accent); }
.wcard-timer { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--orange); }
.timer-dot   { width: 6px; height: 6px; border-radius: 50%; background: var(--orange); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.2} }
.wcard-arrow { font-size: 22px; color: var(--dim); flex-shrink: 0; }

.wcard-exercises { border-top: 1px solid var(--line); }
.wcard-ex-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px 9px 31px; border-bottom: 1px solid var(--line);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.wcard-ex-row:last-child { border-bottom: none; }
.wcard-ex-name { font-size: 14px; color: var(--text); }
.wcard-ex-prog { font-size: 12px; font-weight: 700; color: var(--sub); flex-shrink: 0; }
.wcard-ex-prog.done { color: var(--accent); }
.wcard-no-ex { padding: 12px 16px 12px 31px; font-size: 13px; color: var(--dim); }

/* ── Sheets ──────────────────────────────────────────────── */
#backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#backdrop.visible { opacity: 1; pointer-events: all; }

.sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card); border-radius: 20px 20px 0 0;
  z-index: 100; max-height: 90dvh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.32,.72,0,1);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 30px rgba(0,0,0,0.12);
}
.sheet-tall { max-height: 94dvh; }
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: var(--line); border-radius: 2px; margin: 12px auto 0; flex-shrink: 0; }
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px; border-bottom: 1px solid var(--line); flex-shrink: 0; gap: 10px;
}
.sheet-title { font-size: 17px; font-weight: 700; color: var(--text); }
.sheet-sub   { font-size: 13px; color: var(--sub); margin-top: 2px; display: block; }
.sheet-scroll { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-body   { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.sheet-actions { padding: 12px 18px 16px; display: flex; flex-direction: column; gap: 10px; }

/* detail header */
.detail-sheet-header { display: flex; align-items: flex-start; justify-content: space-between; }
.detail-header-left  { flex: 1; min-width: 0; }
.detail-header-btns  { display: flex; align-items: center; gap: 6px; padding-top: 2px; flex-shrink: 0; }
.detail-meta  { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.status-badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.status-badge.planned   { background: var(--input); color: var(--sub); }
.status-badge.active    { background: var(--orange-d); color: var(--orange); }
.status-badge.completed { background: var(--accent-d); color: var(--accent); }
.workout-timer { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; color: var(--orange); }

.detail-notes {
  font-size: 13px; color: var(--sub); font-style: italic;
  margin-top: 8px; padding: 8px 12px; background: var(--card2);
  border-radius: var(--rs); border-left: 2px solid var(--accent);
}

.btn-trash {
  width: 36px; height: 36px; border-radius: var(--rs);
  display: flex; align-items: center; justify-content: center;
  color: var(--danger); background: rgba(239,68,68,.08); transition: opacity .15s;
}
.btn-trash:active { opacity: .6; }
.btn-close-sheet {
  width: 36px; height: 36px; border-radius: var(--rs);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--sub); background: var(--input); transition: color .15s;
}
.btn-close-sheet:active { color: var(--text); }

/* ── Exercise blocks ─────────────────────────────────────── */
#detail-exercises { padding-top: 12px; }
.ex-block { margin: 0 16px 10px; background: var(--card2); border-radius: var(--rs); overflow: hidden; }

.ex-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.ex-head:active { opacity: .8; }
.ex-head-left  { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ex-name   { font-size: 15px; font-weight: 600; color: var(--text); }
.ex-muscle { font-size: 11px; font-weight: 600; color: var(--accent); }
.ex-head-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.ex-sets-count { font-size: 13px; color: var(--sub); }
.ex-del-btn {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 16px; transition: color .15s, background .15s;
}
.ex-del-btn:active { color: var(--danger); background: rgba(239,68,68,.1); }
.ex-chevron { font-size: 16px; color: var(--dim); transition: transform .2s; }
.ex-chevron.open { transform: rotate(90deg); }

/* ── Sets ────────────────────────────────────────────────── */
.sets-wrap { padding-bottom: 10px; }
.sets-head {
  display: grid; grid-template-columns: 32px 1fr 1fr 46px;
  gap: 6px; padding: 4px 14px 6px;
  font-size: 10px; font-weight: 700; color: var(--dim);
  text-transform: uppercase; letter-spacing: .5px; text-align: center;
}

/* swipe wrapper */
.set-row-wrap { position: relative; overflow: hidden; }
.set-del-bg {
  position: absolute; right: 0; top: 0; bottom: 0; width: 80px;
  background: var(--danger); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .3px;
}

.set-row {
  display: grid; grid-template-columns: 32px 1fr 1fr 46px;
  gap: 6px; align-items: center; padding: 6px 14px;
  background: var(--card2); position: relative;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  touch-action: pan-y; user-select: none;
}
.set-row:last-of-type { border-bottom: none; }

.set-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--input); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--sub);
}
.set-inp-wrap {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--rs); overflow: hidden; transition: border-color .15s;
}
.set-inp-wrap:focus-within { border-color: var(--accent); }
.set-inp {
  width: 100%; text-align: center; padding: 10px 2px;
  font-size: 17px; font-weight: 700; color: var(--text); background: none;
}
.set-check {
  width: 46px; height: 44px; border-radius: var(--rs);
  border: 1.5px solid var(--line); background: var(--card);
  color: var(--dim); display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.set-check.done { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-add-set {
  display: flex; align-items: center; justify-content: center;
  width: calc(100% - 28px); margin: 8px 14px 0;
  padding: 10px; background: none; border: 1.5px dashed rgba(0,0,0,0.12);
  border-radius: var(--rs); color: var(--sub); font-size: 14px; font-weight: 600;
  min-height: 42px; transition: border-color .15s, color .15s;
}
.btn-add-set:active { border-color: var(--accent); color: var(--accent); }

/* ── Picker / Catalog ────────────────────────────────────── */
.picker-search-wrap {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 16px 6px; background: var(--input);
  border-radius: var(--rs); padding: 10px 12px;
}
.picker-search-wrap svg { color: var(--dim); flex-shrink: 0; }
.picker-search-wrap input { flex: 1; background: none; color: var(--text); }
.picker-search-wrap input::placeholder { color: var(--dim); }
.picker-group { padding: 12px 16px 4px; font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .7px; }
.picker-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer; min-height: 52px; -webkit-tap-highlight-color: transparent; transition: background .15s;
}
.picker-item:active { background: var(--card2); }
.picker-item-name  { font-size: 15px; font-weight: 500; color: var(--text); }
.picker-add {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 20px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.catalog-item {
  display: flex; align-items: center; padding: 13px 16px;
  border-bottom: 1px solid var(--line); gap: 10px;
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background .15s;
}
.catalog-item:active { background: var(--card2); }
.catalog-item-name { flex: 1; font-size: 15px; font-weight: 500; color: var(--text); }
.badge { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600; }
.badge-global { background: var(--input); color: var(--sub); }
.badge-custom { background: var(--accent-d); color: var(--accent); }

/* ── Quick picks ─────────────────────────────────────────── */
.quick-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-pick {
  padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
  background: var(--input); color: var(--sub); transition: all .15s; min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.quick-pick.selected { background: var(--accent-d); color: var(--accent); }

/* ── Menu ────────────────────────────────────────────────── */
.menu-list { padding: 8px 0; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px 20px;
  font-size: 16px; font-weight: 500; color: var(--text); transition: background .15s;
}
.menu-item:active { background: var(--card2); }
.menu-item.danger { color: var(--danger); }
.menu-item svg { flex-shrink: 0; color: var(--sub); }
.menu-item.danger svg { color: var(--danger); }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(28px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--text); color: var(--card);
  font-size: 13px; font-weight: 600; padding: 9px 20px;
  border-radius: 20px; z-index: 200; opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Empty ───────────────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 48px 24px; gap: 10px; }
.empty-icon { font-size: 44px; }
.empty-text { font-size: 15px; color: var(--sub); }
