.kpai-bleed {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  clear: both;
}

.kpai-bleed--breakout {
  width: 100vw;
  max-width: 100%;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}

.kpai-bleed--center {
  width: 100%;
  max-width: var(--kpai-max-width, 1400px);
  margin-left: auto;
  margin-right: auto;
}

.kpai-root {
  --kpai-bg: #f4f7fb;
  --kpai-card: #fff;
  --kpai-border: #dbe3ef;
  --kpai-text: #1e293b;
  --kpai-muted: #64748b;
  --kpai-accent: #0369a1;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--kpai-text);
  background: var(--kpai-bg);
  border: 1px solid var(--kpai-border);
  border-radius: 14px;
  overflow: hidden;
  margin: 1rem 0;
  min-height: var(--kpai-height, 720px);
  height: var(--kpai-height, 720px);
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  box-sizing: border-box;
}

.kpai-root *,
.kpai-root *::before,
.kpai-root *::after {
  box-sizing: border-box;
}

.kpai-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem;
  background: var(--kpai-card);
  border-right: 1px solid var(--kpai-border);
  overflow: auto;
  min-height: 0;
}

.kpai-title {
  margin: 0;
  font-size: 1.1rem;
}

.kpai-subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--kpai-muted);
  line-height: 1.4;
}

.kpai-city-badge {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.55rem;
  padding: 0.65rem;
  border: 2px solid var(--kpai-color, #7cb342);
  border-radius: 10px;
  background: color-mix(in srgb, var(--kpai-color) 12%, #fff);
}

.kpai-city-aqi {
  grid-row: span 2;
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--kpai-color);
  line-height: 1;
}

.kpai-city-label {
  font-weight: 700;
  font-size: 0.95rem;
}

.kpai-city-sub {
  font-size: 0.72rem;
  color: var(--kpai-muted);
}

.kpai-weather h3,
.kpai-station-list h3,
.kpai-legend h3,
.kpai-source h3 {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
}

.kpai-weather-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.3rem;
}

.kpai-weather-grid div {
  background: var(--kpai-bg);
  border: 1px solid var(--kpai-border);
  border-radius: 8px;
  padding: 0.4rem;
  text-align: center;
  font-size: 0.72rem;
}

.kpai-weather-grid strong {
  display: block;
  font-size: 0.95rem;
}

.kpai-station-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.kpai-st-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 0.4rem;
  align-items: center;
  width: 100%;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--kpai-border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.kpai-st-row:hover {
  border-color: var(--kpai-accent);
}

.kpai-st-dot {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #1e293b;
  font-weight: 800;
  font-size: 0.78rem;
  border: 2px solid rgba(0, 0, 0, 0.08);
}

.kpai-st-name {
  font-size: 0.8rem;
  font-weight: 600;
}

.kpai-st-lbl {
  font-size: 0.68rem;
  color: var(--kpai-muted);
}

.kpai-legend-row {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.3rem;
  font-size: 0.74rem;
}

.kpai-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.kpai-legend-row small {
  color: var(--kpai-muted);
}

.kpai-source {
  font-size: 0.74rem;
  color: var(--kpai-muted);
  line-height: 1.4;
}

.kpai-source p {
  margin: 0 0 0.3rem;
}

.kpai-disclaimer {
  padding: 0.45rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  color: #c2410c;
  font-size: 0.68rem !important;
}

.kpai-btn {
  width: 100%;
  padding: 0.5rem;
  border: none;
  border-radius: 8px;
  background: var(--kpai-accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.kpai-map-wrap {
  position: relative;
  min-height: 0;
}

.kpai-map-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  gap: 0.35rem;
}

.kpai-map-toolbar button {
  border: 1px solid var(--kpai-border);
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.kpai-map-toolbar button.is-active {
  background: var(--kpai-accent);
  color: #fff;
  border-color: var(--kpai-accent);
}

.kpai-citizen-note,
.kpai-empty-note {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--kpai-muted);
  line-height: 1.4;
}

.kpai-popup-note {
  margin: 0.35rem 0 0;
  font-size: 0.68rem;
  color: var(--kpai-muted);
  font-style: italic;
}

.kpai-map {
  width: 100%;
  height: 100%;
  min-height: var(--kpai-height, 720px);
  background: #e8eef5;
}

/* Station pin — WAQI стил */
.kpai-pin-wrap {
  background: transparent !important;
  border: none !important;
}

.kpai-pin {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
  pointer-events: none;
}

.kpai-pin-bubble {
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 17px;
  background: var(--kpai-color, #7cb342);
  color: #1e293b;
  font-weight: 800;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.kpai-pin-label {
  margin-top: 2px;
  max-width: 72px;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  color: #1e293b;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 1px 1px 2px rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpai-pin-tail {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--kpai-color, #7cb342);
  margin-top: -1px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

/* Граждански сензори — Sensor.Community */
.kpai-dot-wrap {
  background: transparent !important;
  border: none !important;
}

.kpai-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--kpai-color, #7cb342);
  color: #1e293b;
  font-weight: 800;
  font-size: 0.62rem;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.kpai-popup h4 {
  margin: 0 0 0.25rem;
  font-size: 0.92rem;
}

.kpai-popup-aqi {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
}

.kpai-popup-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  line-height: 1.45;
}

.kpai-popup-time {
  margin: 0.4rem 0 0;
  font-size: 0.7rem;
  color: var(--kpai-muted);
}

.kpai-loading,
.kpai-error,
.kpai-setup {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: var(--kpai-height, 720px);
  padding: 2rem;
  text-align: center;
}

.kpai-setup {
  place-items: start center;
  text-align: left;
  max-width: 520px;
  margin: 0 auto;
}

.kpai-setup-note {
  font-size: 0.85rem;
  color: var(--kpai-muted);
}

.kpai-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--kpai-border);
  border-top-color: var(--kpai-accent);
  border-radius: 50%;
  animation: kpai-spin 0.8s linear infinite;
}

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

@media (max-width: 960px) {
  .kpai-root {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr);
    height: auto;
    min-height: var(--kpai-height, 720px);
  }

  .kpai-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--kpai-border);
    max-height: 42vh;
  }

  .kpai-map {
    min-height: 420px;
    height: 420px;
  }
}
