:root {
  --bg: #0a0e12;
  --surface: #141a22;
  --text: #e8f0f8;
  --muted: #8a9aaa;
  --cyan: #00ffff;
  --magenta: #ff00ff;
  --lat-left: #e8a838;
  --lat-right: #5b9aff;
  --accent: #00cccc;
  --danger: #ff4444;
  --warn: #ffcc00;
  --ok: #44dd88;
  --border: #2a3540;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 800px), (max-height: 700px) {
  :root {
    --tap: 44px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 900px) {
  html, body { font-size: 17px; }
}

.hidden {
  display: none !important;
}

.app-header {
  flex: 0 0 auto;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  padding-top: calc(0.35rem + env(safe-area-inset-top, 0px));
}

.header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-title {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 0.35rem;
}

/** Primary GPS readiness — green / yellow / red dot (detail in title). */
.gps-ready {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: var(--danger);
  cursor: default;
}

.gps-ready--ok {
  background: var(--ok);
  box-shadow: 0 0 10px rgba(68, 221, 136, 0.55);
}

.gps-ready--warn {
  background: var(--warn);
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.45);
}

.gps-ready--fault {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.45);
}

.drive-ready-icon {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  z-index: 20;
  width: 1.35rem;
  height: 1.35rem;
}

.status-detail {
  font-size: 0.65rem;
  max-width: 28%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.drive-active .status-detail {
  display: none;
}

.status-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid transparent;
  font-family: inherit;
}

button.status-pill--ntrip {
  cursor: pointer;
  min-height: var(--tap);
}

button.status-pill--ntrip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-pill--ok {
  background: rgba(68, 221, 136, 0.2);
  color: var(--ok);
}
.status-pill--warn {
  background: rgba(255, 204, 0, 0.2);
  color: var(--warn);
}
.status-pill--fault {
  background: rgba(255, 68, 68, 0.25);
  color: var(--danger);
}

.status-pill--ntrip {
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.55rem;
}
.status-pill--idle {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted, #9aa6b2);
}
.status-pill--connecting {
  background: rgba(255, 204, 0, 0.2);
  color: var(--warn);
}
.status-pill--streaming {
  background: rgba(68, 221, 136, 0.2);
  color: var(--ok);
}
.status-pill--error {
  background: rgba(255, 68, 68, 0.25);
  color: var(--danger);
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: #001a1a;
  border-color: var(--accent);
}

.btn--secondary {
  background: #1e2830;
}

.btn--danger {
  background: #3a1518;
  border-color: var(--danger);
  color: #ffcccc;
}

.btn--wide {
  width: 100%;
}

.btn--icon {
  min-width: var(--tap);
  padding: 0.5rem;
}

.btn--gps-on {
  border-color: var(--ok);
  color: var(--ok);
}

.btn--go {
  width: 100%;
  min-height: 56px;
  font-size: 1.25rem;
  background: linear-gradient(180deg, #00dddd, #008888);
  color: #001818;
  border: none;
}

@media (min-height: 720px) {
  .btn--go { min-height: 72px; font-size: 1.5rem; }
}

.btn--go:disabled {
  opacity: 0.4;
}

.btn--small {
  min-height: 40px;
  min-width: auto;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.btn--file {
  display: inline-block;
  text-align: center;
}

.banner {
  background: #2a2030;
  color: var(--warn);
  padding: 0.6rem 1rem;
  text-align: center;
  font-weight: 600;
}

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.drive-active .app-header,
body.drive-active #banner {
  display: none !important;
}

.view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.6rem;
  overflow: auto;
}

#view-picker:not(.hidden) {
  position: relative;
  z-index: 20;
}

.view--map {
  padding: 0;
  overflow: hidden;
  position: relative;
}

.view--drive {
  padding: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.picker-lead {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.project-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.project-list__empty,
.project-list__loading {
  padding: 0.5rem 0;
}

.project-list li {
  pointer-events: auto;
}

.project-list .btn--project {
  width: 100%;
  margin-bottom: 0.5rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  min-height: var(--tap);
  height: auto;
  padding: 0.65rem 0.85rem;
  pointer-events: auto;
  touch-action: manipulation;
}

.btn--project-current {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan);
}

.btn--project__name {
  font-size: 1.05rem;
  font-weight: 700;
}

.btn--project__meta {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.map-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  padding: 0.3rem;
  background: var(--surface);
  z-index: 50;
  align-items: center;
  overflow: hidden;
}

.map-toolbar .btn {
  min-height: var(--tap);
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.map-toolbar .project-title {
  font-size: 0.95rem;
}

@media (max-width: 720px) {
  .map-toolbar .btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }
}

.project-title {
  flex: 1;
  font-weight: 700;
  align-self: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-container {
  flex: 1 1 0;
  min-height: 0;
  z-index: 1;
  touch-action: pan-x pan-y pinch-zoom;
}

.map-container--calibrating,
.map-container--calibrating .leaflet-grab,
.map-container--calibrating .leaflet-interactive {
  cursor: crosshair !important;
}

.btn--align-on {
  border-color: var(--cyan);
  color: var(--cyan);
}

.btn--follow-on {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(68, 221, 136, 0.12);
}

.btn--align-active {
  background: var(--warn);
  border-color: var(--warn);
  color: #1a1400;
  animation: align-pulse 1.1s ease-in-out infinite;
}

@keyframes align-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 204, 0, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(255, 204, 0, 0); }
}

.dialog-help {
  margin: 0.15rem 0 0.4rem;
  font-size: 0.8rem;
  line-height: 1.35;
}

.panel-backdrop {
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.45);
}

.panel-linesets {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 90vw);
  background: rgba(20, 26, 34, 0.98);
  border-left: 1px solid var(--border);
  padding: 0.6rem;
  z-index: 60;
  overflow: auto;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}

.panel-map-menu {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(280px, 88vw);
  background: rgba(20, 26, 34, 0.98);
  border-left: 1px solid var(--border);
  padding: 0.6rem;
  z-index: 62;
  overflow: auto;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}

.panel-map-menu__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.panel-map-menu__head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.map-menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.map-menu-item {
  text-align: left;
  justify-content: flex-start;
}

.btn--menu-open {
  border-color: var(--cyan);
  color: var(--cyan);
}

.panel-linesets__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.panel-linesets__head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.btn--panel-close {
  min-width: 48px;
  min-height: 48px;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
}

.btn--lines-open {
  border-color: var(--cyan);
  color: var(--cyan);
}

.lineset-list {
  list-style: none;
  padding: 0;
}

.lineset-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.row-work-list {
  list-style: none;
  padding: 0 0 0 1.25rem;
  margin: 0.15rem 0 0.65rem;
  width: 100%;
}

.row-work-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.15rem 0;
}

.row-work-item__name--done {
  color: var(--muted);
}

.map-footer {
  padding: 0.35rem 0.6rem calc(0.35rem + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  flex: 0 0 auto;
}

.snap-hint {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.drive-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  touch-action: none;
  background: #0a0e12;
  overflow: hidden;
}

.drive-canvas-wrap canvas {
  display: block;
  position: relative;
  z-index: 1;
  width: 100% !important;
  height: 100% !important;
}

.drive-toolbar {
  position: absolute;
  top: calc(0.35rem + env(safe-area-inset-top, 0px));
  left: 0.35rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: auto;
}

.drive-toolbar .btn {
  background: rgba(20, 26, 34, 0.85);
  border: 1px solid var(--border);
  color: var(--text);
  min-width: 44px;
  min-height: 38px;
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
}

.drive-exit {
  position: absolute;
  top: calc(0.4rem + env(safe-area-inset-top, 0px));
  right: 0.4rem;
  z-index: 30;
  pointer-events: auto;
  min-height: 52px;
  min-width: 72px;
  padding: 0.55rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 10px;
  background: rgba(10, 14, 18, 0.92);
  border: 2px solid var(--cyan);
  color: var(--cyan);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.drive-done-hint {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  margin: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  color: var(--warn);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
}

.overlay-stop--drive {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  padding: 0.65rem;
  text-align: center;
  background: rgba(120, 0, 0, 0.88);
  z-index: 28;
  pointer-events: none;
}

.lightbar--closing .lightbar__along {
  font-weight: 700;
  color: #ff99bb;
}

.dialog--alert .dialog__body {
  margin: 0.5rem 0 1rem;
  font-size: 1rem;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lightbar-root {
  flex-shrink: 0;
  background: #05080a;
  border-top: 2px solid var(--cyan);
  padding: 0.4rem 0.5rem calc(0.4rem + var(--safe-bottom));
}

.lightbar__segments {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 0.35rem;
}

.lightbar__seg {
  width: 20px;
  height: 10px;
  background: #1a2228;
  border-radius: 3px;
}

.lightbar__seg--on {
  background: var(--cyan);
}

.lightbar__seg--left.lightbar__seg--on,
.lightbar__seg--left.lightbar__seg--warn {
  background: var(--lat-left);
  box-shadow: -1px 0 0 var(--lat-left);
}

.lightbar__seg--right.lightbar__seg--on,
.lightbar__seg--right.lightbar__seg--warn {
  background: var(--lat-right);
  box-shadow: 1px 0 0 var(--lat-right);
}

.lightbar__seg--warn {
  background: var(--magenta);
}

.lightbar__main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  max-width: 22rem;
  margin: 0 auto;
}

.lightbar__steer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  border: 3px solid #2a3540;
  background: #12181c;
  opacity: 0.3;
  min-width: 3.75rem;
  transition: opacity 0.12s, border-color 0.12s, background 0.12s, transform 0.12s;
}

.lightbar__steer--left.lightbar__steer--active {
  opacity: 1;
  border-color: var(--lat-left);
  background: rgba(232, 168, 56, 0.18);
  transform: scale(1.06);
}

.lightbar__steer--right.lightbar__steer--active {
  opacity: 1;
  border-color: var(--lat-right);
  background: rgba(91, 154, 255, 0.18);
  transform: scale(1.06);
}

.lightbar__steer--left.lightbar__steer--warn.lightbar__steer--active {
  border-color: var(--lat-left);
  background: rgba(232, 168, 56, 0.28);
}

.lightbar__steer--right.lightbar__steer--warn.lightbar__steer--active {
  border-color: var(--lat-right);
  background: rgba(91, 154, 255, 0.28);
}

.lightbar__steer--left.lightbar__steer--active .lightbar__chevron {
  animation: steer-pulse-left 0.75s ease-in-out infinite;
}

.lightbar__steer--right.lightbar__steer--active .lightbar__chevron {
  animation: steer-pulse-right 0.75s ease-in-out infinite;
}

@keyframes steer-pulse-left {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-5px);
  }
}

@keyframes steer-pulse-right {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(5px);
  }
}

.lightbar__chevron {
  font-size: 2.75rem;
  line-height: 1;
  font-weight: 900;
  color: var(--cyan);
}

.lightbar__steer--warn .lightbar__chevron {
  color: var(--magenta);
}

.lightbar__steer-word {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.lightbar__steer--left.lightbar__steer--active .lightbar__steer-word,
.lightbar__steer--left.lightbar__steer--active .lightbar__chevron {
  color: var(--lat-left);
}

.lightbar__steer--right.lightbar__steer--active .lightbar__steer-word,
.lightbar__steer--right.lightbar__steer--active .lightbar__chevron {
  color: var(--lat-right);
}

.lightbar__readout {
  text-align: center;
  min-width: 5.5rem;
  padding: 0 0.15rem;
}

.lightbar--stale .lightbar__value {
  color: var(--danger);
}

.lightbar__value {
  display: block;
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1;
  color: var(--cyan);
}

.lightbar--lat-right .lightbar__value,
.lightbar--lat-right .lightbar__unit {
  color: var(--lat-right);
}

.lightbar--lat-left .lightbar__value,
.lightbar--lat-left .lightbar__unit {
  color: var(--lat-left);
}

.lightbar--lat-on .lightbar__value {
  color: var(--ok);
}

.lightbar--lat-on .lightbar__unit {
  color: var(--muted);
}

.lightbar__unit {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.lightbar__along {
  margin: 0.3rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay-fault {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(80, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.overlay-fault__panel {
  max-width: 420px;
  text-align: center;
}

.overlay-fault__panel h2 {
  color: #fff;
  font-size: 1.5rem;
}

.overlay-fault__body {
  font-size: 1.1rem;
}

.overlay-fault__hint {
  color: #ffcccc;
}

.overlay-stop {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(255, 0, 100, 0.9);
  color: #fff;
  padding: 1rem 1.5rem;
  font-size: 1.4rem;
  border-radius: 12px;
  pointer-events: none;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  max-width: min(96vw, 560px);
  width: min(96vw, 560px);
  max-height: 90dvh;
  overflow: auto;
  padding: 0.75rem;
}

.dialog h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.dialog fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 0.5rem; padding: 0.5rem 0.65rem; }
.dialog legend { padding: 0 0.35rem; color: var(--muted); font-size: 0.85rem; }

.dialog label {
  display: block;
  margin: 0.35rem 0;
}

.dialog input[type='text'],
.dialog input[type='password'],
.dialog input[type='number'] {
  width: 100%;
  min-height: 44px;
  margin-top: 0.2rem;
  font-size: 1rem;
  background: #0a0e12;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.muted {
  color: var(--muted);
}

.row-label span {
  background: rgba(0, 0, 0, 0.65);
  color: var(--cyan);
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

.row-label--done span {
  color: rgba(180, 220, 220, 0.7);
  background: rgba(0, 0, 0, 0.45);
}

.lineset-progress {
  margin: 0.4rem 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ok);
}

.lineset-progress.muted {
  color: var(--muted);
  font-weight: 500;
}

/* Two-finger rotate (leaflet-rotate). */
.leaflet-container {
  touch-action: pan-x pan-y pinch-zoom;
  background: #1a2228;
  font-family: inherit;
}
