/* ═══════════════════════════════════════════════════════════════════════════
   Forestr Go — CSS
   Theme: Safety Orange (#FF6700) on Carbon Black (#0A0A0A)
   Design: Mobile-first, glove-friendly (≥48 px tap targets), high contrast.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --orange:        #FF6700;
  --orange-dim:    #CC5200;
  --orange-muted:  rgba(255, 103, 0, 0.15);
  --black:         #0A0A0A;
  --surface:       #141414;
  --surface-2:     #1E1E1E;
  --surface-3:     #2A2A2A;
  --border:        rgba(255, 103, 0, 0.25);
  --text:          #F0F0F0;
  --text-dim:      #999;
  --success:       #4CAF50;
  --error:         #F44336;
  --warning:       #FFC107;
  --radius:        12px;
  --radius-lg:     20px;
  --tap-min:       48px;
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:     'SF Mono', 'Fira Code', 'Courier New', monospace;
  --shadow:        0 4px 24px rgba(0, 0, 0, 0.6);
  --shadow-orange: 0 4px 16px rgba(255, 103, 0, 0.35);
  --transition:    0.18s ease;
  --status-h:      0px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--black);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

/* Prevent iOS rubber-band scroll on body */
body { position: fixed; width: 100%; }

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--black);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  z-index: 2;
}

/* ── Status Bar ───────────────────────────────────────────────────────────── */
.status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--status-h);
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  /* Safe area — notch/Dynamic Island */
  padding-top: env(safe-area-inset-top, 0);
  height: calc(var(--status-h) + env(safe-area-inset-top, 0));
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
  min-width: 90px;
}
.status-item.brand {
  color: var(--orange);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  justify-content: center;
  flex: 1;
}
.status-item:last-child { justify-content: flex-end; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-dot.gps-good    { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.gps-medium  { background: var(--warning); }
.status-dot.gps-poor    { background: var(--error); }
.status-dot.gps-none    { background: var(--text-dim); }

/* ── Upload Screen ────────────────────────────────────────────────────────── */
#uploadScreen {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Remove fixed centering — landing-scroll handles layout */
}

.landing-scroll {
  min-height: 100%;
  padding: 24px;
  padding-top: calc(var(--status-h) + env(safe-area-inset-top, 0) + 32px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0) + 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ── Map View Card ────────────────────────────────────────────────────── */
.map-view-card {
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow);
}
.map-view-card:active { transform: scale(0.98); }

.map-view-nz {
  position: relative;
  width: 100%;
  height: 220px;
  background: linear-gradient(160deg, #0d3349 0%, #0e4f3a 40%, #1a6b4a 70%, #0d3349 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Subtle grid lines like a topo/map sheet */
.map-view-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 32px 32px;
}

.nz-silhouette {
  position: relative;
  z-index: 1;
  width: 148px;
  height: auto;
  filter: drop-shadow(0 0 10px rgba(255,103,0,0.35));
}

.map-view-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(255,255,255,0.7);
  z-index: 2;
}


.upload-container {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.brand-logo {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.brand-wordmark {
  width: min(260px, 72vw);
  height: auto;
  display: block;
  /* White logo on dark bg — no filter needed */
}
.brand-tagline {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.drop-zone {
  width: auto;
  max-width: 420px;
  border: 2px solid var(--orange);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 28px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
  position: relative;
}
.drop-zone.drag-over {
  background: var(--orange-muted);
}
.drop-zone-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.drop-zone-text {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drop-zone-text strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.drop-zone-text span {
  font-size: 11px;
  color: var(--text-dim);
}
.file-hint {
  font-size: 11px !important;
  color: var(--text-dim) !important;
  opacity: 0.7;
}

/* Hide native file input but keep it accessible */
#fileInput {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.btn-upload {
  pointer-events: none; /* clicks pass through to #fileInput */
  margin-top: 8px;
}

/* ── Progress Bar ─────────────────────────────────────────────────────────── */
.upload-progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.upload-progress[hidden] {
  display: none;
}
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--orange);
  border-radius: 3px;
  width: 0%;
  transition: width 0.2s ease;
}
#progressText {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

/* Manual bounds entry (GeoPDF fallback) */
.bounds-form {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.bounds-form h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--orange);
}
.bounds-form p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.bounds-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.bounds-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bounds-field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.bounds-field input {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition);
  min-height: var(--tap-min);
}
.bounds-field input:focus {
  border-color: var(--orange);
}

/* ── Saved Maps Section ───────────────────────────────────────────────────── */
.saved-maps-section {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-left: 4px;
}

.saved-maps-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  min-height: var(--tap-min);
  -webkit-tap-highlight-color: transparent;
}
.map-card:hover  { background: var(--surface-2); }
.map-card:active {
  background: var(--orange-muted);
  border-color: var(--orange);
}

.map-card-icon {
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
}

.map-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.map-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-card-meta {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.map-card-delete {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.map-card-delete:hover, .map-card-delete:active {
  color: var(--error);
  background: rgba(244, 67, 54, 0.15);
}

.saved-maps-empty {
  text-align: center;
  padding: 28px 20px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Map Screen ───────────────────────────────────────────────────────────── */
#mapScreen { position: fixed; inset: 0; }

#mapContainer {
  position: absolute;
  inset: 0;
  background: #111;
}
/* MapLibre canvas fills container */
/* Note: do NOT override MapLibre's own canvas sizing here — it manages its own dimensions */
/* Suppress MapLibre attribution in rugged UI */
.maplibregl-ctrl-attrib { display: none !important; }
/* Custom scale bar styling */
.maplibregl-ctrl-scale {
  background: rgba(10,10,10,0.75) !important;
  border-color: var(--orange) !important;
  color: var(--text) !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  letter-spacing: 0.04em !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
}
.maplibregl-ctrl-bottom-left { bottom: 72px !important; left: 12px !important; }

/* ── Basemap offline banner ──────────────────────────────────────────────── */
.basemap-banner {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
.basemap-banner[hidden] { display: none; }

/* ── Coordinate Display ───────────────────────────────────────────────────── */
.coord-display {
  position: absolute;
  top: calc(var(--status-h) + env(safe-area-inset-top, 0) + 8px);
  left: 12px;
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.coord-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.coord-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--orange);
  flex-shrink: 0;
  width: 38px;
}
.coord-row span:last-child {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
  white-space: nowrap;
}

/* ── Map Controls (FAB cluster) ───────────────────────────────────────────── */
.map-controls {
  position: absolute;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.control-btn {
  width: 56px;
  height: 56px;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: rgba(20, 20, 20, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              transform 0.1s ease, box-shadow var(--transition);
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.control-btn svg { width: 24px; height: 24px; flex-shrink: 0; }
.control-btn:active { transform: scale(0.93); }
.control-btn:hover, .control-btn.active {
  background: var(--orange-muted);
  border-color: var(--orange);
  color: var(--orange);
  box-shadow: var(--shadow-orange);
}
.control-btn.btn-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  box-shadow: var(--shadow-orange);
}
.control-btn.btn-primary:hover, .control-btn.btn-primary:active {
  background: var(--orange-dim);
}

/* ── Compass Rose ─────────────────────────────────────────────────────────── */
.compass-rose {
  position: absolute;
  top: calc(var(--status-h) + env(safe-area-inset-top, 0) + 12px);
  right: 14px;
  pointer-events: none;
  transition: transform 0.15s linear;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.7));
}

/* ── Buttons (general) ────────────────────────────────────────────────────── */
.btn-primary {
  min-height: var(--tap-min);
  padding: 0 28px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s ease;
  box-shadow: var(--shadow-orange);
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--orange-dim); transform: scale(0.97); }

.btn-secondary {
  min-height: var(--tap-min);
  padding: 0 20px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:hover, .btn-secondary:active {
  border-color: var(--orange);
  color: var(--orange);
}

.btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover, .btn-icon:active { color: var(--text); background: var(--surface-3); }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.modal-overlay[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.25s ease;
}
.modal-large { max-height: 80vh; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-coords {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.6;
}

.waypoint-input {
  width: 100%;
  min-height: var(--tap-min);
  background: var(--surface-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  color: var(--text);
  font-size: 16px;   /* 16px prevents iOS auto-zoom */
  outline: none;
  transition: border-color var(--transition);
}
.waypoint-input:focus { border-color: var(--orange); }

.modal-actions {
  display: flex;
  gap: 12px;
}
.modal-actions .btn-primary,
.modal-actions .btn-secondary { flex: 1; }

/* ── Waypoints List ───────────────────────────────────────────────────────── */
.waypoints-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: calc(80vh - 180px);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-y: auto;
}

.waypoint-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  background: var(--surface-2);
  min-height: var(--tap-min);
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.waypoint-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.waypoint-item:last-child  { border-radius: 0 0 var(--radius) var(--radius); }
.waypoint-item:hover, .waypoint-item:active { background: var(--surface-3); }

.waypoint-pin-icon {
  width: 32px;
  height: 32px;
  background: var(--orange);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.waypoint-pin-icon::after {
  content: '';
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  transform: rotate(45deg);
}

.waypoint-info {
  flex: 1;
  min-width: 0;
}
.waypoint-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.waypoint-coords {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 2px;
}
.waypoint-time {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}
.waypoint-delete {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.waypoint-delete:hover, .waypoint-delete:active {
  color: var(--error);
  background: rgba(244, 67, 54, 0.15);
}

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 32px 16px;
  line-height: 1.6;
}

/* ── Toast Notifications ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  z-index: 300;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.toast-success { border-color: var(--success); }
.toast.toast-error   { border-color: var(--error); }
.toast.toast-info    { border-color: var(--orange); }

/* ── Accuracy Ring on Blue Dot ────────────────────────────────────────────── */
/* MapLibre feature styling is in map.js via layer paint props */

/* ── GPS Accuracy Pulse Animation ─────────────────────────────────────────── */
@keyframes gpsPulse {
  0%   { opacity: 0.8; transform: scale(1); }
  100% { opacity: 0;   transform: scale(3); }
}
.gps-pulse { animation: gpsPulse 2s ease-out infinite; }

/* ── Scrollbar (minimal) ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* ── Media queries ────────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  .map-controls { right: 20px; bottom: calc(env(safe-area-inset-bottom, 20px) + 20px); }
}

/* ── Loading spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
