/* =====================================================================
   Bramka SMS - panel administracyjny
   Czysty CSS, bez zewnetrznych zaleznosci. Motyw jasny/ciemny:
   prefers-color-scheme + reczne nadpisanie przez data-theme na <html>.
   ================================================================== */

/* ---------------------------- tokeny ------------------------------ */
:root {
  color-scheme: light;

  --surface-0: #f4f4f1;   /* tlo strony      */
  --surface-1: #fcfcfb;   /* karty, tabele   */
  --surface-2: #f0efec;   /* naglowki, hover */
  --border:    #e0dfd9;
  --border-strong: #cbcac2;

  --text-1: #0b0b0b;
  --text-2: #52514e;
  --text-3: #85837c;

  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --accent-soft: #e7f0fc;

  /* paleta statusow (stala, nietematyzowana) */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  /* 'unknown' - wynik nierozstrzygniety. Celowo pomaranczowy: ani zielony
     (nie wiemy, czy sie udalo), ani czerwony (to nie jest zwykly blad). */
  --unknown:  #d2690a;

  --good-soft:     #e4f5e4;
  --warning-soft:  #fdf1d6;
  --critical-soft: #fae4e4;
  --unknown-soft:  #fceadb;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ciemny z ustawien systemu (ustepuje recznemu przelacznikowi) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border:    #34342f;
    --border-strong: #4a4a43;

    --text-1: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #908f85;

    --accent:      #3987e5;
    --accent-ink:  #ffffff;
    --accent-soft: #17304d;

    --good-soft:     #14301a;
    --warning-soft:  #3a2f11;
    --critical-soft: #3a1c1c;
    --unknown:       #ff9d45;
    --unknown-soft:  #3c2612;

    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 14px rgba(0, 0, 0, .35);
  }
}

/* ciemny wymuszony przelacznikiem */
:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border:    #34342f;
  --border-strong: #4a4a43;

  --text-1: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #908f85;

  --accent:      #3987e5;
  --accent-ink:  #ffffff;
  --accent-soft: #17304d;

  --good-soft:     #14301a;
  --warning-soft:  #3a2f11;
  --critical-soft: #3a1c1c;
  --unknown:       #ff9d45;
  --unknown-soft:  #3c2612;

  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 14px rgba(0, 0, 0, .35);
}

/* ---------------------------- podstawy ---------------------------- */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-1);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

[hidden] { display: none !important; }

.muted { color: var(--text-2); }
.small { font-size: .82rem; }
.mono  { font-family: var(--mono); }
.num   { text-align: right; font-variant-numeric: tabular-nums; }

a { color: var(--accent); }

/* ---------------------------- formanty ---------------------------- */
.input,
.field input,
.field select,
.field textarea,
select.input {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-1);
  font: inherit;
}

.input:focus-visible,
.field input:focus-visible,
select.input:focus-visible,
.btn:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Znacznik tempa w tabeli routerow - ma sie roznic od licznikow obok,
   bo to ustawienie, a nie zmierzona wartosc. */
.badge-tempo { color: var(--accent); white-space: nowrap; }

/* ------------------- zwijane objasnienia ("i") ---------------------- */
/* Opisy sa potrzebne raz - przy poznawaniu panelu - a potem tylko zabieraja
   miejsce nad tabelami. Natywne <details>: zero JavaScriptu, dziala z klawiatury
   i z czytnikiem ekranu, a przegladarka sama pamieta stan w obrebie strony. */
.info {
  margin: .6rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  font-size: .88rem;
}
.info > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .6rem;
  color: var(--text-2);
  cursor: pointer;
  list-style: none;          /* chowamy domyslny trojkat... */
  user-select: none;
}
.info > summary::-webkit-details-marker { display: none; }   /* ...takze w WebKit */
.info > summary:hover { color: var(--text-1); background: var(--surface-2); }
.info > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* kolko z litera "i" - jedyny staly element belki */
.info-i {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .75rem;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
}

/* strzalka po prawej - obraca sie po rozwinieciu */
.info > summary::after {
  content: "\25BE";
  margin-left: auto;
  font-size: .7rem;
  color: var(--text-3);
  transition: transform .15s ease;
}
.info[open] > summary::after { transform: rotate(180deg); }
.info[open] > summary { border-bottom: 1px solid var(--border); }

.info-body {
  padding: .6rem .7rem;
  color: var(--text-2);
  line-height: 1.55;
}
.info-body p { margin: 0 0 .5rem; }
.info-body p:last-child { margin-bottom: 0; }
.info-body code { font-family: var(--mono); font-size: .85em; }

/* Warianty dla objasnien, ktore niosa ostrzezenie - belka zachowuje kolor
   znaczenia, ale tresc nadal jest schowana. */
.info-warn  { border-color: var(--warning);  background: var(--warning-soft); }
.info-warn  > summary { color: var(--text-1); }
.info-warn  .info-i { background: var(--warning); color: #000; }
.info-unknown { border-color: var(--unknown); background: var(--unknown-soft); }
.info-unknown > summary { color: var(--text-1); }
.info-unknown .info-i { background: var(--unknown); color: #000; }

/* -------------------------- pasek filtrow --------------------------- */
/* Pola zawijaja sie do kolejnego wiersza zamiast rozpychac panel - przy czterech
   filtrach na telefonie inaczej znika przycisk "Filtruj". */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-end;
  margin: .6rem 0;
  padding: .7rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
}
.filter { display: flex; flex-direction: column; gap: .25rem; flex: 1 1 10rem; }
.filter > span { font-size: .8rem; color: var(--text-2); }
.filter .input { width: 100%; }
.filter-actions { flex: 0 0 auto; flex-direction: row; gap: .4rem; align-self: flex-end; }

/* ------------------ grupa pol w formularzu (tempo) ------------------ */
/* Tempo to dwie liczby czytane razem ("10 na 60 s"), wiec musza stac obok
   siebie i byc wizualnie oddzielone od reszty formularza - inaczej wygladaja
   jak dwa niezwiazane ustawienia. */
.fieldset {
  margin: .8rem 0;
  padding: .7rem .8rem .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.fieldset legend {
  padding: 0 .35rem;
  font-size: .85rem;
  color: var(--text-2);
}
.fieldset .field { margin-bottom: .5rem; }

.pair { display: flex; gap: .7rem; flex-wrap: wrap; }
.pair > .field { flex: 1 1 8rem; margin-bottom: .5rem; }

/* ------------------- edytor profilu routera (JSON) ------------------ */
/* Profil wpisuje sie recznie, wiec pole musi zachowywac wciecia i nie zawijac
   agresywnie - stad monospace, tabulacja 2 i pionowa zmiana rozmiaru. */
.code-area {
  width: 100%;
  font-family: var(--mono);
  font-size: .85rem;
  line-height: 1.5;
  tab-size: 2;
  resize: vertical;
  min-height: 12rem;
  white-space: pre;
  overflow-x: auto;
}

/* Profil WBUDOWANY: pole jest readOnly (tresc ma sie dac zaznaczyc i skopiowac),
   ale musi WYGLADAC na zablokowane - inaczej administrator pisze w nim zmiany,
   ktore i tak nie maja gdzie trafic. */
.code-area.is-locked {
  background: var(--surface-2);
  color: var(--text-2);
  border-style: dashed;
  cursor: not-allowed;
}

/* to samo dla zablokowanych pol tekstowych okna profilu */
.field input:disabled,
.field textarea:disabled {
  background: var(--surface-2);
  color: var(--text-3);
  cursor: not-allowed;
}

select.input { width: auto; min-width: 9rem; }
/* lista wyboru wewnatrz formularza (np. router konta) ma byc pelnej szerokosci -
   ta regula musi stac PO 'select.input', bo obie maja te sama specyficznosc */
.field select.input { width: 100%; }
.input-search { width: min(15rem, 45vw); }

.field { display: block; margin-bottom: .8rem; }
.field > span { display: block; margin-bottom: .25rem; font-size: .85rem; color: var(--text-2); }
.field em { font-style: normal; }

.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .45rem 0;
  font-size: .9rem;
}
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); flex: 0 0 auto; }
.check em { font-style: normal; color: var(--text-2); }
/* pole zablokowane swiadomie (np. wylaczenie routera domyslnego) - musi wygladac
   na zablokowane, inaczej admin klika i nie rozumie, czemu nic sie nie dzieje */
.check input:disabled { opacity: .5; }
.check input:disabled ~ span { color: var(--text-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .5rem .85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-1);
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }

.btn-danger { color: var(--critical); border-color: var(--border-strong); }
.btn-danger:hover:not(:disabled) { background: var(--critical-soft); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-1); }

/* Link wygladajacy jak przycisk (np. "Dokumentacja API" w gornym pasku).
   Reguly .btn pisane byly pod <button>, wiec dla <a> trzeba jeszcze zdjac
   podkreslenie i wymusic kolor - inaczej dziedziczy niebieski z 'a { color }'
   i odstaje od sasiednich przyciskow. */
a.btn { text-decoration: none; color: var(--text-1); }
a.btn-ghost { color: var(--text-2); }
a.btn-ghost:hover { color: var(--text-1); }

.btn-icon { padding: .4rem .55rem; font-size: 1rem; line-height: 1; }
.btn-block { width: 100%; padding: .6rem; font-size: 1rem; }
.btn-xs { padding: .25rem .5rem; font-size: .8rem; }

/* ---------------------------- komunikaty -------------------------- */
.alert {
  margin: .6rem 0;
  padding: .6rem .75rem;
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: .9rem;
}
.alert-error { border-left-color: var(--critical); background: var(--critical-soft); }
.alert-warn  { border-left-color: var(--warning);  background: var(--warning-soft); }
.alert-ok    { border-left-color: var(--good);     background: var(--good-soft); }
/* spokojna informacja - np. brak uprawnien konta smsapi do odczytu statusu modemu.
   Swiadomie NIE jest czerwona: to nie awaria, tylko ograniczenie uprawnien. */
.alert-info  { border-left-color: var(--accent);   background: var(--accent-soft); }
/* lista skutkow w komunikacie (np. co zrobi wymuszenie przy konflikcie 409) */
.alert ul { margin: .45rem 0 .55rem; padding-left: 1.15rem; }
.alert li { margin: .2rem 0; }
/* licznik kolejki pod ostrzezeniem w oknie edycji routera */
#router-edit-queue { margin-top: .45rem; font-weight: 600; }
#router-risk-live { margin: .4rem 0 0; }
/* wysylka o nierozstrzygnietym wyniku ('unknown') */
.alert-unknown { border-left-color: var(--unknown); background: var(--unknown-soft); }
.alert-unknown strong { color: var(--unknown); }
.alert-unknown em { font-style: normal; font-weight: 600; }

/* ---------------------------- logowanie --------------------------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(24rem, 100%);
  padding: 1.75rem;
  text-align: left;
}
.login-card h1 { margin-bottom: .1rem; }
.login-card > .muted { margin: 0 0 1.25rem; font-size: .9rem; }
.login-logo {
  display: inline-grid;
  place-items: center;
  width: 2.6rem; height: 2.6rem;
  margin-bottom: .9rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
}

/* ---------------------------- naglowek ---------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  max-width: 78rem;
  margin: 0 auto;
  padding: .6rem 1rem;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; }
.brand-mark {
  display: grid; place-items: center;
  width: 1.8rem; height: 1.8rem;
  border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink);
  font-size: .6rem; font-weight: 700;
}
.topbar-right { display: flex; align-items: center; gap: .4rem; }
.who { font-size: .85rem; color: var(--text-2); }

.tabs {
  display: flex;
  gap: .15rem;
  max-width: 78rem;
  margin: 0 auto;
  padding: 0 .5rem;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  padding: .6rem .9rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: .92rem;
  cursor: pointer;
}
.tab:hover { color: var(--text-1); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------------------- uklad strony ------------------------ */
.page { max-width: 78rem; margin: 0 auto; padding: 1.1rem 1rem 3rem; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: .9rem;
}
.panel-head-right { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: .9rem; }

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1rem;
  align-items: start;
}
.two-col > .card { margin-bottom: 0; }
@media (max-width: 40rem) { .two-col { gap: 0; } .two-col > .card { margin-bottom: 1rem; } }

/* ---------------------------- kafelki KPI ------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: .7rem;
  margin-bottom: 1rem;
}
.kpi {
  padding: .8rem .9rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-label {
  display: block;
  font-size: .78rem;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.kpi-value {
  display: block;
  margin-top: .25rem;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { display: block; margin-top: .15rem; font-size: .78rem; color: var(--text-3); }
.kpi-good     .kpi-value { color: var(--good); }
.kpi-critical .kpi-value { color: var(--critical); }
.kpi-accent   .kpi-value { color: var(--accent); }
.kpi-unknown  .kpi-value { color: var(--unknown); }
.kpi-unknown { border-color: var(--unknown); }

/* ---------------------------- tabele ------------------------------ */
.table-wrap { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  white-space: nowrap;
}
.table th, .table td {
  padding: .5rem .7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .w-act { width: 1%; }
.table .w-bar { width: 9rem; min-width: 9rem; }
.table .cell-msg { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; }
.table .cell-err { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; color: var(--critical); }
/* opis przerwanej wysylki przy statusie 'unknown' - to nie jest blad routera */
.table .cell-err-unknown { color: var(--unknown); }
/* wiersz z nierozstrzygnietym wynikiem - pomaranczowy znacznik przy lewej krawedzi */
.table tbody tr.row-unknown > td:first-child { box-shadow: inset 3px 0 0 var(--unknown); }
/* Przyciski akcji moga sie zawijac do drugiego wiersza zamiast rozpychac
   tabele w bok - przy czterech akcjach (Testuj/Edytuj/Domyslny/Usun) bez tego
   ostatni przycisk byl ucinany przy prawej krawedzi. */
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }

/* ------------------------ tabela routerow -------------------------- */
/* Komorki grupujace kilka wartosci pionowo (adres+login+modem, konta+wyslane).
   Interlinia ciasniejsza niz domyslna, zeby wiersz nie urosl nadmiernie. */
.table .cell-stack { line-height: 1.45; }
.table .cell-queue { color: var(--unknown, var(--text-2)); }

/* Nazwa routera i notatka moga sie zawijac - to jedyne pola pisane przez
   czlowieka, wiec bywaja dlugie. Reszta tabeli zostaje na nowrap. */
.table-routers td:first-child { white-space: normal; max-width: 16rem; }
.table-routers .w-act { white-space: normal; }
.empty { padding: 1.5rem; text-align: center; color: var(--text-3); white-space: normal; }

/* ---------------------- tabela profili routerow -------------------- */
/* Nazwa i opis profilu pisze czlowiek - moga byc dlugie, wiec sie zawijaja.
   Reszta kolumn (rodzaj, uzycie, akcje) zostaje na nowrap. */
.table-profiles td:first-child { white-space: normal; max-width: 30rem; }
.table-profiles .w-act { white-space: normal; }

/* Odstep miedzy sekcjami zakladki Ustawienia (Routery / Profile routerow) -
   bez niego naglowek drugiej sekcji sklejal sie z akapitem pierwszej. */
.section-gap { margin-top: 2rem; }

/* ---------------------------- odznaki ----------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .5rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-good     { background: var(--good-soft);     color: var(--good);     border-color: var(--good); }
.badge-critical { background: var(--critical-soft); color: var(--critical); border-color: var(--critical); }
.badge-warning  { background: var(--warning-soft);  color: var(--text-1);   border-color: var(--warning); }
.badge-accent   { background: var(--accent-soft);   color: var(--accent);   border-color: var(--accent); }
.badge-muted    { background: var(--surface-2);     color: var(--text-2);   border-color: var(--border-strong); }
/* 'unknown' - wlasny, pomaranczowy kolor; nie mylic z bledem ani z sukcesem */
.badge-unknown  { background: var(--unknown-soft);  color: var(--unknown);  border-color: var(--unknown); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
}
.pill-good     { background: var(--good-soft);     color: var(--good);     border-color: var(--good); }
.pill-warning  { background: var(--warning-soft);  color: var(--text-1);   border-color: var(--warning); }
.pill-critical { background: var(--critical-soft); color: var(--critical); border-color: var(--critical); }
/* neutralna plakietka - stan nieznany z powodu uprawnien, a nie awarii */
.pill-muted    { background: var(--surface-2);     color: var(--text-2);   border-color: var(--border-strong); }

/* ---------------------------- router ------------------------------ */
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .75rem;
}
.kv-item > dt { font-size: .78rem; color: var(--text-2); }
.kv-item > dd { margin: .1rem 0 0; font-size: 1.02rem; font-weight: 600; }
.kv-item .kv-note { font-size: .76rem; font-weight: 400; color: var(--text-3); }
.signal-good     { color: var(--good); }
.signal-warning  { color: var(--warning); }
.signal-critical { color: var(--critical); }

/* ---------------------------- routery (wiele kart SIM) ------------ */
/* Kafelki stanu na kokpicie - jeden na kazdy aktywny router. */
.router-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: .7rem;
}
.router-tile {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .7rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-0);
}
/* czerwona krawedz TYLKO przy realnej awarii - brak uprawnien zostaje neutralny */
.router-tile-bad { border-color: var(--critical); }

.router-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
}
.router-tile-name {
  display: flex;
  align-items: center;
  gap: .4rem;
  min-width: 0;
  flex-wrap: wrap;
}
.router-tile-name > strong { overflow-wrap: anywhere; }

.router-tile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 1rem;
  font-size: .82rem;
  color: var(--text-2);
}
.router-tile-err {
  margin: 0;
  color: var(--critical);
  overflow-wrap: anywhere;
}
.router-tile-err.muted { color: var(--text-3); }
.router-tile-act { display: flex; justify-content: flex-end; }

/* tabela routerow w Ustawieniach */
.row-off > td { opacity: .65; }
.cell-err-text { color: var(--critical); }
/* nazwa routera odziedziczonego (konto z router_id = NULL) - wyroznienie
   ma pokazac, ze to wartosc DZIEDZICZONA, a nie przypisana na sztywno */
.router-inherited { font-style: italic; }

/* ---------------------------- slupki dni -------------------------- */
.legend { display: flex; gap: .8rem; font-size: .78rem; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; }
.swatch-good { background: var(--good); }
.swatch-bad  { background: var(--critical); }

.days { display: grid; gap: .5rem; }
.day-row {
  display: grid;
  grid-template-columns: 4.4rem 1fr auto;
  align-items: center;
  gap: .6rem;
  font-size: .82rem;
}
.day-label { color: var(--text-2); font-variant-numeric: tabular-nums; }
.day-track {
  display: flex;
  gap: 2px;                     /* 2px przerwy miedzy wypelnieniami */
  height: 12px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.day-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.day-fill:first-child { border-radius: 4px 0 0 4px; }
.day-fill-sent   { background: var(--good); }
.day-fill-failed { background: var(--critical); }
.day-nums { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-nums .n-sent   { color: var(--good); font-weight: 600; }
.day-nums .n-failed { color: var(--critical); font-weight: 600; }

/* pasek zuzycia limitu */
.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.bar > i.bar-warning  { background: var(--warning); }
.bar > i.bar-critical { background: var(--critical); }

/* ---------------------------- paginacja --------------------------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  flex-wrap: wrap;
}

/* ---------------------------- modale ------------------------------ */
.dlg {
  width: min(30rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  /* formularz routera jest dlugi - bez tego dolne przyciski wychodza poza ekran
     telefonu i nie da sie ich dosiegnac */
  overflow-y: auto;
  padding: 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-1);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.dlg-wide { width: min(46rem, calc(100vw - 2rem)); }
.dlg::backdrop { background: rgba(0, 0, 0, .5); }
.dlg h3 { margin-bottom: .9rem; }
.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.1rem;
}
.row-form { display: flex; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.row-form .input { flex: 1 1 12rem; }

.secret-box {
  margin: .8rem 0;
  padding: .7rem;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.secret-box code {
  display: block;
  font-family: var(--mono);
  font-size: .9rem;
  word-break: break-all;
  user-select: all;
}

/* ---------------------------- powiadomienia ----------------------- */
.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: min(22rem, calc(100vw - 2rem));
}
.toast {
  padding: .6rem .8rem;
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  box-shadow: var(--shadow);
  font-size: .88rem;
}
.toast-ok    { border-left-color: var(--good); }
.toast-error { border-left-color: var(--critical); }
.toast-info  { border-left-color: var(--accent); }

/* ---------------------------- telefon ----------------------------- */
@media (max-width: 34rem) {
  body { font-size: 14px; }
  .page { padding: .8rem .6rem 3rem; }
  .topbar-in { padding: .5rem .6rem; }
  .brand-text { display: none; }
  .who { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Na telefonie z linku do dokumentacji zostaje sama ikona - pelna etykieta
     rozpychala pasek i wypychala przycisk "Wyloguj" poza ekran. Znaczenie
     niesie aria-label na <a>, wiec czytnik ekranu nic nie traci. */
  .btn-docs-text { display: none; }
  .btn-docs { padding: .4rem .55rem; }
  .panel-head-right { width: 100%; }
  .input-search { width: 100%; }
  .kpi-value { font-size: 1.45rem; }
  .table th, .table td { padding: .45rem .5rem; }
  .day-row { grid-template-columns: 3.6rem 1fr; }
  .day-nums { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
