:root {
  --bg: #F6F4EE;
  --surface: #FFFFFF;
  --ink: #1E2420;
  --muted: #5F6B63;
  --line: #DCD8CC;
  --brand: #2E5E3E;
  --brand-ink: #FFFFFF;
  --accent: #F2C14E;
  --danger: #B3261E;
  --layer: #E0782B;
  --dog: #2F6FD6;
  --hidden: #C0392B;
  --trainer: #2E5E3E;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141815;
    --surface: #1F2521;
    --ink: #ECEFEA;
    --muted: #A3ADA6;
    --line: #36403A;
    --brand: #5FA374;
    --brand-ink: #0D1410;
    --shadow: 0 2px 10px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141815; --surface: #1F2521; --ink: #ECEFEA; --muted: #A3ADA6; --line: #36403A;
  --brand: #5FA374; --brand-ink: #0D1410; --shadow: 0 2px 10px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
#bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
  min-height: 52px;
}
#bar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bar button { background: transparent; color: inherit; border: 0; font-size: 20px; padding: 4px 8px; }
#bar .net { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.18); white-space: nowrap; }
#bar .net.off { background: var(--danger); color: #fff; }
main { flex: 1; overflow: auto; }
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px 40px; }

h2 { font-size: 20px; margin: 18px 0 8px; }
h3 { font-size: 16px; margin: 14px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
a { color: var(--brand); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow);
}
.card.alert { border-color: var(--accent); border-width: 2px; }
.card.hl { border-left: 6px solid var(--brand); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 10px 14px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.big { width: 100%; font-size: 18px; min-height: 56px; margin: 6px 0; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.grow { flex: 1; }

label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea { min-height: 80px; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 15px; }
.check input { width: 22px; height: 22px; flex: none; margin-top: 2px; }

/* Trénink: mapa nahoře, panel dole */
.training { display: flex; flex-direction: column; height: 100%; }
.training .map { flex: 1 1 50%; min-height: 240px; }
.training .panel { flex: 1 1 50%; overflow: auto; background: var(--bg); border-top: 1px solid var(--line); }
.tabs { display: flex; position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; border-radius: 0; flex: 1; font-size: 14px; min-width: 72px; background: transparent; border-bottom: 3px solid transparent; }
.tabs button.on { border-bottom-color: var(--brand); color: var(--brand); }
.tabs .badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }
.panel .inner { padding: 8px 16px 32px; max-width: 720px; margin: 0 auto; }
@media (min-width: 900px) {
  .training { flex-direction: row; }
  .training .map { flex: 1 1 60%; }
  .training .panel { flex: 0 0 420px; border-top: 0; border-left: 1px solid var(--line); }
}
.full-map { height: 46vh; min-height: 260px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }

.person { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.dot { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.person .who { flex: 1; min-width: 0; }
.person .who b { display: block; }
.person .where { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dir { font-size: 18px; font-weight: 700; color: var(--ink); }

.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--line); color: var(--ink); white-space: nowrap; }
.chip.ble { background: #DCE8FF; color: #1D3F8A; }
.chip.sms { background: #FFE8C2; color: #7A4A00; }
.chip.old { background: #F4D6D3; color: #7A1A13; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.metric b { display: block; font-size: 20px; }
.metric span { font-size: 12px; color: var(--muted); }

.qr { display: grid; place-items: center; background: #fff; padding: 12px; border-radius: 12px; }
.qr svg { width: 100%; max-width: 280px; height: auto; }
.code { font-size: 32px; letter-spacing: 6px; font-weight: 800; text-align: center; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); width: 0; transition: width .2s; }
video { width: 100%; border-radius: 12px; background: #000; }
ul.plain { padding-left: 18px; margin: 4px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px;
  max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 1000;
}
#toast.show { opacity: .95; }

/* Mapa */
.mk { border-radius: 50%; color: #fff; font: 700 12px/1 system-ui, sans-serif; display: grid; place-items: center;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.mk.stale { opacity: .55; }
.mk.me { background: #1A73E8 !important; }
.mapy-logo { display: block; width: 90px; height: 27px; }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.leaflet-popup-content .row { margin-top: 6px; }
.leaflet-popup-content a.btn { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.card button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.dialog-back { position: fixed; inset: 0; z-index: 3000; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.dialog { width: 100%; max-width: 480px; background: var(--surface); color: var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 8px; margin-bottom: env(safe-area-inset-bottom); }
.dialog h3 { margin: 0 0 8px; }
.dialog input { width: 100%; }
.dialog .row { justify-content: flex-end; margin-top: 12px; }
