:root {
  --bg: #06111f;
  --card: rgba(5, 17, 31, 0.87);
  --card-soft: rgba(9, 26, 44, 0.78);
  --line: rgba(49, 215, 255, 0.22);
  --line-strong: rgba(49, 215, 255, 0.42);
  --text: #eff8ff;
  --muted: #9eb8cc;
  --cyan: #31d7ff;
  --green: #44f2a1;
  --yellow: #ffd54a;
  --orange: #ff9f43;
  --red: #ff5f6d;
  --purple: #d66bff;
  --blue: #73bfff;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  isolation: isolate;
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, "Segoe UI", sans-serif;
  color: var(--text);
  background: #030b15;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: 0;
  background:
    #030b15
    url("/static/portal-bg.png")
    center center / cover
    no-repeat;
}

body::after {
  z-index: 0;
  background:
    linear-gradient(
      90deg,
      rgba(2, 10, 19, 0.74) 0%,
      rgba(3, 13, 24, 0.59) 45%,
      rgba(3, 10, 18, 0.70) 100%
    ),
    linear-gradient(
      180deg,
      rgba(2, 10, 19, 0.32) 0%,
      rgba(3, 10, 18, 0.48) 58%,
      rgba(3, 10, 18, 0.70) 100%
    );
}

.portal-shell,
.login-page {
  position: relative;
  z-index: 1;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.portal-shell,
.login-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(14px);
}

.brand-mini {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 16px;
  color: var(--bg);
  background: var(--green);
  font-weight: 950;
  box-shadow: 0 0 38px rgba(68, 242, 161, 0.36);
}

.brand-mini strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.brand-mini span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(42px, 5vw, 60px);
  line-height: 1;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(25px, 3vw, 34px);
}

h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.17em;
  font-size: 12px;
  font-weight: 900;
}

label {
  display: block;
  margin-top: 18px;
  color: #bfe4ff;
  font-size: 14px;
}

input,
select {
  width: 100%;
  margin-top: 8px;
  padding: 14px 16px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  outline: none;
}

select option {
  color: #06111f;
}

input:focus,
select:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(49, 215, 255, 0.10);
}

button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 9px;
  margin-top: 20px;
  padding: 13px 18px;
  border: 0;
  border-radius: 999px;
  color: #06111f;
  background: var(--green);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 16px 38px rgba(68, 242, 161, 0.18);
}

button:hover {
  transform: translateY(-1px);
}

button.secondary {
  color: var(--text);
  background: rgba(49, 215, 255, 0.12);
  border: 1px solid var(--line);
  box-shadow: none;
}

button.ghost {
  color: var(--cyan);
  background: transparent;
  border: 1px solid rgba(49, 215, 255, 0.22);
  box-shadow: none;
}

.error {
  min-height: 22px;
  margin-top: 14px;
  color: #ff8791;
}

.portal-header {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: flex-start;
  padding: 28px 0 16px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 9px 13px;
  border: 1px solid rgba(49, 215, 255, 0.18);
  border-radius: 999px;
  color: #bfe4ff;
  background: rgba(49, 215, 255, 0.06);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 10px;
  margin: 0 0 22px;
  border-bottom: 1px solid rgba(49, 215, 255, 0.12);
}

.tab-button {
  margin: 0 0 -1px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: none;
}

.tab-button.active {
  color: var(--cyan);
  background: rgba(49, 215, 255, 0.08);
  border-color: rgba(49, 215, 255, 0.20);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.portal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  gap: 20px;
  align-items: stretch;
}

.panel,
.environment-status,
.kpi,
.charts-card,
.chart-box,
.alerts-panel,
.devices-panel {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--card);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.30);
  backdrop-filter: blur(14px);
}

.panel,
.charts-card,
.alerts-panel,
.devices-panel {
  padding: 28px;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

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

.environment-status {
  min-height: 100%;
  padding: 28px;
  border-color: rgba(68, 242, 161, 0.32);
  background:
    linear-gradient(135deg, rgba(68, 242, 161, 0.13), rgba(5, 17, 31, 0.94));
}

.environment-status strong {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-size: 38px;
  line-height: 1;
}

.environment-status.warning {
  border-color: rgba(255, 213, 74, 0.38);
  background:
    linear-gradient(135deg, rgba(255, 213, 74, 0.14), rgba(5, 17, 31, 0.94));
}

.environment-status.warning strong {
  color: var(--yellow);
}

.environment-status.critical {
  border-color: rgba(255, 95, 109, 0.44);
  background:
    linear-gradient(135deg, rgba(255, 95, 109, 0.14), rgba(5, 17, 31, 0.94));
}

.environment-status.critical strong {
  color: var(--red);
}

.meta-list {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(49, 215, 255, 0.10);
}

.meta-item span {
  color: var(--muted);
}

.meta-item strong {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  text-align: right;
}

.section {
  margin-top: 24px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.section-head span {
  color: var(--cyan);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.chart-controls {
  min-width: 230px;
}

.chart-controls label {
  margin: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi {
  position: relative;
  min-height: 168px;
  padding: 20px;
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  right: -32px;
  bottom: -32px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.07;
}

.kpi-icon {
  margin-bottom: 15px;
  font-size: 26px;
  filter: drop-shadow(0 0 14px currentColor);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 10px;
  color: currentColor;
  font-size: clamp(24px, 2.5vw, 32px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.kpi small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.accent-temperature { color: var(--green); }
.accent-humidity { color: var(--cyan); }
.accent-pressure { color: var(--purple); }
.accent-pm { color: #aebdd0; }
.accent-gas { color: var(--orange); }
.accent-sound { color: #ff7bc3; }
.accent-light { color: var(--yellow); }
.accent-uv { color: #ffbf4d; }
.accent-system { color: var(--cyan); }
.accent-memory { color: #85a9ff; }
.accent-firmware { color: #73bfff; }

.gps-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.gps-card {
  position: relative;
  min-width: 0;
  min-height: 150px;
  padding: 20px;
  overflow: hidden;
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.gps-card::after {
  content: "";
  position: absolute;
  right: -30px;
  bottom: -34px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.07;
}

.gps-card-primary {
  grid-column: span 2;
  color: var(--green);
  background: linear-gradient(135deg, rgba(68, 242, 161, 0.10), rgba(5, 17, 31, 0.94));
}

.gps-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.gps-card-icon {
  font-size: 27px;
  filter: drop-shadow(0 0 14px currentColor);
}

.gps-card em {
  padding: 5px 9px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.gps-card > span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.gps-card > strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 9px;
  color: currentColor;
  font-size: clamp(21px, 2.2vw, 29px);
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.gps-card-primary > strong {
  font-size: clamp(25px, 2.7vw, 34px);
}

.gps-card > small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.gps-card.state-no_data,
.gps-card.state-stale {
  color: var(--yellow);
}

.gps-card.state-offline {
  color: var(--muted);
  filter: grayscale(0.65);
  opacity: 0.76;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.chart-box {
  min-width: 0;
  min-height: 285px;
  padding: 22px;
}

.chart-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.chart-title span {
  color: var(--text);
  font-weight: 900;
}

.chart-title strong {
  color: var(--cyan);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 210px;
}

.chart-canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.devices-table-wrap,
.alerts-table-wrap {
  width: 100%;
  margin-top: 22px;
  overflow-x: auto;
  border: 1px solid rgba(49, 215, 255, 0.14);
  border-radius: 18px;
}

.devices-table,
.alerts-table {
  width: 100%;
  min-width: 1380px;
  border-collapse: collapse;
}

.alerts-table {
  min-width: 720px;
}

.devices-table th,
.devices-table td,
.alerts-table th,
.alerts-table td {
  padding: 14px;
  border-bottom: 1px solid rgba(49, 215, 255, 0.10);
  text-align: left;
}

.devices-table th,
.alerts-table th {
  color: var(--cyan);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(49, 215, 255, 0.05);
}

.devices-table td,
.alerts-table td {
  color: var(--text);
  font-size: 14px;
}

.devices-table th,
.devices-table td {
  vertical-align: top;
  line-height: 1.35;
}

.devices-table th:nth-child(1),
.devices-table td:nth-child(1) { min-width: 165px; }
.devices-table th:nth-child(2),
.devices-table td:nth-child(2) { min-width: 175px; }
.devices-table th:nth-child(3),
.devices-table td:nth-child(3) { min-width: 155px; }
.devices-table th:nth-child(4),
.devices-table td:nth-child(4) { min-width: 130px; }
.devices-table th:nth-child(5),
.devices-table td:nth-child(5) { min-width: 90px; }
.devices-table th:nth-child(6),
.devices-table td:nth-child(6) { min-width: 95px; }
.devices-table th:nth-child(7),
.devices-table td:nth-child(7) { min-width: 105px; }
.devices-table th:nth-child(8),
.devices-table td:nth-child(8) { min-width: 72px; }
.devices-table th:nth-child(9),
.devices-table td:nth-child(9) { min-width: 120px; }
.devices-table th:nth-child(10),
.devices-table td:nth-child(10) { min-width: 185px; }

.devices-table td code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.devices-table tbody tr:hover {
  background: rgba(49, 215, 255, 0.05);
}

.devices-table tbody tr {
  cursor: pointer;
  transition: background 160ms ease, box-shadow 160ms ease;
}

.devices-table tbody tr:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: -2px;
}

.devices-table tbody tr.device-row-selected {
  background: rgba(49, 215, 255, 0.12);
  box-shadow: inset 4px 0 0 var(--cyan);
}

.device-location {
  display: block;
  min-width: 130px;
  line-height: 1.25;
}

.device-location-main,
.device-location-detail {
  display: block;
}

.device-location-main {
  font-size: 13px;
  font-weight: 900;
}

.device-location-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.location-gps .device-location-main { color: var(--cyan); }
.location-fixed .device-location-main { color: var(--green); }
.location-warning .device-location-main { color: var(--yellow); }
.location-unavailable .device-location-main,
.location-unknown .device-location-main { color: var(--muted); }

.map-popup {
  display: grid;
  gap: 7px;
  min-width: 270px;
  max-width: 310px;
  line-height: 1.3;
}

.map-popup-compact {
  min-width: 230px;
  max-width: 270px;
}

.map-popup-title {
  margin-bottom: 5px;
  padding-right: 18px;
  color: var(--cyan);
  font-weight: 900;
  font-size: 15px;
}

.map-popup-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) minmax(0, 1.2fr);
  column-gap: 14px;
  align-items: start;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(49, 215, 255, 0.10);
}

.map-popup-row span {
  color: var(--muted);
  white-space: nowrap;
}

.map-popup-row strong {
  min-width: 0;
  color: var(--text);
  text-align: right;
  overflow-wrap: anywhere;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 900;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.status-online {
  color: var(--green);
}

.status-offline {
  color: var(--red);
}

.rssi-good {
  color: var(--green);
  font-weight: 900;
}

.rssi-mid {
  color: var(--yellow);
  font-weight: 900;
}

.rssi-bad {
  color: var(--red);
  font-weight: 900;
}

.map-section {
  display: grid;
  gap: 18px;
  margin-top: 30px;
}

.map-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
}

.map-section-head > div:first-child {
  min-width: 0;
}

.map-section-head h2 {
  margin-bottom: 8px;
}

.map-toolbar,
.map-layer-switch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.map-toolbar {
  justify-content: flex-end;
}

.map-layer-switch {
  padding: 4px;
  border: 1px solid rgba(49, 215, 255, 0.16);
  border-radius: 14px;
  background: rgba(5, 17, 31, 0.52);
}

.map-tool-button {
  min-height: 38px;
  margin: 0;
  padding: 9px 13px;
  border: 1px solid rgba(49, 215, 255, 0.22);
  border-radius: 11px;
  background: rgba(49, 215, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.map-tool-button:hover:not(:disabled),
.map-tool-button.active {
  border-color: rgba(49, 215, 255, 0.58);
  background: rgba(49, 215, 255, 0.16);
  color: var(--cyan);
}

.map-tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.map-layer-switch .map-tool-button {
  border-color: transparent;
  background: transparent;
}

.map-layer-switch .map-tool-button.active {
  border-color: rgba(49, 215, 255, 0.30);
  background: rgba(49, 215, 255, 0.14);
}

.map-workspace {
  display: grid;
  grid-template-columns: minmax(285px, 0.32fr) minmax(0, 0.68fr);
  gap: 18px;
  align-items: stretch;
  min-height: 590px;
}

.map-device-panel,
.map-canvas-wrap {
  min-width: 0;
  border: 1px solid rgba(49, 215, 255, 0.18);
  border-radius: 22px;
  background: rgba(5, 17, 31, 0.62);
}

.map-device-panel {
  padding: 22px;
}

.map-device-empty {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100%;
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

.map-device-empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 14px;
  border: 1px solid rgba(49, 215, 255, 0.24);
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(49, 215, 255, 0.08);
  font-size: 26px;
}

.map-device-empty strong {
  color: var(--text);
  font-size: 17px;
}

.map-device-empty p {
  max-width: 280px;
  margin: 8px 0 0;
  font-size: 13px;
}

.map-device-header {
  display: grid;
  gap: 14px;
  padding-bottom: 17px;
  border-bottom: 1px solid rgba(49, 215, 255, 0.14);
}

.map-device-header h3 {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 22px;
}

.map-device-header .status-dot {
  width: fit-content;
  font-size: 12px;
}

.map-device-section {
  padding-top: 18px;
}

.map-device-section + .map-device-section {
  margin-top: 16px;
  border-top: 1px solid rgba(49, 215, 255, 0.10);
}

.map-device-section h4 {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.map-device-detail-list {
  display: grid;
  gap: 0;
}

.map-detail-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid rgba(49, 215, 255, 0.08);
}

.map-detail-row:last-child {
  border-bottom: 0;
}

.map-detail-row span {
  color: var(--muted);
  font-size: 12px;
}

.map-detail-row strong {
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.map-canvas-wrap {
  position: relative;
  overflow: hidden;
  min-height: 590px;
}

.devices-map {
  width: 100%;
  min-height: 590px;
  height: 100%;
  background: rgba(255, 255, 255, 0.04);
}

.map-workspace:fullscreen,
.map-workspace.map-expanded-fallback {
  width: 100%;
  min-height: 100vh;
  padding: 18px;
  background: #03101c;
}

.map-workspace:fullscreen .map-canvas-wrap,
.map-workspace:fullscreen .devices-map,
.map-workspace.map-expanded-fallback .map-canvas-wrap,
.map-workspace.map-expanded-fallback .devices-map {
  min-height: calc(100vh - 36px);
}

.map-workspace.map-expanded-fallback {
  position: fixed;
  z-index: 9998;
  inset: 0;
}

.leaflet-container {
  color: #06111f;
  font-family: Inter, system-ui, "Segoe UI", sans-serif;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #06111f;
  color: var(--text);
  border: 1px solid rgba(49, 215, 255, 0.24);
}

.leaflet-popup-content {
  color: var(--text);
}

.alerts-table input[type="number"],
.alerts-table input[type="text"] {
  margin: 0;
  min-width: 120px;
}

.alerts-table input[type="checkbox"] {
  width: auto;
  transform: scale(1.2);
}

.footer-note {
  margin: 30px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 1050px) {
  .portal-grid,
  .map-workspace {
    grid-template-columns: 1fr;
  }

  .map-device-panel {
    min-height: auto;
  }

  .kpi-grid,
  .gps-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .gps-card-primary {
    grid-column: span 3;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .map-section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .map-workspace,
  .map-canvas-wrap,
  .devices-map {
    min-height: 470px;
  }

  .map-device-panel {
    min-height: 0;
  }

  .portal-header,
  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .tabs {
    overflow-x: auto;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel,
  .environment-status,
  .charts-card,
  .alerts-panel,
  .devices-panel {
    padding: 22px;
  }
}

@media (max-width: 520px) {
  .map-toolbar,
  .map-layer-switch {
    width: 100%;
  }

  .map-tool-button {
    flex: 1 1 auto;
  }

  .map-workspace,
  .map-canvas-wrap,
  .devices-map {
    min-height: 410px;
  }

  .kpi-grid,
  .gps-grid {
    grid-template-columns: 1fr;
  }

  .gps-card-primary {
    grid-column: span 1;
  }
}


.alert-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.alert-settings-grid label {
  margin-top: 0;
}

.alert-settings-grid small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 14px 16px;
  border: 1px solid rgba(49, 215, 255, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  transform: scale(1.15);
}

.check-row span {
  color: var(--text);
  font-weight: 800;
}

@media (max-width: 760px) {
  .alert-settings-grid {
    grid-template-columns: 1fr;
  }
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 210px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed rgba(49, 215, 255, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.025);
}

/* Telemetry Portal v2: grupos dinámicos y visualización de viento */
.telemetry-group[hidden] {
  display: none !important;
}

.wind-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.wind-panel {
  min-width: 0;
  padding: 22px;
  border: 1px solid rgba(49, 215, 255, 0.22);
  border-radius: 26px;
  background: rgba(5, 17, 31, 0.72);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.wind-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.wind-panel-head span,
.wind-metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.wind-panel-head strong {
  display: block;
  margin-top: 7px;
  color: var(--cyan);
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1;
}

.wind-panel-head strong small {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.wind-panel-head em {
  padding: 7px 11px;
  border: 1px solid rgba(49, 215, 255, 0.25);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(49, 215, 255, 0.08);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.wind-gauge {
  display: block;
  width: min(100%, 330px);
  margin: 14px auto 0;
}

.wind-gauge-track,
.wind-gauge-value {
  fill: none;
  stroke-width: 15;
  stroke-linecap: round;
}

.wind-gauge-track {
  stroke: rgba(239, 248, 255, 0.10);
}

.wind-gauge-value {
  stroke: var(--cyan);
  stroke-dasharray: 100;
  transition: stroke-dashoffset 0.5s ease;
}

.wind-needle {
  stroke: var(--text);
  stroke-width: 4;
  stroke-linecap: round;
}

.wind-center {
  fill: var(--cyan);
}

.wind-label {
  fill: var(--muted);
  font-size: 12px;
}

.wind-compass {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 14px auto 4px;
}

.wind-compass-ring {
  position: absolute;
  inset: 24px;
  border: 2px solid rgba(49, 215, 255, 0.22);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(49, 215, 255, 0.14) 50%, transparent 50.5%),
    linear-gradient(0deg, transparent 49.5%, rgba(49, 215, 255, 0.14) 50%, transparent 50.5%),
    rgba(5, 17, 31, 0.28);
  backdrop-filter: blur(8px);
}

.wind-compass > span {
  position: absolute;
  z-index: 3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.wind-compass .wc-n { top: 0; left: 50%; transform: translateX(-50%); color: var(--cyan); }
.wind-compass .wc-ne { top: 24px; right: 24px; }
.wind-compass .wc-e { top: 50%; right: 0; transform: translateY(-50%); }
.wind-compass .wc-se { right: 20px; bottom: 24px; }
.wind-compass .wc-s { bottom: 0; left: 50%; transform: translateX(-50%); }
.wind-compass .wc-so { left: 20px; bottom: 24px; }
.wind-compass .wc-o { top: 50%; left: 0; transform: translateY(-50%); }
.wind-compass .wc-no { top: 24px; left: 20px; }

.wind-direction-arrow {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 82px;
  transform-origin: 50% 100%;
  transition: transform 0.5s ease;
}

.wind-arrow-stem {
  position: absolute;
  left: 2px;
  top: 15px;
  width: 4px;
  height: 67px;
  border-radius: 999px;
  background: var(--cyan);
}

.wind-arrow-head {
  position: absolute;
  left: 50%;
  top: 0;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 18px solid var(--cyan);
}

.wind-compass-center {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translate(-50%, -50%);
  border: 4px solid rgba(5, 17, 31, 0.82);
  border-radius: 50%;
  background: var(--cyan);
}

.wind-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.wind-metrics > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(49, 215, 255, 0.14);
  border-radius: 16px;
  background: rgba(5, 17, 31, 0.46);
  backdrop-filter: blur(8px);
}

.wind-metrics strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 16px;
  overflow-wrap: anywhere;
}

.accent-wind { color: var(--cyan); }
.accent-power { color: var(--yellow); }
.accent-battery { color: var(--green); }

@media (max-width: 760px) {
  .wind-grid {
    grid-template-columns: 1fr;
  }

  .wind-panel {
    padding: 20px;
  }
}


/* Telemetry schema 1: conexión, salud y diagnóstico por sensor */
.environment-status.offline {
  border-color: rgba(158, 184, 204, 0.38);
  background: linear-gradient(135deg, rgba(158, 184, 204, 0.12), rgba(5, 17, 31, 0.96));
}

.environment-status.offline strong {
  color: var(--muted);
}

.environment-status.degraded {
  border-color: rgba(255, 213, 74, 0.38);
  background: linear-gradient(135deg, rgba(255, 213, 74, 0.12), rgba(5, 17, 31, 0.96));
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.kpi-top .kpi-icon {
  margin-bottom: 15px;
}

.sensor-state-badge {
  position: relative;
  z-index: 2;
  padding: 5px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: inherit;
  background: rgba(5, 17, 31, 0.48);
  font-size: 10px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.kpi.state-error,
.wind-panel.state-error {
  color: var(--red);
  border-color: rgba(255, 95, 109, 0.62);
  background: linear-gradient(135deg, rgba(255, 95, 109, 0.14), rgba(5, 17, 31, 0.96));
}

.kpi.state-error strong,
.wind-panel.state-error .wind-panel-head strong,
.wind-panel.state-error .wind-status-message strong {
  color: var(--red);
}

.kpi.state-no_data,
.wind-panel.state-no_data,
.kpi.state-unknown,
.wind-panel.state-unknown {
  color: var(--yellow);
  border-color: rgba(255, 213, 74, 0.38);
  background: linear-gradient(135deg, rgba(255, 213, 74, 0.09), rgba(5, 17, 31, 0.96));
}

.kpi.state-stale,
.wind-panel.state-stale {
  color: var(--yellow);
  border-color: rgba(255, 213, 74, 0.45);
  filter: saturate(0.65);
  opacity: 0.82;
}

.kpi.state-offline,
.wind-panel.state-offline {
  color: var(--muted);
  border-color: rgba(158, 184, 204, 0.30);
  filter: grayscale(0.78);
  opacity: 0.70;
}

.sensor-state-detail {
  min-height: 34px;
}

.state-error .sensor-state-detail {
  color: #ff9da5;
  font-weight: 800;
}

.state-no_data .sensor-state-detail,
.state-unknown .sensor-state-detail,
.state-stale .sensor-state-detail {
  color: #ffe28a;
  font-weight: 700;
}

.wind-disabled {
  opacity: 0.42;
  filter: grayscale(1);
}

.wind-error-symbol {
  fill: currentColor;
  color: inherit;
  font-size: 46px;
  font-weight: 950;
}

.wind-compass-error {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  color: inherit;
  font-size: 48px;
  font-weight: 950;
}

.wind-status-message {
  display: grid;
  gap: 6px;
  min-height: 68px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid currentColor;
  border-radius: 16px;
  background: rgba(5, 17, 31, 0.48);
}

.wind-status-message strong {
  color: inherit;
  font-size: 17px;
}

.wind-status-message span {
  color: var(--muted);
  font-size: 12px;
}

.status-warning,
.status-stale,
.status-degraded {
  color: var(--yellow);
}

.status-critical,
.status-error {
  color: var(--red);
}

.status-offline {
  color: var(--muted);
}


/* Mapa orientativo de dispersión por viento y material particulado */
.wind-dispersion-section {
  margin-top: 20px;
  padding: 20px;
  border: 1px solid rgba(49, 215, 255, 0.24);
  border-radius: 26px;
  background: rgba(5, 17, 31, 0.78);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

.wind-dispersion-section[hidden] {
  display: none !important;
}

.wind-dispersion-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 16px;
}

.wind-dispersion-head h3 {
  margin: 0;
  font-size: clamp(20px, 2.4vw, 27px);
}

.wind-dispersion-head p {
  max-width: 720px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.wind-map-layer-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}

.wind-map-tool {
  padding: 8px 11px;
  border: 1px solid rgba(49, 215, 255, 0.25);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(5, 17, 31, 0.72);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.wind-map-tool:hover,
.wind-map-tool.active {
  color: var(--cyan);
  border-color: rgba(49, 215, 255, 0.58);
  background: rgba(49, 215, 255, 0.10);
}

.wind-dispersion-layout {
  display: grid;
  grid-template-columns: minmax(245px, 0.34fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 450px;
}

.wind-dispersion-sidebar,
.wind-dispersion-map-wrap {
  min-width: 0;
  border: 1px solid rgba(49, 215, 255, 0.16);
  border-radius: 20px;
  background: rgba(5, 17, 31, 0.55);
}

.wind-dispersion-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.wind-dispersion-kicker {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.wind-pm-list {
  display: grid;
  gap: 8px;
}

.wind-pm-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) 58px minmax(70px, auto);
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid rgba(49, 215, 255, 0.16);
  border-radius: 14px;
  background: rgba(9, 26, 44, 0.70);
}

.wind-pm-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.wind-pm-name i {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px currentColor;
}

.wind-pm-row.level-moderate .wind-pm-name i {
  background: var(--yellow);
}

.wind-pm-row.level-elevated .wind-pm-name i {
  background: var(--orange);
}

.wind-pm-row.level-high .wind-pm-name i {
  background: var(--red);
}

.wind-pm-row strong {
  color: var(--text);
  font-size: 18px;
}

.wind-pm-row em {
  color: var(--green);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.wind-pm-row.level-moderate em {
  color: var(--yellow);
}

.wind-pm-row.level-elevated em {
  color: var(--orange);
}

.wind-pm-row.level-high em {
  color: var(--red);
}

.wind-pm-empty {
  padding: 14px;
  border: 1px dashed rgba(158, 184, 204, 0.26);
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.wind-dispersion-summary {
  padding: 14px;
  border: 1px solid rgba(49, 215, 255, 0.16);
  border-radius: 16px;
  background: rgba(49, 215, 255, 0.05);
}

.wind-dispersion-summary > span,
.wind-dispersion-summary small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.wind-dispersion-summary strong {
  display: block;
  margin-top: 5px;
  color: var(--cyan);
  font-size: 16px;
}

.wind-dispersion-summary p {
  margin: 10px 0 8px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.wind-dispersion-note {
  margin-top: auto;
  padding: 13px;
  border-left: 3px solid var(--yellow);
  border-radius: 10px;
  background: rgba(255, 213, 74, 0.06);
}

.wind-dispersion-note strong,
.wind-dispersion-note span {
  display: block;
}

.wind-dispersion-note strong {
  color: var(--yellow);
  font-size: 12px;
}

.wind-dispersion-note span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.wind-dispersion-map-wrap {
  position: relative;
  overflow: hidden;
}

.wind-dispersion-map {
  width: 100%;
  height: 100%;
  min-height: 450px;
  background: #07131f;
}

.wind-map-legend {
  position: absolute;
  z-index: 500;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px 13px;
  max-width: calc(100% - 24px);
  padding: 8px 10px;
  border: 1px solid rgba(49, 215, 255, 0.18);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(5, 17, 31, 0.84);
  backdrop-filter: blur(10px);
  font-size: 10px;
  pointer-events: none;
}

.wind-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.wind-map-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
}

.wind-legend-node {
  border: 3px solid var(--cyan);
  border-radius: 50%;
  background: var(--text);
}

.wind-legend-arrow {
  height: 3px !important;
  border-radius: 999px;
  background: var(--cyan);
}

.wind-legend-plume {
  border-radius: 50%;
  background: rgba(68, 242, 161, 0.52);
  box-shadow: 8px 0 0 rgba(255, 213, 74, 0.34);
}

.wind-node-icon-wrap,
.wind-plume-arrow-wrap {
  background: transparent;
  border: 0;
}

.wind-node-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid rgba(239, 248, 255, 0.94);
  border-radius: 50%;
  background: rgba(49, 215, 255, 0.28);
  box-shadow: 0 0 0 8px rgba(49, 215, 255, 0.10), 0 0 24px rgba(49, 215, 255, 0.75);
}

.wind-node-icon i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
}

.wind-plume-arrow {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--cyan);
  font-size: 28px;
  line-height: 1;
  text-shadow: 0 0 16px rgba(49, 215, 255, 0.86);
}

.wind-dispersion-popup {
  min-width: 150px;
}

.wind-dispersion-popup strong,
.wind-dispersion-popup span,
.wind-dispersion-popup small {
  display: block;
}

.wind-dispersion-popup strong {
  color: var(--cyan);
}

.wind-dispersion-popup span {
  margin-top: 4px;
  color: var(--text);
}

.wind-dispersion-popup small {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 900px) {
  .wind-dispersion-head,
  .wind-dispersion-layout {
    grid-template-columns: 1fr;
  }

  .wind-dispersion-head {
    flex-direction: column;
  }

  .wind-map-layer-switch {
    justify-content: flex-start;
  }

  .wind-dispersion-layout {
    display: grid;
  }

  .wind-dispersion-map,
  .wind-dispersion-layout {
    min-height: 390px;
  }
}

@media (max-width: 560px) {
  .wind-dispersion-section {
    padding: 14px;
    border-radius: 20px;
  }

  .wind-map-tool {
    flex: 1 1 auto;
  }

  .wind-pm-row {
    grid-template-columns: minmax(75px, 1fr) 48px minmax(60px, auto);
  }

  .wind-dispersion-map {
    min-height: 340px;
  }

  .wind-map-legend {
    left: 10px;
    right: 10px;
  }
}

/* Retención temporal del último dato válido por sensor */
.kpi.state-grace,
.wind-panel.state-grace {
  color: var(--cyan);
  border-color: rgba(49, 215, 255, 0.48);
  background: linear-gradient(135deg, rgba(49, 215, 255, 0.10), rgba(5, 17, 31, 0.96));
}

.kpi.state-grace .sensor-state-detail,
.wind-panel.state-grace .wind-grace-note {
  color: #9feaff;
  font-weight: 700;
}

.kpi.state-warming,
.wind-panel.state-warming {
  color: var(--yellow);
  border-color: rgba(255, 213, 74, 0.38);
  background: linear-gradient(135deg, rgba(255, 213, 74, 0.09), rgba(5, 17, 31, 0.96));
}

.kpi.state-warming .sensor-state-detail,
.wind-panel.state-warming .sensor-state-detail {
  color: #ffe28a;
  font-weight: 700;
}

.wind-grace-note {
  display: block;
  margin: 0 0 12px;
  font-size: 12px;
}


/* =========================================================
   FONDO FOTOGRÁFICO DEL PORTAL
   La imagen permanece fija mientras el contenido se desplaza.
   ========================================================= */

.login-card,
.panel,
.environment-status,
.kpi,
.gps-card,
.charts-card,
.chart-box,
.alerts-panel,
.devices-panel,
.map-device-panel,
.wind-dispersion-sidebar {
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

@media (max-width: 760px) {
  body::before {
    background-position: 42% center;
  }

  body::after {
    background:
      linear-gradient(
        180deg,
        rgba(2, 10, 19, 0.58) 0%,
        rgba(3, 10, 18, 0.72) 100%
      );
  }
}

.chart-controls-extended{display:flex;align-items:flex-end;justify-content:flex-end;gap:10px;flex-wrap:wrap}.chart-controls-extended label{min-width:170px}.chart-controls-extended input,.chart-controls-extended select{width:100%}.chart-controls-extended button{white-space:nowrap}@media(max-width:760px){.chart-controls-extended{justify-content:stretch}.chart-controls-extended label,.chart-controls-extended button{width:100%}}


/* Histórico V1.1: período superior y fechas alineadas debajo */
.chart-controls-extended {
  display: grid;
  grid-template-columns: minmax(320px, 440px);
  gap: 12px;
  width: min(100%, 620px);
  align-items: stretch;
  justify-content: end;
}

.chart-controls-extended label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.chart-controls-extended label > span {
  display: block;
}

.chart-controls-extended input,
.chart-controls-extended select {
  width: 100%;
  min-width: 0;
}

.history-period-control {
  width: 100%;
}

.history-date-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.history-refresh-row {
  display: flex;
  justify-content: flex-end;
}

.history-refresh-row button {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .chart-controls-extended {
    width: 100%;
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .history-date-row {
    grid-template-columns: 1fr;
  }

  .history-refresh-row {
    justify-content: stretch;
  }

  .history-refresh-row button {
    width: 100%;
  }
}

/* Alinear título de Gráficas con la parte superior de los controles */
.charts-header {
  align-items: flex-start;
}

.charts-header > div:first-child {
  align-self: flex-start;
  padding-top: 2px;

}
