/* ==========================================================================
   RTGMS — Real-time GNSS Monitoring System for Poland
   assets/style.css

   ARCHITEKTURA (warstwy od ogółu do szczegółu):
   ─────────────────────────────────────────────
   01. Fonts
   02. Tokeny (CSS Custom Properties) — JEDYNE miejsce gdzie są kolory/rozmiary
   03. Reset — ustawienia bazowe, box-sizing, marginesy
   04. Layout — html / body / #app-container (siatka strony)
   05. Komponenty — Header, Menu, Footer, Card, Button, Form
   06. Widoki — strona główna, high/low/medium monitoring, page-full
   07. Tabele — Dash DataTable
   08. Mapy — Plotly Scattermapbox, legenda, popup
   09. Wykresy — Plotly Graph
   10. Biblioteki zewnętrzne — datepicker, dropdown
   11. Specyficzne panele — settings, admin, alert-service
   12. Breakpointy — od najszerszego do najwęższego (mobile-last)
   13. Utility — klasy pomocnicze

   ZASADY:
   - ID komponentów wyłącznie z myślnikami (nigdy podkreślniki)
   - !important tylko tam gdzie nadpisujemy inline style z Pythona/Dash
   - Każda reguła ma komentarz jeśli jej cel nie jest oczywisty
   - Brak duplikatów — każda klasa zdefiniowana raz
   ========================================================================== */


/* ==========================================================================
   01. FONTS
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');


/* ==========================================================================
   02. TOKENY — CSS Custom Properties
   Wszystkie kolory, rozmiary i odstępy są tutaj.
   Zmiana motywu = zmiana wartości zmiennych, nic więcej.
   ========================================================================== */

:root {
  /* ── Kolory — Light mode ───────────────────────────────────────────────── */
  --bg:                  #f0f4f8;   /* tło strony */
  --bg-subtle:           #e8edf3;   /* tło subtelne (paskowanie tabel itp.) */
  --fg:                  #0f172a;   /* kolor tekstu główny */
  --fg-muted:            #475569;   /* kolor tekstu wyciszony (etykiety, opisy) */
  --primary:             #0ea5e9;   /* kolor akcentu (przyciski, linki, focus) */
  --primary-hover:       #0284c7;
  --primary-contrast:    #ffffff;   /* tekst na tle --primary */
  --accent:              #00529B;
  --border:              #e2e8f0;   /* obramowania ogólne */
  --link-color:          var(--primary);

  /* ── Karty ────────────────────────────────────────────────────────────── */
  --card-bg:             #ffffff;
  --card-border:         #e2e8f0;
  --card-shadow:         0 1px 3px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.06);
  --card-radius:         12px;      /* używane przez border-radius na .card */

  /* ── Header ───────────────────────────────────────────────────────────── */
  --header-bg:           #ffffff;
  --header-fg:           #0f172a;
  --header-border:       #e8edf3;

  /* ── Menu ─────────────────────────────────────────────────────────────── */
  --menu-bg:             #ffffff;
  --menu-fg:             #334155;
  --menu-border:         #e8edf3;
  --menu-active-bg:      rgba(15,23,42,.07);
  --menu-active-fg:      #0f172a;
  --menu-hover-bg:       rgba(14,165,233,.07);

  /* ── Footer ───────────────────────────────────────────────────────────── */
  --footer-bg:           #ffffff;
  --footer-fg:           #64748b;
  --footer-border:       #e8edf3;

  /* ── Tabele ───────────────────────────────────────────────────────────── */
  --table-bg:            #ffffff;
  --table-fg:            #0f172a;
  --table-border:        #e2e8f0;
  --table-header-bg:     #f8fafc;
  --table-header-fg:     #0f172a;
  --table-stripe-bg:     #f8fafc;
  --table-hover-bg:      #eaf6ff;
  --dt-tip-bg:           #ffffff;
  --dt-tip-fg:           #111827;
  --dt-tip-border:       #d1d5db;
  --dt-tip-shadow:       0 6px 16px rgba(0,0,0,.18);

  /* ── Mapa ─────────────────────────────────────────────────────────────── */
  --map-border:          #e2e8f0;

  /* ── Cookie banner ────────────────────────────────────────────────────── */
  --cookie-bg:           #ffffff;
  --cookie-fg:           #0b1220;

  /* ── Aliasy dla Dash komponentów settings (używane przez Python) ──────── */
  --color-text:          #0f172a;
  --color-text-muted:    #475569;
  --color-border:        #e2e8f0;
  --color-surface:       #ffffff;
  --color-surface-subtle: rgba(0,0,0,.015);

  /* ── Wymiary układu strony ────────────────────────────────────────────── */
  /* clamp(min, preferred, max) — skaluje płynnie z dvh/vw */
  --header-h:            clamp(90px,  10.5dvh, 108px);
  --menu-h:              clamp(44px,  5dvh,    52px);
  --footer-h:            clamp(56px,  7dvh,    76px);
  --page-gutter:         clamp(12px,  2vw,     24px);  /* poziomy margines stron */

  /* ── Loga w headerze ──────────────────────────────────────────────────── */
  /* Logo ESA PNG ma duże puste marginesy (~33% treści). Logo RTGMS ~87%.
     Korekcja 2.6× sprawia że oba logo wyglądają tak samo wysoko wizualnie. */
  --esa-h:               clamp(120px, 14dvh,   167px);
  --rtgms-h:             clamp(54px,  6.3dvh,  75px);
  --branding-gap:        clamp(2px,   0.3vw,   6px);

  /* ── Wysokości górnych rzędów (mapa+tabela) w high/low ───────────────── */
  --high-top-h:          clamp(408px, 50dvh, 600px);
  --low-top-h:           clamp(384px, 50dvh, 576px);

  /* ── Typografia ───────────────────────────────────────────────────────── */
  --font-body:           'Inter', system-ui, -apple-system, sans-serif;
  --font-size-base:      0.9375rem;
  --font-size-sm:        0.8125rem;
  --font-size-xs:        0.75rem;
  --font-size-lg:        1.0625rem;
  --font-size-title:     clamp(1.15rem, 1.6vw, 1.45rem);

  /* ── Odstępy ──────────────────────────────────────────────────────────── */
  --gap-xs:  4px;
  --gap-sm:  8px;
  --gap-md:  12px;
  --gap-lg:  16px;
  --gap-xl:  24px;

  /* ── Przejścia ────────────────────────────────────────────────────────── */
  --transition-fast:     100ms ease;
  --transition-base:     160ms ease;
}

/* ── Dark mode — nadpisuje tylko tokeny, reszta CSS się nie zmienia ──────── */
.theme--dark,
body.dark {
  --bg:                  #0b1220;
  --bg-subtle:           #0d1528;
  --fg:                  #e2e8f0;
  --fg-muted:            #94a3b8;
  --primary:             #22d3ee;
  --primary-hover:       #06b6d4;
  --primary-contrast:    #0b1220;
  --accent:              #38bdf8;
  --border:              #1e293b;

  --card-bg:             #0f172a;
  --card-border:         #1e293b;
  --card-shadow:         0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);

  --header-bg:           #06090f;
  --header-fg:           #e2e8f0;
  --header-border:       #1e293b;

  --menu-bg:             #0b1220;
  --menu-fg:             #cbd5e1;
  --menu-border:         #1e293b;
  --menu-active-bg:      rgba(255,255,255,.10);
  --menu-active-fg:      #ffffff;
  --menu-hover-bg:       rgba(255,255,255,.06);

  --footer-bg:           #06090f;
  --footer-fg:           rgba(255,255,255,.45);
  --footer-border:       #1e293b;

  --table-bg:            #0f172a;
  --table-fg:            #e2e8f0;
  --table-border:        #1e293b;
  --table-header-bg:     #0d1528;
  --table-header-fg:     #94a3b8;
  --table-stripe-bg:     #0d1528;
  --table-hover-bg:      #1a2540;

  --dt-tip-bg:           #111827;
  --dt-tip-fg:           #e5e7eb;
  --dt-tip-border:       #374151;
  --dt-tip-shadow:       0 8px 22px rgba(0,0,0,.45);

  --map-border:          #243042;
  --cookie-bg:           #050a14;
  --cookie-fg:           #e2e8f0;

  --color-text:          #e2e8f0;
  --color-text-muted:    #94a3b8;
  --color-border:        #1e293b;
  --color-surface:       #0f172a;
  --color-surface-subtle: rgba(255,255,255,.04);
}


/* ==========================================================================
   03. RESET
   Ustawienia zerowe — każdy browser zaczyna z tymi samymi wartościami.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;  /* width/height obejmuje padding i border */
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;  /* zapobiega automatycznemu powiększaniu tekstu na iOS */
  scroll-behavior: smooth;
  overflow-x: hidden;              /* globalnie blokuje poziomy scroll */
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;  /* desktop: cały UI mieści się w 100dvh, żaden element nie wystaje */
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--link-color);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Formularze dziedziczą font z body (domyślnie browser ich nie dziedziczy) */
button, input, select, textarea {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
}

/* Dash wymusza własny font na komponentach — !important nadpisuje inline style */
#app-container,
#app-container * {
  font-family: var(--font-body) !important;
}


/* ==========================================================================
   04. LAYOUT STRONY
   Siatka 4 wierszy: header | menu | main (flex) | footer.
   Cały viewport = 100dvh, żaden element nie wystaje poza ekran.
   ========================================================================== */

html, body {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* Fallback dla przeglądarek bez dvh (Safari < 15.4, Chrome < 108) */
@supports not (height: 100dvh) {
  html, body { height: 100vh; max-height: 100vh; }
}

#app-container {
  display: grid;
  grid-template-rows:
    var(--header-h)            /* wiersz 1: header */
    var(--menu-h)              /* wiersz 2: nawigacja */
    1fr                        /* wiersz 3: główna treść — bierze całą resztę */
    minmax(var(--footer-h), auto); /* wiersz 4: footer rośnie gdy tekst się zawija */
  grid-template-columns: 1fr;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;
}

@supports not (height: 100dvh) {
  #app-container { height: 100vh; max-height: 100vh; }
}

/* Wiersz 3 — kontener strony. overflow-y:auto pozwala wewnętrznym kartom scrollować. */
.main {
  grid-row: 3;
  grid-column: 1;
  min-height: 0;        /* flex/grid child może być mniejszy niż zawartość */
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  width: 100%;
  box-sizing: border-box;
}

/* Każdy widok bezpośrednio w .main ma min-height:0 żeby flex:1 działał poprawnie */
.main > div { min-height: 0; }

.page { display: block; min-height: 0; }


/* ==========================================================================
   05. KOMPONENTY
   ========================================================================== */

/* ── 5a. Header ─────────────────────────────────────────────────────────── */

.header {
  grid-row: 1;
  grid-column: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-lg);
  padding: 0 var(--page-gutter);
  height: var(--header-h);
  min-height: 0;
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 1px solid var(--header-border);
  z-index: 10000;   /* header zawsze nad wszystkimi elementami strony */
  overflow: hidden;
}

.header__left {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2vw, 32px);
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.branding {
  display: inline-flex;
  align-items: center;
  gap: var(--branding-gap);
  flex-shrink: 0;
  height: 100%;
}

/* Logo ESA — domyślnie ukryte, widoczne przez selektor motywu poniżej */
img.logo-esa { display: none; }
img.logo-esa {
  height: var(--esa-h);
  max-height: var(--esa-h);
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

/* Pokaż właściwy wariant ESA zależnie od motywu */
#app-container.theme--light .logo-esa--light,
#app-container.theme--dark  .logo-esa--dark,
body.dark                   .logo-esa--dark { display: block; }
body.dark                   .logo-esa--light { display: none; }

/* Logo RTGMS — !important bo Dash może mieć inline style na tym elemencie */
.logo-rtgms img {
  height: var(--rtgms-h) !important;
  max-height: var(--rtgms-h) !important;
  width: auto !important;
  object-fit: contain !important;
  display: block !important;
}

.title {
  font-size: var(--font-size-title);
  font-weight: 700;
  color: var(--header-fg);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header__right {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  flex-shrink: 0;
}

/* ── 5b. Przełącznik języka i motywu ────────────────────────────────────── */

.lang-switch,
.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--header-border);
  border-radius: 20px;
  padding: 2px 4px;
}

.btn--lang {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--header-fg);
  font-size: var(--font-size-sm);
  font-weight: 600;
  font-family: var(--font-body);
  padding: 3px 8px;
  border-radius: 16px;
  cursor: pointer;
  opacity: 0.65;
  transition: background var(--transition-fast), opacity var(--transition-fast);
}
.btn--lang:hover               { opacity: 1; background: var(--menu-active-bg); }
.btn--lang.active              { background: var(--primary); color: #fff; opacity: 1; }

.switch,
.btn--theme,
#btn-theme {
  appearance: none;
  border: 1px solid var(--header-border);
  background: transparent;
  color: var(--header-fg);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.switch:hover,
.btn--theme:hover,
#btn-theme:hover { background: var(--menu-active-bg); border-color: var(--fg-muted); }

/* ── 5c. Przyciski ogólne ───────────────────────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: var(--font-size-sm);
  font-family: var(--font-body);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.btn:hover                { background: var(--bg-subtle); transform: translateY(-1px); }
.btn--primary             { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.btn--primary:hover       { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--danger              { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn--danger:hover        { filter: brightness(.95); }
.btn--action {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.btn--action:hover        { background: var(--bg-subtle); border-color: var(--primary); }

.theme--dark .btn:hover,
body.dark    .btn:hover   { filter: brightness(1.08); }

button { cursor: pointer; font-family: var(--font-body); }

/* ── 5d. Menu / Nawigacja ───────────────────────────────────────────────── */

.menu {
  grid-row: 2;
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 var(--page-gutter);
  height: var(--menu-h);
  min-height: 0;
  background: var(--menu-bg);
  border-bottom: 1px solid var(--menu-border);
  /* Poziomy scroll ukryty gdy wszystkie linki mieszczą się w jednej linii */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.menu::-webkit-scrollbar { display: none; }

.menu__link {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  height: calc(var(--menu-h) - 10px);
  border-radius: 6px;
  border: 1px solid transparent;
  color: var(--menu-fg);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast);
}
.menu__link:hover         { background: var(--menu-hover-bg); text-decoration: none; }
.menu__link--active {
  background: var(--menu-active-bg);
  color: var(--menu-active-fg);
  font-weight: 600;
  border-color: rgba(51,65,85,.3);
}
.menu__link--active:hover { background: var(--menu-active-bg); }

/* Dark mode — aktywny link */
.theme--dark .menu__link--active,
body.dark    .menu__link--active {
  background: rgba(255,255,255,.10);
  color: #fff;
  border-color: rgba(255,255,255,.25);
}
.theme--dark .menu__link--active:hover,
body.dark    .menu__link--active:hover { background: rgba(255,255,255,.12); }

/* Focus ring dla klawiatury */
.menu__link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

/* ── 5e. Karty ──────────────────────────────────────────────────────────── */

/* .card — bazowy kontener treści. Zawiera: card__title, card__content > card__body */
.card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;       /* przycina zawartość do zaokrąglonych rogów */
  min-height: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Nagłówek karty — border-radius na górnych rogach zapobiega "zakrywaniu" przez tło */
.card__title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--fg);
  padding: 6px 14px;   /* minimalny padding — tytuł blisko górnej krawędzi karty */
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;         /* nagłówek nie kurczy się gdy karta jest za mała */
  line-height: 1.3;
  background: var(--card-bg);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
}

.card__content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.card__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--gap-md) var(--gap-lg);
}

/* ── Warianty kart ── */

/* card--settings: dropdowny i datepickery wychodzą poza kartę */
.card--settings {
  overflow: visible !important;
}
.card--settings .card__content,
.card--settings .card__body { overflow: visible !important; }
.card--settings > .card__title { border-radius: var(--card-radius) var(--card-radius) 0 0; }
.card--settings .card__body {
  padding: var(--gap-lg);
  gap: var(--gap-md);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  border-radius: 0 0 var(--card-radius) var(--card-radius);
}

/* card--map: zawiera mapę Plotly/Leaflet — padding 0 żeby mapa wypełniała kartę */
.card--map {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  flex: 1;                /* rośnie do dostępnej wysokości w kontenerze */
}
.card--map .card__body,
.card--map .card__content {
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

/* card--side: karta tabeli po lewej stronie — wypełnia kolumnę gridu */
.card--side {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.card--side .card__body {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.card--side .card__body > div {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* card--tall: karty wykresów — minimalna wysokość żeby wykresy były czytelne */
.card--tall {
  min-height: clamp(179px, 22dvh, 269px);
}
.card--tall .card__body { overflow-y: auto; }

/* card--flush: bez paddingu wewnętrznego */
.card--flush .card__content,
.card--flush .card__body { padding: 0; }

/* Karta z formularzem (alert service, admin) — dropdowny wychodzą poza kartę */
.card.content,
#alert-service-card {
  overflow: visible !important;
}
.card.content .card__content,
.card.content .card__body {
  overflow: visible !important;
}

/* ── 5f. Footer ─────────────────────────────────────────────────────────── */

.footer {
  grid-row: 4;
  grid-column: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;        /* na małych ekranach loga i tekst idą do następnej linii */
  gap: 8px;
  padding: 6px var(--page-gutter);
  min-height: var(--footer-h);
  height: auto;           /* rośnie do zawartości gdy tekst się zawija */
  background: var(--footer-bg);
  color: var(--footer-fg);
  border-top: 1px solid var(--footer-border);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}

/* Safe area dla urządzeń z notch (iPhone X+) */
@supports (padding: max(0px)) {
  .header {
    padding-left:  max(var(--page-gutter), env(safe-area-inset-left));
    padding-right: max(var(--page-gutter), env(safe-area-inset-right));
  }
  .footer {
    padding-left:   max(var(--page-gutter), env(safe-area-inset-left));
    padding-right:  max(var(--page-gutter), env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

.footer__left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: clamp(4px, 1vw, 16px);
  min-width: 0;
  flex-shrink: 1;
}

/* Loga w stopce — !important bo Dash generuje inline style="height:100px" z Pythona */
.footer__left img,
.footer__left a img {
  height: clamp(28px, 3.5dvh, 44px) !important;
  max-height: 44px !important;
  width: auto !important;
  object-fit: contain;
  display: block !important;
  flex-shrink: 1;
}
/* Logo ESA ma duże marginesy w pliku PNG — potrzebuje więcej wysokości niż pozostałe */
.footer__left a:first-child img {
  height: clamp(36px, 5dvh, 60px) !important;
  max-height: 60px !important;
}

.theme--dark .footer__left img,
body.dark    .footer__left img { opacity: 0.8; }
.footer__left img:hover        { opacity: 1; }

.footer__right,
#footer-right-text {
  font-size: var(--font-size-xs);
  color: var(--footer-fg);
  white-space: normal;
  text-align: right;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-width: 0;       /* flex item może się kurczyć poniżej zawartości tekstowej */
  flex-shrink: 1;
}

/* ── 5g. Cookie banner ──────────────────────────────────────────────────── */

#cookie-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
  flex-wrap: wrap;
  padding: var(--gap-md) var(--page-gutter);
  background: var(--cookie-bg);
  color: var(--cookie-fg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}
#app-container.theme--light #cookie-banner { background: #ffffff; color: #0b1220; }
#app-container.theme--dark  #cookie-banner { background: #050a14; color: #e2e8f0; }
#cookie-banner .link { color: var(--primary); text-decoration: underline; }

#cookie-accept, #cookie-reject {
  appearance: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: var(--font-size-sm);
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}
#cookie-accept { background: var(--primary); color: var(--primary-contrast); border: 1px solid var(--primary); }
#cookie-accept:hover { background: var(--primary-hover); }
#cookie-reject { background: transparent; color: var(--cookie-fg); border: 1px solid currentColor; }
#cookie-reject:hover { background: rgba(0,0,0,.06); }

/* ── 5h. Info popup (overlay) ───────────────────────────────────────────── */

.info-popup {
  position: fixed;
  inset: 0;
  z-index: 50000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  pointer-events: none;
}
.info-popup--visible,
.info-popup[style*="flex"],
.info-popup[style*="block"] { display: flex !important; pointer-events: auto; }

.info-popup__inner {
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  width: clamp(320px, 40vw, 680px);
  max-height: 70vh;
  overflow-y: auto;
  padding: var(--gap-xl);
}

/* ── 5i. Formularze ─────────────────────────────────────────────────────── */

.settings-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap-md);
  padding: var(--gap-md) 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.form-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Dash dropdown / input — nadpisujemy browser domyślne przez zmienne */
.Select-control,
.Select-menu-outer,
.VirtualizedSelectOption,
input[type="text"],
input[type="date"],
.dash-dropdown .Select-control {
  background: var(--card-bg) !important;
  color: var(--fg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  font-size: var(--font-size-sm) !important;
  font-family: var(--font-body) !important;
}
.Select-control:hover        { border-color: var(--primary) !important; }
.Select-menu-outer           { border: 1px solid var(--border) !important; box-shadow: 0 4px 12px rgba(0,0,0,.15) !important; }
.VirtualizedSelectOption     { background: var(--card-bg) !important; color: var(--fg) !important; }
.VirtualizedSelectFocusedOption { background: var(--table-hover-bg) !important; }

.dash-checkbox input[type="checkbox"] { accent-color: var(--primary); }
input[type="radio"]                   { accent-color: var(--primary); }

/* Scrollbar — jednolity styl we wszystkich kontenerach */
::-webkit-scrollbar       { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg-subtle); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* Pasek stanu / odnowienia tabeli */
.table-footer-bar,
.status-bar {
  flex-shrink: 0;
  padding: 4px var(--gap-lg);
  font-size: var(--font-size-xs);
  color: var(--fg-muted);
  border-top: 1px solid var(--card-border);
  background: var(--card-bg);
}


/* ==========================================================================
   06. WIDOKI
   Każdy widok to osobna siatka/flex wewnątrz .main.
   ========================================================================== */

/* ── 6a. Widok Mapa (strona główna) — tabela 30% | mapa 70% ────────────── */

.grid-menu_map--split {
  display: grid;
  grid-template-columns: 30% 1fr; /* 1fr bierze resztę po odjęciu gap — nie przekracza */
  gap: 10px;
  padding: 10px var(--page-gutter);
  flex: 1;          /* rośnie do całej wysokości .main (grid row 1fr) */
  min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  width: 100%;
}

.grid-menu_map--split .grid-item {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;     /* grid child musi mieć ustaloną wysokość żeby flex:1 w karcie działał */
}
.grid-menu_map--split .grid-item > .card { flex: 1; min-height: 0; }

/* Wrapper tabeli głównej — wypełnia kartę z scrollem */
#main-table-wrapper,
.main-table-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── 6b. Monitoring High — siatka 2 kolumn z rzędem mapa+tabela na górze ─ */

.grid-menu_high {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: auto;
  gap: var(--gap-md);
  padding: var(--gap-md) var(--page-gutter);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;  /* karty nie rozciągają się do końca gridu */
  width: 100%;
  box-sizing: border-box;
}

.grid-menu_high .grid-item--full {
  grid-column: 1 / -1;  /* zajmuje obie kolumny */
  min-width: 0;
}
.grid-menu_high .grid-item { min-width: 0; display: flex; flex-direction: column; }
.grid-menu_high .grid-item > .card { flex: 1; min-width: 0; }
.grid-menu_high .grid-item > .card .card__content,
.grid-menu_high .grid-item > .card .card__body { min-width: 0; }

/* Wykresy Plotly w siatce — nie mogą przekraczać komórki */
.grid-menu_high .grid-item:not(.grid-item--full) .dash-graph,
.grid-menu_high .grid-item:not(.grid-item--full) .js-plotly-plot,
.grid-menu_high .grid-item:not(.grid-item--full) .plotly-graph-div {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* Górny rząd high: tabela 30% | mapa 70%, stała wysokość */
.grid-high-top {
  display: grid;
  grid-template-columns: 3fr 7fr;  /* fr uwzględnia gap — nie przekracza 100% jak % */
  gap: var(--gap-md);
  min-height: 0;
  height: var(--high-top-h);
  overflow: visible;  /* overflow:visible żeby border-radius kart był widoczny */
}
.grid-high-top__table,
.grid-high-top__map {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;  /* nie przycinamy kart — border-radius musi być widoczny */
  height: 100%;
}
.grid-high-top__table > .card,
.grid-high-top__map   > .card { flex: 1; min-height: 0; height: 100%; }

/* Karty wykresów w high — minimalna wysokość i flex dla wykresu */
.grid-menu_high .card--tall {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 320px !important;
}
.grid-menu_high .card--tall .card__content,
.grid-menu_high .card--tall .card__body { min-height: 0; height: 100%; }
.grid-menu_high .card--tall .card__body { flex: 1; min-height: 0; overflow: hidden; }
.grid-menu_high .card--tall .dash-graph,
.grid-menu_high .card--tall .js-plotly-plot,
.grid-menu_high .card--tall .plotly,
.grid-menu_high .card--tall .plotly-graph-div { height: 320px !important; }

.charts-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-md);
}

/* Wykresy high — karty wyższe przez CSS override dcc.Graph */
.grid-menu_high .grid-item:not(.grid-item--full) .chart-wrapper .dash-graph,
.grid-menu_high .grid-item:not(.grid-item--full) .chart-wrapper .js-plotly-plot,
.grid-menu_high .grid-item:not(.grid-item--full) .chart-wrapper .plotly-graph-div {
  height: 480px !important;
}

/* CNO — pełna szerokość */
.grid-menu_high .grid-item--full .chart-wrapper .dash-graph,
.grid-menu_high .grid-item--full .chart-wrapper .js-plotly-plot,
.grid-menu_high .grid-item--full .chart-wrapper .plotly-graph-div {
  height: 540px !important;
}

/* ── 6c. Monitoring Medium — lista kart (wykresy roczne itp.) ─────────── */

.grid-menu_medium {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  padding: var(--gap-md) var(--page-gutter);
  min-height: 100%;
  height: auto;
  overflow-y: visible;
  overflow-x: hidden;
}
.grid-menu_medium .grid-item  { display: flex; flex-direction: column; }
.grid-menu_medium .card       { min-height: auto; }
.grid-menu_medium .card--tall { min-height: clamp(300px, 40dvh, 500px); }

/* ── 6d. Monitoring Low — analogicznie do high ─────────────────────────── */

.grid-menu_low {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  padding: var(--gap-md) var(--page-gutter);
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  box-sizing: border-box;
}
.grid-menu_low .grid-item--full { flex-shrink: 0; }
.grid-menu_low .card--tall      { min-height: clamp(380px, 50dvh, 600px); }

/* Górny rząd low: tabela 30% | mapa 70%, stała wysokość */
.grid-low-top {
  display: grid;
  grid-template-columns: 3fr 7fr;
  gap: var(--gap-md);
  height: var(--low-top-h);
  flex-shrink: 0;
  overflow: visible;
}
.grid-low-top__table,
.grid-low-top__map { display: flex; flex-direction: column; min-height: 0; overflow: visible; height: 100%; }
.grid-low-top__table > .card,
.grid-low-top__map  > .card { flex: 1; min-height: 0; height: 100%; }

/* ── 6e. Widoki pełnoekranowe (Project, Information, Alert, Admin) ──────── */

.page-full {
  display: flex;
  flex-direction: column;
  padding: var(--gap-md) var(--page-gutter);
  height: 100%;
  min-height: 0;
  /* overflow:visible — dropdowny w formularzach muszą wychodzić poza kontener */
  overflow: visible;
  overflow-y: auto;
  gap: var(--gap-md);
}
.grid-menu_map { display: flex; flex-direction: column; gap: var(--gap-md); flex: 1; min-height: 0; }
.page-full .grid-item--full { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-full .grid-item--full > .card > .card__title { padding: 14px clamp(24px, 4vw, 56px); font-size: 1.1rem; }
.page-full .card__body { overflow-y: auto; }

/* Strona Informacje — responsywny rozmiar czcionki */
.page-full .card__body {
  font-size: clamp(0.78rem, 1.8vw, 1rem);
}
.page-full .card__body h2 { font-size: clamp(1rem, 2.5vw, 1.4rem); }
.page-full .card__body h3 { font-size: clamp(0.9rem, 2vw, 1.15rem); }
.page-full .card__body h4 { font-size: clamp(0.82rem, 1.8vw, 1rem); }

.page-full .card__body {
  padding: clamp(16px, 2.5dvh, 32px) clamp(20px, 3vw, 40px);
}


/* ==========================================================================
   07. TABELE — Dash DataTable
   ========================================================================== */

.dash-spreadsheet-container {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  background: var(--table-bg);
}

.dash-spreadsheet,
.dash-table-container table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--font-size-sm);
  color: var(--table-fg);
  background: var(--table-bg);
}

/* Nagłówki kolumn — pogrubione, uppercase, border */
.dash-header,
.dash-spreadsheet thead th,
.dash-table-container .dash-header {
  background: var(--table-header-bg) !important;
  color: var(--table-header-fg) !important;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px !important;
  border-bottom: 2px solid var(--table-border) !important;
  border-right: 1px solid var(--table-border) !important;
  white-space: nowrap;
}

.dash-cell,
.dash-spreadsheet td,
.dash-table-container .dash-cell {
  background: var(--table-bg) !important;
  color: var(--table-fg) !important;
  border-right: 1px solid var(--table-border) !important;
  border-bottom: 1px solid var(--table-border) !important;
  padding: 5px 8px !important;
  font-size: var(--font-size-sm);
}

/* Paskowanie wierszy */
.dash-spreadsheet tbody tr:nth-child(even) .dash-cell,
.dash-table-container tr:nth-child(even) td { background: var(--table-stripe-bg) !important; }

/* Hover wierszy */
.dash-spreadsheet tbody tr:hover .dash-cell,
.dash-table-container tr:hover td { background: var(--table-hover-bg) !important; transition: background 80ms; }
.card--side .dash-spreadsheet tbody tr:hover .dash-cell,
.card--side .dash-table-container tr:hover td { background: var(--table-hover-bg) !important; }
.dash-spreadsheet tbody tr:hover .dash-cell:empty { background: var(--table-bg) !important; }

.dash-sort-arrow,
.column-header--sort { opacity: 0.7; }

.dash-cell.focused,
.dash-table-container td:focus { outline: 2px solid var(--primary) !important; outline-offset: -2px; }

/* Ukryj wbudowane menu Dash DataTable (jest niepotrzebne w naszym UI) */
.dash-spreadsheet-menu,
.dash-table-container .dash-spreadsheet-menu { display: none !important; }

/* Tooltip Dash */
.dash-tooltip,
[class*='dash-tooltip'] {
  background: var(--dt-tip-bg) !important;
  color: var(--dt-tip-fg) !important;
  border: 1px solid var(--dt-tip-border) !important;
  box-shadow: var(--dt-tip-shadow) !important;
  border-radius: 6px;
  font-size: var(--font-size-xs);
}

/* Scrollbar wewnątrz tabeli */
.dash-spreadsheet-container::-webkit-scrollbar       { width: 6px; height: 6px; }
.dash-spreadsheet-container::-webkit-scrollbar-track { background: var(--bg-subtle); }
.dash-spreadsheet-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.dash-spreadsheet-container::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* Dash renderuje .dash-table-tooltip bezpośrednio w <body>,
   poza #app-container — selektor musi być globalny */
.dash-table-tooltip {
  font-size: 12px !important;
  border-radius: 8px !important;
  padding: 6px 8px !important;
  /* Szerokość dopasowana do tekstu, max 200px — tekst zawija się */
  width: max-content !important;
  max-width: 200px !important;
  white-space: normal !important;
  word-break: break-word !important;
  box-shadow: 0 4px 12px rgba(0,0,0,.18) !important;
}

/* Light mode */
body:not(.dark) .dash-table-tooltip,
.theme--light .dash-table-tooltip {
  background-color: #ffffff !important;
  color: #111827 !important;
  border: 1px solid #d1d5db !important;
  box-shadow: 0 8px 18px rgba(15,23,42,.16) !important;
  opacity: 1 !important;
}

/* Dark mode */
body.dark .dash-table-tooltip,
.theme--dark .dash-table-tooltip {
  background-color: #111827 !important;
  color: #e5e7eb !important;
  border: 1px solid #374151 !important;
  box-shadow: 0 6px 16px rgba(0,0,0,.35) !important;
}

/* ── table-frame: wrapper tabeli z fixed_rows ──────────────────────────── */
/* Problem: Dash DataTable z fixed_rows oblicza wysokość scrollbara od
   .dash-spreadsheet-container. Ten kontener musi mieć height:100% (!)
   żeby suwak docierał do ostatniego wiersza. Cały łańcuch flex:1 od karty
   w dół zapewnia że height:100% działa poprawnie. */

.table-frame {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}
.table-frame .dash-table-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.table-frame .dash-spreadsheet-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: auto !important;
  height: 100% !important;  /* !important — Dash oblicza scrollbar od tej wartości */
}
.table-frame .dash-spreadsheet-inner {
  overflow-y: auto !important;
  overflow-x: auto !important;
}

.datatable--stretch {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}
.datatable--stretch,
.datatable--stretch .dash-table-container,
.datatable--stretch .dash-spreadsheet-container,
.datatable--stretch .dash-spreadsheet-inner,
.datatable--stretch .dash-spreadsheet-inner table { width: 100% !important; max-width: none !important; }
.datatable--stretch .dash-table-container .row { margin: 0; width: 100%; }

/* Wrappers tabel w widokach high/low/main */
.grid-menu_map--split .card--side #main-table-wrapper,
.grid-high-top__table #high-table-wrapper,
.grid-low-top__table  #low_table_wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.grid-high-top__table #high-table-wrapper .dash-spreadsheet-container,
.grid-low-top__table  #low_table_wrapper  .dash-spreadsheet-container { overflow-x: auto !important; }

.grid-menu_map--split .card--side #main-table-wrapper .dash-table-container,
.grid-menu_map--split .card--side #main-table-wrapper .dash-spreadsheet-container,
.grid-menu_map--split .card--side #main-table-wrapper .dash-spreadsheet-inner {
  height: 100% !important;
  max-height: none !important;
  min-height: 0;
}
.grid-menu_map--split .card--side #main-table-wrapper .dash-spreadsheet-container { flex: 1; }

/* Identyfikatory specyficzne dla high/low tabel */
#high-table, #low-table { flex: 1; min-height: 0; }

.theme--dark  #high-table .dash-header { background-color: #0b1220; color: #e5e7eb; }
.theme--light #high-table .dash-header { background-color: #f8fafc; color: #0f172a; }

.table__refresh {
  margin-top: 6px;
  font-size: var(--font-size-xs);
  line-height: 1.1;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ==========================================================================
   08. MAPY — Plotly Scattermapbox + Leaflet
   ========================================================================== */

/* ── map-frame: bezpośredni kontener dcc.Graph ──────────────────────────── */
/* position:relative — punkt odniesienia dla absolutnie pozycjonowanej legendy.
   flex:1 + min-height:0 — wypełnia card__body bez rozpychania.
   NIE ustawiamy height:100% — przy flex:1 jest zbędne i może powodować
   podwójne liczenie wysokości w przeglądarce. */
.map-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 0 0 var(--card-radius) var(--card-radius);
}

/* dcc.Graph — bezpośrednie dziecko map-frame, musi wypełnić kontener */
.map-frame > .dash-graph,
.map-frame > .js-plotly-plot { flex: 1; min-height: 0; width: 100% !important; height: 100% !important; }

/* Plotly wewnętrzne divy */
.map-frame .js-plotly-plot,
.map-frame .plot-container,
.map-frame .plotly { flex: 1; min-height: 0; width: 100% !important; height: 100% !important; }

/* Inne divy w map-frame (np. Leaflet) — nie dotyczy legendy ani popupu */
.map-frame iframe,
.map-frame > div:not(.map-legend):not(.map-popup):not([id$="-legend"]):not([id$="-popup"]) {
  width: 100% !important;
  height: 100% !important;
}

/* Leaflet-specific */
.map-frame .leaflet-container,
.map-frame > div[id*="map"] { width: 100% !important; height: 100% !important; }
.leaflet-container { border: 1px solid var(--map-border); border-radius: 0 0 var(--card-radius) var(--card-radius); }

/* high i medium: ukryj modebar na mobile */
@media (max-width: 600px) {
  .grid-menu_high .chart-wrapper .modebar-container,
  .grid-menu_medium .chart-wrapper .modebar-container {
    display: none !important;
  }
}

/* low-spectrum: modebar wyżej żeby nie nachodził na legendę */
.low-spectrum-wrapper .modebar-container {
  top: -3px !important;
}

/* low-spectrum mobile: ukryj modebar — na telefonie nie ma sensu zoom myszą */
@media (max-width: 600px) {
  .low-spectrum-wrapper .modebar-container {
    display: none !important;
  }
}

/* Plotly modebar — przesunięty do prawego dolnego rogu (doprecyzowane w JS) */
.map-frame .modebar    { z-index: 10 !important; }
.map-frame .hoverlayer { z-index: 9  !important; }
.map-frame .zoomlayer,
.map-frame .draglayer  { z-index: 8  !important; }
.map-frame .modebar-container { top: auto !important; bottom: 40px !important; right: 35px !important; left: auto !important; }
.map-frame .modebar-group { opacity: 0.6; }
.map-frame .modebar-group:hover { opacity: 1; }

/* Plotly wbudowana legenda (ta od Plotly, nie nasza custom) */
.map-frame .js-plotly-plot .legend rect.bg  { fill: rgba(255,255,255,.92) !important; stroke: rgba(0,0,0,.15) !important; rx: 6 !important; }
.map-frame .js-plotly-plot .legend text     { fill: #1e293b !important; font-size: 11px !important; font-family: 'Inter', system-ui, sans-serif !important; }

/* ── Legenda mapy (custom overlay) ─────────────────────────────────────── */
/* Trzy oddzielne ID bo każda mapa ma inną strukturę HTML:
   - #high-map-legend / #low-map-legend  : przyciski bezpośrednio w legendzie
   - #main-map-legend                    : dwa .map-legend-row (status + monitoring type) */

#high-map-legend,
#low-map-legend,
#main-map-legend {
  /* !important nadpisuje inline style="top:12px;right:12px" z Pythona */
  position: absolute !important;
  top: 10px !important;
  right: 10px !important;
  bottom: auto !important;
  left: auto !important;
  z-index: 500 !important;

  width: fit-content !important;
  min-width: 0 !important;
  max-width: min(320px, 55%) !important;  /* panel legendy — nowrap, tekst się nie ucina */
  height: auto !important;
  min-height: 0 !important;
  overflow: hidden !important;

  display: inline-flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 1px !important;
  flex: 0 0 auto !important;

  background: rgba(255,255,255,.95) !important;
  border: 1px solid rgba(0,0,0,.13) !important;
  border-radius: 6px !important;
  padding: 5px 8px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.14) !important;
  box-sizing: border-box !important;

  font-size: 11px !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  color: #1e293b !important;
  line-height: 1.4 !important;
  pointer-events: auto;
}

.theme--dark #high-map-legend,
.theme--dark #low-map-legend,
.theme--dark #main-map-legend {
  background: rgba(15,23,42,.95) !important;
  border: 1px solid rgba(255,255,255,.12) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.45) !important;
  color: #e2e8f0 !important;
}

/* high/low: przyciski bezpośrednio w legendzie */
#high-map-legend > .legend-item,
#low-map-legend  > .legend-item { display: inline-flex !important; width: fit-content !important; }
#high-map-legend > .legend-item + .legend-item,
#low-map-legend  > .legend-item + .legend-item { margin-top: 1px !important; }

/* main_map: dwa wiersze (status zakłóceń + typ monitorowania) */
.map-legend-row {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 1px !important;
  width: fit-content !important;
  min-width: 0 !important;
}
.map-legend-row + .map-legend-row,
.map-legend-row--monitoring {
  border-top: 1px solid rgba(0,0,0,.10) !important;
  margin-top: 4px !important;
  padding-top: 4px !important;
  width: fit-content !important;
}
.theme--dark .map-legend-row + .map-legend-row,
.theme--dark .map-legend-row--monitoring { border-top-color: rgba(255,255,255,.12) !important; }
.map-legend-row > .legend-item { display: inline-flex !important; width: fit-content !important; }
.map-legend-row > .legend-item + .legend-item { margin-top: 1px !important; }

/* Przyciski legendy */
.legend-item {
  display: inline-flex !important;
  align-items: center !important;
  gap: 5px !important;
  white-space: nowrap !important;
  padding: 2px 4px !important;
  margin: 0 !important;
  font-size: 11px !important;
  font-weight: 400 !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  color: inherit !important;
  background: transparent !important;
  border: none !important;
  border-radius: 4px !important;
  cursor: pointer !important;
  line-height: 1.3 !important;
  width: fit-content !important;
  height: fit-content !important;
}
.legend-item--off   { opacity: 0.45; text-decoration: line-through; }
.legend-item:hover  { background: transparent; }

/* Popup info — scroll na mobile */
#info-popup-overlay {
  -webkit-overflow-scrolling: touch;
}
#info-popup-content {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

/* ── Legend toggle (mobile only) ─────────────────────────────────────── */
/* Na desktop: przycisk toggle ukryty, legenda zawsze rozwinięta */
#main-legend-toggle { display: none !important; }

/* Na mobile (≤600px): pokaż przycisk toggle, tekst zawija się */
@media (max-width: 600px) {
  #main-legend-toggle {
    display: flex !important;
    align-self: flex-end;
  }
  /* Tekst w legendzie zawija się na mobile */
  #main-map-legend .legend-item {
    white-space: normal !important;
    max-width: 160px !important;
    align-items: flex-start !important;
  }
  #main-map-legend {
    max-width: min(180px, 50%) !important;
  }
}

/* Kółko koloru w legendzie */
.legend-swatch {
  width: 10px !important;
  height: 10px !important;
  border-radius: 50% !important;
  display: inline-block !important;
  flex-shrink: 0 !important;
}
.legend-swatch--good   { background: #22c55e; }
.legend-swatch--warn,
.legend-swatch--low    { background: #f59e0b; }
.legend-swatch--bad    { background: #ef4444; }
.legend-swatch--nodata { background: #94a3b8; }

.legend-label {
  font-size: 11px !important;
  line-height: 1.3 !important;
  color: inherit !important;
}

/* ── Popup mapy (kliknięcie na marker) ──────────────────────────────────── */

.map-popup {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.2);
  min-width: 220px;
  z-index: 120;
}
.theme--dark .map-popup { box-shadow: 0 8px 22px rgba(0,0,0,.45); }

.popup__header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.25rem; }
.popup__title  { font-size: 1rem; font-weight: 700; line-height: 1.2; margin: 0; }
.popup__close  {
  appearance: none; border: 0; background: transparent; color: var(--fg);
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  cursor: pointer; transition: opacity var(--transition-fast), background var(--transition-fast);
}
.popup__close:hover         { opacity: 0.8; }
.popup__close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
:not(.theme--dark) .popup__close:hover { background: rgba(0,0,0,.06); }
.theme--dark .popup__close:hover,
body.dark    .popup__close:hover { background: rgba(255,255,255,.06); }
.popup__close .icon { width: 16px; height: 16px; display: block; background: currentColor; }
.popup__close .icon-close {
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M18.3 5.7 12 12l6.3 6.3-1.4 1.4L10.6 13.4 4.3 19.7 2.9 18.3 9.2 12 2.9 5.7 4.3 4.3 10.6 10.6 16.9 4.3z'/></svg>") no-repeat center/contain;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M18.3 5.7 12 12l6.3 6.3-1.4 1.4L10.6 13.4 4.3 19.7 2.9 18.3 9.2 12 2.9 5.7 4.3 4.3 10.6 10.6 16.9 4.3z'/></svg>") no-repeat center/contain;
}
.popup__divider { border: none; border-top: 1px solid var(--card-border); opacity: .9; margin: 0.35rem 0 0.5rem; }
.popup__content { display: flex; flex-direction: column; gap: 0.35rem; }
.popup__row     { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; }
.popup__dot     { display: inline-block; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.25); flex-shrink: 0; }
.popup__dot--good { background: #16a34a; }
.popup__dot--low  { background: #f59e0b; }
.popup__dot--bad  { background: #dc2626; }

/* ── Kontrolki mapy (zoom, pan) ─────────────────────────────────────────── */

.map-controls { display: flex; flex-direction: column; gap: 8px; z-index: 120; }
.map-controls .btn-ctrl {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--card-bg); color: var(--fg); border: 1px solid var(--card-border);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,.08);
  transition: transform var(--transition-fast);
}
.map-controls .btn-ctrl:hover  { transform: translateY(-1px); }
.map-controls .btn-ctrl--active { outline: 2px solid var(--primary); }
.map-controls .icon { width: 18px; height: 18px; display: block; background: currentColor; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: center; mask-position: center; -webkit-mask-size: contain; mask-size: contain; }
.map-controls .icon-zoom-in  { -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M11 5v6H5v2h6v6h2v-6h6v-2h-6V5z'/></svg>") no-repeat center/contain; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M11 5v6H5v2h6v6h2v-6h6v-2h-6V5z'/></svg>") no-repeat center/contain; }
.map-controls .icon-zoom-out { -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M5 11h14v2H5z'/></svg>") no-repeat center/contain; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M5 11h14v2H5z'/></svg>") no-repeat center/contain; }
.map-controls .icon-reset    { -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M12 5V2l-4 4 4 4V7a5 5 0 1 1-5 5H5a7 7 0 1 0 7-7z'/></svg>") no-repeat center/contain; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M12 5V2l-4 4 4 4V7a5 5 0 1 1-5 5H5a7 7 0 1 0 7-7z'/></svg>") no-repeat center/contain; }
.map-controls .icon-pan      { -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M9 11V6a1 1 0 1 1 2 0v5h1V5a1 1 0 1 1 2 0v6h1V7a1 1 0 1 1 2 0v8.2A3.8 3.8 0 0 1 13.2 19H11a4 4 0 0 1-4-4v-1.5a1.5 1.5 0 1 1 2 0V11z'/></svg>") no-repeat center/contain; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23000' d='M9 11V6a1 1 0 1 1 2 0v5h1V5a1 1 0 1 1 2 0v6h1V7a1 1 0 1 1 2 0v8.2A3.8 3.8 0 0 1 13.2 19H11a4 4 0 0 1-4-4v-1.5a1.5 1.5 0 1 1 2 0V11z'/></svg>") no-repeat center/contain; }

/* Alarm info block w popupie */
.alarm-info-block { display: flex; flex-direction: column; gap: 4px; }
.alarm-param-row  { display: flex; justify-content: space-between; gap: 12px; font-size: var(--font-size-sm); }
.alarm-param-label { font-weight: 500; cursor: help; text-decoration: underline dotted; }
.alarm-param-value { text-align: right; white-space: nowrap; }


/* ==========================================================================
   09. WYKRESY — Plotly Graph
   ========================================================================== */

.js-plotly-plot,
.plotly-graph-div { width: 100% !important; max-width: 100% !important; min-height: 0; }

.dash-graph { width: 100% !important; max-width: 100% !important; overflow: hidden; min-width: 0; }

/* SNR wykresy — muszą wypełniać kontener w pionie */
.snr-graph,
.snr-graph .dash-graph,
.snr-graph .js-plotly-plot,
.snr-graph .plotly,
.snr-graph .main-svg { height: 100% !important; width: 100% !important; }
.snr-graph { min-height: 320px; }


/* ==========================================================================
   10. BIBLIOTEKI ZEWNĘTRZNE — react-dates DatePicker
   ========================================================================== */

.mc2 { display: grid; gap: 0.5rem; }
.mc2 .dp-wrap { display: inline-block; }
.mc2 .dp-label { font-size: 0.9rem; color: var(--fg-muted); }
.mc2 .dp-value { font-weight: 700; color: var(--fg); }

.SingleDatePicker { display: inline-block; }
.SingleDatePickerInput { background: var(--card-bg); color: var(--fg); border: 1px solid var(--card-border); border-radius: 10px; overflow: hidden; }
.DateInput_input { background: var(--card-bg); color: var(--fg); padding: 0.55rem 0.7rem; height: 36px; font-size: 0.95rem; font-family: var(--font-body); }
.DateInput_input__focused { border: 0; box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 22%, transparent); }
.SingleDatePicker_picker { background: var(--bg); color: var(--fg); border: 1px solid var(--card-border); border-radius: 12px; box-shadow: 0 6px 16px rgba(0,0,0,.08); z-index: 5000 !important; }
.rtgms-dp .SingleDatePicker,
.rtgms-dp .SingleDatePickerInput { z-index: 5000; }
.rtgms-dp .SingleDatePicker_picker { z-index: 5000 !important; }
.rtgms-dp .DayPickerKeyboardShortcuts_buttonReset { z-index: 5001 !important; }

.CalendarMonth_caption { color: var(--fg); font-weight: 700; }
.DayPicker_weekHeader_li { color: var(--fg-muted); }
.CalendarDay__default { border: 1px solid var(--card-border); background: var(--card-bg); color: var(--fg); }
.CalendarDay__hovered_span,
.CalendarDay__hovered { filter: brightness(1.06); }
.CalendarDay__blocked_out_of_range,
.CalendarDay__blocked_calendar { color: color-mix(in oklab, var(--fg-muted) 70%, transparent); }
.CalendarDay__today  { background: color-mix(in oklab, var(--primary) 75%, var(--card-bg)); color: var(--primary-contrast); border-color: var(--primary); }
.CalendarDay__selected { background: color-mix(in oklab, var(--primary) 86%, var(--card-bg)); color: var(--primary-contrast); border-color: var(--primary); }
.DayPickerNavigation_button { background: var(--card-bg); color: var(--fg); border: 1px solid var(--card-border); }
.DayPickerNavigation_button:hover { filter: brightness(1.06); }

/* Dark mode datepicker */
.theme--dark .rtgms-dp {
  --dp-bg: #1f2532; --dp-panel: #262d3d; --dp-border: #3a465b; --dp-text: #e6eef7; --dp-text-muted: #a7b4c7;
  --dp-day-bg: #222a3b; --dp-day-hover: #2e384d; --dp-day-selected: #1fb6ff; --dp-day-selected-text: #08131f;
  --dp-today-ring: #66ccff; --dp-nav-bg: #2a3446; --dp-nav-icon: #e6eef7; --dp-week-header: #b8c3d4;
  --dp-help-bg: #0b3d91; --dp-help-panel-bg: #1b2130; --dp-help-panel-text: #eef3f8; --dp-help-muted: #b9c6d8;
  --dp-kbd-bg: #2b3347; --dp-kbd-border: #495873; --dp-focus: #1fb6ff;
}
.theme--dark .rtgms-dp .SingleDatePickerInput  { background: var(--dp-bg) !important; border: 1px solid var(--dp-border) !important; }
.theme--dark .rtgms-dp .DateInput               { background: transparent !important; }
.theme--dark .rtgms-dp .DateInput_input         { background: transparent !important; color: var(--dp-text) !important; }
.theme--dark .rtgms-dp .DayPicker,
.theme--dark .rtgms-dp .CalendarMonthGrid,
.theme--dark .rtgms-dp .CalendarMonth           { background: var(--dp-panel) !important; border-color: var(--dp-border) !important; color: var(--dp-text) !important; }
.theme--dark .rtgms-dp .CalendarMonth_caption   { color: var(--dp-text) !important; }
.theme--dark .rtgms-dp .DayPickerNavigation_button { background: var(--dp-nav-bg) !important; border: 1px solid var(--dp-border) !important; }
.theme--dark .rtgms-dp .DayPickerNavigation_button__default svg { fill: var(--dp-nav-icon) !important; }
.theme--dark .rtgms-dp .DayPicker_weekHeader_li small { color: var(--dp-week-header) !important; }
.theme--dark .rtgms-dp .CalendarDay__default    { background: var(--dp-day-bg) !important; border: 1px solid var(--dp-panel) !important; color: var(--dp-text) !important; }
.theme--dark .rtgms-dp .CalendarDay__default:hover { background: var(--dp-day-hover) !important; }
.theme--dark .rtgms-dp .CalendarDay__today      { box-shadow: 0 0 0 1px var(--dp-today-ring) inset !important; }
.theme--dark .rtgms-dp .CalendarDay__selected,
.theme--dark .rtgms-dp .CalendarDay__selected:active { background: var(--dp-day-selected) !important; color: var(--dp-day-selected-text) !important; border: 1px solid var(--dp-day-selected) !important; }
.theme--dark .rtgms-dp .CalendarDay__blocked_out_of_range { color: var(--dp-text-muted) !important; background: #1b2130 !important; opacity: .7 !important; }
.theme--dark .rtgms-dp .DayPickerKeyboardShortcuts__panel { background: var(--dp-help-panel-bg) !important; color: var(--dp-help-panel-text) !important; border: 1px solid var(--dp-border) !important; }
.theme--dark .rtgms-dp .DayPickerKeyboardShortcuts__kbd   { background: var(--dp-kbd-bg) !important; border: 1px solid var(--dp-kbd-border) !important; color: #fff !important; }
.DayPickerKeyboardShortcuts__panel { background: #1b2130 !important; color: #eef3f8 !important; border: 1px solid #3a465b !important; box-shadow: 0 10px 30px rgba(0,0,0,.45) !important; }
.DayPickerKeyboardShortcuts__kbd   { background: #2b3347 !important; border: 1px solid #495873 !important; color: #fff !important; }
.DayPickerKeyboardShortcuts__close { color: #eef3f8 !important; }


/* ==========================================================================
   11. SPECYFICZNE PANELE
   Reguły dla konkretnych komponentów Dash (settings, admin, alert-service).
   Używamy !important bo Dash wstrzykuje inline style z Pythona.
   ========================================================================== */

/* Settings panel (high_all_settings / medium_all_settings) */
#all-settings-block span,
#medium-settings-block span { color: var(--fg) !important; }
#all-settings-block [style*="border: 1px solid"],
#medium-settings-block [style*="border: 1px solid"] { border-color: var(--border) !important; background: var(--bg-subtle) !important; }
#all-settings-block button,
#medium-settings-block button { background: var(--card-bg) !important; color: var(--fg) !important; border-color: var(--border) !important; }
#all-settings-block button:hover,
#medium-settings-block button:hover { background: var(--bg-subtle) !important; border-color: var(--primary) !important; }
#all-settings-block [style*="width: 1px"],
#medium-settings-block [style*="width: 1px"] { background: var(--border) !important; }
#all-settings-block label,
#medium-settings-block label { color: var(--fg) !important; }

/* High CNO panel */
.high-cno label,
.high-cno span { color: var(--fg) !important; font-family: var(--font-body) !important; font-size: var(--font-size-sm) !important; }

/* Low Anritsu panel */
#low-anr-wrapper span,
#low-anr-wrapper label { color: var(--fg) !important; }
#low-anr-wrapper [style*="border: 1px solid"] { border-color: var(--border) !important; background: var(--bg-subtle) !important; }
#low-anr-wrapper button { background: var(--card-bg) !important; color: var(--fg) !important; border-color: var(--border) !important; }
#low-anr-wrapper button:hover { background: var(--bg-subtle) !important; border-color: var(--primary) !important; }

/* Alert service — dropdowny muszą wychodzić poza kartę */
#alert-service-card,
#alert-service-card .card__content,
#alert-service-card .card__body {
  overflow: visible !important;
}

#alert-service-card .card__content { padding: 20px 28px 36px 28px !important; color: var(--fg); }
#alert-service-card label,
#alert-service-card p,
#alert-service-card span { color: var(--fg); }
#alert-service-card .muted,
#alert-service-card p.muted { color: var(--fg-muted); }
#alert-service-card .dash-checklist label { color: var(--fg) !important; }
#alert-service-card input[type="email"] { background: var(--bg-subtle); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; }
#alert-service-card input[type="email"]::placeholder { color: var(--fg-muted); opacity: .7; }

/* Auth / Admin */
body.dark { background: var(--bg); color: var(--fg); }

.auth-card {
  width: 100%; max-width: 560px; margin: 1.25rem auto;
  background: var(--card-bg); color: var(--fg);
  border: 1px solid var(--card-border); border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,.08); padding: 18px 20px;
}
.auth-card .auth-card__title { font-size: 1.35rem; font-weight: 800; margin: 0 0 0.75rem; color: var(--fg); }

:root {
  --auth-pill-bg:    #374151; --auth-pill-border: #374151;
  --auth-pill-fg:    #ffffff; --auth-pill-hover:  #2d3340;
}
.header .auth { display: flex !important; flex-direction: column !important; align-items: flex-end !important; gap: 0.35rem !important; }
.header .auth a {
  background: var(--auth-pill-bg) !important; border: 1px solid var(--auth-pill-border) !important;
  color: var(--auth-pill-fg) !important; border-radius: 9999px !important;
  padding: 0.35rem 0.7rem !important; font-weight: 700 !important;
  display: inline-flex !important; align-items: center !important; gap: 0.35rem !important; text-decoration: none !important;
}
.header .auth a:hover { background: var(--auth-pill-hover) !important; transform: translateY(-1px); }
.header .auth .auth-name { background: transparent !important; border: 0 !important; padding: 0 !important; font-weight: 600; color: var(--header-fg); }

/* Formularze admin */
.form { display: block; }
.form__row { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.75rem; }
.form__row label { font-weight: 700; color: var(--fg); }
.form__row input,
.form__row select,
.form__row textarea { appearance: none; background: var(--card-bg); color: var(--fg); border: 1px solid var(--card-border); border-radius: 10px; padding: 0.55rem 0.7rem; outline: none; font-family: var(--font-body); }
.form__row input:focus,
.form__row select:focus,
.form__row textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 22%, transparent); }
.form__actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.25rem; }
.form__hint { margin-top: 0.35rem; color: var(--fg-muted); font-size: var(--font-size-sm); }
.flash-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.5rem 0 0.75rem; }
.flash { background: color-mix(in oklab, var(--primary) 12%, var(--card-bg)); border: 1px solid var(--card-border); color: var(--fg); padding: 0.55rem 0.7rem; border-radius: 10px; }
.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.6rem; }
.toolbar__item input { background: var(--card-bg); color: var(--fg); border: 1px solid var(--card-border); border-radius: 10px; padding: 0.45rem 0.55rem; font-family: var(--font-body); }

/* Tabela admin */
.page.admin-page .table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--table-bg); color: var(--table-fg);
  border: 1px solid var(--table-border); border-radius: 12px;
  font-size: 0.92rem; box-sizing: border-box;
}
.page.admin-page .table th,
.page.admin-page .table td { box-sizing: border-box; }
.page.admin-page .table thead { position: sticky; top: 0; z-index: 8; background: var(--table-header-bg); box-shadow: 0 1px 0 var(--table-border); }
.page.admin-page .table thead th { border-bottom: 1px solid var(--table-border); padding: 0; white-space: nowrap; }
.page.admin-page .table thead th .th-inner,
.page.admin-page .table thead th .th__label { display: block; padding: 0.6rem 0.9rem 0.6rem 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page.admin-page .table tbody td { border-bottom: 1px solid var(--table-border); padding: 0.55rem 0.65rem; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page.admin-page .table tbody tr:nth-child(odd)  td { background: var(--table-bg); }
.page.admin-page .table tbody tr:nth-child(even) td { background: var(--table-stripe-bg); }
.page.admin-page .table tbody tr:hover td { background: var(--table-hover-bg); transition: background .12s; }

/* Szerokości kolumn tabeli admin */
.page.admin-page .table thead th:nth-child(1),  .page.admin-page .table tbody td:nth-child(1)  { min-width: 64px;  width: 72px;  text-align: right; }
.page.admin-page .table thead th:nth-child(2),  .page.admin-page .table tbody td:nth-child(2)  { min-width: 260px; width: 300px; word-break: break-all; }
.page.admin-page .table thead th:nth-child(3),  .page.admin-page .table tbody td:nth-child(3)  { min-width: 88px;  width: 100px; text-align: center; }
.page.admin-page .table thead th:nth-child(4),  .page.admin-page .table tbody td:nth-child(4)  { min-width: 104px; width: 116px; text-align: center; }
.page.admin-page .table thead th:nth-child(5),  .page.admin-page .table tbody td:nth-child(5)  { min-width: 104px; width: 116px; text-align: center; }
.page.admin-page .table thead th:nth-child(6),  .page.admin-page .table tbody td:nth-child(6)  { min-width: 104px; width: 116px; text-align: center; }
.page.admin-page .table thead th:nth-child(7),  .page.admin-page .table tbody td:nth-child(7)  { min-width: 130px; width: 150px; }
.page.admin-page .table thead th:nth-child(8),  .page.admin-page .table tbody td:nth-child(8)  { min-width: 150px; width: 170px; }
.page.admin-page .table thead th:nth-child(9),  .page.admin-page .table tbody td:nth-child(9)  { min-width: 130px; width: 150px; }
.page.admin-page .table thead th:nth-child(10), .page.admin-page .table tbody td:nth-child(10) { min-width: 180px; width: 200px; }
.page.admin-page .table thead th:nth-child(11), .page.admin-page .table tbody td:nth-child(11) { min-width: 140px; width: 160px; }
.page.admin-page .table thead th:nth-child(12), .page.admin-page .table tbody td:nth-child(12) { min-width: 88px;  width: 100px; text-align: center; }
.page.admin-page .table thead th:nth-child(13), .page.admin-page .table tbody td:nth-child(13) { min-width: 106px; width: 120px; text-align: center; }
.page.admin-page .table thead th:nth-child(14), .page.admin-page .table tbody td:nth-child(14) { min-width: 170px; width: 190px; }
.page.admin-page .table thead th:nth-child(15), .page.admin-page .table tbody td:nth-child(15) { min-width: 170px; width: 190px; }
.page.admin-page .table thead th:nth-child(16), .page.admin-page .table tbody td:nth-child(16) { min-width: 240px; width: 280px; }
.page.admin-page .table thead th:nth-child(17), .page.admin-page .table tbody td:nth-child(17) { min-width: 320px; width: 360px; }

/* Resize kolumn admin */
.page.admin-page .table.table--resizable { table-layout: fixed; }
.page.admin-page .table.table--resizable thead th { position: relative; }
.page.admin-page .table.table--resizable .col-resizer { position: absolute; top: 0; right: 0; width: 12px; height: 100%; cursor: col-resize; user-select: none; }
.page.admin-page .table.table--resizable .col-resizer::before { content: ""; position: absolute; top: 0; left: 5px; width: 3px; height: 100%; background: var(--primary); opacity: .45; transition: opacity .12s; }
.page.admin-page .table.table--resizable .col-resizer:hover::before { opacity: .98; }
.table--resizing * { cursor: col-resize !important; }
.col-resize-guide { position: fixed; top: 0; bottom: 0; width: 2px; background: var(--primary); pointer-events: none; z-index: 9999; }

.page.admin-page .filters { display: grid !important; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 0.5rem; background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 10px; padding: 0.6rem; }
.page.admin-page .status { display: inline-flex; align-items: center; justify-content: center; width: 1.6em; height: 1.6em; border-radius: 50%; font-weight: 800; border: 1px solid var(--card-border); }
.page.admin-page .status--ok   { background: rgba(34,197,94,.18);  color: #16a34a; border-color: rgba(34,197,94,.35); }
.page.admin-page .status--err  { background: rgba(239,68,68,.15);  color: #b91c1c; border-color: rgba(239,68,68,.35); }
.page.admin-page .status--warn { background: rgba(245,158,11,.15); color: #b45309; border-color: rgba(245,158,11,.35); }
.page.admin-page .badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: .82em; font-weight: 700; border: 1px solid var(--card-border); }
.page.admin-page .pager { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; margin-top: .5rem; }
.page.admin-page .btn.btn--sm { font-size: .86rem; padding: .4rem .55rem; border-radius: 8px; }
.page.admin-page .btn.btn--warn { background: #f59e0b; color: #0b1220; border-color: #f59e0b; }


/* ==========================================================================
   12. BREAKPOINTY RESPONSYWNE
   Kolejność: od najszerszego do najwęższego.
   Każdy breakpoint nadpisuje tylko to co się zmienia — reszta dziedziczy.
   ========================================================================== */

/* ── 1366px: laptop/mały desktop ────────────────────────────────────────── */
@media (max-width: 1366px) {
  :root {
    --page-gutter: clamp(10px, 1.5vw, 18px);
    --esa-h:       clamp(71px, 8.4dvh, 98px);
    --rtgms-h:     clamp(32px, 3.8dvh, 44px);
    --high-top-h:  clamp(360px, 50dvh, 528px);
    --low-top-h:   clamp(360px, 50dvh, 528px);
  }

  .title                         { font-size: clamp(1.1rem, 2vw, 1.5rem); }
  /* Kolumna tabeli ma min-width żeby tekst się nie ciął */
  .grid-menu_map--split          { grid-template-columns: minmax(240px, 290px) 1fr; }
  .grid-high-top,
  .grid-low-top                  { grid-template-columns: minmax(200px, 3fr) 7fr; }
}

/* ── 1024px: tablet poziomo / mały laptop ───────────────────────────────── */
@media (max-width: 1024px) {
  :root {
    --header-h:    clamp(87px, 10dvh, 105px);
    --menu-h:      clamp(40px, 6dvh, 52px);
    --footer-h:    clamp(48px, 7dvh, 64px);
    --page-gutter: 10px;
    --esa-h:       58px;
    --rtgms-h:     26px;
  }

  .title { font-size: clamp(0.95rem, 1.8vw, 1.3rem); }

  /* Strona główna: tabela pod mapą */
  .grid-menu_map--split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr minmax(200px, 40%);
    padding: var(--gap-sm) var(--page-gutter);
    gap: var(--gap-sm);
  }
  .grid-menu_map--split .grid-item:first-child { order: 2; }  /* tabela pod mapą */
  .grid-menu_map--split .grid-item:last-child  { order: 1; }  /* mapa na górze */

  /* High/Low: mapa na górze, tabela pod */
  .grid-high-top { grid-template-columns: 1fr; grid-template-rows: 65dvh minmax(160px, auto); height: auto; overflow: visible; }
  .grid-high-top__map   { order: 1; }
  .grid-high-top__table { order: 2; }
  .grid-low-top  { grid-template-columns: 1fr; grid-template-rows: 65dvh minmax(160px, auto); height: auto; overflow: visible; }
  .grid-low-top__map    { order: 1; }
  .grid-low-top__table  { order: 2; }

  /* Wykresy: jedna kolumna */
  .charts-grid-2col { grid-template-columns: 1fr; }

  /* High/Low gridy: jedna kolumna, auto height */
  .grid-menu_high { grid-template-columns: 1fr; overflow-y: visible; height: auto; }
  .grid-menu_low  { overflow-y: visible; height: auto; }
  .grid-menu_high .card--tall { min-height: clamp(320px, 45dvh, 500px); }

  .menu { gap: 1px; }
  .menu__link { padding: 4px 10px; font-size: var(--font-size-xs); }
}

/* ── 768px: tablet pionowo ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --header-h:       clamp(78px, 10dvh, 90px);
    --menu-h:         auto;   /* menu rośnie gdy linki się zawijają */
    --footer-h:       clamp(44px, 8dvh, 60px);
    --page-gutter:    8px;
    --font-size-base: 0.875rem;
    --esa-h:          62px;
    --rtgms-h:        28px;
  }

  /* Menu: zawijanie do wielu wierszy */
  .menu {
    height: auto; min-height: 36px; flex-wrap: wrap;
    overflow: visible; padding: 4px var(--page-gutter);
    gap: 3px; align-items: flex-start; align-content: flex-start;
  }
  .menu__link { height: 30px; padding: 4px 10px; }

  /* Grid row 2 (menu) musi rosnąć gdy linki się zawijają */
  #app-container { grid-template-rows: var(--header-h) auto 1fr auto; }

  .grid-menu_map--split { grid-template-rows: minmax(220px, 1fr) minmax(160px, auto); overflow-y: auto; }
  .card--tall { min-height: 260px; }
  .page-full  { padding: var(--gap-sm) var(--page-gutter); }

  /* Footer: loga 24/30px */
  .footer__left img,
  .footer__left a img          { height: 24px !important; max-height: 24px !important; }
  .footer__left a:first-child img { height: 30px !important; max-height: 30px !important; }
  .footer__left { gap: 6px; flex-wrap: wrap; }

  #cookie-banner { flex-direction: column; align-items: flex-start; gap: var(--gap-sm); }
}

/* ── 600px: telefon duży — przełącznik na layout mobilny ───────────────── */
@media (max-width: 600px) {
  :root {
    --header-h:    auto;   /* header rośnie do zawartości na małym ekranie */
    --menu-h:      auto;
    --footer-h:    auto;
    --page-gutter: 6px;
    --esa-h:       44px;
    --rtgms-h:     20px;
  }

  /* Na mobile html/body scrollują normalnie (desktop ma overflow:hidden) */
  html, body {
    height: auto;
    max-height: none;
    overflow: auto;
    overflow-x: hidden;
  }

  /* Kontener przełącza się z grid na flex — prostszy model na telefonie */
  #app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
    overflow-x: hidden;
  }

  .header {
    flex-shrink: 0; width: 100%; box-sizing: border-box;
    padding: 6px; height: auto; min-height: 60px; flex-wrap: wrap;
  }
  .branding  { gap: 4px; }
  .title     { font-size: 0.75rem; white-space: normal; line-height: 1.2; max-width: 160px; }

  .menu {
    flex-shrink: 0; width: 100%; box-sizing: border-box;
    height: auto; min-height: 32px; flex-wrap: wrap;
    overflow-x: hidden; padding: 3px 4px; gap: 2px;
  }
  .menu__link { height: 26px; padding: 3px 7px; font-size: 0.7rem; }

  .main { flex: 1; width: 100%; max-width: 100%; box-sizing: border-box; overflow-x: hidden; height: auto; }

  /* Footer: kolumna — loga na górze, tekst poniżej */
  .footer { flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px var(--page-gutter); min-height: 0; }
  .footer__left { flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; }
  .footer__left img,
  .footer__left a img          { height: 20px !important; max-height: 20px !important; }
  .footer__left a:first-child img { height: 24px !important; max-height: 24px !important; }
  .footer__right, #footer-right-text { text-align: left; width: 100%; font-size: 0.65rem; }

  .card { max-width: 100%; box-sizing: border-box; }
  .card__body  { padding: var(--gap-sm); }
  .card__title { padding: 4px var(--gap-md); font-size: 0.9rem; }
  .dash-header, .dash-cell { font-size: 0.7rem !important; padding: 4px !important; }
  .settings-panel { flex-direction: column; gap: var(--gap-sm); }
  .form-group     { min-width: 100%; }

  /* Siatka mapy głównej: flex column */
  .grid-menu_map--split { display: flex; flex-direction: column; width: 100%; box-sizing: border-box; padding: var(--gap-sm) var(--page-gutter); height: auto; gap: var(--gap-sm); overflow: visible; }
  .grid-menu_map--split .grid-item { width: 100%; min-width: 0; }
  .grid-menu_map--split .grid-item:first-child { order: 2; }  /* tabela — pod mapą */
  .grid-menu_map--split .grid-item:last-child  { order: 1; }  /* mapa — na górze */
  .grid-menu_map--split .grid-item:last-child > .card  { height: 65dvh; min-height: 280px; overflow: hidden; }  /* mapa */
  .grid-menu_map--split .grid-item:first-child > .card { max-height: 45dvh; overflow: hidden; }  /* tabela — ograniczona */
  .grid-menu_map--split .grid-item:first-child .card__body { overflow-y: auto; }  /* tabela scrolluje wewnątrz */

  /* High/Low: flex column */
  .grid-high-top, .grid-low-top { display: flex; flex-direction: column; width: 100%; box-sizing: border-box; height: auto; gap: var(--gap-sm); overflow: visible; }
  .grid-high-top__map, .grid-low-top__map,
  .grid-high-top__table, .grid-low-top__table { width: 100%; min-width: 0; box-sizing: border-box; }
  .grid-high-top__map   { order: 1; } .grid-high-top__table { order: 2; }
  .grid-low-top__map    { order: 1; } .grid-low-top__table  { order: 2; }
  .grid-high-top__map, .grid-low-top__map { height: 65dvh; min-height: 280px; flex-shrink: 0; }
  .grid-high-top__map > .card, .grid-low-top__map > .card { height: 100%; min-height: 0; flex-shrink: 0; overflow: hidden; width: 100%; box-sizing: border-box; }
  .grid-high-top__table > .card,
  .grid-low-top__table  > .card {
    display: flex; flex-direction: column;
    height: auto; flex-shrink: 0; width: 100%; overflow: visible;
  }
  .grid-high-top__table > .card { max-height: 280px; }
  .grid-low-top__table  > .card { max-height: 340px; }
  .grid-high-top__table > .card .datatable--stretch,
  .grid-low-top__table  > .card .datatable--stretch {
    flex: 1; min-height: 0; overflow: hidden;
  }
  .grid-high-top__table > .card .table__refresh,
  .grid-low-top__table  > .card .table__refresh {
    flex-shrink: 0;  /* stopka zawsze widoczna */
  }

  /* Tabele: poziomy scroll */
  #high-table-wrapper .dash-spreadsheet-container,
  #low_table_wrapper  .dash-spreadsheet-container,
  #main-table-wrapper .dash-spreadsheet-container { overflow-x: auto !important; overflow-y: auto !important; }

  .grid-menu_high, .grid-menu_low { width: 100%; box-sizing: border-box; padding: var(--gap-sm) var(--page-gutter); overflow-y: visible; height: auto; }
  .grid-menu_high .grid-item, .grid-menu_low .grid-item,
  .grid-menu_high .grid-item--full, .grid-menu_low .grid-item--full { width: 100%; min-width: 0; box-sizing: border-box; }
  .map-frame { min-height: 0; }
}

/* ── 480px: telefon średni ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root { --page-gutter: 4px; --esa-h: 40px; --rtgms-h: 18px; }

  .title { font-size: 0.65rem; max-width: 120px; }
  .btn--lang          { padding: 2px 5px; font-size: 0.65rem; }
  .btn--theme, #btn-theme { width: 28px; height: 28px; font-size: 0.9rem; }
  .menu               { padding: 2px 4px; gap: 2px; }
  .menu__link         { height: 24px; padding: 2px 6px; font-size: 0.65rem; }

  .grid-high-top__map, .grid-low-top__map { height: 65dvh; min-height: 260px; flex-shrink: 0; }
  .grid-high-top__map > .card, .grid-low-top__map > .card { height: 100%; min-height: 0; }
  .grid-high-top__table > .card { max-height: 240px; }
  .grid-low-top__table  > .card { max-height: 300px; }

  .footer { flex-direction: column; align-items: flex-start; padding: 6px var(--page-gutter); gap: 4px; min-height: 0; }
  .footer__left { display: flex !important; flex-wrap: wrap; gap: 6px; width: 100%; }
  .footer__left img,
  .footer__left a img          { display: block !important; height: 16px !important; max-height: 16px !important; }
  .footer__left a:first-child img { height: 20px !important; max-height: 20px !important; }
  .footer__right, #footer-right-text { width: 100%; text-align: left; font-size: 0.6rem; }
}

/* ── 360px: mały telefon (np. 360×800) — dedykowany breakpoint ──────────── */
@media (max-width: 360px) {
  :root { --page-gutter: 4px; --esa-h: 36px; --rtgms-h: 16px; }

  .title                { font-size: 0.6rem; max-width: 100px; }
  .header               { padding: 4px; gap: 4px; }
  .menu                 { padding: 2px 3px; gap: 1px; }
  .menu__link           { height: 22px; padding: 2px 5px; font-size: 0.6rem; }
  .card__title          { font-size: 0.8rem; padding: 5px 8px; }
  .card__body           { padding: 6px; }
  .dash-header, .dash-cell { font-size: 0.65rem !important; padding: 3px !important; }

  .grid-high-top__map, .grid-low-top__map { height: 65dvh; min-height: 240px; flex-shrink: 0; }
  .grid-high-top__map > .card, .grid-low-top__map > .card { height: 100%; min-height: 0; }
  .grid-high-top__table > .card { max-height: 220px; }
  .grid-low-top__table  > .card { max-height: 280px; }

  .footer               { padding: 4px var(--page-gutter); gap: 4px; }
  .footer__left img,
  .footer__left a img          { height: 14px !important; max-height: 14px !important; }
  .footer__left a:first-child img { height: 17px !important; max-height: 17px !important; }
  .footer__right, #footer-right-text { font-size: 0.58rem; }
}

/* Admin: dodatkowy breakpoint dla filtrów */
@media (max-width: 1100px) {
  .page.admin-page .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .page.admin-page .table thead { display: none; }
  .page.admin-page .table,
  .page.admin-page .table tbody,
  .page.admin-page .table tr,
  .page.admin-page .table td { display: block; width: 100%; }
  .page.admin-page .table tr { margin: 0.5rem 0; border: 1px solid var(--table-border); border-radius: 10px; }
  .page.admin-page .table td { display: grid; grid-template-columns: 160px 1fr; gap: 0.5rem; border-bottom: 1px solid var(--table-border); white-space: normal; }
  .page.admin-page .table td::before { content: attr(data-label); font-weight: 700; color: var(--fg-muted); }
}
@media (max-width: 560px) {
  .auth-card { padding: 16px; border-radius: 14px; }
}


/* ==========================================================================
   13. UTILITY CLASSES
   Krótkie klasy pomocnicze — używać oszczędnie, tylko gdy sens jest jasny.
   ========================================================================== */

/* Kolor tekstu */
.text-muted    { color: var(--fg-muted); }
.text-sm       { font-size: var(--font-size-sm); }
.text-xs       { font-size: var(--font-size-xs); }
.text-primary  { color: var(--primary); }
.font-bold     { font-weight: 700; }
.font-medium   { font-weight: 500; }

/* Widoczność */
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Marginesy / padding */
.mt-sm  { margin-top: var(--gap-sm); }
.mt-md  { margin-top: var(--gap-md); }
.mt-lg  { margin-top: var(--gap-lg); }
.mb-sm  { margin-bottom: var(--gap-sm); }
.mb-md  { margin-bottom: var(--gap-md); }
.p-md   { padding: var(--gap-md); }

/* Flex helpers */
.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap    { flex-wrap: wrap; }
.flex-1       { flex: 1; min-height: 0; }  /* min-height:0 kluczowe dla nested flex */
.gap-sm       { gap: var(--gap-sm); }
.gap-md       { gap: var(--gap-md); }

/* Overflow */
.overflow-hidden  { overflow: hidden; }
.overflow-auto    { overflow: auto; }
.overflow-y-auto  { overflow-y: auto; }

/* Scrollbar cienki */
.scrollbar-thin::-webkit-scrollbar       { width: 5px; height: 5px; }
.scrollbar-thin::-webkit-scrollbar-track { background: transparent; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Divider */
.divider { height: 1px; background: var(--border); margin: var(--gap-md) 0; }

/* Link */
.link       { color: var(--link-color); text-decoration: underline; cursor: pointer; }
.link:hover { color: var(--primary-hover); }

/* Status dot */
.status-dot         { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot--ok     { background: #22c55e; }
.status-dot--warn   { background: #f59e0b; }
.status-dot--error  { background: #ef4444; }
.status-dot--nodata { background: #94a3b8; }
