:root {
  --brand: #1e5f8c;
  --brand-dark: #123a56;
  --accent: #e0392c;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a2229;
  --muted: #6b7680;
  --border: #dde3e8;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 30, 40, 0.15);
  color-scheme: light;
}

* { box-sizing: border-box; }

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

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
  color: var(--brand-dark);
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.field input:focus, .field select:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 46px;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #eef2f5; color: var(--text); }
.btn-secondary:hover { background: #e2e8ec; }
.btn-danger { background: var(--accent); color: #fff; }
.btn-small { padding: 8px 12px; font-size: 0.85rem; min-height: 36px; width: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 18px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.error-msg {
  background: #fdecea;
  color: #a12a20;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.info-msg {
  background: #eaf2f8;
  color: var(--brand-dark);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-top: 14px;
}

.passkey-offer {
  margin-top: 16px;
  padding: 14px;
  background: #f0f7ee;
  border-radius: 8px;
  border: 1px solid #cfe6c5;
}
.passkey-offer p { margin: 0 0 10px; font-size: 0.88rem; }
.passkey-offer .row { display: flex; gap: 8px; }
.passkey-offer .row .btn { flex: 1; }

/* ---------- App shell ---------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#map {
  position: absolute;
  inset: 0;
  background: #cfd6db;
}

.searchbar-wrap {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  padding: 10px 10px 0;
  pointer-events: none;
}

.searchbar {
  pointer-events: auto;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  padding: 4px 6px;
}

.searchbar input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  padding: 12px 10px;
  background: transparent;
}

.searchbar .clear-btn {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  color: var(--muted);
  padding: 8px 10px;
  display: none;
}

.search-results {
  pointer-events: auto;
  margin-top: 6px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 50vh;
  overflow-y: auto;
  display: none;
}

.search-results.open { display: block; }

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:active { background: #f0f4f7; }
.search-result-item .name { font-weight: 600; }
.search-result-item .meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.search-empty { padding: 14px 16px; color: var(--muted); font-size: 0.9rem; }

.back-btn {
  position: absolute;
  z-index: 1000;
  top: 70px;
  left: 10px;
  background: var(--card);
  border: none;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--brand-dark);
}
.back-btn.visible { display: flex; }

.breadcrumb {
  position: absolute;
  z-index: 1000;
  top: 70px;
  left: 66px;
  right: 10px;
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  box-shadow: var(--shadow);
  display: none;
  white-space: nowrap;
  overflow-x: auto;
}
.breadcrumb.visible { display: block; }

.locate-btn {
  position: absolute;
  z-index: 1000;
  right: 12px;
  bottom: 90px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--card);
  border: none;
  box-shadow: var(--shadow);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.locate-btn.active { background: var(--brand); color: #fff; }

.logout-btn {
  position: absolute;
  z-index: 1000;
  right: 12px;
  top: 10px;
  background: var(--card);
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---------- Admin bottom bar ---------- */

.admin-bar {
  position: absolute;
  z-index: 1000;
  left: 0; right: 0; bottom: 0;
  display: none;
  background: var(--card);
  box-shadow: 0 -2px 10px rgba(20,30,40,0.15);
  padding: 8px calc(8px + env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-right));
  gap: 6px;
  overflow-x: auto;
}
.admin-bar.visible { display: flex; }
.admin-bar button {
  flex: 1 0 auto;
  min-width: 84px;
  border: none;
  background: #eef2f5;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.admin-bar button.active { background: var(--brand); color: #fff; }
.admin-bar button .icon { font-size: 1.2rem; }

.admin-hint {
  position: absolute;
  z-index: 1000;
  left: 10px; right: 10px;
  bottom: 76px;
  background: var(--brand-dark);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: var(--shadow);
}
.admin-hint.visible { display: flex; }
.admin-hint #admin-hint-text { flex: 1; text-align: center; }
.admin-hint button {
  flex-shrink: 0;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}
.admin-hint button:active { background: rgba(255,255,255,0.3); }
#shape-edit-bar #shape-edit-done { background: #2f7a3f; }
#shape-edit-bar #shape-edit-done:active { background: #256231; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,15,20,0.5);
  z-index: 2000;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal {
  position: relative;
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal { border-radius: 16px; }
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  color: var(--brand-dark);
}

.modal .actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.modal .actions .btn { flex: 1; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--muted);
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  padding: 0;
  cursor: pointer;
  position: relative;
}
.color-swatch.selected {
  border-color: var(--text);
}
.color-swatch.selected::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
}

/* Users / calibration lists */

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.list-item:last-child { border-bottom: none; }
.list-item .info { min-width: 0; }
.list-item .info .primary { font-weight: 600; }
.list-item .info .secondary { font-size: 0.78rem; color: var(--muted); }
.list-item .row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.list-item .row-actions button {
  border: none;
  background: #eef2f5;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.78rem;
}
.list-item .row-actions button.danger { background: #fdecea; color: #a12a20; }

.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 18px 0 6px;
}
.section-title:first-child { margin-top: 0; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: #eef2f5;
  color: var(--muted);
}
.badge.admin { background: #fdecea; color: #a12a20; }

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2229;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.visible { opacity: 1; }

.step-list { margin: 0; padding-left: 18px; font-size: 0.88rem; color: var(--muted); }
.step-list li { margin-bottom: 6px; }

.leaflet-popup-content { font-size: 0.9rem; min-width: 180px; }
.leaflet-popup-content .popup-title { font-weight: 700; margin-bottom: 2px; }
.leaflet-popup-content .popup-meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 6px; }
.leaflet-popup-content .popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.leaflet-popup-content .popup-actions button {
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.78rem;
  background: #eef2f5;
}
.leaflet-popup-content .popup-actions button.danger { background: #fdecea; color: #a12a20; }

.gps-arrow-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
