:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #15191e;
  --muted: #5f6b78;
  --border: #dde2e8;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d5efec;
  --danger: #b42318;
  --good: #15803d;
  --chart-1: #0f766e;
  --chart-2: #c2410c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1114;
    --surface: #171b20;
    --surface-2: #20262d;
    --text: #e8ecf0;
    --muted: #96a2ae;
    --border: #2b323a;
    --accent: #2dd4bf;
    --accent-text: #04201d;
    --accent-soft: #123a36;
    --danger: #f97066;
    --good: #4ade80;
    --chart-1: #2dd4bf;
    --chart-2: #fb923c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1114; --surface: #171b20; --surface-2: #20262d; --text: #e8ecf0; --muted: #96a2ae;
  --border: #2b323a; --accent: #2dd4bf; --accent-text: #04201d; --accent-soft: #123a36;
  --danger: #f97066; --good: #4ade80; --chart-1: #2dd4bf; --chart-2: #fb923c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn:disabled { opacity: .5; }

.hero-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-bottom: 18px; }

.search {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px;
}

.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 10px; cursor: pointer; box-shadow: var(--shadow);
}
.list-item:active { background: var(--surface-2); }
.list-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { font-size: 14px; color: var(--muted); }
.list-item .weight { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; vertical-align: middle;
}

.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty svg { color: var(--accent); }

/* Machine detail */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
.settings-note { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-top: 10px; }

.stepper-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; text-align: center; }
.steppers { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 48px; border: 0; background: var(--surface-2); font-size: 22px; font-weight: 600; cursor: pointer; }
.stepper button:active { background: var(--accent-soft); }
.stepper input {
  flex: 1; min-width: 0; width: 100%; text-align: center; border: 0; background: transparent;
  font-size: 22px; font-weight: 700; padding: 10px 0; font-variant-numeric: tabular-nums;
}
.stepper input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.quick { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip:active, .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.sets { list-style: none; margin: 10px 0 0; padding: 0; }
.sets li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.sets li:first-child { border-top: 0; }
.sets .idx { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.sets .x { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.pr { color: var(--good); font-size: 12px; font-weight: 700; }

.history-day { padding: 10px 0; border-top: 1px solid var(--border); }
.history-day:first-of-type { border-top: 0; }
.history-day .date { font-weight: 600; font-size: 14px; }
.history-day .sets-line { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Charts */
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart-1); opacity: .12; }
.chart .dot { fill: var(--surface); stroke: var(--chart-1); stroke-width: 2; }
.chart .dot.active { fill: var(--chart-1); }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-tip { font-size: 14px; min-height: 22px; font-variant-numeric: tabular-nums; }

/* Forms / dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(92vw, 440px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { padding: 20px; }
.dlg h3 { margin: 0 0 6px; font-size: 18px; }
.dlg .actions { display: flex; gap: 10px; margin-top: 18px; }
.dlg .actions .btn { flex: 1; }
label.field { display: block; margin-top: 12px; font-size: 14px; color: var(--muted); }
label.field input, label.field select, label.field textarea {
  display: block; width: 100%; margin-top: 4px; min-height: 46px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px;
}
label.field textarea { min-height: 70px; resize: vertical; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 8px; color: var(--muted); }

/* Scanner */
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; left: 50%; top: 42%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 24px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.9);
}
.scan-hint { position: absolute; left: 16px; right: 16px; top: calc(42% + min(35vw, 150px) + 20px); text-align: center; color: #fff; margin: 0; text-shadow: 0 1px 3px #000; }
.scan-actions { position: absolute; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 24px); display: flex; gap: 10px; }
.scan-actions .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; z-index: 60;
  font-weight: 600; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 20;
  width: 64px; height: 64px; border-radius: 20px; border: 0; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); cursor: pointer;
}
@media (min-width: 700px) { .fab { right: calc(50% - 320px + 16px); } }

/* Overzicht met foto's */
.tile { padding: 10px 14px 10px 10px; }
.thumb {
  position: relative; flex: none; width: 60px; height: 60px; border-radius: 12px; overflow: hidden;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
}
.thumb.big { width: 72px; height: 72px; font-size: 22px; }
.thumb img, .photo-big img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile .right { text-align: right; flex: none; }
.tile .weight { font-size: 20px; }
.tile .sr { color: var(--text); font-variant-numeric: tabular-nums; }
.growth { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.growth.up { color: var(--good); }
.growth.down { color: var(--muted); }

.setting-card { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.setting-card:active { background: var(--surface-2); }
.setting-main { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.sheet-photo { display: block; position: relative; margin-top: 10px; cursor: pointer; }
.photo-big {
  position: relative; width: 100%; height: 140px; border-radius: 14px; overflow: hidden;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
  font-size: 40px; font-weight: 700;
}
.photo-btn {
  position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
}
dialog { max-height: 92vh; overflow-y: auto; }

/* Afstelling (stoel, rugleuning, ...) */
.adj { margin-top: 12px; }
.adj-rows { display: grid; gap: 8px; margin-bottom: 8px; }
.adj-row { display: flex; align-items: center; gap: 8px; }
.adj-row > input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px;
}
.adj-row .x { border: 0; background: transparent; color: var(--muted); font-size: 22px; padding: 4px 6px; cursor: pointer; }
.stepper.small { flex: none; width: 128px; }
.stepper.small button { width: 38px; font-size: 20px; }
.stepper.small input { font-size: 18px; padding: 8px 0; }
.adj-line {
  font-size: 13px; color: var(--accent); font-weight: 600; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.setting-card .adj-line { white-space: normal; }
.icon-btn:focus:not(:focus-visible) { outline: none; }

/* Spiergroepen */
.mchips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip input { position: absolute; opacity: 0; pointer-events: none; }
.mchip span {
  display: inline-block; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; font-weight: 600; cursor: pointer; background: var(--surface);
}
.mchip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.mchip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.muscle-line { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mfilter { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.mfilter .chip { flex: none; }
.adj-rows { grid-template-columns: minmax(0, 1fr); }

/* Trainingsschema */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-weight: 600; cursor: pointer;
}
.switch-row input {
  appearance: none; -webkit-appearance: none; flex: none; width: 50px; height: 30px; border-radius: 999px;
  background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
.switch-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(20px); }
.switch-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.off-schedule { margin-top: 6px; }
.off-schedule summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 10px 2px; }
.tile.off { opacity: .75; }
.tile.off .chip { flex: none; }
.recent-off { margin-top: 18px; }
.section-title { margin: 0 2px 8px; font-size: 16px; }
.recent-off .tile.off { opacity: 1; }
.tile .right .chip { margin-top: 6px; }
.kind-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.kind-seg label { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 40px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.kind-seg input { position: absolute; opacity: 0; pointer-events: none; }
.kind-seg label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.kind-seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Lichaamsfiguur */
:root { --body: #dde1e6; --body-line: #f7f8fa; --body-edge: #b9c0c9; --hair: #5b4636; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --body: #3a424c; --body-line: #22282f; --body-edge: #55606c; --hair: #2a2018; } }
:root[data-theme="dark"] { --body: #3a424c; --body-line: #22282f; --body-edge: #55606c; --hair: #2a2018; }
.body-map { display: block; width: 100%; height: auto; }
.body-map path { stroke-linejoin: round; }
.body-map .sil-edge path { fill: var(--body-edge); stroke: var(--body-edge); stroke-width: 4.3; }
.body-map .sil path { fill: var(--body); stroke: var(--body); stroke-width: 3.4; }
.body-map .hair-front { fill: var(--hair); }
.body-map .body-part path { fill: var(--body); stroke: none; }
.body-map .mu path { fill: var(--body); stroke: var(--body-line); stroke-width: .45; stroke-opacity: .8; }
.body-map .mu.on path { fill: color-mix(in srgb, var(--accent) calc(var(--w) * 100%), var(--body)); }
.body-map .mu.sel path { stroke: var(--text); stroke-width: .9; stroke-opacity: 1; }
.body-map.tappable .mu.on { cursor: pointer; }
.body-map .face ellipse { fill: var(--muted); }
.body-map .face path { stroke: var(--muted); stroke-width: .8; stroke-linecap: round; }
.body-map .body-part.hair path { fill: var(--hair); stroke: var(--hair); stroke-width: 3.4; }
.body-map .body-label { fill: var(--muted); font-size: 10px; font-weight: 600; }
.body-wrap { max-width: 300px; margin: 0 auto; }
.edit-body { max-width: 220px; margin: 0 auto 8px; }
.sheet-top { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.sheet-top:has(.sheet-body) { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: center; }
.sheet-top .sheet-photo { margin-top: 10px; }
.sheet-body { margin-top: 10px; }
/* Licht en schaduw over elke spier (na de kleurregels, zodat het erbovenop komt). */
.body-map .mu .shade path, .body-map .mu.on .shade path { fill: url(#muShade); stroke: none; pointer-events: none; }

/* Autocomplete voor toestelnamen */
.suggest {
  list-style: none; margin: 4px 0 0; padding: 4px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto;
}
.suggest li { display: flex; flex-direction: column; gap: 1px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.suggest li:active, .suggest li:hover { background: var(--accent-soft); }
.suggest li span { font-size: 12px; color: var(--muted); }
