/* ============================================================================
   PORTAL OBYWATELA — CLEAN REBUILD
   Zastepuje geoportal.css + inline <style>
   ============================================================================ */

:root {
  --blue: #4F6CE0;
  --blue-hover: #3E5BC4;
  --blue-bg: #F5F7FF;
  --text: #1A1E2E;
  --text-muted: #4A5578;
  --text-dim: #7A8BB5;
  --border: #E2E6F0;
  --border-light: #F0F2F8;
  --bg: #FAFBFE;
  --white: #FFFFFF;
  --header-h: 56px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============================================================================
   LAYOUT — header na górze, mapa pełny ekran pod nim
   Sidebar to overlay (position:fixed), nie zajmuje miejsca w layoucie
   ============================================================================ */

.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  width: 100vw;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
  grid-row: 1;
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 20;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue) 0%, rgba(79,108,224,0.15) 60%, transparent 100%);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-branding {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-branding img {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.header-branding .divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 640px;
  margin: 0 auto;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

/* ============================================================================
   SEARCH BOX (w headerze)
   ============================================================================ */

.search-box {
  position: relative;
  width: 100%;
  max-width: 520px;
}

.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 40px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  font-size: 14px;
  color: var(--text);
  transition: all 150ms ease-out;
}

.search-box input::placeholder { color: var(--text-dim); }

.search-box input:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(79,108,224,0.12);
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-dim);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 420px;
  overflow-y: auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 120ms;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--blue-bg); }
.result-name { font-size: 13px; font-weight: 600; color: var(--text); }
.result-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ============================================================================
   PORTAL ACTION BUTTONS (header right)
   ============================================================================ */

.portal-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease-out;
  white-space: nowrap;
  font-family: inherit;
}

.portal-action-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.portal-action-btn.primary {
  background: linear-gradient(135deg, #1a4b8c, #2d6cc0);
  color: var(--white);
  border: none;
}

.portal-action-btn.primary:hover {
  background: linear-gradient(135deg, #163f79, #265fa8);
  color: var(--white);
}

.portal-action-icon { font-size: 15px; line-height: 1; }

/* Logged-in user pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.user-pill-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a4b8c, #2d6cc0);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.user-pill-name { font-size: 12.5px; font-weight: 600; color: var(--text); }

.user-pill-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
}

.user-pill-logout:hover { background: var(--blue-bg); color: var(--blue); }

/* ============================================================================
   MAP CONTAINER
   ============================================================================ */

.map-container {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  overflow: hidden;
}

.map-container .ol-viewport { background: #e5e9f0; }

/* OpenLayers zoom controls — top-right, white clean */
.ol-zoom {
  top: 12px !important;
  right: 12px !important;
  left: auto !important;
  background: none !important;
  border: none !important;
  padding: 0 !important;
}

.ol-zoom button {
  width: 36px !important;
  height: 36px !important;
  background: var(--white) !important;
  color: var(--text-muted) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  margin: 0 0 4px 0 !important;
  font-size: 18px !important;
  font-weight: 500 !important;
  box-shadow: var(--shadow-sm) !important;
  transition: all 150ms !important;
  cursor: pointer;
}

.ol-zoom button:hover {
  background: var(--blue-bg) !important;
  color: var(--blue) !important;
  border-color: var(--blue) !important;
}

.ol-full-screen {
  top: 88px !important;
  right: 12px !important;
}

.ol-full-screen button {
  width: 36px !important;
  height: 36px !important;
  background: var(--white) !important;
  color: var(--text-muted) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: all 150ms !important;
  cursor: pointer;
}

.ol-full-screen button:hover { background: var(--blue-bg) !important; color: var(--blue) !important; }

.ol-scale-line {
  background: rgba(255,255,255,0.92) !important;
  backdrop-filter: blur(8px);
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 4px 10px !important;
  bottom: 12px !important;
  left: 12px !important;
  font-size: 11px !important;
}

.ol-scale-line-inner {
  border-color: var(--text-muted) !important;
  color: var(--text-muted) !important;
}

.ol-attribution {
  background: rgba(255,255,255,0.92) !important;
  backdrop-filter: blur(8px);
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  bottom: 12px !important;
  font-size: 10px !important;
}

/* Mouse coordinates — bottom-right */
.mouse-coords {
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 4px 12px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-sm);
  z-index: 15;
}

.mouse-coords span { color: var(--text); font-weight: 600; }

/* ============================================================================
   LAYERS BUTTON (floating, top-left) — klik otwiera sidebar
   ============================================================================ */

.layers-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 40px;
  height: 40px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 150ms ease-out;
  z-index: 25;
}

.layers-btn:hover {
  background: var(--white);
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: var(--shadow-lg);
}

.layers-btn:active { transform: scale(0.96); }

.layers-btn svg { width: 22px; height: 22px; }

/* ============================================================================
   VERTICAL TOOLBAR (floating, left, pod przyciskiem warstw)
   ============================================================================ */

.floating-tools {
  position: absolute;
  top: 60px;
  left: 12px;
  transition: left 220ms ease-out;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow: var(--shadow-md);
  z-index: 20;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Gdy sidebar (warstwy) jest otwarty, przesuń toolbar i przycisk warstw za prawą krawędź sidebara */
body.sidebar-open .floating-tools { left: 312px; }
body.sidebar-open .layers-btn { left: 312px; transition: left 220ms ease-out; }

.floating-tools::-webkit-scrollbar { width: 4px; }
.floating-tools::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.floating-tools::-webkit-scrollbar-track { background: transparent; }

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  position: relative;
}

/* Wyraźniejszy separator między grupami — krótka ciemna linia na środku */
.tool-group + .tool-group {
  margin-top: 3px;
  padding-top: 3px;
  border-top: none;
}
.tool-group + .tool-group::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 1px;
  background: #B8C1D6;
}

.tool-group-label { display: none; } /* ukryte — tylko ikony */

.tool-group-btns {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.floating-tools .floater-separator { display: none; }

.floater-btn,
.draw-tool-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.floater-btn:hover,
.draw-tool-btn:hover {
  background: var(--blue-bg);
  color: var(--blue);
}

.floater-btn.active,
.draw-tool-btn.active {
  background: var(--blue);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(79,108,224,0.35);
}

.floater-btn.danger:hover {
  background: rgba(239,68,68,0.12);
  color: #EF4444;
}

.floater-btn svg,
.draw-tool-btn svg { width: 20px; height: 20px; }

.tool-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--blue);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================================
   SIDEBAR — overlay, position:fixed, slide-in
   ============================================================================ */

.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: 300px;
  height: calc(100vh - var(--header-h));
  background: var(--white);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0,0,0,0.08);
  display: none;            /* JS toggles to flex */
  flex-direction: column;
  z-index: 100;
  animation: sidebarSlideIn 220ms ease-out;
}

@keyframes sidebarSlideIn {
  from { transform: translateX(-100%); opacity: 0.5; }
  to   { transform: translateX(0);      opacity: 1; }
}

/* Sidebar header — tytuł + strzałka w jednym rzędzie */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--blue-bg) 0%, rgba(245,247,255,0.35) 100%);
}

.sidebar-title {
  flex: 1;
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: 0.1px;
}

.sidebar-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 120ms;
  font-family: inherit;
}

.sidebar-close:hover {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: var(--blue);
}

.sidebar-close svg { width: 18px; height: 18px; }

/* Tabs */
.sidebar-tabs {
  display: flex;
  padding: 8px 10px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 120ms;
  font-family: inherit;
}

.sidebar-tab:hover { color: var(--blue); }

.sidebar-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* Tab content — scrollable */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

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

/* ============================================================================
   SIDEBAR — LAYERS TAB (sekcje, kategorie, warstwy)
   ============================================================================ */

.sidebar-section {
  padding: 3px 0;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child { border-bottom: none; }

.sidebar-heading {
  font-size: 13.5px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0.1px;
  color: var(--text);
  padding: 8px 14px 6px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
}

/* Główna sekcja sidebara — "Zbiór aktów planowania przestrzennego".
   Tytuł przeniesiony do sidebar-header. Sekcja dostaje mocniejszy separator. */
.sidebar-section.section-main {
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
  padding-top: 8px;
}

/* Category tiles stack (WZ, DCP, MPZP, ZPI, POG) */
.category-tiles-stack {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}

.category-tile-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--tile-color, var(--blue));
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  margin-bottom: 2px;
  cursor: pointer;
  transition: all 120ms;
}

.category-tile-row:hover {
  background: var(--blue-bg);
  transform: translateX(2px);
}

.category-tile-row svg {
  color: var(--tile-color, var(--blue));
  flex-shrink: 0;
}

.category-tile-label {
  flex: 1;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: normal;
  line-height: 1.2;
}

.category-tile-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--white);
  padding: 1px 8px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}

.category-tile-toggle {
  width: 28px;
  height: 14px;
  border-radius: 8px;
  border: none;
  background: #CBD2E0;
  cursor: pointer;
  position: relative;
  transition: all 150ms;
  flex-shrink: 0;
  padding: 0;
}

.category-tile-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 150ms;
}

.category-tile-toggle.toggle-on { background: var(--blue); }
.category-tile-toggle.toggle-on::after { transform: translateX(14px); }

/* Layer list under each category (expanded when clicked) */
.layers-list {
  padding: 0 10px 4px 28px;
}

.layers-list:empty { display: none; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-muted);
}

.layer-row input[type="checkbox"] { flex-shrink: 0; }

.layer-row label {
  flex: 1;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Section toggle button ("Moje warstwy", "Mapy bazowe") */
.section-toggle-btn {
  width: 28px;
  height: 14px;
  border-radius: 8px;
  border: none;
  background: #CBD2E0;
  cursor: pointer;
  position: relative;
  padding: 0;
  flex-shrink: 0;
}

.section-toggle-btn::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 150ms;
}

.section-toggle-btn.toggle-on { background: var(--blue); }
.section-toggle-btn.toggle-on::after { transform: translateX(14px); }

/* Add layer button in My Layers section */
#add-layer-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--blue);
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
  transition: all 120ms;
}

#add-layer-btn:hover { background: var(--blue); color: var(--white); }

/* Basemaps & user layers */
.basemap-list,
.my-layers-list {
  padding: 2px 10px 4px;
}

.basemap-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.basemap-item label {
  flex: 1;
  cursor: pointer;
  color: var(--text);
}

.basemap-item input[type="checkbox"] { flex-shrink: 0; }

/* Strzałki reorder — ukryte (zbędne, zaśmiecają UI) */
.reorder-arrows,
.reorder-btn,
#geoportal-layers .reorder-arrows,
#geoportal-layers button[data-dir],
.basemap-item .reorder-arrows,
.basemap-item .reorder-btn {
  display: none !important;
}

.opacity-slider {
  width: 40px;
  height: 3px;
  accent-color: var(--blue);
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}

.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: 2px solid var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.opacity-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: 2px solid var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.opacity-slider::-moz-range-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  border: none;
}

.my-layers-empty {
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 8px 0;
  font-style: italic;
  text-align: center;
}

/* ============================================================================
   GEOPORTAL LAYERS — mapy tematyczne (dynamicznie generowane przez map.js)
   Pełna spójność z resztą sidebar: karty z kolorową krawędzią, rotujące chevrony,
   kompaktowe wiersze warstw, schowane strzałki reorder.
   ============================================================================ */

#geoportal-layers {
  padding: 0 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Grupa (karta) */
#geoportal-layers .geoportal-group {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
}

#geoportal-layers .geoportal-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  user-select: none;
  transition: background 120ms;
}

#geoportal-layers .geoportal-group-header:hover { background: var(--blue-bg); }

/* Poziom 1 — grupa geoportalu ("Mapa zasadnicza", "Planowanie przestrzenne") — mniejsza niż sidebar-heading */
#geoportal-layers .geoportal-group-title {
  flex: 1;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  line-height: 1.2;
}

/* Schowaj wszystkie strzałki reorder (grupy + warstwy) i strzałki tekstowe */
#geoportal-layers .reorder-arrows,
#geoportal-layers .gp-reorder-arrows,
#geoportal-layers button[data-dir],
#geoportal-layers .gp-group-reorder {
  display: none !important;
}

/* Chevron rozwijania grupy — rotuje */
#geoportal-layers .gp-collapse-arrow {
  font-size: 9px;
  color: var(--text-dim);
  transition: transform 180ms ease-out;
  line-height: 1;
  flex-shrink: 0;
}

#geoportal-layers .geoportal-group.collapsed .gp-collapse-arrow {
  transform: rotate(-90deg);
}

/* Toggle całej grupy (kulka) — TAKI SAM rozmiar jak "Mapy bazowe" */
#geoportal-layers .group-toggle-btn {
  width: 28px;
  height: 14px;
  border-radius: 8px;
  border: none;
  background: #CBD2E0;
  cursor: pointer;
  position: relative;
  padding: 0;
  flex-shrink: 0;
}

#geoportal-layers .group-toggle-btn::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 150ms;
}

#geoportal-layers .group-toggle-btn.toggle-on { background: var(--blue); }
#geoportal-layers .group-toggle-btn.toggle-on::after { transform: translateX(14px); }

/* Body grupy — ukrywane gdy collapsed */
#geoportal-layers .geoportal-group-body {
  border-top: 1px solid var(--border-light);
  background: var(--white);
  padding: 2px 0;
}

#geoportal-layers .geoportal-group.collapsed .geoportal-group-body {
  display: none;
}

/* Pojedynczy wiersz warstwy (poziom 2 — liść bezpośrednio pod grupą) */
#geoportal-layers .geoportal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 14px;
  font-size: 10.5px;
  color: var(--text-muted);
  transition: background 100ms;
  line-height: 1.3;
}

#geoportal-layers .geoportal-item:hover { background: var(--bg); }

#geoportal-layers .geoportal-item input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: var(--blue);
  width: 14px;
  height: 14px;
}

#geoportal-layers .geoportal-item label {
  flex: 1;
  cursor: pointer;
  line-height: 1.25;
  font-size: 10.5px;
}

#geoportal-layers .geoportal-item .opacity-slider {
  width: 40px;
  height: 3px;
  flex-shrink: 0;
}

/* Poziom 2 — podwarstwa rozwijalna ("Ewidencja gruntów i budynków", "Użytki gruntowe") */
#geoportal-layers .geoportal-parent-item {
  font-weight: 600;
  font-size: 11px;
  color: var(--text);
  padding: 3px 14px;
}

#geoportal-layers .geoportal-parent-item label {
  font-size: 11px;
  font-weight: 600;
}

#geoportal-layers .sublayer-toggle {
  font-size: 9px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 4px;
  transition: transform 180ms ease-out;
  flex-shrink: 0;
}

#geoportal-layers .geoportal-sublayer-group:not(.expanded) .sublayer-toggle {
  /* strzałka ▶ domyślnie */
}

#geoportal-layers .geoportal-sublayer-group.expanded .sublayer-toggle {
  transform: rotate(90deg);
}

#geoportal-layers .geoportal-sublayers {
  padding-left: 18px;
  border-left: 2px solid var(--border-light);
  margin-left: 14px;
}

#geoportal-layers .geoportal-sublayers.collapsed { display: none; }

/* Poziom 3 — najgłębsze dzieci ("Działki i numery", "Budynki") */
#geoportal-layers .geoportal-child-item {
  padding-left: 8px;
  padding-right: 12px;
  padding-top: 2px;
  padding-bottom: 2px;
}

#geoportal-layers .geoportal-child-item label {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-dim);
}

/* ============================================================================
   SIDEBAR — SEARCH TAB
   ============================================================================ */

.search-panel {
  padding: 14px;
}

.search-panel label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.search-panel input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.search-panel input:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(79,108,224,0.10);
}

.search-panel .btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms;
  font-family: inherit;
}

.search-panel .btn-primary:hover { background: var(--blue-hover); }

/* ============================================================================
   SIDEBAR — LEGEND TAB
   ============================================================================ */

.legend-panel {
  padding: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
}

.legend-item:last-child { border-bottom: none; }

.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ============================================================================
   POPUP (info na mapie)
   ============================================================================ */

.ol-popup {
  position: absolute;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px 14px 14px;
  min-width: 220px;
  max-width: 400px;
  bottom: 14px;
  left: -50%;
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  color: var(--text);
}

.ol-popup:after, .ol-popup:before {
  top: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.ol-popup:after {
  border-top-color: var(--white);
  border-width: 10px;
  left: 48px;
  margin-left: -10px;
}

.ol-popup:before {
  border-top-color: var(--border);
  border-width: 11px;
  left: 48px;
  margin-left: -11px;
}

.ol-popup-closer {
  position: absolute;
  top: 6px;
  right: 10px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 20px;
  background: none;
  border: none;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}

.ol-popup-closer:hover { background: var(--blue-bg); color: var(--blue); }

/* Measurement tooltip */
.measure-tooltip {
  position: relative;
  background: rgba(26,30,46,0.92);
  color: var(--white);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.measure-tooltip:before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: rgba(26,30,46,0.92);
}

/* ============================================================================
   MODALS (print, buffer, share, import)
   ============================================================================ */

.modal-overlay,
.print-panel,
.buffer-dialog,
.share-dialog,
.import-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 290;
}

.modal-card {
  background: var(--white);
  padding: 20px;
  border-radius: 14px;
  min-width: 320px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* Login modal */
.btn-login-method {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 150ms;
}
.btn-login-method:hover {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
  color: var(--text-dim);
  font-size: 11px;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

.login-error {
  color: #EF4444;
  font-size: 12px;
  margin-top: 6px;
  padding: 6px 10px;
  background: rgba(239,68,68,0.08);
  border-radius: 6px;
}

.modal-desc {
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 0 0 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.print-panel { width: 480px; }
.buffer-dialog { width: 380px; }
.share-dialog { width: 440px; }
.import-dialog { width: 500px; max-height: 80vh; }

.print-panel-header,
.buffer-dialog-header,
.share-dialog-header,
.import-dialog-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
}

.panel-title,
.buffer-dialog-header h3,
.share-dialog-header h3,
.import-dialog-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title svg { color: var(--blue); }

.panel-close,
.buffer-dialog-close,
.share-dialog-close,
.import-dialog-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  color: var(--text-dim);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms;
  font-family: inherit;
}

.panel-close:hover,
.buffer-dialog-close:hover,
.share-dialog-close:hover,
.import-dialog-close:hover {
  background: var(--blue-bg);
  color: var(--blue);
  transform: rotate(90deg);
}

.print-panel-body,
.buffer-dialog-body,
.share-dialog-body,
.import-dialog-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.print-panel-footer,
.buffer-dialog-footer,
.share-dialog-footer,
.import-dialog-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Form inputs in modals */
.form-group { margin-bottom: 14px; }
.form-group.compact { margin-bottom: 10px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.form-group label,
.input-group label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea,
.input-group input,
.input-group select,
.input-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: all 120ms;
}

.form-group input:focus,
.form-group select:focus,
.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(79,108,224,0.10);
}

.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; }
.checkbox-group.compact { gap: 8px 14px; }

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}

/* Buttons */
.btn,
.btn-primary,
.btn-secondary {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms;
  border: none;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-hover); }

.btn-secondary {
  background: var(--white);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: var(--blue);
}

.print-preview-info {
  background: var(--blue-bg);
  color: var(--blue);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.print-preview-info.compact { padding: 6px 10px; font-size: 11.5px; }

/* ============================================================================
   PORTAL OVERLAY PANELS (Konsultacje, e-Wyrys, Rejestr)
   ============================================================================ */

.portal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.30);
  backdrop-filter: blur(2px);
  z-index: 250;
  display: flex;
  justify-content: flex-end;
}

.portal-panel {
  width: 480px;
  max-width: 92%;
  height: 100%;
  background: var(--white);
  box-shadow: -8px 0 32px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  animation: slideInRight 220ms ease-out;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.portal-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  height: 58px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.portal-panel-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.portal-panel-close {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: none;
  border-radius: 50%;
  font-size: 19px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 150ms;
  font-family: inherit;
}

.portal-panel-close:hover {
  background: var(--blue-bg);
  color: var(--blue);
  transform: rotate(90deg);
}

.portal-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}

/* Consultation cards */
.consul-card {
  background: var(--bg);
  border: 1.5px solid var(--border-light);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 150ms;
}

.consul-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79,108,224,0.10);
}

.consul-card-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.consul-card-meta { font-size: 12.5px; color: var(--text-dim); }
.consul-status-open { color: #15803d; font-weight: 700; }
.consul-status-closed { color: #dc2626; font-weight: 700; }

/* Registry rows */
.registry-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.registry-type-badge {
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--white);
}

/* e-Wyrys form */
.ewyrys-form { display: flex; flex-direction: column; gap: 12px; }

.ewyrys-form label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.ewyrys-form input {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  background: var(--bg);
  color: var(--text);
  transition: all 120ms;
  font-family: inherit;
}

.ewyrys-form input:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79,108,224,0.10);
}

/* ============================================================================
   MESSAGES (skrzynka wiadomości — wspólna dla panel urzędu i projektanta)
   ============================================================================ */

/* Badge nieprzeczytanych w przycisku/linku */
.msg-unread-badge {
  display: inline-block;
  margin-left: 6px;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #E74C3C;
  color: white;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

/* Layout dwukolumnowy */
.messages-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 200px);
  min-height: 500px;
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  overflow: hidden;
}

.messages-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
  background: var(--bg);
}

.messages-filters {
  display: flex;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--border-light);
  background: var(--white);
}

.msg-filter-btn {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--white);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 150ms;
}
.msg-filter-btn:hover { background: var(--blue-bg); color: var(--blue); }
.msg-filter-btn.active {
  background: var(--blue); color: var(--white); border-color: var(--blue);
}

.messages-threads-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.msg-thread-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 120ms;
}
.msg-thread-item:hover { background: var(--blue-bg); }
.msg-thread-item.active {
  background: rgba(79,108,224,0.1);
  border-left: 3px solid var(--blue);
  padding-left: 13px;
}
.msg-thread-item.unread { background: rgba(79,108,224,0.04); }
.msg-thread-item.unread .msg-thread-subject,
.msg-thread-item.unread .msg-thread-person {
  font-weight: 700; color: var(--text);
}

.msg-thread-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.msg-thread-person {
  font-size: 13px; font-weight: 600; color: var(--text);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-thread-date {
  font-size: 11px; color: var(--text-dim); flex-shrink: 0; margin-left: 8px;
}
.msg-thread-subject {
  font-size: 13.5px; color: var(--text); margin-bottom: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-thread-snippet {
  font-size: 12px; color: var(--text-dim); line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 4px;
}
.msg-thread-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.msg-case-chip {
  display: inline-block;
  padding: 2px 8px;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.msg-attach-icon { font-size: 11px; color: var(--text-dim); }

/* Prawy panel — widok wątku */
.messages-thread-view {
  display: flex;
  flex-direction: column;
  background: var(--white);
}
.thread-empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1;
}
.thread-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
}
.thread-header h2 {
  font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 8px;
}
.thread-header-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.thread-messages {
  flex: 1; overflow-y: auto; padding: 16px 24px;
  display: flex; flex-direction: column; gap: 16px;
}

.msg-single {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 14px 16px;
}
.msg-single-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-size: 13px;
}
.msg-status-pill {
  display: inline-block; padding: 1px 8px;
  font-size: 10px; font-weight: 700; border-radius: 10px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.msg-status-pill.unread { background: var(--blue); color: white; }

.msg-single-body {
  font-size: 14px; color: var(--text); line-height: 1.6;
  white-space: pre-wrap; margin-bottom: 8px;
}

.msg-attachments {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border-light);
}
.msg-attach-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 12.5px;
}
.msg-attach-name {
  flex: 1; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-attach-size { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.msg-attach-download {
  color: var(--blue); font-weight: 600; text-decoration: none;
  padding: 2px 8px; border-radius: 4px; transition: background 120ms;
}
.msg-attach-download:hover { background: var(--blue-bg); }

.thread-reply {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border-light);
  background: var(--bg);
}
.thread-reply textarea { margin-bottom: 8px; }
.thread-reply-bar { display: flex; align-items: center; gap: 8px; }

.compose-dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  transition: all 150ms;
}
.compose-dropzone:hover,
.compose-dropzone.dragover {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}
.compose-attachments-list {
  margin-top: 10px; display: flex; flex-direction: column; gap: 4px;
}
.compose-attach-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--blue-bg); border-radius: 6px;
  font-size: 12.5px;
}
.compose-attach-remove {
  background: none; border: none; color: #E74C3C; font-size: 18px; line-height: 1;
  cursor: pointer; padding: 0 6px; font-family: inherit;
}
.compose-attach-remove:hover { color: #C0392B; }

.compose-case-chip {
  display: inline-block;
  padding: 4px 12px;
  background: var(--blue-bg);
  color: var(--blue);
  font-weight: 700;
  border-radius: 10px;
  font-size: 12px;
}

@media (max-width: 1024px) {
  .messages-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 80vh;
  }
  .messages-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    max-height: 300px;
  }
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
  .header-center { display: none; }
  .portal-action-btn span:not(.portal-action-icon) { display: none; }
  .portal-action-btn { padding: 7px 10px; }
  .sidebar { width: 85%; }
}
