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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f6f4;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #1a6b3c;
  color: white;
  flex-shrink: 0;
}
header h1 { font-size: 1rem; font-weight: 600; letter-spacing: 0.02em; }
#settings-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
#settings-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Settings Panel ── */
#settings-panel {
  position: fixed;
  top: 0; right: 0;
  width: 300px;
  height: 100vh;
  background: white;
  box-shadow: -2px 0 12px rgba(0,0,0,0.18);
  z-index: 1001; /* Leaflet buttons and text are at Z-index 1000 */
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#settings-panel h2 { font-size: 1rem; color: #1a6b3c; }
.setting-row { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.setting-row input[type=range] { width: 100%; }
.setting-row label { display: flex; align-items: center; gap: 6px; }
.setting-group { border: 1px solid #e0e0e0; border-radius: 6px; padding: 10px 12px; }
.setting-group legend { font-size: 0.75rem; color: #666; padding: 0 4px; }
.setting-group label { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; margin-bottom: 4px; }
#settings-close {
  padding: 8px;
  background: #1a6b3c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  margin-top: auto;
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  background: white;
  border-bottom: 2px solid #e0e0e0;
  padding: 0 16px;
  flex-shrink: 0;
}
.tab-btn {
  padding: 9px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: #666;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}
.tab-btn.active { color: #1a6b3c; border-bottom-color: #1a6b3c; font-weight: 600; }

/* ── Main layout ── */
.main-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.main-layout {
  display: flex;
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
}

/* ── Controls panel ── */
.controls-panel {
  width: 300px;
  flex-shrink: 0;
  background: white;
  border-radius: 8px;
  padding: 14px;
  overflow-y: auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.tab-content { display: none; flex-direction: column; gap: 10px; }
.tab-content.active { display: flex; }
.tab-content h2 { font-size: 0.95rem; color: #1a6b3c; margin-bottom: 2px; }

.field-label { font-size: 0.8rem; color: #555; display: block; margin-bottom: 3px; }
.controls-panel select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.875rem;
  background: white;
}
.radio-group, .check-group { display: flex; flex-direction: column; gap: 4px; }
.radio-group label, .check-group label {
  display: flex; align-items: center; gap: 6px; font-size: 0.85rem; cursor: pointer;
}

/* ── Buttons ── */
.primary-btn {
  width: 100%;
  padding: 8px;
  background: #1a6b3c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
}
.primary-btn:hover:not(:disabled) { background: #145a32; }
.primary-btn:disabled { background: #9cb89c; cursor: not-allowed; }
.secondary-btn {
  width: 100%;
  padding: 7px;
  background: white;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.secondary-btn:hover { background: #f5f5f5; }

/* ── GPS ── */
#gps-status { font-size: 0.75rem; color: #666; min-height: 16px; }

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed #ccc;
  border-radius: 6px;
  padding: 18px 12px;
  text-align: center;
  font-size: 0.85rem;
  color: #888;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag-over { border-color: #1a6b3c; background: #f0faf4; color: #1a6b3c; }
.file-label { color: #1a6b3c; cursor: pointer; text-decoration: underline; }

/* ── Gallery ── */
.gallery { display: flex; flex-wrap: wrap; gap: 6px; }
.gallery-item { position: relative; }
.gallery-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; border: 1px solid #e0e0e0; display: block; }
.gallery-item .remove-btn {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: #c0392b;
  color: white;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

/* ── Map panel ── */
.map-panel { flex: 1; min-width: 0; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
#map { width: 100%; height: 100%; }

/* ── Status bar ── */
.status-bar {
  padding: 5px 16px;
  font-size: 0.78rem;
  color: #555;
  background: #f9f9f9;
  border-top: 1px solid #eee;
  flex-shrink: 0;
  min-height: 24px;
}

/* ── Resizable output pane ── */
#output-section {
  background: white;
  border-top: 2px solid #e0e0e0;
  flex-shrink: 0;
  height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.resize-handle {
  width: 100%;
  height: 10px;
  background: #f0f0f0;
  border-bottom: 1px solid #e0e0e0;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}
.resize-handle span {
  font-size: 12px;
  color: #aaa;
  letter-spacing: 2px;
  pointer-events: none;
}
.resize-handle:hover { background: #e4f0e9; }

/* ── Output content: viewer left, metrics right ── */
.output-content {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}
.viewer-area {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.schema-panels {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

/* ── Multi-pane viewer ── */
.viewer-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e0e0e0;
  overflow: hidden;
}
.viewer-pane:last-child { border-right: none; }

/* Header row: tabs on the left, action button on the right */
.pane-header {
  display: flex;
  align-items: flex-end;
  padding: 6px 8px 0;
  background: #f5f5f5;
  border-bottom: 2px solid #e0e0e0;
  flex-shrink: 0;
  gap: 6px;
  overflow-x: auto;
}
.pane-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  flex-wrap: nowrap;
}
.pane-tab-btn {
  padding: 5px 14px;
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: #ebebeb;
  cursor: pointer;
  font-size: 0.825rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.pane-tab-btn.active {
  background: white;
  color: #1a6b3c;
  font-weight: 600;
  position: relative;
  bottom: -2px;
  border-bottom-color: white;
}
.pane-tab-btn:hover:not(.active) { background: #ddd; }

.pane-action-btn {
  flex-shrink: 0;
  align-self: center;
  margin-bottom: 4px;
  padding: 2px 8px;
  border: 1px solid #ddd;
  border-radius: 3px;
  background: white;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.4;
  transition: background 0.12s, border-color 0.12s;
}
.pane-action-btn:hover:not(:disabled) { background: #e8f5e9; border-color: #1a6b3c; color: #1a6b3c; }
.pane-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.pane-remove-btn:hover:not(:disabled) { background: #fdecea; border-color: #c0392b; color: #c0392b; }

.pane-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 0.875rem;
  padding: 20px;
  text-align: center;
}

model-viewer {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: #fafafa;
  display: block;
}

/* ── Metrics sidebar ── */
.metrics-area {
  width: 180px;
  flex-shrink: 0;
  padding: 12px 10px;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.metrics-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1a6b3c;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.yield-metrics { display: flex; flex-direction: column; gap: 8px; }
.metric-card {
  background: #f9fdf9;
  border: 1px solid #d4e8d4;
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}
.metric-label { font-size: 0.7rem; color: #666; text-transform: uppercase; letter-spacing: 0.06em; }
.metric-value { font-size: 0.95rem; font-weight: 600; color: #1a6b3c; margin-top: 3px; }

/* ── Utility ── */
.hidden { display: none !important; }

.sat-toggle-btn {
  padding: 4px 10px;
  cursor: pointer;
  background: white;
  border: 1px solid #aaa;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
}

/* ── Database Upload Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  background: white;
  border-radius: 10px;
  padding: 24px;
  width: 440px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-card h2 { font-size: 1.1rem; color: #1a6b3c; }
.form-row { display: flex; gap: 10px; }
.form-row .field-label { flex: 1; }
.form-input {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 7px 9px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.875rem;
}
.form-input:focus { outline: none; border-color: #1a6b3c; box-shadow: 0 0 0 2px rgba(26,107,60,0.12); }
.form-error { color: #c0392b; font-size: 0.8rem; padding: 4px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
