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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1a1a2e;
  color: #e0e0e0;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- Toolbar --- */
#toolbar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}

#toolbar h1 {
  font-size: 16px;
  font-weight: 600;
  color: #e94560;
}

/* --- Map --- */
#map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* --- Map prompt (zoom in / click to select) --- */
#map-prompt {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 33, 62, 0.92);
  color: #ccd6f6;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.3s;
  border: 1px solid #0f3460;
}

/* --- No-stream notice (flashes on bad click) --- */
#no-stream-notice {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(233, 69, 96, 0.9);
  color: #fff;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 1001;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* --- Status bar --- */
#status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 4px 12px;
  background: rgba(22, 33, 62, 0.9);
  font-size: 12px;
  color: #8892b0;
  z-index: 1000;
}

/* --- Side panels --- */
.panel {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(22, 33, 62, 0.95);
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 16px;
  z-index: 1000;
  min-width: 220px;
  max-width: 320px;
}

.panel h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: #e94560;
}

.panel label {
  font-size: 12px;
  color: #8892b0;
}

.panel input[type="number"] {
  width: 80px;
  padding: 3px 6px;
  font-size: 13px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #1a1a2e;
  color: #e0e0e0;
}

#area-info {
  font-size: 12px;
  color: #8892b0;
  margin: 8px 0;
}

/* --- Buttons --- */
.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  padding: 8px;
  margin-top: 6px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  background: #e94560;
  color: #fff;
}

.btn-primary:hover { background: #c73652; }

.btn-secondary {
  background: transparent;
  border: 1px solid #0f3460;
  color: #8892b0;
}

.btn-secondary:hover {
  border-color: #8892b0;
  color: #e0e0e0;
}

/* --- Stream select --- */
#stream-list {
  max-height: 300px;
  overflow-y: auto;
}

.stream-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #0f3460;
  font-size: 13px;
}

.stream-item:last-child { border-bottom: none; }

.stream-item input[type="checkbox"] {
  accent-color: #e94560;
}

.stream-item .stream-name {
  flex: 1;
}

.stream-item .stream-type {
  font-size: 11px;
  color: #8892b0;
}

/* --- Progress panel --- */
#progress-list {
}

.progress-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.5);
}

.progress-item:last-child { border-bottom: none; }

.progress-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.progress-item.running .progress-icon { color: #ffd54f; }
.progress-item.done .progress-icon { color: #69f0ae; }
.progress-item.error .progress-icon { color: #ef5350; }

.progress-label {
  font-weight: 500;
  color: #ccd6f6;
}

.progress-detail {
  font-size: 11px;
  color: #8892b0;
  margin-top: 2px;
}

/* --- NHD stream labels on map --- */
.nhd-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  color: #b3e5fc;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow:
    -1px -1px 0 #0a0a1a,
     1px -1px 0 #0a0a1a,
    -1px  1px 0 #0a0a1a,
     1px  1px 0 #0a0a1a,
     0   -1px 0 #0a0a1a,
     0    1px 0 #0a0a1a,
    -1px  0   0 #0a0a1a,
     1px  0   0 #0a0a1a;
  pointer-events: none;
}

/* --- Toolbar button --- */
.toolbar-btn:first-of-type {
  margin-left: auto;
}

.toolbar-btn {
  margin-left: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(15, 52, 96, 0.8);
  color: #ccd6f6;
  border: 1px solid #0f3460;
  border-radius: 4px;
  cursor: pointer;
}

.toolbar-btn:hover {
  background: #0f3460;
  color: #fff;
}

.toolbar-btn.active {
  background: #e94560;
  color: #fff;
  border-color: #e94560;
}

.toolbar-btn.active:hover {
  background: #c73652;
  border-color: #c73652;
}

.toolbar-btn-danger {
  color: #ef5350;
  border-color: #ef5350;
}

.toolbar-btn-danger:hover {
  background: rgba(239, 83, 80, 0.2);
  color: #fff;
  border-color: #ef5350;
}

/* --- History panel --- */
#history-panel {
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#history-list {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 8px;
  max-height: 50vh;
}

.history-empty {
  font-size: 12px;
  color: #8892b0;
  padding: 12px 0;
  text-align: center;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.5);
  font-size: 12px;
}

.history-item:last-child { border-bottom: none; }

.history-item:hover {
  background: rgba(15, 52, 96, 0.4);
  border-radius: 4px;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-label {
  font-weight: 500;
  color: #ccd6f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 11px;
  color: #8892b0;
}

.history-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.history-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0.7;
}

.history-actions button:hover {
  opacity: 1;
  background: rgba(15, 52, 96, 0.6);
}

.history-delete { color: #ef5350; }
.history-view { color: #4fc3f7; }
.history-fly { color: #ffd54f; }

/* --- History markers on map --- */
.history-marker {
  background: none !important;
  border: none !important;
}

.history-pin {
  width: 14px;
  height: 14px;
  background: #e94560;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* --- Panel header with minimize/close --- */
.panel-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  gap: 6px;
}

.panel-header h3 {
  margin-bottom: 0;
  flex: 1;
}

.panel-header-buttons {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.panel-toggle {
  background: none;
  border: 1px solid #0f3460;
  color: #8892b0;
  width: 24px;
  height: 24px;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-toggle:hover {
  color: #fff;
  border-color: #8892b0;
}

/* --- History panel --- */
#history-panel {
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#history-panel.hidden { display: none !important; }

#history-list {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 8px;
  max-height: 50vh;
}

.history-empty {
  font-size: 12px;
  color: #8892b0;
  padding: 12px 0;
  text-align: center;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.5);
  font-size: 12px;
}

.history-item:last-child { border-bottom: none; }

.history-item:hover {
  background: rgba(15, 52, 96, 0.4);
  border-radius: 4px;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-label {
  font-weight: 500;
  color: #ccd6f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 11px;
  color: #8892b0;
}

.history-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.history-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0.7;
}

.history-actions button:hover {
  opacity: 1;
  background: rgba(15, 52, 96, 0.6);
}

.history-delete { color: #ef5350; }
.history-view { color: #4fc3f7; }
.history-fly { color: #ffd54f; }

/* --- Loading spinner --- */
.loading-spinner {
  width: 24px;
  height: 24px;
  margin: 12px auto 0;
  border: 3px solid #0f3460;
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-status {
  font-size: 12px;
  color: #ccd6f6;
}

/* --- Result panel --- */
#result-panel {
  max-height: 70vh;
  overflow-y: auto;
}

.result-section {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.5);
}

.result-section:last-child {
  border-bottom: none;
}

.result-label {
  font-size: 12px;
  font-weight: 600;
  color: #e94560;
  margin-bottom: 4px;
}

.result-value {
  font-size: 13px;
  color: #ccd6f6;
}

.result-note {
  font-size: 11px;
  color: #8892b0;
  margin-bottom: 4px;
}

.result-error {
  color: #ef5350;
  font-size: 12px;
  padding: 8px 0;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.result-table th {
  text-align: left;
  color: #8892b0;
  font-weight: 500;
  padding: 3px 6px 3px 0;
  border-bottom: 1px solid #0f3460;
}

.result-table td {
  padding: 3px 6px 3px 0;
  color: #ccd6f6;
}

.result-table .char-name {
  color: #8892b0;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-table .char-value {
  text-align: right;
  font-weight: 500;
  color: #ccd6f6;
}

.result-table .char-unit {
  color: #8892b0;
  font-size: 10px;
}

/* --- LiDAR controls --- */
.lidar-spacing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.lidar-spacing-row label {
  font-size: 12px;
  color: #8892b0;
  white-space: nowrap;
}

.lidar-spacing-row input {
  width: 60px;
  padding: 3px 6px;
  font-size: 13px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #1a1a2e;
  color: #e0e0e0;
}

.lidar-warning {
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.lidar-warning-block {
  background: rgba(239, 83, 80, 0.15);
  border: 1px solid #ef5350;
  color: #ef5350;
}

.lidar-warning-caution {
  background: rgba(255, 213, 79, 0.12);
  border: 1px solid #ffd54f;
  color: #ffd54f;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: #0f3460;
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: #e94560;
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* --- Aerials panel --- */
#aerials-panel {
  max-height: 70vh;
  overflow-y: auto;
}

#aerials-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.aerial-year-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: rgba(15, 52, 96, 0.3);
  border: 1px solid #0f3460;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.aerial-year-item:hover {
  background: rgba(15, 52, 96, 0.6);
}

.aerial-year-item.active {
  background: rgba(79, 195, 247, 0.15);
  border-color: #4fc3f7;
}

.aerial-year-label {
  font-size: 13px;
  font-weight: 600;
  color: #ccd6f6;
}

.aerial-year-item.active .aerial-year-label {
  color: #4fc3f7;
}

.aerial-year-source {
  font-size: 11px;
  color: #8892b0;
}

.aerial-year-toggle {
  font-size: 11px;
  color: #8892b0;
  flex-shrink: 0;
}

.aerial-year-item.active .aerial-year-toggle {
  color: #4fc3f7;
}

/* --- Historical Aerial Items --- */
#historical-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
}

.historical-item {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(15, 52, 96, 0.3);
  border: 1px solid #0f3460;
  border-radius: 4px;
}

.historical-item:hover {
  background: rgba(15, 52, 96, 0.5);
}

.historical-thumb {
  width: 64px;
  height: 64px;
  border-radius: 3px;
  object-fit: cover;
  background: #0a0a1a;
  flex-shrink: 0;
  cursor: pointer;
}

.historical-thumb.no-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #555;
  border: 1px solid #0f3460;
}

.historical-info {
  flex: 1;
  min-width: 0;
}

.historical-date {
  font-size: 12px;
  font-weight: 600;
  color: #ccd6f6;
}

.historical-id {
  font-size: 10px;
  color: #8892b0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.historical-dataset {
  font-size: 10px;
  color: #8892b0;
  margin-top: 2px;
}

.historical-link {
  font-size: 10px;
  color: #4fc3f7;
  text-decoration: none;
}

.historical-link:hover {
  text-decoration: underline;
}

/* --- Measure tool dropdown --- */
.toolbar-dropdown {
  position: relative;
  display: inline-block;
  margin-left: 8px;
}

.toolbar-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  z-index: 2000;
  min-width: 110px;
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.toolbar-dropdown-menu hr {
  border: none;
  border-top: 1px solid #0f3460;
  margin: 4px 0;
}

.measure-option {
  display: block;
  width: 100%;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: #ccd6f6;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}

.measure-option:hover {
  background: #0f3460;
  color: #fff;
}

.measure-option.active {
  color: #e94560;
}

.measure-option.measure-clear {
  color: #ef5350;
}

/* --- Measure labels on map --- */
.measure-label {
  background: rgba(22, 33, 62, 0.92) !important;
  border: 1px solid #e94560 !important;
  border-radius: 4px !important;
  padding: 3px 8px !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3) !important;
}

.measure-label-area {
  border-color: #e94560 !important;
  color: #fff !important;
}

.measure-vertex {
  width: 10px !important;
  height: 10px !important;
  background: #e94560 !important;
  border: 2px solid #fff !important;
  border-radius: 50% !important;
  margin-left: -5px !important;
  margin-top: -5px !important;
}

/* --- Utilities --- */
.hidden { display: none !important; }
