/* ===================================================
   Taakkaart Generator — Stylesheet
   =================================================== */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2E7D32;
  --primary-light: #4CAF50;
  --primary-dark: #1B5E20;
  --primary-bg: #E8F5E9;
  --surface: #ffffff;
  --bg: #f4f6f4;
  --text: #1a1a1a;
  --text-secondary: #616161;
  --text-muted: #9e9e9e;
  --border: #e0e0e0;
  --error: #d32f2f;
  --warning: #f57c00;
  --sidebar-w: 370px;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --transition: .2s ease;
}

html, body { height: 100%; width: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ---------- App Layout ---------- */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
  line-height: 1;
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.subtitle {
  margin-top: 4px;
  font-size: 12px;
  opacity: .8;
  font-weight: 400;
}

.subtitle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.subtitle-row .subtitle {
  margin-top: 0;
}

.github-link {
  display: flex;
  align-items: center;
  opacity: 0.35;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.github-link:hover {
  opacity: 0.85;
}

/* Language toggle button */
.lang-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--text-primary, #e6edf3);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  padding: 2px 7px;
  cursor: pointer;
  transition: border-color 0.15s, opacity 0.15s;
  flex-shrink: 0;
  line-height: 1.6;
}
.lang-toggle:hover {
  border-color: rgba(255,255,255,0.6);
  opacity: 0.9;
}
.github-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.sidebar-steps {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-steps::-webkit-scrollbar {
  width: 5px;
}

.sidebar-steps::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ---------- Steps ---------- */
.step {
  border-bottom: 1px solid var(--border);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.step-header:hover {
  background: var(--bg);
}

.step-indicator {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--border);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.step.active .step-indicator,
.step.completed .step-indicator {
  background: var(--primary);
  color: white;
}

.step.completed .step-indicator span {
  display: none;
}

.step.completed .step-indicator::after {
  content: '✓';
  font-size: 14px;
}

.step-header h2 {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.step.disabled .step-header h2 {
  color: var(--text-muted);
}

.chevron {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.step.active .chevron {
  transform: rotate(90deg);
}

.step-body {
  max-height: 0;
  /* overflow:hidden was removed here because during a CSS max-height transition
     browsers enforce overflow:hidden for the full animation duration, which makes
     <select> dropdowns and other interactive elements inside unresponsive.
     Instead we use opacity+pointer-events to hide/disable the collapsed body. */
  overflow: visible;
  opacity: 0;
  pointer-events: none;
  transition: max-height .35s ease, opacity .2s ease, padding .35s ease;
  padding: 0 20px;
}

.step.active .step-body {
  max-height: 2400px;
  opacity: 1;
  /* pointer-events changes instantly (non-animatable) so selects are
     interactive immediately on open, without waiting for the animation. */
  pointer-events: auto;
  padding: 0 20px 20px;
}

.step.disabled .step-body {
  max-height: 0;
  padding: 0 20px;
}

.step-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ---------- File Upload ---------- */
.file-drop {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg);
}

.file-drop:hover,
.file-drop.drag-over {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

.file-drop input[type="file"] {
  display: none;
}

.upload-icon {
  width: 36px;
  height: 36px;
  fill: var(--text-muted);
  margin-bottom: 8px;
}

.file-drop:hover .upload-icon {
  fill: var(--primary);
}

.file-drop-text {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.file-drop-hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Info rows ---------- */
.file-info, #parcel-info {
  margin-top: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
}

.info-row .label {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ---------- Form Elements ---------- */
.form-row {
  margin-bottom: 12px;
}

.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: var(--text);
  transition: border-color var(--transition);
  /* Prevent the 300 ms touch-delay and scroll-interception on mobile
     so tapping a <select> or <input> registers immediately. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}

/* ---------- Unit Select Hint ---------- */
.unit-hint {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding-left: 2px;
  line-height: 1.4;
  min-height: 16px;
}

/* ---------- Optgroup styling for unit select ---------- */
select optgroup {
  font-style: normal;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 4px 6px;
  font-size: 11px;
  letter-spacing: .3px;
}
select optgroup option {
  font-weight: 400;
  font-size: 13px;
  color: var(--text);
  padding: 4px 8px;
}

/* ---------- Range Slider ---------- */
.range-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  touch-action: pan-x;
  pointer-events: auto;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow);
  margin-top: -7px;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow);
}

.range-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-dark);
  min-width: 42px;
  text-align: right;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(.98);
}

.btn:disabled {
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-bg);
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.btn-classify-hint {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  line-height: 1.4;
  white-space: nowrap;
}
.btn-classify-hint:hover {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
}

.btn-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Classes Config ---------- */
.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  margin: 16px 0 8px;
}

.class-row {
  display: grid;
  grid-template-columns: 24px 1fr 54px 54px 28px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.class-row:last-child {
  border-bottom: none;
}

.class-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  padding: 0;
}

.class-row input[type="text"],
.class-row input[type="number"] {
  padding: 5px 6px;
  font-size: 12px;
}

.class-row .remove-class {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}

.class-row .remove-class:hover {
  background: #ffebee;
  color: var(--error);
}

.class-labels {
  display: grid;
  grid-template-columns: 24px 1fr 54px 54px 28px;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Dosage Editor (Step 5) ---------- */
.dosage-row {
  display: grid;
  grid-template-columns: 20px 1fr auto 95px 85px;
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.dosage-row:last-child {
  border-bottom: none;
}
.dosage-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}
.dosage-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dosage-ndvi-range {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dosage-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}
.dosage-input-wrap input[type="number"] {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  background: white;
  color: var(--text);
  text-align: right;
}
.dosage-input-wrap input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}
.dosage-unit-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 30px;
}

/* ---------- Export Stats ---------- */
#export-stats {
  margin-bottom: 16px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}

.stat-row .stat-label {
  color: var(--text-secondary);
}

.stat-row .stat-value {
  font-weight: 600;
}

.stat-class {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.stat-class-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---------- Map Area ---------- */
.map-area {
  flex: 1;
  position: relative;
}

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

/* ---------- Loading Overlay ---------- */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  backdrop-filter: blur(2px);
}

#loading-overlay.hidden { display: none; }

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

#loading-text {
  margin-top: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1a1a1a;
  color: white;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1200;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--error);
}

.toast.hidden {
  display: none;
}

/* ---------- NDVI scale (inside ULC panel) ---------- */
.ulc-ndvi-section {
  padding-bottom: 2px;
}

.legend-gradient {
  width: 100%;
  height: 18px;
  border-radius: 4px;
  /* The actual gradient colours are set dynamically via JS
     (generateNdviGradientCss in map.js) — this is a fallback. */
  background: linear-gradient(to right,
    #b40000, #e63c00, #ff9600, #ffdc00, #b4e632, #50c828, #14a014, #006e0a, #003c00
  );
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
  margin: 6px 0 2px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

/* ---------- WMS legend helpers ---------- */
.wms-legend-empty {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  padding: 2px 0;
}

/* AHN elevation bar legend */
#ahn-legend-section .ulc-section-title {
  font-size: 10px;
  font-weight: 700;
  margin-top: 2px;
}
#ahn-legend-info {
  margin: 4px 0 2px;
}
.ahn-legend-bar {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ahn-legend-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 36px;
}
.ahn-legend-label:first-child { text-align: left; }
.ahn-legend-label:last-child  { text-align: right; }
.ahn-legend-gradient {
  flex: 1;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(to right, #2c7bb6, #abd9e9, #ffffbf, #fdae61, #d7191c);
  border: 1px solid var(--border);
}

/* Bodem legend items with colour swatches */
#bodem-legend-section .ulc-section-title {
  font-size: 10px;
  font-weight: 700;
  margin-top: 2px;
}
#bodem-legend-items {
  margin: 4px 0 2px;
  max-height: 160px;
  overflow-y: auto;
}
.bodem-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 1px 0;
  font-size: 10px;
  line-height: 1.4;
}
.bodem-legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.bodem-legend-name {
  color: var(--text-secondary);
  word-break: break-word;
}

/* ---------- NDVI legend — parcel crop section ---------- */
.legend-parcel-sep {
  height: 1px;
  background: var(--border);
  margin: 8px 0 6px;
}

.lp-current {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 3px;
}

.lp-crop {
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  line-height: 1.3;
}

.lp-year {
  font-size: 10px;
  font-weight: 600;
  color: white;
  background: var(--primary);
  border-radius: 8px;
  padding: 0 5px;
  flex-shrink: 0;
}

.lp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  margin-top: 2px;
}

.lp-table tr:nth-child(even) { background: var(--bg); }

.lp-yr {
  font-weight: 700;
  color: var(--primary-dark);
  padding-right: 6px;
  white-space: nowrap;
}

.lp-cn { color: var(--text-secondary); }

/* ---------- Hint text ---------- */
.hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 8px;
}

/* ---------- Quick-export "off-ramp" card (Step 3) ----------
   Visually separated download for the clipped NDVI so it does
   not compete with the primary "Continue → task map" CTA. */
.quick-export-card {
  margin-top: 14px;
  padding: 10px 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}
.quick-export-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.quick-export-icon {
  font-size: 13px;
  line-height: 1;
}
.quick-export-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
}
.quick-export-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 8px;
  line-height: 1.35;
}
.quick-export-card .btn {
  width: 100%;
}

/* ---------- Parcel history (in sidebar) ---------- */
.parcel-hist-item {
  padding: 4px 0 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

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

.phi-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 4px;
}

.phi-name {
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.phi-area {
  font-weight: 400;
  color: var(--text-muted);
}

.phi-hist {
  margin-top: 3px;
  padding-left: 2px;
}

.phi-row {
  display: flex;
  gap: 6px;
  padding: 1px 0;
}

.phi-yr {
  font-weight: 700;
  color: var(--primary-dark);
  min-width: 32px;
  flex-shrink: 0;
}

.phi-crop {
  color: var(--text-secondary);
}

.phi-loading, .phi-none, .phi-error {
  color: var(--text-muted);
  font-style: italic;
}

.phi-error { color: var(--error); }

.remove-parcel {
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: bold;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.remove-parcel:hover { color: var(--error); }

/* ---------- Drawing Tools (Step 2) ---------- */
.draw-section {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.draw-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.draw-section-icon {
  font-size: 14px;
  line-height: 1;
}
.draw-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-secondary);
}
.draw-toolbar {
  display: flex;
  gap: 6px;
}
.draw-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  background: #e3f2fd;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #1565c0;
  font-weight: 500;
}

/* ---------- Cell Override Editor (Step 5) ---------- */
.cell-override-section {
  margin-top: 12px;
  padding: 10px 12px;
  background: #fff8e1;
  border-radius: var(--radius-sm);
  border: 1px solid #ffe082;
}
.cell-override-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.cell-override-icon {
  font-size: 14px;
  line-height: 1;
}
.cell-override-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #e65100;
}
.cell-override-info {
  margin-bottom: 8px;
  padding: 6px 8px;
  background: rgba(255,255,255,0.6);
  border-radius: 4px;
}
.cell-override-info .info-row {
  font-size: 12px;
  padding: 2px 0;
}

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

/* ---------- Leaflet overrides ---------- */
/* Remove browser focus outline on SVG paths (parcel boundaries) */
.leaflet-interactive:focus {
  outline: none;
}

.leaflet-control-layers {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
}

/* NDVI legend is now inside the ULC panel (both desktop and mobile) */

/* ---------- Unified layer control ---------- */
.ulc-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
}

.ulc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--text-secondary);
  transition: color 0.15s, background 0.15s;
  padding: 0;
}
.ulc-toggle svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}
.ulc-toggle.active,
.ulc-toggle:hover {
  color: var(--text-primary);
  background: var(--bg);
}

.ulc-panel {
  position: absolute;
  bottom: 42px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  min-width: 180px;
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 1000;
}
.ulc-panel.hidden {
  display: none;
}

/* On desktop: panel always visible, no toggle button */
@media (min-width: 769px) {
  .ulc-toggle {
    display: none;
  }
  .ulc-panel {
    position: relative;
    bottom: auto;
    right: auto;
  }
  /* Override .hidden so the panel is always shown on desktop */
  .ulc-panel.hidden {
    display: flex !important;
  }

  #mobile-toggle {
    display: none !important;
  }
}

.ulc-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.ulc-sep {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.ulc-radio,
.ulc-check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 2px 0;
  user-select: none;
}
.ulc-radio input,
.ulc-check input {
  cursor: pointer;
  accent-color: var(--primary-light);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* ---------- Mobile toggle button (hidden on desktop) ---------- */
#mobile-toggle {
  display: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  :root {
    --sidebar-w: 100vw;
  }

  .app {
    flex-direction: column;
    position: relative;
  }

  /* Full-screen map behind sidebar */
  .map-area {
    position: fixed;
    inset: 0;
    z-index: 0;
  }

  /* Sidebar as slide-up panel over the map */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    /* Use dvh (dynamic viewport height) where supported so the panel     */
    /* accounts for browser chrome (address bar) on iOS/Android.          */
    max-height: 65vh;
    max-height: 65dvh;
    border-right: none;
    border-top: 2px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 1000;
    transition: max-height .35s ease;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    /* Momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.collapsed {
    max-height: 56px;
    overflow: hidden;
  }

  /* Drag handle — visible pill above the header text */
  .sidebar-header::before {
    content: '';
    display: block;
    width: 40px;
    height: 5px;
    background: rgba(255,255,255,.6);
    border-radius: 3px;
    margin: 0 auto 12px;
  }

  /* Mobile toggle button — pill floating on map */
  #mobile-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 24px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    cursor: pointer;
    white-space: nowrap;
    transition: background .2s;
  }

  #mobile-toggle:active {
    background: var(--primary-dark);
  }

  /* When sidebar is not collapsed, push the toggle up */
  .sidebar:not(.collapsed) ~ #mobile-toggle,
  #mobile-toggle.panel-open {
    bottom: calc(65vh + 12px);
    bottom: calc(65dvh + 12px);
  }

  /* Larger touch targets */
  .btn {
    padding: 12px 16px;
    font-size: 15px;
  }

  .step-header {
    padding: 16px 20px;
    min-height: 52px;
  }

  select, input[type="text"], input[type="number"] {
    padding: 10px 12px;
    font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
    min-height: 44px; /* Apple HIG / Android Material minimum touch target */
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  /* Toast moves up when sidebar is open */
  .toast {
    bottom: calc(65vh + 16px);
    bottom: calc(65dvh + 16px);
  }

  /* Leaflet zoom controls — move away from sidebar */
  .leaflet-top.leaflet-right {
    top: 12px !important;
  }

  /* Class row narrower on small screens */
  .class-row {
    grid-template-columns: 22px 1fr 46px 46px 54px 24px;
    gap: 4px;
  }

  .class-labels {
    grid-template-columns: 22px 1fr 46px 46px 54px 24px;
    gap: 4px;
  }
}

/* ============================================
   WIZARD MODE — Show only active step body
   ============================================ */

/* Hide bodies of all non-active steps */
.step:not(.active) .step-body {
  max-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  padding: 0 20px !important;
  overflow: hidden;
}

/* Step progress indicator bar */
.step-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 8px;
  gap: 4px;
}

.step-progress-item {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.step-progress-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--border);
  color: var(--text-muted);
  transition: all var(--transition);
}

.step-progress-item.active .step-progress-dot {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 0 3px rgba(46,125,50,.2);
}

/* ---------- WMS GetFeatureInfo popup ---------- */
.wms-popup-sep {
  height: 1px;
  background: #ddd;
  margin: 4px 0;
}

.step-progress-item.completed .step-progress-dot {
  background: var(--primary-light);
  color: white;
}

.step-progress-item.completed .step-progress-dot::after {
  content: '✓';
  font-size: 12px;
}

.step-progress-item.completed .step-progress-dot span {
  display: none;
}

.step-progress-dot span {
  font-size: 10px;
}

.step-progress-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  min-width: 8px;
}

.step-progress-item.completed + .step-progress-item .step-progress-line,
.step-progress-item.completed .step-progress-line {
  background: var(--primary-light);
}

.step-progress-label {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-progress-item.active .step-progress-label {
  color: var(--primary);
  font-weight: 700;
}

.step-progress-item.completed .step-progress-label {
  color: var(--text-secondary);
}

/* Wizard navigation buttons */
.step-nav {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.step-nav .btn {
  flex: 1;
}

.btn-back {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-back:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

/* Advanced options toggle */
.advanced-toggle-wrap {
  margin-bottom: 12px;
}

.advanced-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
}

.advanced-toggle-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-secondary);
  background: var(--bg);
}

.advanced-toggle-btn .chevron-sm {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--transition);
}

.advanced-toggle-btn.open .chevron-sm {
  transform: rotate(90deg);
}

.advanced-content {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height .3s ease, opacity .2s ease, margin .3s ease;
  margin-top: 0;
}

.advanced-content.open {
  max-height: 800px;
  opacity: 1;
  margin-top: 10px;
}

/* Loading progress detail */
#loading-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
}

/* Step completion badge on the header */
.step.completed .step-header .step-indicator::after {
  content: '✓' !important;
  font-size: 14px !important;
}
.step.completed .step-header .step-indicator span {
  display: none !important;
}

/* Status badge on step headers — "Laden", "Index", etc. */
.step-status-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--primary-bg);
  color: var(--primary);
  margin-left: auto;
  white-space: nowrap;
  opacity: 0.7;
}

.step.active .step-status-badge {
  background: var(--primary);
  color: white;
  opacity: 1;
}

.step.completed .step-status-badge {
  opacity: 0.5;
}

/* Step summary text below the progress bar */
.step-summary {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 20px 4px;
  font-style: italic;
}

.step-summary strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ---------- VI Formula Info Panel ---------- */
.vi-info {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  line-height: 1.5;
}

.vi-formula {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(76,175,80,.08);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 6px;
  text-align: center;
}

.vi-desc {
  color: var(--text);
  margin-bottom: 4px;
}

.vi-details {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.vi-details span {
  white-space: nowrap;
}

/* ============================================
   WDVI Soil Line Parameter
   ============================================ */
#wdvi-soil-line-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
}
#wdvi-soil-line-section .wdvi-preset-btn {
  flex: 1;
  min-width: 60px;
  padding: 5px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: background .15s, border-color .15s;
}
#wdvi-soil-line-section .wdvi-preset-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
#wdvi-soil-line-section .wdvi-preset-btn:active {
  background: var(--primary-dark, #388e3c);
}

/* ============================================
   PDF Export — Capture optimisation
   ============================================ */

/* When the map is being captured for PDF, briefly disable
   pointer events so tooltips/popups don't show */
#map.pdf-capture {
  pointer-events: none;
}
#map.pdf-capture .leaflet-control-zoom {
  display: none;
}
#map.pdf-capture .selection-path {
  display: none !important;
}

/* ============================================
   Print styles — hide sidebar & chrome
   ============================================ */
@media print {
  .sidebar,
  #mobile-toggle,
  #loading-overlay,
  #toast,
  .leaflet-control-zoom {
    display: none !important;
  }
  .map-area {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }
  #map {
    width: 100% !important;
    height: 100% !important;
  }
  .app {
    display: block !important;
  }
}
