/* ── Telegram theme variables (with browser fallbacks) ────────────────── */
:root {
  --tg-bg:           var(--tg-theme-bg-color,           #ffffff);
  --tg-text:         var(--tg-theme-text-color,         #1c1c1e);
  --tg-hint:         var(--tg-theme-hint-color,         #8e8e93);
  --tg-link:         var(--tg-theme-link-color,         #2481cc);
  --tg-button:       var(--tg-theme-button-color,       #2481cc);
  --tg-button-text:  var(--tg-theme-button-text-color,  #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
}

/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Full-screen map ──────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* Keep Leaflet attribution readable without blocking layout */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255,255,255,0.75) !important;
}

/* ── Generic overlay button ───────────────────────────────────────────── */
.ctrl-btn {
  background: var(--tg-bg);
  color: var(--tg-text);
  border: none;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.20);
  white-space: nowrap;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:active { opacity: .65; }

/* ── WMS layer control (top-left, below zoom buttons) ────────────────── */
.layer-ctrl {
  position: fixed;
  top: 80px;
  left: 10px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.layer-ctrl-btn {
  background: var(--tg-bg);
  color: var(--tg-text);
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.20);
  -webkit-tap-highlight-color: transparent;
}
.layer-ctrl-btn:active { opacity: .65; }
.layer-ctrl-panel {
  background: var(--tg-bg);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.20);
  padding: 10px 14px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 140px;
}
.layer-ctrl-panel.hidden { display: none; }
.layer-ctrl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--tg-text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.layer-ctrl-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--tg-button);
}

/* ── Polygon toggle (top-center) ──────────────────────────────────────── */
#btn-toggle {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
}
#btn-toggle.hidden-alert {
  opacity: .55;
}

/* ── Bottom sheet ─────────────────────────────────────────────────────── */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--tg-bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -3px 18px rgba(0,0,0,0.18);
  /* Collapsed: show only the peek strip (handle + title row) */
  --peek: 72px;
  transform: translateY(calc(100% - var(--peek)));
  transition: transform .35s cubic-bezier(.25,.8,.25,1);
  max-height: 62vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-sheet.expanded {
  transform: translateY(0);
}

/* Drag handle pill */
.sheet-handle-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 20px 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.handle-pill {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-hint);
  opacity: .5;
  margin-bottom: 10px;
}

/* Peek strip: title + date */
.sheet-peek {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 20px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.sheet-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--tg-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-date {
  font-size: 12px;
  color: var(--tg-hint);
  flex-shrink: 0;
}

/* Expanded body */
.sheet-body {
  padding: 0 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(62vh - 72px);
}
.sheet-description {
  font-size: 14px;
  line-height: 1.65;
  color: var(--tg-text);
  white-space: pre-wrap;
}

/* Legend */
.legend {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--tg-secondary-bg);
}
.legend-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--tg-hint);
  margin-bottom: 12px;
}
.legend-items { display: flex; flex-direction: column; gap: 12px; }
.legend-item  { display: flex; gap: 10px; align-items: flex-start; }
.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,.15);
  margin-top: 2px;
}
.legend-text  { display: flex; flex-direction: column; gap: 3px; }
.legend-label { font-size: 13px; font-weight: 700; color: var(--tg-text); }
.legend-desc  { font-size: 13px; line-height: 1.55; color: var(--tg-text); }

/* Empty state */
.no-alert {
  padding: 20px 0;
  font-size: 14px;
  color: var(--tg-hint);
  text-align: center;
}
