:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #9aa0a6;
  --line: #e6e8eb;
  --accent: #3b5bdb;
  --accent-soft: #eef1f6;
  --done: #2f9e44;
  --skip: #e8590c;
  --radius: 16px;
  --nav-h: 64px;
  --maxw: 520px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Arial, "Noto Sans Hebrew", sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

#app { max-width: var(--maxw); margin: 0 auto; }

.screen {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 16px
    calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}

/* Header */
.header { padding: 6px 4px 18px; }
.header h1 { font-size: 24px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }
.header .meta { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

.section-label {
  font-size: 12px; color: var(--muted); font-weight: 600;
  text-transform: none; margin: 4px 4px 10px;
}

/* Cards (program list) */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.card:active { transform: scale(0.985); }
.card .name { font-size: 16px; font-weight: 600; }
.chip {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  padding: 7px 13px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Generic list rows */
.row {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.row .top { display: flex; justify-content: space-between; align-items: baseline; }
.row .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; width: 100%; padding: 15px;
  border: none; border-radius: 14px;
  font-size: 16px; font-weight: 700; font-family: inherit;
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn:active { filter: brightness(0.95); }
.btn.dark { background: var(--text); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: #fff0ed; color: var(--skip); }
.btn.sm { width: auto; padding: 10px 16px; font-size: 14px; border-radius: 12px; }

/* Inputs */
label.field { display: block; margin-bottom: 14px; }
label.field .lbl { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: block; }
input, textarea, select {
  width: 100%; padding: 13px 14px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
input[type="number"] { text-align: start; }
textarea { resize: vertical; min-height: 64px; }
.inline { display: flex; gap: 10px; align-items: center; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.toggle-row input { width: auto; }

/* Back / top bar */
.topbar { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.topbar .back {
  background: none; border: none; font-size: 22px; color: var(--accent);
  cursor: pointer; padding: 4px 8px 4px 0; font-family: inherit;
}
.topbar h2 { font-size: 20px; font-weight: 800; margin: 0; }

/* Workout entry */
.entry {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.entry.skipped { opacity: 0.55; }
.entry .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.entry .ename { font-weight: 600; font-size: 15px; }
.entry .controls { display: flex; gap: 10px; align-items: center; }
.entry .controls .w { flex: 1; }
.entry .controls .w input { padding: 10px 12px; }
.statusbtn {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.statusbtn.done { background: #e9f7ee; color: var(--done); border-color: transparent; }
.statusbtn.skip { background: #fdece4; color: var(--skip); border-color: transparent; }
.entry .note input { margin-top: 8px; padding: 9px 12px; font-size: 14px; }

/* Timeline */
.timeline { margin-top: 6px; }
.tl-item { display: flex; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.tl-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex: none; }
.tl-item .txt { font-size: 14px; }
.tl-item .when { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* FAB */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  left: max(16px, calc(50% - var(--maxw) / 2 + 16px));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 18px rgba(59, 91, 219, 0.4); z-index: 20;
}

/* Bottom nav */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: center; z-index: 15;
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
  flex: 1; padding-top: 4px;
}
.nav a .ic { font-size: 20px; line-height: 1; }
.nav a.active { color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; font-size: 15px; }

/* Modal / sheet */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; z-index: 40;
}
.sheet {
  background: #fff; width: 100%; max-width: var(--maxw); margin: 0 auto;
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slideup 0.18s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { margin: 0 0 16px; font-size: 19px; }

/* Login */
.login {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; text-align: center;
}
.login h1 { font-size: 26px; margin-bottom: 8px; }
.login p { color: var(--muted); margin-top: 0; }
.login form { width: 100%; max-width: 320px; margin-top: 16px; }
.login form input { margin-bottom: 10px; }
.login .err { color: var(--skip); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* Top user bar */
.userbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 0;
  max-width: var(--maxw); margin: 0 auto;
}
.userbar .who { font-size: 14px; font-weight: 700; color: var(--text); }
.userbar .owner-switch {
  width: auto; flex: 1; max-width: 70%; padding: 9px 12px; font-size: 14px;
  font-weight: 700; border-radius: 999px;
}
.userbar .ub-gear {
  text-decoration: none; font-size: 20px; line-height: 1; padding: 6px;
  flex: none;
}
.ro-banner {
  max-width: var(--maxw); margin: 8px auto 0; padding: 8px 16px;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); text-align: center;
}

/* Segmented toggle + range pills (history list/analytics) */
.toggle {
  display: flex; gap: 4px; background: var(--accent-soft);
  border-radius: 999px; padding: 4px; margin: 0 4px 16px;
}
.toggle button {
  flex: 1; width: auto; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 700; color: var(--muted);
  padding: 9px 12px; border-radius: 999px;
}
.toggle button.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.range { display: flex; gap: 8px; margin: 0 4px 14px; }
.range button {
  width: auto; border: 1px solid var(--line); background: #fff; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--muted);
  padding: 7px 14px; border-radius: 999px;
}
.range button.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Headline stat chips */
.stat-chips { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--card); border-radius: var(--radius);
  padding: 14px 8px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat b { display: block; font-size: 22px; font-weight: 800; color: var(--accent); }
.stat span { font-size: 12px; color: var(--muted); }

/* Inline SVG charts */
#prog-ex { margin-bottom: 10px; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .cax { font-size: 9px; fill: var(--muted); }

/* Adherence proportion bar + most-skipped list */
.propbar {
  display: flex; height: 14px; border-radius: 999px; overflow: hidden;
  background: var(--accent-soft); margin-bottom: 8px;
}
.propbar span { display: block; height: 100%; }
.skip-list { margin-top: 10px; border-top: 1px solid var(--line); }
.skip-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 2px; font-size: 14px; border-bottom: 1px solid var(--line);
}
.skip-item:last-child { border-bottom: none; }

/* Read-only displays */
.readout {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.readout .lbl { font-size: 13px; color: var(--muted); }
.entry .note.ro { margin-top: 8px; font-size: 14px; color: var(--muted); }
.statusbtn.ro { cursor: default; }
