:root {
  --brand: #0c3b24;
  --brand-light: #1b6b45;
  --brand-dark: #082818;
  --accent: #d9a441;
  --bg: #f2f5f2;
  --card: #ffffff;
  --border: #e3e8e3;
  --border-strong: #cfd8cf;
  --text: #182720;
  --muted: #6b8073;
  --stale: #b45309;
  --stale-bg: #fef3c7;
  --active-status: #15803d;
  --active-status-bg: #dcfce7;
  --offline-status: #b91c1c;
  --offline-status-bg: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(15, 40, 25, .06), 0 1px 3px rgba(15, 40, 25, .08);
  --shadow-md: 0 4px 10px rgba(15, 40, 25, .08), 0 2px 4px rgba(15, 40, 25, .06);
  --shadow-lg: 0 10px 30px rgba(15, 40, 25, .14);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; }

/* ---------- Topbar ---------- */

.topbar {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  min-height: 60px;
  row-gap: 8px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 500;
}

.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.topbar .brand img { height: 28px; border-radius: 6px; }
.topbar a { color: #fff; text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; font-size: 13.5px; row-gap: 6px; }
.topbar nav .muted { color: #b9d4c3; }

@media (max-width: 480px) {
  .topbar { padding: 10px 16px; }
  .topbar nav { gap: 12px; font-size: 12.5px; }
  .topbar nav .muted { display: none; }
}
.topbar nav a { padding: 6px 12px; border-radius: 999px; transition: background .15s ease; }
.topbar nav a:hover { background: rgba(255,255,255,.12); }

.container { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; }

/* ---------- Layout primitives ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.card:has(h3 a:hover) { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.card h3 { margin: 0 0 10px; font-size: 17px; }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { color: var(--brand); }

.section-title {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 22px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title:first-child { margin-top: 0; }

h1 { font-size: 26px; margin: 4px 0 18px; }

/* ---------- Metric / layer tiles ---------- */

.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.metric {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #fafcfa 0%, #f5f8f5 100%);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.metric .label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; overflow-wrap: break-word; }
.metric .value { font-size: 18px; font-weight: 700; margin-top: 2px; color: var(--brand-dark); }

.layer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.layer {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #fafcfa 0%, #f5f8f5 100%);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}
.layer .n { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.layer .val { font-size: 14.5px; font-weight: 600; margin-top: 3px; color: var(--brand-dark); }

.empty-note { color: var(--muted); font-size: 13.5px; font-style: italic; }

.badge-stale {
  display: inline-block;
  background: var(--stale-bg);
  color: var(--stale);
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 10px;
}
.badge-active { background: var(--active-status-bg); color: var(--active-status); }
.badge-offline { background: var(--offline-status-bg); color: var(--offline-status); }
.badge-active, .badge-offline {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 10px;
}

.timestamp { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ---------- Buttons ---------- */

.btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--brand-light); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); }

.btn-secondary {
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}
.btn-secondary:hover { background: #f2f7f3; border-color: var(--brand); }

/* Toggle chips: parameter filters (map + charts) */
.chip {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--brand-light); color: var(--brand); }
.chip.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand-light); outline-offset: 1px; }

.chart {
  width: 100%;
  height: 340px;
  margin-bottom: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ---------- Login ---------- */

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 92vh; }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 340px;
  box-shadow: var(--shadow-lg);
}
.login-card img { height: 44px; display: block; margin: 0 auto 20px; }
.login-card .field { margin-bottom: 16px; }
.login-card .field label { font-size: 12.5px; }
.error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.back-link {
  font-size: 13.5px;
  margin-bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.back-link:hover { color: var(--brand); }

/* ---------- Map ---------- */

#map { position: relative; z-index: 0; }

.map-pin-wrap {
  background: transparent;
  border: none;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
}
.map-pin {
  position: relative;
  background: var(--pin-color, #fff);
  border: 2px solid var(--pin-color, var(--brand));
  border-radius: var(--radius-sm);
  padding: 5px 10px 6px;
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transform: translate(-50%, calc(-100% - 8px));
  text-align: center;
  color: var(--brand);
}
.map-pin:hover { filter: brightness(0.96); z-index: 1000 !important; }
.map-pin::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid var(--pin-color, var(--brand));
}
.map-pin-name { font-weight: 700; font-size: 12px; color: inherit; }
.map-pin-value { font-weight: 700; font-size: 15px; color: inherit; }
.map-pin-unit { font-weight: 500; font-size: 11px; opacity: .8; margin-left: 2px; }
.map-pin-arrow { font-size: 20px; font-weight: 700; line-height: 1; margin: 2px 0; display: inline-block; }

.map-cluster-wrap {
  background: transparent;
  border: none;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
}
.map-cluster {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: 3px solid #fff;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.map-list-popup-wrap .leaflet-popup-content-wrapper { border-radius: var(--radius-sm); padding: 0; box-shadow: var(--shadow-lg); }
.map-list-popup-wrap .leaflet-popup-content { margin: 0; }
.map-list-popup { display: flex; flex-direction: column; min-width: 190px; }
.map-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.map-list-row:last-child { border-bottom: none; }
.map-list-row:hover { background: var(--bg); }
.map-list-name { font-weight: 700; color: var(--brand); }
.map-list-value { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- Forecast ---------- */

.forecast-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.forecast-day {
  flex: 0 0 130px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 12px;
  text-align: center;
}
.forecast-date { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.forecast-icon { font-size: 30px; margin: 8px 0 2px; }
.forecast-label { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; min-height: 15px; }
.forecast-temps { font-size: 15px; margin-bottom: 8px; }
.forecast-max { font-weight: 700; color: var(--brand-dark); }
.forecast-min { color: var(--muted); margin-left: 6px; }
.forecast-rain, .forecast-wind { font-size: 12px; color: var(--muted); margin-top: 4px; }
