:root {
  --green: #22301f;
  --green-2: #2f4430;
  --ink: #16211a;
  --muted: #6b7a6d;
  --line: #d8ded6;
  --surface: #ffffff;
  --accent: #c1502e;
  --tap: 46px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #eef1ec;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  touch-action: pan-x pan-y;
}

/* ---------- горна лента ---------- */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  background: color-mix(in srgb, var(--green) 92%, transparent);
  color: #f2f5ef;
  font-size: 0.95rem;
  backdrop-filter: blur(6px);
}

.bar strong { font-size: 1.05rem; letter-spacing: 0.02em; }

.status {
  margin-left: auto;
  font-size: 0.78rem;
  color: #c9d6c6;
  text-align: right;
  max-width: 60%;
}

/* ---------- бутони ---------- */

.fabs {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 6;
  display: flex;
  gap: 10px;
  align-items: center;
}

.fab {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(20, 35, 20, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.fab--wide {
  flex: 1;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.fab--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.fab:active { transform: scale(0.97); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---------- панел с точки ---------- */

.panel {
  position: fixed;
  z-index: 8;
  left: 8px;
  right: 8px;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(20, 35, 20, 0.22);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
}

.panel-head h2 { margin: 0; font-size: 1.05rem; }

.plain {
  margin-left: auto;
  border: 0;
  background: none;
  font-size: 1.1rem;
  color: var(--muted);
  min-height: 34px;
  min-width: 34px;
}

#search {
  margin: 0 14px 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #f7f9f5;
}

#pointList {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#pointList li button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border: 0;
  border-bottom: 1px solid #eef1ec;
  background: none;
  font: inherit;
  text-align: left;
}

.li-name { font-weight: 600; }

.li-dist {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

#pointList .empty {
  padding: 14px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-foot {
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px) / 2);
  border-top: 1px solid var(--line);
}

.panel-foot button,
.panel-foot .filebtn {
  flex: 1;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9f5;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
}

/* ---------- нова точка ---------- */

.sheet {
  position: fixed;
  z-index: 9;
  left: 8px;
  right: 8px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px) / 2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(20, 35, 20, 0.25);
}

.sheet h2 { margin: 0 0 10px; font-size: 1.05rem; }

.sheet label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.sheet input,
.sheet textarea {
  width: 100%;
  margin-top: 4px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  color: var(--ink);
  background: #f7f9f5;
}

.sheet textarea { resize: vertical; }

.sheet .row { display: flex; gap: 10px; }

.sheet .row button {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f2f4f0;
  font: inherit;
  font-weight: 600;
}

.sheet .row .primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.muted { color: var(--muted); font-size: 0.82rem; }

/* ---------- маркери ---------- */

.pin {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  pointer-events: auto;
}

.pin-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  flex: none;
}

.pin-label {
  font-size: 11.5px;
  font-weight: 600;
  color: #22301f;
  background: rgba(255, 255, 255, 0.88);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.me-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1e6fd9;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(30, 111, 217, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* ---------- изскачащ прозорец ---------- */

.pop { font-size: 0.9rem; line-height: 1.35; max-width: 220px; }
.pop strong { font-size: 1rem; display: block; margin-bottom: 2px; }
.pop p { margin: 4px 0 8px; }
.pop .link-danger {
  border: 0;
  background: none;
  padding: 0;
  color: #a3311c;
  font: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
}

.maplibregl-popup-content {
  border-radius: 12px !important;
  padding: 12px 14px !important;
}

/* ---------- известие ---------- */

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(22, 33, 26, 0.92);
  color: #fff;
  font-size: 0.9rem;
  white-space: nowrap;
}

@media (min-width: 720px) {
  .panel { left: auto; width: 340px; right: 14px; bottom: 84px; max-height: 70vh; }
  .sheet { left: auto; width: 360px; right: 14px; }
  .fabs { left: 14px; right: auto; width: 320px; }
}

/* ---------- режим собственик ---------- */

[hidden] { display: none !important; }

body:not(.admin) .owner-only { display: none !important; }

.fab--pub {
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  background: #fdf3ec;
  border-color: #e0b79c;
  color: #8a3f14;
  padding: 0 12px;
}

.coord-row { display: flex; gap: 10px; }
.coord-row label { flex: 1; }

.sheet-del {
  margin-top: 10px;
  width: 100%;
  min-height: 40px;
  border: 0;
  background: none;
  font-size: 0.88rem;
}

.err {
  margin: 0 0 8px;
  color: #a3311c;
  font-size: 0.85rem;
  min-height: 1.1em;
}

.pop-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 2px;
}

.pop .link-action {
  border: 0;
  background: none;
  padding: 0;
  color: #22301f;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: underline;
}

/* лента „само за собственика“ */
body.admin .bar strong::after {
  content: " · собственик";
  font-size: 0.72rem;
  font-weight: 400;
  color: #cbb9a4;
}

/* точката се слага на мястото, където си — маркерът се плъзга */
.pos-hint {
  margin: 2px 0 10px;
  font-size: 0.83rem;
  line-height: 1.35;
  color: #5a6353;
}

.draft-pin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #b4551b;
  border: 3px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  cursor: grab;
  touch-action: none;
}

.draft-pin:active { cursor: grabbing; }

/* предупреждение: човекът е извън района на Агатово */
.away {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 52px;
  z-index: 5;
  padding: 9px 12px;
  border-radius: 10px;
  background: #7d2b18;
  border: 1px solid #a83a20;
  color: #fff;
  font-size: 0.82rem;
  line-height: 1.3;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.away strong { display: block; font-size: 0.86rem; }

.away-dist {
  display: block;
  margin-top: 2px;
  color: #f3d7cd;
  font-size: 0.78rem;
}

/* лента, когато няма позиция — за да се знае защо нищо не се случва */
.geobar {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 62px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  background: #3a2a12;
  border: 1px solid #8a6a2a;
  color: #ffd899;
  font-size: 0.84rem;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.geobar[hidden] { display: none; }
.geobar span { flex: 1; }
.geobar-btn {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid #8a6a2a;
  background: #503a16;
  color: #ffe0a8;
  font-size: 0.8rem;
  font-family: inherit;
}
body.away .geobar { top: 108px; }
body.away #addBtn { opacity: 0.5; }
