:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #fff;
  --line: #d7dee8;
  --text: #17202c;
  --muted: #667383;
  --gold: #ffc629;
  --blue: #1688e8;
  --green: #2ca145;
  --red: #e84d3d;
  --black: #111821;
  --shadow: 0 10px 32px rgba(18, 28, 40, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button,
.primary-link {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafc;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

button:active,
.primary-link:active { transform: translateY(1px); }

.locator-shell {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 10px 72px;
  display: grid;
  gap: 10px;
}

.locator-header,
.locator-menu,
.panel,
.map-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.locator-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.menu-button {
  position: relative;
  width: 52px;
  min-height: 52px;
  display: grid;
  place-items: center;
  font-size: 28px;
  line-height: 1;
}

.menu-button.has-unread {
  border-color: #7dc8ff;
  background: linear-gradient(180deg, #eef8ff, #dff1ff);
  color: #0b6fba;
}

.menu-button-icon,
.menu-button-mail {
  grid-area: 1 / 1;
  transition: opacity 160ms ease, transform 160ms ease;
}

.menu-button-mail {
  opacity: 0;
  transform: translateY(4px) scale(0.88);
}

.menu-button.has-unread .menu-button-icon {
  opacity: 0;
  transform: translateY(-4px) scale(0.88);
}

.menu-button.has-unread .menu-button-mail {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.menu-button-unread {
  position: absolute;
  right: -7px;
  top: -7px;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  background: #ef4444;
  color: #fff;
  font-size: 13px;
  font-weight: 950;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.locator-header strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.locator-header span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.signal-pill {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 9px;
  border-radius: 8px;
  background: #eef9f0;
  color: #168330 !important;
  font-weight: 850;
  white-space: nowrap;
}

.signal-pill.warn {
  background: #fff6d9;
  color: #9b6800 !important;
}

.locator-menu .locator-chat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.locator-menu-row-badge {
  min-width: 26px;
  border-radius: 999px;
  padding: 2px 8px;
  display: inline-grid;
  place-items: center;
  background: #ef4444;
  color: #fff;
  font-size: 14px;
  font-weight: 950;
}

.signal-pill.bad {
  background: #ffebe8;
  color: #b4271b !important;
}

.locator-menu {
  position: sticky;
  top: 76px;
  z-index: 29;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.locator-menu a,
.locator-menu button,
.primary-link {
  display: grid;
  place-items: center;
  padding: 10px 12px;
}

.panel,
.map-panel {
  padding: 10px;
}

.search-panel {
  position: relative;
  z-index: 1;
}

.auth-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.auth-panel p {
  margin: 0 0 14px;
  color: var(--muted);
}

.search-box {
  position: relative;
  display: block;
}

.search-box span {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 12px 12px 40px;
  font-size: 20px;
  font-weight: 850;
  text-transform: uppercase;
  background: #fff;
}

.search-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.search-actions button:first-child,
.primary-link {
  border-color: #dfa600;
  background: linear-gradient(#ffd75a, #ffc01f);
}

#nextPointButton {
  background: #fff;
}

.message {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}

.message.error { color: var(--red); }

.panel-title,
.map-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.panel-title h2,
.map-top h2 {
  margin: 0;
  font-size: 18px;
}

.panel-title span,
.map-top span {
  color: var(--muted);
  font-weight: 800;
}

.anchor-list {
  display: grid;
  gap: 7px;
}

.route-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.route-actions button:first-child,
#photoGpsCalibrationButton,
#saveRouteButton {
  border-color: #dfa600;
  background: linear-gradient(#ffd75a, #ffc01f);
}

.route-actions #photoGpsCalibrationButton,
.route-actions #saveRouteButton {
  grid-column: 1 / -1;
}

.route-name {
  display: grid;
  gap: 5px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.route-name input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.route-status {
  margin-bottom: 8px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  background: #fbfcfe;
}

.anchor-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.anchor-row strong {
  display: block;
}

.anchor-row small {
  color: var(--muted);
  font-weight: 700;
}

.anchor-row button {
  min-height: 38px;
  padding: 6px 10px;
}

.anchor-row.axis-a { border-left: 5px solid var(--blue); }
.anchor-row.axis-b { border-left: 5px solid var(--gold); }
.anchor-row.rejected { opacity: .58; }

.server-calibrations {
  margin-top: 10px;
}

.server-calibrations summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 900;
}

.server-calibration-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.server-calibration-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.server-calibration-card strong,
.server-calibration-card small {
  display: block;
}

.server-calibration-card small {
  color: var(--muted);
  font-weight: 750;
}

.map-buttons {
  display: flex;
  gap: 7px;
}

.map-buttons button {
  padding: 0 10px;
}

.locator-map {
  position: relative;
  height: min(68vh, 620px);
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(23,32,44,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23,32,44,.07) 1px, transparent 1px),
    #f8fafc;
  background-size: 28px 28px;
  touch-action: none;
}

.map-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.map-point {
  position: absolute;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 3px solid #83909d;
  border-radius: 50%;
  background: rgba(255,255,255,.92);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(18, 28, 40, .12);
}

.map-point.done { border-color: var(--green); background: rgba(44,161,69,.9); }
.map-point.partial_blocked { border-color: var(--black); background: linear-gradient(90deg, var(--green) 0 50%, var(--black) 50%); }
.map-point.attention { border-color: #dba200; background: var(--gold); }
.map-point.problem { border-color: var(--red); background: rgba(232,77,61,.9); }
.map-point.lift {
  border-color: var(--red);
  background: rgba(255,255,255,.96);
}
.map-point.lift::after {
  content: attr(data-lift-percent);
  color: var(--red);
  font-size: 11px;
  font-weight: 950;
}
.map-point.blocked::before,
.map-point.blocked::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 4px;
  border-radius: 4px;
  background: var(--black);
}
.map-point.blocked::before { transform: rotate(45deg); }
.map-point.blocked::after { transform: rotate(-45deg); }

.map-point strong {
  position: absolute;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255,255,255,.88);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.map-panel.full-map-mode .phone-marker {
  display: none;
}

.map-panel.full-map-mode .locator-map {
  background-size: 22px 22px;
}

.map-panel.full-map-mode .map-point strong {
  top: 38px;
  font-size: 11px;
}

.fit-map-button {
  width: 100%;
  margin-top: 8px;
  border-color: #dfa600;
  background: linear-gradient(#ffd75a, #ffc01f);
}

.phone-marker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border: 4px solid var(--blue);
  border-radius: 50%;
  background: rgba(22,136,232,.15);
  box-shadow: 0 0 0 18px rgba(22,136,232,.08);
  pointer-events: none;
}

.phone-marker span {
  position: absolute;
  left: 50%;
  top: -18px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 18px solid var(--blue);
}

.nearby-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.nearby-card {
  position: relative;
  min-height: 66px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.direction-arrow {
  position: absolute;
  right: 8px;
  top: 7px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(#ffd75a, #ffc01f);
  color: var(--text);
  font-weight: 950;
  transform-origin: center;
}

.nearby-card strong {
  display: block;
  font-size: 18px;
  padding-right: 32px;
}

.nearby-card small {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.app-version {
  position: fixed;
  right: max(18px, env(safe-area-inset-right) + 18px);
  bottom: max(12px, env(safe-area-inset-bottom) + 8px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 430px) {
  .locator-shell { padding-left: 10px; padding-right: 10px; }
  .search-actions { grid-template-columns: 1fr; }
  .route-actions { grid-template-columns: 1fr; }
  .route-actions #photoGpsCalibrationButton,
  .route-actions #saveRouteButton { grid-column: auto; }
  .map-top { align-items: flex-start; }
  .map-buttons { flex-direction: column; }
  .nearby-list { grid-template-columns: 1fr 1fr; }
}
