/* ===================================================
   CAMPO ALERTA — Design System 2026
   Mobile-first · Dark agri · Premium
   =================================================== */

:root {
  --bg-deep:       #060E08;
  --bg-base:       #0A1610;
  --bg-surface:    #0F1D14;
  --bg-card:       #132218;
  --bg-card-hover: #1A2E20;
  --bg-header:     rgba(6, 14, 8, 0.92);

  --green:         #22C55E;
  --green-soft:    rgba(34, 197, 94, 0.12);
  --green-border:  rgba(34, 197, 94, 0.28);
  --yellow:        #FACC15;
  --yellow-soft:   rgba(250, 204, 21, 0.10);
  --yellow-border: rgba(250, 204, 21, 0.28);
  --red:           #EF4444;
  --red-soft:      rgba(239, 68, 68, 0.10);
  --red-border:    rgba(239, 68, 68, 0.28);
  --blue:          #3B82F6;
  --blue-soft:     rgba(59, 130, 246, 0.10);
  --blue-border:   rgba(59, 130, 246, 0.28);
  --cyan:          #06B6D4;

  --accent:        #22C55E;
  --accent-soft:   rgba(34, 197, 94, 0.14);
  --accent-border: rgba(34, 197, 94, 0.38);

  --text-1:        #E8F5EC;
  --text-2:        #6B9B7A;
  --text-3:        #3A5C45;

  --border:        rgba(255, 255, 255, 0.06);
  --border-card:   rgba(255, 255, 255, 0.07);

  --pad:           16px;
  --card-r:        20px;
  --header-h:      60px;
  --nav-h:         68px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-deep);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(34, 197, 94, 0.10) 0%, transparent 70%),
    linear-gradient(165deg, #081A0D 0%, #060E08 55%, #0A1A12 100%);
  background-attachment: fixed;
}

button, input, select { border: none; background: none; cursor: pointer; font-family: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* === HEADER === */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  background: var(--bg-header);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 100%; padding: 0 var(--pad); max-width: 480px; margin: 0 auto;
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.brand-logo {
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 0 6px rgba(34,197,94,0.4));
}
.brand-name { font-size: 17px; font-weight: 800; color: var(--text-1); letter-spacing: -0.5px; }
.brand-accent { color: var(--green); font-weight: 900; }

.header-location {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 100px;
  background: var(--green-soft); border: 1px solid var(--green-border);
  color: var(--green); font-size: 12px; font-weight: 600;
  max-width: 200px; transition: all 0.2s;
}
.header-location:active { transform: scale(0.95); }
.header-location span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === MODAL === */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  width: 100%; max-width: 480px; max-height: 80vh;
  background: var(--bg-card); border-radius: 24px 24px 0 0;
  border: 1px solid var(--border-card); border-bottom: none;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s ease;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 0;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close { font-size: 24px; color: var(--text-3); padding: 4px 8px; }

.modal-list {
  flex: 1; overflow-y: auto; padding: 12px 12px 20px;
  scrollbar-width: thin; scrollbar-color: var(--text-3) transparent;
}
.commune-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px; border-radius: 12px; margin-bottom: 2px;
  font-size: 14px; font-weight: 500; color: var(--text-2);
  transition: all 0.15s; cursor: pointer;
}
.commune-item:hover, .commune-item:focus { background: var(--green-soft); color: var(--text-1); }
.commune-item .region { font-size: 11px; color: var(--text-3); }
.commune-item.active-parcela { color: var(--green); font-weight: 700; }
.commune-item.add-new { color: var(--green); margin-top: 8px; }

/* === MAP MODAL (fullscreen) === */
.modal--map {
  max-height: 100vh;
  height: 100vh;
  border-radius: 0;
}

.modal-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.modal-view.hidden { display: none !important; }

/* --- Map header (search bar row) --- */
.map-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px;
  background: var(--bg-card);
  z-index: 10;
  position: relative;
}
.map-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  color: var(--text-2);
  flex-shrink: 0;
}
.map-back-btn:active { background: var(--green-soft); }

.map-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-3);
}
.map-search-input {
  flex: 1;
  font-size: 14px;
  color: var(--text-1);
  outline: none;
  background: transparent;
  border: none;
}
.map-search-input::placeholder { color: var(--text-3); }

/* --- Search results dropdown --- */
.map-search-results {
  position: absolute;
  top: 60px;
  left: 12px;
  right: 12px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  scrollbar-width: thin;
  scrollbar-color: var(--text-3) transparent;
}
.search-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  padding: 12px 14px 4px;
}
.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover,
.search-result-item:active {
  background: var(--green-soft);
}
.search-result-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
}
.search-result-region {
  font-size: 11px;
  color: var(--text-3);
}
.search-no-results {
  text-align: center;
  padding: 20px;
  color: var(--text-3);
  font-size: 13px;
}

/* --- Map container --- */
#mapContainer {
  flex: 1;
  width: 100%;
  min-height: 0;
  z-index: 1;
}

/* Dark theme for OSM tiles */
#mapContainer .leaflet-tile-pane {
  filter: brightness(0.7) contrast(1.1) saturate(0.6) hue-rotate(70deg);
}

/* Leaflet UI overrides */
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-1) !important;
  border-color: var(--border-card) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
}
.leaflet-control-attribution {
  background: rgba(6, 14, 8, 0.8) !important;
  color: var(--text-3) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a {
  color: var(--text-3) !important;
}

/* Custom green pin */
.custom-pin {
  background: transparent !important;
  border: none !important;
}
.pin-marker {
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.4));
  animation: pin-drop 0.3s ease;
}
@keyframes pin-drop {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* --- GPS button (floating) --- */
.map-gps-btn {
  position: absolute;
  bottom: 120px;
  right: 16px;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: all 0.2s;
}
.map-gps-btn:active { transform: scale(0.9); }
.map-gps-btn.loading {
  animation: pulse 1s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* --- Bottom info bar --- */
.map-info-bar {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  padding: 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-card);
  border-radius: 20px 20px 0 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
}
.map-info-location {
  display: flex;
  align-items: center;
  gap: 10px;
}
.map-info-icon { font-size: 24px; }
.map-info-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
}
.map-info-coords {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.map-confirm-btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--green);
  color: #060E08;
  font-size: 15px;
  font-weight: 700;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(34,197,94,0.3);
}
.map-confirm-btn:active { transform: scale(0.97); }

/* --- Name input overlay --- */
.map-name-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}
.map-name-overlay.hidden { display: none !important; }
.map-name-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  padding: 24px;
}
.map-name-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-1);
}
.map-name-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 15px;
  color: var(--text-1);
  outline: none;
  margin-bottom: 16px;
}
.map-name-input:focus {
  border-color: var(--green-border);
}
.map-name-input::placeholder { color: var(--text-3); }

.map-name-actions {
  display: flex;
  gap: 10px;
}
.map-name-cancel {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
}
.map-name-save {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  background: var(--green);
  color: #060E08;
  font-size: 14px;
  font-weight: 700;
}

/* === MAIN === */
.main {
  padding-top: calc(var(--header-h) + 16px);
  padding-bottom: calc(var(--nav-h) + 8px);
  max-width: 480px; margin: 0 auto;
}

/* === WELCOME SCREEN === */
.welcome-screen {
  text-align: center; padding: 60px var(--pad) 40px;
}
.welcome-icon { font-size: 56px; margin-bottom: 16px; display: block; }
.welcome-title { font-size: 22px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
.welcome-text { font-size: 14px; color: var(--text-2); line-height: 1.7; max-width: 300px; margin: 0 auto 24px; }
.welcome-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 28px; border-radius: 100px;
  background: var(--green); color: #060E08;
  font-size: 14px; font-weight: 700; transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(34,197,94,0.3);
}
.welcome-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(34,197,94,0.4); }
.welcome-btn:active { transform: scale(0.96); }

/* === SECTIONS === */
.section { padding: 0 var(--pad); margin-bottom: 20px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; color: var(--text-2);
  margin-bottom: 12px; letter-spacing: -0.2px;
}
.section-icon { font-size: 16px; }

/* === ALERTS === */
.alerts-section { padding: 0 var(--pad); margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }

.alert-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 16px;
  animation: card-in 0.4s ease both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-card.alert-red    { background: var(--red-soft);    border: 1px solid var(--red-border); }
.alert-card.alert-yellow { background: var(--yellow-soft); border: 1px solid var(--yellow-border); }
.alert-card.alert-green  { background: var(--green-soft);  border: 1px solid var(--green-border); }
.alert-card.alert-blue   { background: var(--blue-soft);   border: 1px solid var(--blue-border); }

.alert-icon { font-size: 22px; flex-shrink: 0; }
.alert-info { flex: 1; }
.alert-title { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.alert-card.alert-red .alert-title    { color: var(--red); }
.alert-card.alert-yellow .alert-title { color: var(--yellow); }
.alert-card.alert-green .alert-title  { color: var(--green); }
.alert-card.alert-blue .alert-title   { color: var(--blue); }
.alert-desc { font-size: 12px; color: var(--text-2); line-height: 1.4; }

/* === CURRENT WEATHER GRID === */
.current-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.weather-tile {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 16px; padding: 16px;
  animation: card-in 0.4s ease both;
}
.weather-tile.wide { grid-column: 1 / -1; }
.tile-label { font-size: 10px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 6px; }
.tile-value { font-size: 26px; font-weight: 800; letter-spacing: -1px; color: var(--text-1); }
.tile-value.green  { color: var(--green); }
.tile-value.yellow { color: var(--yellow); }
.tile-value.red    { color: var(--red); }
.tile-value.blue   { color: var(--blue); }
.tile-value.cyan   { color: var(--cyan); }
.tile-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* Big temperature tile */
.temp-main { display: flex; align-items: baseline; gap: 4px; }
.temp-main .tile-value { font-size: 42px; }
.temp-unit { font-size: 18px; font-weight: 600; color: var(--text-3); }
.temp-feels { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* === SOIL GRID === */
.soil-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}

/* === FORECAST === */
.forecast-scroll {
  display: flex; gap: 10px; overflow-x: auto; padding: 0 0 8px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.forecast-scroll::-webkit-scrollbar { display: none; }

.forecast-day {
  flex-shrink: 0; width: 110px;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 16px; padding: 14px 12px; text-align: center;
  animation: card-in 0.4s ease both;
}
.forecast-name { font-size: 11px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.forecast-icon { font-size: 28px; margin-bottom: 8px; display: block; }
.forecast-temps { display: flex; justify-content: center; gap: 8px; margin-bottom: 6px; }
.forecast-max { font-size: 15px; font-weight: 700; color: var(--text-1); }
.forecast-min { font-size: 15px; font-weight: 500; color: var(--text-3); }
.forecast-rain { font-size: 11px; color: var(--blue); font-weight: 600; }
.forecast-day.frost { border-color: var(--red-border); }
.forecast-frost-badge { font-size: 9px; font-weight: 700; color: var(--red); background: var(--red-soft); padding: 2px 8px; border-radius: 100px; margin-top: 6px; display: inline-block; }

/* === IRRIGATION CARD === */
.irrigation-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--card-r); padding: 20px;
}
.irrigation-status { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.irrigation-icon { font-size: 32px; }
.irrigation-level { font-size: 18px; font-weight: 800; }
.irrigation-level.green  { color: var(--green); }
.irrigation-level.yellow { color: var(--yellow); }
.irrigation-level.red    { color: var(--red); }
.irrigation-desc { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.irrigation-bar-bg { height: 6px; background: rgba(255,255,255,0.07); border-radius: 100px; overflow: hidden; margin-top: 14px; }
.irrigation-bar-fill { height: 100%; border-radius: 100px; transition: width 1s ease; }

/* === FROST HOURS === */
.frost-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--card-r); padding: 20px;
}
.frost-value { font-size: 36px; font-weight: 900; color: var(--cyan); letter-spacing: -1px; }
.frost-label { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.frost-desc { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-top: 12px; }

/* === LAST UPDATE === */
.last-update { text-align: center; font-size: 11px; color: var(--text-3); padding: 16px var(--pad) 0; }

/* === LOADING === */
.skeleton-line {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === HIDDEN === */
.hidden { display: none !important; }

/* === BOTTOM NAV === */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(6, 14, 8, 0.94);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  padding: 0 4px; padding-bottom: env(safe-area-inset-bottom); z-index: 200;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 14px; color: var(--text-3); border-radius: 14px;
  min-width: 64px; transition: all 0.2s;
}
.nav-btn.active { color: var(--green); }
.nav-btn span { font-size: 10px; font-weight: 500; }
.nav-btn:active { transform: scale(0.88); }

/* === DISCLAIMER === */
.disclaimer {
  margin: 24px var(--pad) 0; padding: 20px 0 24px;
  border-top: 1px solid var(--border); text-align: center;
}
.disclaimer-text { font-size: 11px; color: var(--text-3); line-height: 1.7; max-width: 400px; margin: 0 auto 8px; }
.disclaimer-copy { font-size: 10px; color: var(--text-3); }

/* === RESPONSIVE === */
@media (min-width: 640px) {
  :root { --pad: 24px; }
  .header-inner, .main { max-width: 720px; }
  .current-grid { grid-template-columns: repeat(3, 1fr); }
  .soil-grid { grid-template-columns: repeat(3, 1fr); }
  .modal--map {
    max-width: 640px;
    height: 90vh;
    max-height: 90vh;
    border-radius: 24px;
    margin: auto;
    border: 1px solid var(--border-card);
  }
}

@media (min-width: 1024px) {
  :root { --pad: 32px; }
  .header-inner { max-width: 1200px; }
  .main { max-width: 900px; }
  .bottom-nav { display: none; }
  .current-grid { grid-template-columns: repeat(4, 1fr); }
  .modal--map {
    max-width: 720px;
    height: 85vh;
  }
}
