:root {
  --bg: #0c0f16;
  --bg-elev: #151a24;
  --card: #161c28;
  --card-2: #1d2533;
  --line: rgba(255,255,255,0.08);
  --text: #eef2f8;
  --muted: #93a0b5;
  --accent: #4f8cff;
  --green: #45d483;
  --red: #ff5d6c;
  --orange: #ff8a3d;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; position: relative; }

/* ---- header ---- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 18px 10px;
  background: linear-gradient(180deg, var(--bg) 65%, transparent);
}
.appbar h1 { font-size: 22px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }
.appbar .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7b5cff); color: #fff; font-weight: 900; font-size: 16px;
}
.appbar .spacer { flex: 1; }
.appbar .date-pill { font-size: 12px; color: var(--muted); background: var(--card); padding: 6px 11px; border-radius: 20px; }

/* ---- main scroll ---- */
main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
#view { display: flex; flex-direction: column; gap: 14px; }

/* ---- bottom nav ---- */
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 560px; margin: 0 auto;
  display: flex; justify-content: space-around;
  background: rgba(18,23,33,0.92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  height: calc(var(--nav-h) + var(--safe-b));
}
.nav-item {
  flex: 1; background: none; border: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; cursor: pointer; padding: 8px 2px;
  transition: color .15s; font-family: inherit;
}
.nav-item .nav-icon { display: grid; place-items: center; }
.nav-item .nav-icon svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.active { color: var(--accent); }
.nav-item.active { color: var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-item.active { --c: var(--accent); }
.nav-item.active { color: var(--accent); }

/* ---- cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.tight { padding: 13px; }
.hero {
  background: radial-gradient(120% 140% at 0% 0%, rgba(79,140,255,0.22), transparent 60%), var(--card);
}
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px;
  margin: 6px 2px 2px;
}
.section-title button { background: none; border: 0; color: var(--accent); font-weight: 700; font-size: 13px; cursor: pointer; font-family: inherit; }

/* ---- stats grid ---- */
.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: 1fr 1fr; }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; display: flex; flex-direction: column; gap: 4px;
  border-left: 3px solid var(--accent, #4f8cff);
}
.stat-val { font-size: 23px; font-weight: 800; letter-spacing: -0.5px; }
.stat-unit { font-size: 12px; font-weight: 600; color: var(--muted); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---- rings & dashboard hero ---- */
.rings { display: flex; gap: 8px; align-items: center; justify-content: space-around; flex-wrap: wrap; }
.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ring-wrap .rl { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---- lists ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.li .li-main { flex: 1; min-width: 0; }
.li .li-title { font-weight: 600; font-size: 15px; }
.li .li-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.li .li-val { font-weight: 700; font-size: 15px; text-align: right; white-space: nowrap; }
.li .li-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--card-2); font-size: 19px; flex-shrink: 0;
}
.li.tap { cursor: pointer; transition: background .12s; }
.li.tap:active { background: var(--card-2); }
.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--card-2); color: var(--muted); font-weight: 600; }

/* ---- progress bar ---- */
.pbar { height: 8px; background: rgba(255,255,255,0.08); border-radius: 6px; overflow: hidden; }
.pbar-fill { height: 100%; border-radius: 6px; transition: width .35s ease; }

/* ---- buttons ---- */
.btn {
  appearance: none; border: 0; border-radius: 13px; padding: 13px 16px;
  font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
  background: var(--accent); color: #fff; flex: 1; transition: filter .12s, transform .05s;
}
.btn:active { transform: scale(0.98); }
.btn.ghost { background: var(--card-2); color: var(--text); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); color: #06281a; }
.btn.sm { padding: 9px 12px; font-size: 13px; flex: none; border-radius: 11px; }

/* ---- fab ---- */
.fab {
  position: fixed; right: max(18px, calc(50% - 280px + 18px)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  z-index: 25; width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: linear-gradient(135deg, var(--accent), #7b5cff); color: #fff;
  font-size: 30px; font-weight: 300; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 24px rgba(79,140,255,0.45); display: grid; place-items: center;
}
.fab:active { transform: scale(0.94); }

/* ---- rows ---- */
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.mini { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; font-weight: 700; color: var(--text); }
.right { text-align: right; }
.center { text-align: center; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,138,61,0.45); } 50% { box-shadow: 0 0 0 6px rgba(255,138,61,0); } }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.input {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; font-family: inherit; width: 100%;
  outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2393a0b5' d='M6 8 0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* segmented control */
.seg { display: flex; background: var(--bg-elev); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: 0; background: none; color: var(--muted); font-weight: 700; font-size: 13px;
  padding: 8px; border-radius: 9px; cursor: pointer; font-family: inherit;
}
.seg button.on { background: var(--accent); color: #fff; }

/* ---- empty ---- */
.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14px; }

/* ---- sheet ---- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .22s;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg-elev);
  border-radius: 22px 22px 0 0; max-height: 90dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
  padding-bottom: calc(var(--safe-b) + 16px);
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-head { position: sticky; top: 0; background: var(--bg-elev); display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 8px; }
.sheet-head h3 { margin: 0; font-size: 18px; font-weight: 800; }
.sheet-x { background: var(--card-2); border: 0; color: var(--muted); width: 32px; height: 32px; border-radius: 50%; font-size: 15px; cursor: pointer; }
.sheet-body { padding: 8px 18px 4px; }

/* ---- charts ---- */
.chart { width: 100%; display: block; }
.ring { display: block; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 24px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: #fff; color: #0c0f16; font-weight: 700; font-size: 14px;
  padding: 11px 18px; border-radius: 30px; z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- barcode scanner ---- */
.scan-wrap { position: relative; width: 100%; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 3 / 4; }
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18% 12%; border: 3px solid rgba(255,255,255,0.85); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.35); }
.scan-frame::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: var(--red); box-shadow: 0 0 8px var(--red); animation: scanline 1.8s ease-in-out infinite; }
@keyframes scanline { 0%,100% { transform: translateY(-46px); } 50% { transform: translateY(46px); } }

/* ---- exercise sets & video ---- */
.set-box { margin-bottom: 7px; }
.ex-video { width: 100%; border-radius: 12px; background: #000; margin-top: 8px; max-height: 240px; }
.video-btn { display: inline-flex; align-items: center; gap: 6px; }
.upload-prog { height: 6px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.upload-prog > div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }

/* ---- körper records ---- */
.rec-media { width: 100%; border-radius: 12px; background: #000; max-height: 280px; object-fit: contain; display: block; }
img.rec-media { cursor: zoom-in; }
.pdf-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.pdf-card .li-sub { color: var(--accent); }
textarea.input { line-height: 1.45; }

/* ---- auth gate ---- */
.auth-gate {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto;
  background: radial-gradient(120% 90% at 50% 0%, rgba(79,140,255,0.18), transparent 60%), var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top,0px) + 24px) 20px calc(env(safe-area-inset-bottom,0px) + 24px);
}
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { width: 60px; height: 60px; border-radius: 18px; margin: 0 auto 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #7b5cff); color: #fff; font-weight: 900; font-size: 30px; box-shadow: 0 10px 30px rgba(79,140,255,.4); }
.auth-title { text-align: center; font-size: 26px; font-weight: 800; margin: 0 0 6px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin: 0 0 22px; line-height: 1.5; }
.auth-err { color: var(--red); font-size: 13px; font-weight: 600; min-height: 18px; margin-bottom: 6px; text-align: center; }
.auth-switch { display: block; width: 100%; background: none; border: 0; color: var(--accent); font-weight: 600; font-size: 13.5px; margin-top: 16px; cursor: pointer; font-family: inherit; }

/* tap targets / misc */
button { touch-action: manipulation; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.tagrow { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 13px; padding: 8px 13px; border-radius: 11px; background: var(--bg-elev); border: 1px solid var(--line); color: var(--text); cursor: pointer; font-weight: 600; }
.tag.on { background: var(--accent); border-color: var(--accent); color: #fff; }
