:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-elev: #1c232c;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #2ea043;
  --accent-2: #3b82f6;
  --danger: #f85149;
  --warn: #d29922;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Klasy z display:flex biją regułę [hidden] z UA stylesheet — wymuszamy ukrycie. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(13, 17, 23, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}
.dot.live { background: var(--accent); box-shadow: 0 0 0 0 rgba(46,160,67,.7); animation: pulse 1.8s infinite; }
.dot.err  { background: var(--danger); }

@keyframes pulse {
  70%  { box-shadow: 0 0 0 12px rgba(46,160,67,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,160,67,0); }
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2 { font-size: 15px; margin: 0; color: var(--text); font-weight: 600; }
.card-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block; min-width: 22px; text-align: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; font-size: 12px; color: var(--text-dim);
}

/* ---------- status ---------- */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}
.stat-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }
.stat-value { display: block; font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.hint { color: var(--text-dim); font-size: 13px; margin: 10px 0 0; }
.hint.err { color: var(--danger); }
.hint.ok { color: var(--accent); }

/* ---------- map ---------- */
.map-card { padding-bottom: 14px; }
#map {
  height: 300px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  z-index: 1;
}
#map.picking { outline: 2px solid var(--accent-2); outline-offset: 2px; cursor: crosshair; }
.leaflet-container { background: #1c232c; font-family: inherit; }

/* ---------- form ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 150px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12px; color: var(--text-dim); }

input[type=text], input[type=number], textarea, select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); }
textarea { resize: vertical; }

input[type=range] { width: 100%; accent-color: var(--accent); margin: 6px 0; }

.chk {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.chk input { accent-color: var(--accent); width: 17px; height: 17px; }
.chk b { color: var(--text); font-weight: 600; }

.switches { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary.stop { background: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* ---------- points list ---------- */
.points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.point {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
}
.point.inside { border-color: var(--accent); }
.point.off { opacity: .5; }

.point-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.point-name { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.point-dist { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.point-dist.near { color: var(--accent); }
.point-msg { font-size: 13px; color: var(--text-dim); margin: 4px 0 0; overflow-wrap: anywhere; }
.point-meta { font-size: 12px; color: var(--text-dim); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.tag { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.tag.hit { color: var(--accent); border-color: var(--accent); }

.point-actions { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.point-actions .btn { padding: 5px 10px; font-size: 12px; }
.btn-del { color: var(--danger); }

.empty { text-align: center; padding: 8px 0; }

/* ---------- log ---------- */
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.log li { font-size: 13px; color: var(--text-dim); border-left: 2px solid var(--border); padding-left: 10px; }
.log li b { color: var(--text); font-weight: 600; }
.log time { font-variant-numeric: tabular-nums; opacity: .7; margin-right: 6px; }

/* ---------- note ---------- */
.note summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.note p, .note li { font-size: 13px; color: var(--text-dim); }
.note ul { padding-left: 18px; }
.note code { background: var(--bg-elev); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 1000;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 14px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: rise .25s ease-out;
  max-width: 700px;
  margin: 0 auto;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0 } }
.toast-body { flex: 1; min-width: 0; }
.toast-body strong { display: block; font-size: 15px; }
.toast-body p { margin: 3px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.toast-close { background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; padding: 0 2px; }

@media (min-width: 560px) {
  .status-grid { grid-template-columns: repeat(4, 1fr); }
  #map { height: 360px; }
}
