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

:root {
  --color-bg: #f5f0e8;
  --color-panel: #ffffff;
  --color-primary: #2e7d32;
  --color-primary-light: #43a047;
  --color-primary-dark: #1b5e20;
  --color-accent: #d4a373;
  --color-text: #2b2b2b;
  --color-text-light: #6b6b6b;
  --color-handle: #ff7043;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 8px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* === Header (2 rows) === */
#app-header {
  display: flex;
  flex-direction: column;
  background: var(--color-primary-dark);
  color: white;
  box-shadow: var(--shadow-md);
  z-index: 1000;
}

/* -- Top bar (row 1) -- */
.header-topbar {
  display: flex;
  align-items: center;
  padding: 8px 20px;
  gap: 16px;
  min-height: 48px;
}

.header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: white;
}

/* Logo Croptia — componente base (inline-block = underline/slogan misma anchura que texto) */
.logo-crop { font-weight: 800; }
.logo-tia  { font-weight: 400; }
.logo-underline {
  display: block;
  height: 3px;
  background: linear-gradient(90deg, #43a047, #66bb6a);
  border-radius: 2px;
  margin-top: 2px;
}
.logo-slogan {
  display: block;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: #66bb6a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-brand-name {
  display: inline-block;
  font-family: 'DM Sans', sans-serif;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
  line-height: 1;
  white-space: nowrap;
}
.header-brand-name .logo-crop { color: #fff; }
.header-brand-name .logo-tia  { color: #ddd; }
.header-brand-name .logo-underline { height: 2px; margin-top: 2px; }

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.parcel-name-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: white;
  font-size: 1rem;
  font-weight: 600;
  padding: 4px 10px;
  text-align: right;
  max-width: 220px;
  width: auto;
  min-width: 80px;
  transition: border-color 0.2s, background 0.2s;
  font-family: inherit;
}

.parcel-name-input:hover {
  border-color: rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06);
}

.parcel-name-input:focus {
  outline: none;
  border-color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.1);
}

.parcel-name-input::placeholder {
  color: rgba(255,255,255,0.4);
}

.parcel-municipality {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.55);
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Auth button (not logged in) */
.header-auth-btn {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.header-auth-btn:hover {
  background: rgba(255,255,255,0.22);
}

/* User dropdown menu (logged in) */
.header-user-menu {
  position: relative;
}

.header-user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.header-user-btn:hover {
  background: rgba(255,255,255,0.2);
}

.header-user-arrow {
  font-size: 0.65rem;
  opacity: 0.7;
}

.header-user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  min-width: 220px;
  z-index: 2000;
  padding: 12px 0;
  color: var(--color-text);
}

.header-user-dropdown.open {
  display: block;
}

.dropdown-section {
  padding: 8px 16px;
}

.dropdown-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-light);
  font-weight: 600;
}

.dropdown-email {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text);
  margin-top: 4px;
}

.dropdown-divider {
  border: none;
  border-top: 1px solid #eee;
  margin: 4px 0;
}

.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}

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

.dropdown-logout {
  color: #c62828;
}

.dropdown-logout:hover {
  background: #fef2f2;
}

/* -- Sub-nav bar (row 2, step tabs) -- */
.header-subnav {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 4px 20px 8px;
  background: rgba(0,0,0,0.12);
  min-height: 36px;
}

/* Nav tab buttons */
.nav-btn {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  border: none;
  padding: 6px 14px 6px 10px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  position: relative;
}

.nav-btn:hover:not(.locked) {
  background: rgba(255,255,255,0.18);
}

.nav-btn.active {
  background: var(--color-primary-light);
  color: white;
  font-weight: 600;
}

/* Locked */
.nav-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.nav-btn.locked .nav-icon::before {
  content: '\1F512';
  font-size: 0.65rem;
}

/* Editing: orange dot */
.nav-btn:not(.locked):not(.saved) .nav-icon::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #ff9800;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(255,152,0,0.5);
}

/* Saved: green checkmark */
.nav-btn.saved .nav-icon::before {
  content: '\2713';
  font-size: 0.8rem;
  font-weight: 900;
  color: #66bb6a;
}

.nav-btn.saved {
  opacity: 1;
}

.nav-btn.active.saved {
  box-shadow: inset 0 0 0 2px rgba(102,187,106,0.5);
}

/* === Main Layout === */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* === Panel Lateral === */
#panel-lateral {
  width: 300px;
  min-width: 300px;
  background: var(--color-panel);
  padding: 20px;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  z-index: 500;
}

#panel-lateral h2 {
  font-size: 1rem;
  color: var(--color-primary-dark);
  font-weight: 600;
}

#panel-lateral h3 {
  font-size: 0.85rem;
  color: var(--color-text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#panel-lateral hr {
  border: none;
  border-top: 1px solid #e8e8e8;
}

/* === Inputs === */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 0.8rem;
  color: var(--color-text-light);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input[type="text"],
.input-group input[type="number"] {
  padding: 10px 12px;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text);
  transition: border-color 0.2s;
  width: 100%;
  font-family: 'Courier New', monospace;
}

.input-group input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.input-with-btn {
  display: flex;
  gap: 6px;
}

.input-with-btn input {
  flex: 1;
}

.btn-icon {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--color-primary-dark);
}

.btn-icon:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* === Status message === */
.status-msg {
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: var(--radius);
  line-height: 1.4;
}

.hidden { display: none; }
.status-msg.hidden { display: none; }
.status-msg.loading { background: #e3f2fd; color: #1565c0; }
.status-msg.success { background: #e8f5e9; color: #2e7d32; }
.status-msg.error   { background: #fce4ec; color: #c62828; }

/* === Info Box === */
.info-box {
  background: #f0f7ed;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-row span:first-child {
  font-size: 0.85rem;
  color: var(--color-text-light);
}

.info-row span:last-child {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}

/* === Hints === */
.hint-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hint {
  font-size: 0.78rem;
  color: var(--color-text-light);
  line-height: 1.4;
  padding: 2px 0;
}

/* === Layer toggles === */
.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

/* === Buttons === */
.btn-primary {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: auto;
}

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

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

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

/* === Custom Leaflet markers === */
.vertex-marker {
  background: #ff7043;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  cursor: grab;
  transition: transform 0.1s;
}

.vertex-marker:hover,
.vertex-marker.dragging {
  background: #e64a19;
  transform: scale(1.3);
}

.vertex-marker-secondary {
  background: #ffab91;
  border-width: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  opacity: 0.85;
}

.vertex-marker-secondary:hover {
  background: #ff7043;
  opacity: 1;
  transform: scale(1.3);
}

/* Vertex delete popup */
.vertex-delete-popup .leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}

.vertex-delete-popup .leaflet-popup-content {
  margin: 0;
}

.vertex-popup {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.vertex-popup-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
}

.vertex-popup-delete {
  background: #c62828;
  color: white;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.vertex-popup-delete:hover {
  background: #b71c1c;
}

/* Edge length tooltips (terrain wall totals) */
.edge-label {
  background: rgba(255,255,255,0.92);
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  color: #333;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  pointer-events: none;
}

/* Edge detail labels (individual segments within a wall, shown at high zoom, behind totals) */
.edge-label-detail {
  font-size: 9px;
  font-weight: 500;
  color: #888;
  background: rgba(240, 240, 240, 0.85);
  border-color: #e0e0e0;
  padding: 1px 4px;
  box-shadow: none;
  opacity: 0.85;
}

/* === Step content sections === */
.step-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* === Tree Catalog === */
.tree-catalog {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.tree-catalog-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f0f7ed;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: grab;
  transition: all 0.15s;
  font-size: 0.82rem;
  user-select: none;
}

.tree-catalog-item:hover {
  border-color: var(--color-primary);
  background: #e8f5e9;
}

.tree-catalog-item:active {
  cursor: grabbing;
}

.tree-emoji {
  font-size: 1.1rem;
  line-height: 1;
}

.tree-emoji-lg {
  font-size: 1.5rem;
  line-height: 1;
}

.tree-catalog-name {
  font-weight: 500;
  color: var(--color-text);
}

/* === Tree markers on map === */
.tree-marker {
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.tree-marker:hover {
  transform: scale(1.3);
  z-index: 1000 !important;
}

.tree-marker-selected {
  border-color: var(--color-handle);
  box-shadow: 0 0 0 3px rgba(255,112,67,0.4), 0 2px 6px rgba(0,0,0,0.3);
}

.tree-marker-emoji {
  font-size: 18px;
  line-height: 1;
}

/* Floating selection label (appears above highlighted tree) */
.tree-selection-label-anchor {
  background: none !important;
  border: none !important;
}
.tree-selection-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--color-handle);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* === Advanced options (details/summary) === */
.advanced-options {
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  padding: 0;
}

.advanced-options summary {
  padding: 10px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-light);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.advanced-options summary::before {
  content: '\u25B6';
  font-size: 0.65rem;
  transition: transform 0.2s;
}

.advanced-options[open] summary::before {
  transform: rotate(90deg);
}

.advanced-options summary::-webkit-details-marker {
  display: none;
}

.advanced-options > .layer-toggles {
  padding: 0 12px 12px;
}

/* === Placement mode cursor === */
#map.placement-mode {
  cursor: crosshair !important;
}

/* === Tree list: grouped === */
.tree-list-grouped {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

/* === Tree list (flat, legacy) === */
.tree-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

/* Tree group */
.tree-group {
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  overflow: hidden;
}

.tree-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f0f7ed;
  cursor: pointer;
  font-size: 0.85rem;
  user-select: none;
  transition: background 0.15s;
}

.tree-group-header:hover {
  background: #e8f5e9;
}

.tree-group-name {
  flex: 1;
  font-weight: 600;
  color: var(--color-primary-dark);
}

.tree-group-count {
  background: var(--color-primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.tree-group-items {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tree-group.collapsed .tree-group-items {
  display: none;
}

.tree-list-variety {
  font-size: 0.75rem;
  color: var(--color-text-light);
  font-style: italic;
}

.tree-list-empty {
  font-size: 0.82rem;
  color: var(--color-text-light);
  font-style: italic;
  text-align: center;
  padding: 12px;
}

.tree-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #fafafa;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.tree-list-item:hover {
  background: #e8f5e9;
}

.tree-list-item.selected {
  border-color: var(--color-primary-light);
  background: #e8f5e9;
}

.tree-list-name {
  flex: 1;
  font-weight: 500;
}

.tree-list-age {
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.tree-list-locate,
.tree-list-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.tree-list-locate:hover,
.tree-list-delete:hover {
  opacity: 1;
}

/* === Tree detail panel === */
.tree-detail {
  background: #f0f7ed;
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 2px solid var(--color-primary-light);
}

.tree-detail.hidden {
  display: none;
}

.tree-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-detail-header h3 {
  flex: 1;
  font-size: 1rem;
  color: var(--color-primary-dark);
  text-transform: none;
  letter-spacing: 0;
}

.tree-detail .input-group input,
.tree-detail .input-group textarea {
  padding: 8px 10px;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--color-text);
  width: 100%;
  transition: border-color 0.2s;
}

.tree-detail .input-group input:focus,
.tree-detail .input-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.tree-detail .input-group textarea {
  resize: vertical;
  min-height: 60px;
}

.text-muted {
  font-size: 0.82rem;
  color: var(--color-text-light);
  font-family: 'Courier New', monospace;
}

.btn-icon-sm {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-text-light);
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.btn-icon-sm:hover {
  background: rgba(0,0,0,0.08);
}

.tree-detail-actions {
  display: flex;
  gap: 8px;
}

.tree-detail-actions .btn-primary,
.tree-detail-actions .btn-danger {
  flex: 1;
  margin-top: 0;
}

.btn-danger {
  background: #c62828;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-danger:hover {
  background: #b71c1c;
}

.btn-danger-confirm {
  background: #b71c1c;
  animation: pulse-danger 0.8s ease infinite alternate;
}

@keyframes pulse-danger {
  from { opacity: 1; }
  to { opacity: 0.75; }
}

/* ===============================
   CUSTOM SELECT DROPDOWN
   =============================== */

.custom-select {
  position: relative;
}

.custom-select-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--color-text);
  transition: border-color 0.2s;
}

.custom-select-btn:hover {
  border-color: #bdbdbd;
}

.custom-select.open .custom-select-btn {
  border-color: var(--color-primary);
}

.custom-select-preview {
  font-size: 1.1rem;
  line-height: 1;
}

.custom-select-label {
  flex: 1;
  text-align: left;
}

.custom-select-arrow {
  font-size: 0.8rem;
  color: #999;
  transition: transform 0.2s;
}

.custom-select.open .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  max-height: 240px;
  overflow-y: auto;
}

.custom-select.open .custom-select-dropdown {
  display: block;
}

.custom-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.1s;
}

.custom-select-option:hover {
  background: #f5f5f5;
}

.custom-select-option.selected {
  background: #e8f5e9;
}

.custom-select-option .custom-select-emoji {
  font-size: 1.1rem;
  line-height: 1;
}

.custom-select-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

/* ===============================
   COLOR SWATCH PICKER
   =============================== */

.color-swatch-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.selected {
  border-color: var(--color-text);
}

.color-swatch-custom {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px dashed #bdbdbd;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #999;
  background: white;
  transition: border-color 0.15s;
}

.color-swatch-custom:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ===============================
   ZONE / ESTRUCTURAS STYLES
   =============================== */

/* Emoji picker */
.zone-emoji-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zone-emoji-input {
  width: 60px;
  text-align: center;
  font-size: 1.2rem;
  padding: 6px 8px;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  transition: border-color 0.2s;
}

.zone-emoji-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.zone-emoji-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.zone-emoji-quick-btn {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.zone-emoji-quick-btn:hover {
  background: #e8e8e8;
  border-color: var(--color-primary);
  transform: scale(1.15);
}

/* Emoji grid picker (detail panel) */
.zone-emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.zone-emoji-grid-btn {
  width: 36px;
  height: 36px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, transform 0.1s;
}

.zone-emoji-grid-btn:hover {
  border-color: var(--color-primary);
  transform: scale(1.1);
}

.zone-emoji-grid-btn.selected {
  border-color: var(--color-primary);
  background: #e8f5e9;
}

.zone-emoji-grid-plus {
  font-size: 1.1rem;
  font-weight: 700;
  color: #999;
}

.zone-emoji-grid-plus.selected {
  color: var(--color-primary);
}

.emoji-custom-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.emoji-custom-input {
  width: 100%;
  padding: 6px 10px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.emoji-custom-input:focus {
  border-color: var(--color-primary);
}

.zone-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.zone-emoji {
  font-size: 1.1rem;
  line-height: 1;
}

.zone-emoji-lg {
  font-size: 1.5rem;
  line-height: 1;
}

.zone-catalog-name {
  font-weight: 500;
  color: var(--color-text);
}

/* Zone labels on map (stacked: emoji / name / area) */
/* Anchor div: invisible 0×0 point at the centroid, Leaflet positions this */
.zone-label-anchor {
  overflow: visible !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  pointer-events: none;
}

.zone-label-clickable {
  pointer-events: auto;
  cursor: pointer;
}

/* Full label (inner div centered on anchor point) */
.zone-label-inner {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.92);
  border-radius: 6px;
  padding: 3px 8px 3px 5px;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.15s, box-shadow 0.15s;
}

.zone-label-clickable:hover .zone-label-inner {
  background: rgba(255,255,255,1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transform: translate(-50%, -50%) scale(1.05);
}

/* Emoji-only label (inner div centered on anchor point) */
.zone-label-emoji-only-inner {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  background: rgba(255,255,255,0.85);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.15s;
}

.zone-label-clickable:hover .zone-label-emoji-only-inner {
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.zone-label-emoji {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.zone-label-info {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.zone-label-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  letter-spacing: 0.2px;
}

.zone-label-area {
  font-size: 9px;
  color: var(--color-text-light);
  line-height: 1.2;
  font-weight: 500;
}

/* Zone blueprint label (arboles/huerto steps — flat gray, no background) */
.zone-label-blueprint {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  font-size: 10px;
  font-weight: 500;
  color: #aaa;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
  text-transform: uppercase;
}

/* Zone edge labels (wall lengths on map) */
.zone-edge-label {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 700;
  color: #555;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  pointer-events: none;
}

.zone-edge-label-live {
  background: rgba(255,243,224,0.95);
  border-color: var(--color-handle);
  color: var(--color-handle);
}

/* Zone action popup */
.zone-action-popup .leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}

.zone-action-popup .leaflet-popup-content {
  margin: 0;
  min-width: 160px;
}

.zone-popup {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zone-popup-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.zone-popup-emoji {
  font-size: 1.2rem;
}

.zone-popup-info {
  font-size: 0.78rem;
  color: var(--color-text-light);
}

.zone-popup-actions {
  display: flex;
  gap: 6px;
}

.zone-popup-btn {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.zone-popup-edit {
  background: var(--color-primary);
  color: white;
}

.zone-popup-edit:hover {
  background: var(--color-primary-dark);
}

.zone-popup-center {
  background: #e0e0e0;
  color: var(--color-text);
}

.zone-popup-center:hover {
  background: #bdbdbd;
}

.zone-popup-delete {
  background: #ffebee;
  color: #c62828;
}

.zone-popup-delete:hover {
  background: #ffcdd2;
}

/* Drawing mode cursor */
#map.drawing-mode {
  cursor: crosshair !important;
}

/* Zone list */
.zone-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.zone-list-empty {
  font-size: 0.82rem;
  color: var(--color-text-light);
  font-style: italic;
  text-align: center;
  padding: 12px;
}

.zone-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #fafafa;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.zone-list-item:hover {
  background: #f0f0f0;
}

.zone-list-item.selected {
  border-color: var(--color-handle);
  background: #fff3e0;
}

.zone-list-name {
  flex: 1;
  font-weight: 500;
}

.zone-list-locate,
.zone-list-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.zone-list-locate:hover,
.zone-list-delete:hover {
  opacity: 1;
}

/* Zone detail panel */
.zone-detail {
  background: #fafafa;
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 2px solid var(--color-handle);
}

.zone-detail.hidden {
  display: none;
}

.zone-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zone-detail-header h3 {
  flex: 1;
  font-size: 1rem;
  color: var(--color-text);
  text-transform: none;
  letter-spacing: 0;
}

.zone-detail .input-group input,
.zone-detail .input-group textarea,
.zone-detail .input-group select {
  padding: 8px 10px;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--color-text);
  width: 100%;
  transition: border-color 0.2s;
}

.zone-detail .input-group input:focus,
.zone-detail .input-group textarea:focus,
.zone-detail .input-group select:focus {
  outline: none;
  border-color: var(--color-handle);
}

.zone-detail .input-group textarea {
  resize: vertical;
  min-height: 50px;
}

.zone-detail .input-group input[type="color"] {
  height: 36px;
  padding: 2px;
  cursor: pointer;
}

.zone-detail-actions {
  display: flex;
  gap: 8px;
}

.zone-detail-actions .btn-primary,
.zone-detail-actions .btn-danger {
  flex: 1;
  margin-top: 0;
}

/* ===============================
   HUERTO STYLES
   =============================== */

/* Bed list */
.bed-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.bed-list-empty {
  font-size: 0.82rem;
  color: var(--color-text-light);
  font-style: italic;
  text-align: center;
  padding: 12px;
}

.bed-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #fafafa;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.bed-list-item:hover {
  background: #fdf0e6;
}

.bed-list-item.selected {
  border-color: var(--color-accent);
  background: #fdf0e6;
}

.bed-list-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.bed-list-name {
  flex: 1;
  font-weight: 500;
}

.bed-list-dims {
  font-size: 0.75rem;
  color: var(--color-text-light);
}

/* Bed detail panel — now uses .zone-detail classes (see zone styles above) */

/* Plant catalog */
.plant-catalog {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.plant-catalog-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #fdf6ee;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: grab;
  transition: all 0.15s;
  font-size: 0.82rem;
  user-select: none;
}

.plant-catalog-item:hover {
  border-color: var(--color-accent);
  background: #fdf0e6;
}

.plant-catalog-item:active {
  cursor: grabbing;
}

.plant-emoji {
  font-size: 1.1rem;
  line-height: 1;
}

.plant-catalog-name {
  font-weight: 500;
  color: var(--color-text);
}

.plant-catalog-spacing {
  font-size: 0.7rem;
  color: var(--color-text-light);
  margin-left: auto;
}

/* Bed polygon label on map */
.bed-polygon-label {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--color-accent);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #5d4037;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  pointer-events: none;
}

/* Plant markers on map */
.plant-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s;
}

.plant-marker:hover {
  transform: scale(1.5);
  z-index: 1000 !important;
}

.bed-polygon-selected {
  box-shadow: 0 0 0 3px rgba(212,163,115,0.5);
}

/* (old zone-label-emoji-only removed – now uses .zone-label-emoji-only-inner inside .zone-label-anchor) */

/* Save/Cancel buttons on map during zone edit */
/* Polygon appear animation */
@keyframes zoneAppearFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.zone-appear-anim {
  animation: zoneAppearFade 0.4s ease-out;
}

.zone-map-edit-btns {
  overflow: visible !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  transition: transform 0.12s ease-out;
}

.zone-map-edit-btns-inner {
  position: absolute;
  left: 0;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.zone-map-btn-save {
  background: #43a047;
  color: white;
  border: none;
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: background 0.15s;
  font-family: inherit;
}

.zone-map-btn-save:hover {
  background: #388e3c;
}

.zone-map-btn-cancel {
  background: rgba(255,255,255,0.92);
  color: var(--color-text);
  border: 1px solid #ccc;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: background 0.15s;
  font-family: inherit;
}

.zone-map-btn-cancel:hover {
  background: #f5f5f5;
}

/* ===============================
   TREE ZOOM LABELS
   =============================== */

/* ===============================
   SAVE BUTTON & TOAST
   =============================== */

.btn-save {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  width: 100%;
  margin-top: 8px;
  letter-spacing: 0.3px;
}

.btn-save:hover {
  background: var(--color-primary-dark);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-save:active {
  transform: scale(0.98);
}

/* btn-secondary (detect buildings, etc.) */
.btn-secondary {
  background: #e8eaf6;
  color: #283593;
  border: 2px solid #c5cae9;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #c5cae9;
  border-color: #7986cb;
}

/* Save toast notification */
.save-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2e7d32;
  color: white;
  padding: 12px 28px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

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

.save-toast.hidden {
  display: block;
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

/* Map-centered toast */
.map-toast {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 800;
  white-space: nowrap;
}

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

/* ===============================
   COLLAPSIBLE ADVANCED SECTIONS
   =============================== */

.advanced-section {
  border-top: 1px solid #e8e8e8;
  margin-top: 2px;
}

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.advanced-toggle::-webkit-details-marker {
  display: none;
}

.advanced-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
}

.advanced-toggle-icon::before {
  content: '\25B6';
  font-size: 0.6rem;
  transition: transform 0.2s;
  display: inline-block;
  color: var(--color-text-light);
}

.advanced-section[open] .advanced-toggle-icon::before {
  transform: rotate(90deg);
}

.advanced-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

/* ===============================
   HELP BUTTON + TOOLTIP
   =============================== */

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--color-text-light);
  background: transparent;
  color: var(--color-text-light);
  font-size: 0.6rem;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  margin-left: 4px;
  position: relative;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
}

.help-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Global help tooltip (appended to body via JS) */
.help-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--color-primary-dark);
  color: white;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: var(--radius);
  width: max-content;
  max-width: 240px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: normal;
  text-transform: none;
  letter-spacing: 0;
}
.help-tooltip.visible {
  opacity: 1;
}
.help-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-primary-dark);
}

/* Fix label layout to support inline help button */
.input-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ===============================
   FLOATING MAP HELP BUTTON
   =============================== */

.map-help-control {
  position: relative;
}

.map-help-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: white;
  color: var(--color-primary-dark);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: background 0.15s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.map-help-btn:hover {
  background: #f0f7ed;
  transform: scale(1.1);
}

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

.map-help-panel {
  display: none;
  position: absolute;
  bottom: 44px;
  left: 0;
  background: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 260px;
  max-width: 300px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  z-index: 1000;
}

.map-help-panel.visible {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-help-panel .hint {
  font-size: 0.8rem;
}

/* ===========================
   PRIMERA VISITA (#landing-screen)
   Bienvenida y «¿Dónde está tu finca?», con el sistema «cuaderno de campo»
   (docs/diseno.md): hoja blanca sobre el mapa real velado con el color papel.
   Prefijo fr- (first run). Los tokens están en app-shell.css.
   =========================== */

#landing-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) 20px max(24px, env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* Velo papel sobre el mapa: se ve la textura del terreno, sin foto ni partículas */
.landing-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(247, 248, 245, 0.9);
  transition: opacity 0.5s ease-out;
}
.landing-overlay.fade-out { opacity: 0; }

.fr-sheet {
  width: 100%;
  max-width: 440px;
  margin: auto 0; /* centrado vertical que sigue dejando desplazar si no cabe */
  padding: 28px 24px 24px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-sheet);
  transition: opacity 0.25s ease-out;
}
.fr-sheet.fade-out { opacity: 0; }

#landing-screen :focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Bienvenida */
.fr-logo {
  display: inline-block;
  align-self: flex-start; /* el subrayado mide lo que la palabra */
  font-size: 34px;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 28px;
}
.fr-logo .logo-crop { color: #1a1a1a; }
.fr-logo .logo-tia { color: #777; }
.fr-logo .logo-underline { height: 4px; margin-top: 4px; }

.fr-lead {
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 28px;
  text-wrap: balance;
}

.fr-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fr-foot {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: center;
}
.fr-quiet-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  border-radius: var(--r-ctl);
  color: var(--stone);
  font-size: 0.9375rem;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}
.fr-quiet-link:hover { color: var(--ink); text-decoration-color: currentColor; }

/* Botones */
.fr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--r-ctl);
  border: 1px solid transparent;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.fr-btn:disabled { opacity: 0.55; cursor: progress; }
.fr-btn-primary { background: var(--leaf); color: #fff; }
.fr-btn-primary:hover:not(:disabled),
.fr-btn-primary:active { background: var(--forest); }
.fr-btn-outline { background: var(--sheet); color: var(--ink); border-color: var(--line-strong); font-weight: 500; }
.fr-btn-outline:hover:not(:disabled) { background: var(--hover); }
.fr-btn-text { background: none; color: var(--leaf); min-height: 44px; }
.fr-btn-text:hover { background: var(--leaf-tint); }

/* ¿Dónde está tu finca? */
.fr-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin: -12px 0 8px -10px;
  padding: 0 12px 0 6px;
  border: none;
  border-radius: var(--r-ctl);
  background: none;
  color: var(--stone);
  font: inherit;
  font-size: 0.9375rem;
  cursor: pointer;
}
.fr-back:hover { color: var(--ink); background: var(--hover); }

.fr-title {
  font-size: 1.75rem;
  line-height: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
.fr-sub {
  font-size: 0.9375rem;
  line-height: 1.375rem;
  color: var(--stone);
  margin: 0 0 20px;
}

.fr-options {
  border: 1px solid var(--line);
  border-radius: 12px;
}
.fr-option + .fr-option { border-top: 1px solid var(--line); }

.fr-option-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  border: none;
  border-radius: 11px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.fr-option-head:hover { background: var(--hover); }
.fr-option-head[aria-expanded="true"] { border-radius: 11px 11px 0 0; }
.fr-option-head[aria-expanded="true"]:hover { background: none; }
.fr-option-icon { flex: none; color: var(--leaf); }
.fr-option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fr-option-title { font-size: 1rem; line-height: 1.5rem; font-weight: 600; }
.fr-option-hint { font-size: 0.875rem; line-height: 1.25rem; color: var(--stone); }
.fr-chevron { flex: none; color: var(--stone); transition: transform 0.2s ease-out; }
.fr-option-head[aria-expanded="true"] .fr-chevron { transform: rotate(180deg); }

.fr-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 14px 16px;
}
.fr-panel[hidden] { display: none; }

.fr-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
}
.fr-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-ctl);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-size: 1rem; /* 16px: iOS no hace zoom al enfocar */
  transition: border-color 0.15s, box-shadow 0.15s;
}
.fr-input::placeholder { color: var(--stone-light); }
.fr-input:focus { outline: none; border-color: var(--leaf); box-shadow: var(--focus-ring); }
.fr-input[aria-invalid="true"],
.fr-input[aria-invalid="true"]:focus { border-color: var(--heat); }
.fr-input-ref {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.fr-input-ref:not(:placeholder-shown) { text-transform: uppercase; }

.fr-error {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--heat);
}
.fr-error.hidden { display: none; }

.fr-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  color: var(--stone);
  font-size: 0.9375rem;
}
.fr-progress.hidden { display: none; }
.fr-progress .spinner-ring {
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--leaf);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.fr-help { margin-top: 2px; }
.fr-help summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding-right: 8px;
  border-radius: var(--r-ctl);
  color: var(--leaf);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
.fr-help summary::-webkit-details-marker { display: none; }
.fr-help summary:hover { color: var(--forest); }
.fr-help[open] summary .fr-chevron { transform: rotate(180deg); }
.fr-help summary .fr-chevron { color: currentColor; }
.fr-help ol {
  margin: 4px 0 0;
  padding-left: 22px;
  list-style: decimal;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: var(--stone);
}
.fr-help li + li { margin-top: 6px; }
.fr-help li::marker { color: var(--ink); font-variant-numeric: tabular-nums; }
.fr-help a { color: var(--leaf); text-underline-offset: 2px; }
.fr-help code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--hover);
  color: var(--ink);
  font-size: 0.8125rem;
}

/* Móvil: la hoja ocupa la pantalla entera, sin marco que robe anchura */
@media (max-width: 479px) {
  #landing-screen { padding: 0; }
  .fr-sheet {
    max-width: none;
    min-height: 100%;
    margin: 0;
    padding: max(24px, env(safe-area-inset-top, 0px)) 20px max(24px, env(safe-area-inset-bottom, 0px));
    border: none;
    border-radius: 0;
  }
  #landing-welcome { display: flex; flex-direction: column; justify-content: center; }
  .fr-option-head { padding: 12px; }
  .fr-panel { padding: 2px 12px 16px; }
}

@media (min-width: 600px) {
  .fr-sheet { padding: 36px 36px 28px; }
  .fr-lead { font-size: 1.75rem; line-height: 2.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .landing-overlay, .fr-sheet, .fr-chevron { transition: none; }
  .fr-progress .spinner-ring { animation-duration: 2s; }
}

/* ===========================
   TARJETA OSCURA (la usa el popup de acceso)
   =========================== */

.landing-card {
  position: relative;
  pointer-events: all;
  background: rgba(18, 18, 18, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 48px 40px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  animation: landingFadeIn 0.6s ease-out both;
}

.landing-logo {
  display: inline-block;
  font-family: 'DM Sans', sans-serif;
  font-size: 48px;
  letter-spacing: -0.03em;
  margin-bottom: 32px;
  animation: logoBounce 0.8s ease-out 0.3s both;
  line-height: 1;
}
.landing-logo .logo-crop { color: #fff; }
.landing-logo .logo-tia  { color: #ddd; }
.landing-logo .logo-underline { height: 5px; margin-top: 4px; }
.landing-logo .logo-slogan {
  font-size: 11px;
  margin-top: 6px;
}

.landing-title {
  font-size: 16px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 6px;
}

/* Landing buttons */
.landing-btn {
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.landing-btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 4px 16px rgba(46, 125, 50, 0.3);
}
.landing-btn-primary:hover {
  background: var(--color-primary-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(46, 125, 50, 0.4);
}
.landing-btn-primary:active {
  transform: translateY(0);
}

.landing-btn-secondary {
  background: transparent;
  color: #66bb6a;
  border: 2px solid rgba(102, 187, 106, 0.4);
}
.landing-btn-secondary:hover {
  background: rgba(102, 187, 106, 0.1);
  border-color: #66bb6a;
  transform: translateY(-1px);
}

.landing-error {
  color: #ef9a9a;
  font-size: 13px;
  text-align: left;
  padding: 0 4px;
}
.landing-error.hidden {
  display: none;
}

/* App hidden / entering transitions */
#app-header.app-hidden {
  opacity: 0;
  pointer-events: none;
}
#panel-lateral.app-hidden {
  opacity: 0;
  pointer-events: none;
}
.sidebar-toggle.app-hidden {
  opacity: 0;
  pointer-events: none;
}

#app-header.app-entering {
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}
#panel-lateral.app-entering {
  transition: opacity 0.5s ease-out 0.1s, transform 0.5s ease-out 0.1s;
  opacity: 1;
  pointer-events: all;
  transform: translateX(0);
}
.sidebar-toggle.app-entering {
  transition: opacity 0.4s ease-out 0.3s;
  opacity: 1;
  pointer-events: all;
}

/* Landing card fade-out */
.landing-card.fade-out {
  animation: landingFadeOut 0.4s ease-in forwards;
}

/* Keyframes */
@keyframes landingFadeIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes logoBounce {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  60% {
    opacity: 1;
    transform: scale(1.15);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

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

@keyframes landingFadeOut {
  to {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
  }
}

/* ===========================
   LANDING AUTH CARD
   =========================== */

.landing-auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius);
  padding: 4px;
}

.landing-auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.5);
  transition: all 0.2s;
  font-family: inherit;
}

.landing-auth-tab.active {
  background: rgba(102, 187, 106, 0.2);
  color: #66bb6a;
  box-shadow: none;
}

.landing-auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.landing-auth-form .input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.landing-auth-form .input-group label {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 600;
}

.landing-auth-form .input-group input {
  padding: 10px 14px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  font-size: 0.95rem;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-family: inherit;
  text-align: left;
  letter-spacing: normal;
  transition: border-color 0.2s;
}

.landing-auth-form .input-group input::placeholder { color: rgba(255, 255, 255, 0.3); }
.landing-auth-form .input-group input:focus {
  border-color: #66bb6a;
  outline: none;
}

/* Forgot password link & desc */
.auth-forgot-link {
  background: none;
  border: none;
  color: #66bb6a;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  text-align: center;
  margin-top: 2px;
}
.auth-forgot-link:hover {
  text-decoration: underline;
}
.auth-forgot-desc {
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 0 0 6px;
  line-height: 1.4;
}
.auth-forgot-success {
  background: rgba(102, 187, 106, 0.15);
  color: #66bb6a;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.4;
}
.auth-forgot-success.hidden {
  display: none;
}

/* ===========================
   AUTH MODAL (header login)
   =========================== */

/* Centralized auth popup (dark, reuses .landing-card styles) */
.auth-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.auth-popup-overlay .landing-card {
  max-width: 400px;
  width: 90%;
  animation: landingFadeIn 0.3s ease-out;
  position: relative;
}

.auth-popup-close-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1;
  padding: 4px;
}
.auth-popup-close-btn:hover {
  color: #fff;
}
.auth-popup-subtitle {
  text-align: center;
  color: #b0b0b0;
  font-size: 0.85rem;
  margin: 4px 0 8px;
  line-height: 1.4;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===========================
   SIDEBAR PLAN
   =========================== */

.sidebar-plan {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid #eee;
}

.sidebar-plan-label {
  font-size: 0.72rem;
  color: var(--color-text-light);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-plan-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.sidebar-plan-btn:hover {
  background: #eeeeee;
}

.plan-badge {
  font-weight: 600;
  font-size: 0.85rem;
}

.plan-badge.free {
  color: var(--color-text-light);
}

.plan-badge.pro {
  color: var(--color-primary);
}

.plan-arrow {
  color: var(--color-text-light);
  font-size: 1.1rem;
}

/* ===========================
   SIDEBAR TOGGLE
   =========================== */

.sidebar-toggle {
  position: absolute;
  left: 300px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 600;
  width: 22px;
  height: 44px;
  background: var(--color-panel);
  border: 1px solid #e0e0e0;
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.3s ease, background 0.15s;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
  padding: 0;
  font-family: inherit;
}

.sidebar-toggle:hover {
  background: #f0f0f0;
  color: var(--color-text);
}

.sidebar-toggle.collapsed {
  left: 0;
}

/* Sidebar collapse transition */
#panel-lateral {
  transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
}

#panel-lateral.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  border-right: none;
}

/* ===========================
   RESPONSIVE – Mobile (<768px)
   =========================== */
@media (max-width: 768px) {

  /* Header: compact single row */
  .header-topbar {
    padding: 6px 12px;
    gap: 8px;
    min-height: 42px;
  }
  .header-brand-name { display: none; }
  .header-brand-icon { font-size: 1.3rem; }
  .parcel-name-input {
    font-size: 0.85rem;
    max-width: 140px;
    padding: 3px 6px;
  }
  .parcel-municipality { font-size: 0.72rem; }
  .header-subnav {
    gap: 2px;
    padding: 3px 8px 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .nav-btn {
    font-size: 0.7rem;
    padding: 4px 8px;
    white-space: nowrap;
  }

  /* Layout: panel as bottom sheet */
  main {
    flex-direction: column;
    position: relative;
  }

  #map-container {
    flex: 1;
    min-height: 0;
  }

  #panel-lateral {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    min-width: 0 !important;
    max-height: 45vh;
    height: auto;
    border-right: none;
    border-top: 2px solid var(--color-primary);
    border-radius: 14px 14px 0 0;
    padding: 10px 16px 16px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 800;
    transition: transform 0.3s ease, opacity 0.2s ease;
  }

  #panel-lateral::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 0 auto 10px;
    flex-shrink: 0;
  }

  #panel-lateral.collapsed {
    transform: translateY(100%);
    opacity: 1;
    overflow: hidden;
    padding: 0;
  }

  /* Sidebar toggle: bottom-right floating button */
  .sidebar-toggle {
    position: fixed;
    left: auto !important;
    right: 12px;
    bottom: 12px;
    top: auto;
    transform: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #ddd;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 900;
  }

  .sidebar-toggle.collapsed {
    left: auto !important;
  }

  /* Landing cards smaller */
  .landing-card {
    padding: 28px 20px;
    max-width: 92vw;
  }

  /* Help tooltip: narrower */
  .help-tooltip {
    max-width: 200px;
  }
}

/* === Confirm button: confirmed (disabled) state === */
.btn-save.confirmed {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

/* === Continue to next step button (map overlay) === */
.map-continue-btn {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
  display: none;
}

.map-continue-btn:hover {
  background: var(--color-primary-dark);
  transform: translateX(-50%) scale(1.04);
}

.map-continue-btn.visible {
  display: block;
}

/* ── Cluster markers ── */
.cluster-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  border: 2px solid var(--color-primary, #2e7d32);
  cursor: pointer;
  position: relative;
}
.cluster-emoji {
  font-size: 22px;
  line-height: 1;
}
.cluster-plants .cluster-emoji {
  font-size: 18px;
}
.cluster-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--color-primary, #2e7d32);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  text-align: center;
  padding: 0 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.cluster-popup-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 13px;
  margin: 0;
  padding: 0;
}
.cluster-popup-list li {
  padding: 3px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cluster-popup-list .cluster-item-count {
  color: #888;
  font-size: 11px;
}

/* ===== Multi-parcela: selector de parcela en el header ===== */
.parcel-switcher {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  max-width: 170px;
  cursor: pointer;
}
.parcel-switcher option { color: #1e2621; }

/* ===== Banner de modo prueba (demo → registro) ===== */
#demo-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: #1b5e20;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  flex-wrap: wrap;
  justify-content: center;
}
#demo-banner-cta {
  background: #66bb6a;
  border: none;
  color: #10240f;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
}
#demo-banner-cta:hover { background: #7dc981; }
#demo-banner-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* ===== Export: botón y menú ===== */
.export-menu-wrap { position: relative; }
.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid #dce4d8;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  z-index: 2500;
  min-width: 170px;
  overflow: hidden;
}
.export-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 14px;
  font-size: 14px;
  color: #1e2621;
  cursor: pointer;
}
.export-menu-item:hover { background: #e7f1e5; }
