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

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --region-fill: rgba(59, 130, 246, 0.06);
  --region-stroke: rgba(147, 197, 253, 0.45);
  --region-hover: rgba(59, 130, 246, 0.18);

  --status-unknown: #94a3b8;
  --status-ok: #22c55e;
  --status-temp-rare: #eab308;
  --status-temp-frequent: #f97316;
  --status-permanent: #ef4444;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

.header__brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.header__brand p {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.header__controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search {
  position: relative;
}

.search input {
  width: min(280px, 70vw);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.search-results li button {
  display: block;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 0.85rem;
}

.search-results li button:hover,
.search-results li button:focus {
  background: rgba(59, 130, 246, 0.15);
}

.search-results .meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.zoom-info {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #0a1628;
}

.legend {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 1000;
  padding: 0.75rem 1rem;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  font-size: 0.8rem;
  max-width: 280px;
}

.legend h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.legend ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.legend__heat {
  margin: 0.5rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.legend__heat-bar {
  display: block;
  height: 8px;
  margin-top: 0.35rem;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    #64748b,
    #22c55e,
    #eab308,
    #f97316,
    #ef4444
  );
}

.legend__report-btn {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.12);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}

.legend__report-btn:hover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.2);
}

.legend__note {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.legend__note a {
  color: var(--accent);
  text-decoration: none;
}

.legend__note a:hover {
  text-decoration: underline;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.dot--unknown { background: var(--status-unknown); }
.dot--ok { background: var(--status-ok); }
.dot--temp-rare { background: var(--status-temp-rare); }
.dot--temp-frequent { background: var(--status-temp-frequent); }
.dot--permanent { background: var(--status-permanent); }

.city-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  min-width: 260px;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.city-popup[hidden] {
  display: none;
}

.city-popup__close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.city-popup h3 {
  margin: 0 2rem 0.75rem 0;
  font-size: 1.05rem;
}

.city-popup dl {
  margin: 0;
  display: grid;
  gap: 0.4rem;
}

.city-popup dl > div {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.5rem;
}

.city-popup dt {
  color: var(--muted);
  font-size: 0.8rem;
}

.city-popup dd {
  margin: 0;
  font-size: 0.85rem;
}

.city-popup__comment-row dd {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  line-height: 1.35;
}

.popup-admin textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 2.5rem;
}

.popup-admin textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-attribution {
  background: rgba(15, 20, 25, 0.8) !important;
  color: var(--muted) !important;
  font-size: 0.65rem !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.legend-toggle {
  display: none;
}

/* ── Mobile ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .header {
    padding: 0.55rem 0.75rem;
    gap: 0.55rem;
    align-items: stretch;
  }

  .header__brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .header__brand h1 {
    font-size: 0.95rem;
    line-height: 1.2;
  }

  .header__brand p {
    display: block;
    font-size: 0.68rem;
    line-height: 1.3;
    margin-top: 0.2rem;
  }

  .header__controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .search {
    flex: 1 1 100%;
    order: 1;
  }

  .search input {
    width: 100%;
    font-size: 16px;
    padding: 0.6rem 0.75rem;
  }

  .zoom-info {
    order: 2;
    font-size: 0.75rem;
    flex: 1 1 auto;
  }

  .admin-reports-toggle,
  .admin-toggle {
    order: 3;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.05rem;
  }

  .legend-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    z-index: 1002;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(26, 35, 50, 0.95);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
  }

  .legend {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    max-height: min(72vh, 520px);
    overflow-y: auto;
    transform: translateY(110%);
    transition: transform 0.25s ease;
    pointer-events: none;
  }

  .legend.legend--open {
    transform: translateY(0);
    pointer-events: auto;
  }

  .legend h2 {
    font-size: 0.9rem;
  }

  .legend li {
    font-size: 0.78rem;
  }

  .legend__note {
    font-size: 0.7rem;
  }

  .city-popup,
  .region-popup {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    min-width: 0;
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: min(75vh, 480px);
    overflow-y: auto;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .city-popup dl > div {
    grid-template-columns: 6.5rem 1fr;
    gap: 0.35rem 0.5rem;
  }

  .report-dialog,
  .admin-login,
  .admin-reports {
    align-items: flex-end;
    padding: 0;
  }

  .report-dialog__panel,
  .admin-login__panel,
  .admin-reports__panel {
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  .admin-reports__meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .admin-reports__meta span {
    white-space: normal;
  }

  .admin-reports__actions button {
    flex: 1 1 auto;
    min-height: 2.5rem;
  }

  .leaflet-top.leaflet-left {
    top: auto;
    bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
    left: 0.5rem;
    right: auto;
  }

  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 1.1rem !important;
  }

  .leaflet-control-attribution {
    max-width: calc(100vw - 7rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 380px) {
  .header__brand p {
    display: none;
  }

  .legend-toggle {
    right: 0.5rem;
    bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    padding: 0.5rem 0.7rem;
    font-size: 0.75rem;
  }
}

@media (min-width: 769px) {
  .legend-toggle {
    display: none !important;
  }
}

.admin-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.admin-toggle:hover {
  border-color: var(--accent);
}

.admin-toggle--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.admin-login {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 1rem;
}

.admin-login[hidden] {
  display: none;
}

.admin-login__panel {
  position: relative;
  width: min(360px, 100%);
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.admin-login__close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.admin-login h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.admin-login p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.admin-login form {
  display: grid;
  gap: 0.6rem;
}

.admin-login label {
  font-size: 0.8rem;
  color: var(--muted);
}

.admin-login input {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.admin-login button[type="submit"] {
  margin-top: 0.25rem;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.admin-login__error,
.popup-admin__error {
  margin: 0;
  color: #f87171;
  font-size: 0.8rem;
}

.popup-admin__success {
  margin: 0;
  color: #4ade80;
  font-size: 0.8rem;
}

.popup-admin {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.6rem;
}

.popup-admin[hidden] {
  display: none;
}

.popup-admin label {
  font-size: 0.8rem;
  color: var(--muted);
}

.popup-admin select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.popup-admin__save {
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.popup-admin__save:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.region-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  width: min(320px, 92vw);
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.region-popup[hidden] {
  display: none;
}

.region-popup__close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.region-popup h3 {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.05rem;
}

.region-popup__intensity {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.region-popup__stats {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.region-popup__stats li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.region-popup__total {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.report-dialog {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 1rem;
}

.report-dialog[hidden] {
  display: none;
}

.report-dialog__panel {
  position: relative;
  width: min(420px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.report-dialog__close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.report-dialog h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.report-dialog p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.report-dialog form {
  display: grid;
  gap: 0.55rem;
}

.report-dialog label {
  font-size: 0.8rem;
  color: var(--muted);
}

.report-dialog input,
.report-dialog select,
.report-dialog textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.report-dialog button[type="submit"] {
  margin-top: 0.25rem;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.report-city-search {
  position: relative;
}

.report-dialog__error {
  margin: 0;
  color: #f87171;
  font-size: 0.8rem;
}

.report-dialog__success {
  margin: 0;
  color: #4ade80;
  font-size: 0.8rem;
}

.report-success-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem 2.5rem;
  min-height: 200px;
}

.report-success-screen[hidden] {
  display: none;
}

.report-success-screen__icon {
  margin: 0 0 1rem;
  width: 3.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.report-success-screen__text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text);
}

.admin-reports-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.admin-reports-toggle:hover {
  border-color: var(--accent);
}

.admin-reports {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 1rem;
}

.admin-reports[hidden] {
  display: none;
}

.admin-reports__panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.admin-reports__close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.admin-reports h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.admin-reports__count {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.admin-reports__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.75rem;
}

.admin-reports__item {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.35);
}

.admin-reports__item--done {
  opacity: 0.65;
}

.admin-reports__meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.admin-reports__meta span {
  color: var(--muted);
  white-space: nowrap;
}

.admin-reports__status {
  margin-top: 0.35rem;
  color: var(--accent);
  font-size: 0.8rem;
}

.admin-reports__message {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
  line-height: 1.4;
}

.admin-reports__contact {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-reports__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.admin-reports__actions button {
  padding: 0.4rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  cursor: pointer;
}

.admin-reports__dismiss {
  background: transparent !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}

.admin-reports__empty {
  color: var(--muted);
  font-size: 0.85rem;
}
