* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

button,
select,
input {
  font: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Roboto', sans-serif;
  background: #fff;
  overflow: hidden;
  color-scheme: light;
}

:root {
  --topbar-height: 56px;
  --statusbar-height: 76px;
  --control-gap: 12px;
  --safe-top: env(safe-area-inset-top);
  --map-control-top: calc(var(--safe-top) + var(--topbar-height) + var(--statusbar-height) + 10px);
}

/* Map Container */
#map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  min-height: 56px;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: white;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  z-index: 100;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  safe-area-inset: auto;
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  font-size: 28px;
  color: white;
}

.app-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.map-select {
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  color: #333;
  background: white;
  min-width: 150px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.icon-button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  transition: background 0.2s;
}

.icon-button:active {
  background: rgba(255, 255, 255, 0.2);
}

/* Status Bar */
.status-bar {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid #e0e0e0;
  z-index: 99;
  safe-area-inset: auto;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  flex: 1 1 40%;
  min-width: 110px;
}

.status-label {
  color: #666;
  font-weight: 500;
}

#distance-text,
#points-count {
  color: #1a73e8;
  font-weight: 600;
}

/* Quick Action Buttons (During Survey) */
.quick-actions {
  position: fixed;
  bottom: 24px;
  right: 12px;
  width: 315px;
  max-width: 90vw;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 220;
  pointer-events: auto;
  align-items: stretch;
}

.quick-actions.hidden {
  display: none !important;
}

.quick-btn {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  width: 100%;
  pointer-events: auto;
  padding: 22px 20px;
  min-height: 97px;
  border: none;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: white;
  -webkit-text-fill-color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.2);
  white-space: normal;
  text-align: center;
}

.quick-btn .material-icons {
  font-size: 35px;
}

.quick-btn > span:last-child {
  flex: 1 1 auto;
  white-space: normal;
  font-size: 0.92rem;
  line-height: 1.1;
}

.quick-btn.single-off {
  background-color: #0288d1;
  background-image: linear-gradient(135deg, #29b6f6, #0288d1);
}

.quick-btn.single-off:active {
  background-color: #0277bd;
  background-image: linear-gradient(135deg, #0288d1, #0277bd);
  transform: scale(0.98);
}

.quick-btn.double-off {
  background-color: #6a1b9a;
  background-image: linear-gradient(135deg, #8e24aa, #6a1b9a);
}

.quick-btn.double-off:active {
  background-color: #4a148c;
  background-image: linear-gradient(135deg, #6a1b9a, #4a148c);
  transform: scale(0.98);
}

.quick-btn.highmast-off {
  background-color: #e64a19;
  background-image: linear-gradient(135deg, #ff7043, #e64a19);
}

.quick-btn.highmast-off:active {
  background-color: #bf360c;
  background-image: linear-gradient(135deg, #e64a19, #bf360c);
  transform: scale(0.98);
}

/* FAB Container */
.fab-container {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 220;
}

/* make FAB slightly higher on mobile to avoid quick-actions overlap */
.fab-container.mobile-adjust {
  bottom: calc(110px + env(safe-area-inset-bottom));
}

.fab-right {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 220;
}

.current-location-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4285f4;
  border: 3px solid white;
  box-shadow: 0 0 0 6px rgba(66, 133, 244, 0.18);
  position: relative;
}

.current-location-marker::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(66, 133, 244, 0.12);
}

.map-control-group {
  position: fixed;
  top: var(--map-control-top);
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 240;
}

.map-control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: white;
  color: #1a73e8;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.16s;
}

.map-control-btn.active {
  background: #1a73e8;
  color: white;
}

.map-control-right {
  position: fixed;
  top: var(--map-control-top);
  right: 12px;
  z-index: 240;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-control-btn:hover {
  transform: translateY(-1px);
}

.map-control-btn .material-icons {
  font-size: 22px;
}

.maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show) .maplibregl-ctrl-attrib-inner,
.maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show):hover .maplibregl-ctrl-attrib-inner,
.mapboxgl-ctrl-attrib.mapboxgl-compact:not(.mapboxgl-compact-show) .mapboxgl-ctrl-attrib-inner,
.mapboxgl-ctrl-attrib.mapboxgl-compact:not(.mapboxgl-compact-show):hover .mapboxgl-ctrl-attrib-inner {
  display: none !important;
}

.survey-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: white;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  border: 2px solid #fff;
}

.survey-marker.single {
  background: #f9a825;
}

.survey-marker.double {
  background: #d32f2f;
}

.survey-marker.highmast {
  background: #ef6c00;
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  font-size: 24px;
}

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

.fab-primary {
  background: #34a853;
}

.fab-secondary {
  background: #1a73e8;
}

.fab-danger {
  background: #d32f2f;
}

/* Menu Dropdown */
.menu-dropdown {
  position: fixed;
  top: 56px;
  right: 16px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  z-index: 101;
  min-width: 200px;
  display: none;
}

.menu-dropdown.active {
  display: block;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-size: 0.9rem;
  color: #333;
  transition: background 0.2s;
}

.menu-item:hover {
  background: #f5f5f5;
}

.menu-item .material-icons {
  font-size: 20px;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 98vw;
  width: min(1250px, 98vw);
  max-height: 96vh;
  min-height: 75vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
  font-size: 1.3rem;
  color: #333;
  margin: 0;
}

.modal-subtitle {
  margin: 4px 0 0;
  color: #666;
  font-size: 0.95rem;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-header-actions .btn {
  min-height: 40px;
}

.close-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: background 0.2s;
}

.close-btn:hover {
  background: #f0f0f0;
}

.close-btn .material-icons {
  color: #666;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 70vh;
  overflow-y: auto;
}

.history-item {
  padding: 12px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item:hover {
  background: #f5f5f5;
  border-color: #1a73e8;
}

.history-info h4 {
  font-size: 0.95rem;
  color: #333;
  margin-bottom: 4px;
}

.history-info small {
  color: #999;
  font-size: 0.85rem;
}

.history-badge {
  background: #1a73e8;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Survey Stats */
.survey-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-item {
  padding: 12px;
  background: #f5f5f5;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: #999;
  font-weight: 500;
}

#stat-time,
#stat-duration,
#stat-distance,
#stat-points {
  font-size: 1rem;
  color: #1a73e8;
  font-weight: 600;
}

hr {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 16px 0;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  background: #f5f5f5;
  padding: 8px;
  text-align: left;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #e0e0e0;
}

.data-table td {
  padding: 8px;
  border-bottom: 1px solid #e0e0e0;
  color: #666;
}

.data-table tr:hover {
  background: #fafafa;
}

/* Modal Actions */
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  min-width: 96px;
  padding: 12px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn .material-icons {
  font-size: 18px;
}

.btn-primary {
  background: #1a73e8;
  color: white;
}

.btn-primary:active {
  background: #1565c0;
  transform: scale(0.98);
}

.btn-danger {
  background: #d33025;
  color: white;
}

.btn-danger:active {
  background: #a50e0e;
  transform: scale(0.98);
}

.btn-secondary {
  background: #f4f6f8;
  color: #1a73e8;
  border: 1px solid #dfe3e8;
}

.btn-secondary:active {
  background: #e8edf3;
  transform: scale(0.98);
}

/* Responsive */
@media (max-width: 600px) {
  :root {
    --statusbar-height: 78px;
    --control-gap: 8px;
    --map-control-top: calc(var(--safe-top) + var(--topbar-height) + var(--statusbar-height) + 8px);
  }

  .top-bar {
    justify-content: flex-start;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
  }

  .brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
  }

  .app-title {
    font-size: 1.4rem;
  }

  .top-actions {
    justify-content: flex-start;
    width: 100%;
    display: none;
  }

  .map-select {
    width: 100%;
    min-width: 0;
  }

  .survey-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .status-bar {
    padding: 10px 14px;
  }

  .status-item {
    min-width: 136px;
    font-size: 0.9rem;
  }

  .top-bar {
    padding: 10px 12px;
  }

  .quick-actions {
    width: min(250px, calc(100vw - 96px));
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: auto;
    align-items: flex-end;
    gap: 10px;
    padding: 8px;
  }

  .quick-btn {
    min-height: 96px;
    padding: 18px 16px;
    border-radius: 12px;
    gap: 8px;
    font-size: 0.94rem;
  }

  .quick-btn .material-icons {
    font-size: 34px;
  }

  .quick-btn > span:last-child {
    font-size: 0.9rem;
    line-height: 1.18;
  }

  .fab-container {
    left: 8px;
    bottom: 24px;
  }

  .fab-right {
    right: 8px;
    bottom: 24px;
  }

  .map-control-group {
    top: var(--map-control-top);
    left: 10px;
    flex-direction: column;
    gap: var(--control-gap);
  }

  .map-control-right {
    top: var(--map-control-top);
    right: 10px;
    flex-direction: column;
    gap: var(--control-gap);
  }

  .map-control-btn {
    width: 48px;
    height: 48px;
  }

  .data-table {
    font-size: 0.75rem;
  }

  .data-table th,
  .data-table td {
    padding: 6px;
  }

  .modal-content {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
    min-height: 0;
    border-radius: 10px;
  }

  .modal {
    align-items: stretch;
    justify-content: center;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .modal-header {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
    background: white;
    padding: 10px 12px;
  }

  .modal-header h3 {
    font-size: 1rem;
    line-height: 1.2;
    max-height: 2.4em;
    overflow: hidden;
  }

  .modal-body {
    min-height: 0;
    padding: 12px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .stat-item {
    padding: 10px;
    min-width: 0;
  }

  .stat-label {
    font-size: 0.76rem;
  }

  #stat-time,
  #stat-duration,
  #stat-distance,
  #stat-points {
    font-size: 0.92rem;
    word-break: break-word;
  }

  hr {
    margin: 12px 0;
  }

  .data-table {
    display: block;
    width: 100%;
    min-width: 620px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .data-table th,
  .data-table td {
    vertical-align: top;
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
    background: white;
    padding-top: 10px;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
