/*
 * Panel licencji Ofertownika - warstwa wizualna.
 *
 * Implementacja systemu z design/README.md: tokeny, typografia, komponenty.
 * Panel nie uzywa Bootstrapa ani szablonu Bracket - system jest na tyle dokladnie
 * opisany, ze wlasny arkusz jest wierniejszy i lzejszy niz nadpisywanie cudzego.
 * Z bibliotek zostaje tylko Font Awesome 5 na ikony (w design systemie sa Material
 * Symbols - mapowanie 1:1 jest w README, sekcja Assets).
 *
 * Trzy szerokosci, zgodnie z README: desktop >= 1280px (sidebar 240px),
 * tablet 768-1279px (sidebar 64px, tylko ikony), telefon < 768px (gorny pasek
 * i dolna nawigacja, tabele zamieniaja sie w karty).
 */

/* ===== Tokeny ============================================================= */

:root {
    --ink: #0A0A0A;
    --fg: #18181B;
    --muted: #71717A;
    --subtle: #A1A1AA;
    --line: #E4E4E7;
    --line-soft: #F1F1F3;
    --bg: #FFFFFF;
    --app: #FAFAFA;

    --acc: #2563EB;
    --acc-soft: #EFF6FF;
    --acc-line: #BFDBFE;
    --ok: #15803D;
    --ok-soft: #F0FDF4;
    --ok-line: #BBF7D0;
    --warn: #B45309;
    --warn-soft: #FFFBEB;
    --warn-line: #FDE68A;
    --dang: #B91C1C;
    --dang-soft: #FEF2F2;
    --dang-line: #FECACA;
    --money: #0F766E;
    --money-soft: #F0FDFA;
    --money-line: #99F6E4;

    --side-bg: #FFFFFF;
    --side-fg: #18181B;
    --side-muted: #8A8A93;
    --side-line: #EDEDEF;
    --side-active: #F4F4F5;

    --r: 6px;
    --r-lg: 8px;
    --sh: 0 1px 2px rgba(16, 24, 40, .05);
    --sh-md: 0 4px 12px -2px rgba(16, 24, 40, .10), 0 2px 4px -2px rgba(16, 24, 40, .06);
    --row-py: 11px;

    --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ===== Podstawy =========================================================== */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: 'Geist', system-ui, -apple-system, sans-serif;
    background: var(--app);
    color: var(--fg);
    font-size: 14px;
    line-height: 20px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--acc); text-decoration: none; }
a:hover { color: #1D4ED8; text-decoration: underline; }

input, select, textarea, button { font: inherit; color: inherit; }
button { white-space: nowrap; }
::selection { background: var(--acc-soft); }

h1, h2, h3, h4, h5 { margin: 0; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

code, .mono, pre { font-family: var(--mono); }

@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* paski przewijania w kontenerach tabel */
.table-wrap::-webkit-scrollbar, .scroll-x::-webkit-scrollbar { height: 8px; width: 8px; }
.table-wrap::-webkit-scrollbar-thumb, .scroll-x::-webkit-scrollbar-thumb {
    background: #D4D4D8;
    border-radius: 8px;
}

/* ===== Powloka ============================================================ */

.app { display: flex; min-height: 100vh; background: var(--app); }

.side {
    width: 240px;
    flex: 0 0 240px;
    background: var(--side-bg);
    border-right: 1px solid var(--side-line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.side-head {
    height: 56px;
    flex: 0 0 56px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid var(--side-line);
    overflow: hidden;
}

.logo-mark {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 7px;
    background: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -.02em;
}

.side-head-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.side-head-name {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--side-fg);
    white-space: nowrap;
}
.side-head-sub { font-size: 11px; color: var(--side-muted); white-space: nowrap; }

.side-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-group-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--side-muted);
    padding: 4px 8px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 34px;
    padding: 0 9px;
    border-radius: var(--r);
    color: var(--side-fg);
    font-size: 13.5px;
    text-decoration: none;
}
.nav-item:hover { background: var(--side-active); color: var(--side-fg); text-decoration: none; }
.nav-item.is-active { background: var(--side-active); font-weight: 500; }
.nav-item i { width: 19px; font-size: 16px; text-align: center; color: #52525B; flex: 0 0 19px; }
.nav-item.is-active i { color: var(--fg); }
.nav-item-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item-count {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 11.5px;
    background: var(--line-soft);
    border-radius: 999px;
    padding: 1px 6px;
    color: var(--muted);
}

.side-foot {
    border-top: 1px solid var(--side-line);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    background: #E4E4E7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #3F3F46;
}

.side-foot-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.side-foot-name {
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.side-foot-role { font-size: 11px; color: var(--side-muted); }

.side-foot-logout {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r);
    color: var(--subtle);
}
.side-foot-logout:hover { background: var(--line-soft); color: var(--fg); text-decoration: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 56px;
    flex: 0 0 56px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.crumb { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.crumb strong { color: var(--fg); font-weight: 500; }
.crumb-sep { color: var(--subtle); }

.topbar-search { margin-left: auto; flex: 0 1 260px; }
.topbar-search .input { height: 32px; }

.topbar-help {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
    box-shadow: var(--sh);
    color: var(--subtle);
}
.topbar-help:hover { background: var(--line-soft); color: var(--fg); text-decoration: none; }

.page { padding: 22px 24px 40px; display: flex; flex-direction: column; gap: 16px; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}
.page-title { font-size: 24px; line-height: 1.3; font-weight: 600; letter-spacing: -.02em; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== Karta / sekcja ===================================================== */

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh);
}

.card-head {
    padding: 13px 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card-body { padding: 16px; }
.card-body > :last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-cols { display: grid; gap: 16px; }

/* ===== Przyciski ========================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
    color: var(--fg);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--sh);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--line-soft); color: var(--fg); text-decoration: none; }
.btn i { font-size: 14px; }

.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #27272A; border-color: #27272A; color: #fff; }

.btn-ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.btn-ok:hover { background: #DCFCE7; color: var(--ok); }

.btn-dang { background: #fff; border-color: var(--dang-line); color: var(--dang); }
.btn-dang:hover { background: var(--dang-soft); color: var(--dang); }

.btn-dang-solid { background: var(--dang); border-color: var(--dang); color: #fff; }
.btn-dang-solid:hover { background: #991B1B; border-color: #991B1B; color: #fff; }

.btn-dashed { height: 32px; padding: 0 10px; border: 1px dashed var(--line); color: var(--muted); box-shadow: none; }
.btn-dashed:hover { border-color: var(--subtle); background: #fff; color: var(--fg); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-sm i { font-size: 13px; }

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    color: var(--subtle);
}
.btn-icon:hover { background: var(--line-soft); color: var(--fg); }
.btn-icon.is-dang:hover { background: var(--dang-soft); color: var(--dang); }

.btn[disabled], .btn.is-disabled {
    background: #fff;
    color: var(--subtle);
    cursor: not-allowed;
    opacity: .6;
    pointer-events: none;
}

.btn-row { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

/* ===== Pola formularza ==================================================== */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.label { font-size: 13px; font-weight: 500; }
.label .req { color: var(--dang); }
.hint { font-size: 12.5px; color: var(--muted); }

.input, .select, .textarea {
    height: 34px;
    width: 100%;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
    font-size: 13.5px;
    box-shadow: var(--sh);
}
.textarea { height: auto; padding: 9px 10px; line-height: 1.55; resize: vertical; }

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--acc);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

.input[readonly], .input:disabled, .select:disabled, .textarea[readonly] {
    background: var(--line-soft);
    color: var(--muted);
}

.input-mono { font-family: var(--mono); font-size: 12.5px; }

.input-icon { position: relative; }
.input-icon i {
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--subtle);
    pointer-events: none;
}
.input-icon .input { padding-left: 29px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 14px; }

.form-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
}

/* ===== Toggle ============================================================= */

.toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    margin-bottom: 14px;
    user-select: none;
}
.toggle-row:last-child { margin-bottom: 0; }

.toggle {
    position: relative;
    width: 36px;
    height: 20px;
    flex: 0 0 36px;
    border-radius: 999px;
    background: #D4D4D8;
    transition: background .15s;
    margin-top: 1px;
}
.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #fff;
    box-shadow: var(--sh);
    transition: left .15s;
}
.toggle.is-on { background: var(--acc); }
.toggle.is-on::after { left: 18px; }

.toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle-label { font-size: 13.5px; font-weight: 500; }

/* ===== Badge ============================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 8px;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: var(--line-soft);
    color: #52525B;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.badge i { font-size: 11px; }

.badge-acc { background: var(--acc-soft); color: #1E40AF; border-color: var(--acc-line); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge-dang { background: var(--dang-soft); color: var(--dang); border-color: var(--dang-line); }
.badge-ink { background: var(--ink); color: #fff; border-color: var(--ink); }
.badge-money { background: var(--money-soft); color: var(--money); border-color: var(--money-line); }

.badge-sm { height: 20px; padding: 0 7px; font-size: 11.5px; }

.badges { display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap; }

/* ===== Tabela ============================================================= */

.table-wrap { overflow-x: auto; }

.table { border-collapse: collapse; width: 100%; }

.table thead tr { background: #FCFCFD; }
.table th {
    font-size: 11.5px;
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: .04em;
    color: var(--muted);
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table th:first-child, .table td:first-child { padding-left: 14px; }
.table th:last-child, .table td:last-child { padding-right: 14px; }

.table td {
    padding: var(--row-py) 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
    font-size: 13px;
}
.table tbody tr:hover { background: #FCFCFD; }
.table tbody tr:last-child td { border-bottom: 0; }

.table .num, .table th.num { text-align: right; font-family: var(--mono); }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }

/* wiersz wyrozniony - np. podsumowanie */
.table tr.is-total { background: #FCFCFD; font-weight: 600; }

/* kubelek rozwijany do pojedynczych pomiarow (stan serwera) */
.bucket-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--fg);
    text-decoration: none;
}
.bucket-toggle i { font-size: 10px; color: var(--subtle); }
.bucket-toggle:hover { text-decoration: underline; }

/* wiersze podrzedne: pomiary rozwinietej godziny */
.table tr.is-sample { background: #FCFCFD; }
.table tr.is-sample td { font-size: 12.5px; color: var(--muted); }
.table tr.is-sample td:first-child { padding-left: 34px; }

/* glowna wartosc w komorce plus druga linia opisu */
.cell-main { font-size: 13.5px; font-weight: 500; }
.cell-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cell-meta-mono { font-family: var(--mono); font-size: 11.5px; color: var(--subtle); margin-top: 2px; }

/* ===== Lista dane / wartosc =============================================== */

.data { display: grid; grid-template-columns: minmax(140px, 38%) 1fr; }
.data > div {
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: 13px;
}
.data > div:nth-child(odd) { color: var(--muted); padding-right: 12px; }
.data > div:nth-last-child(-n+2) { border-bottom: 0; }
.data code { font-family: var(--mono); font-size: 12px; }

/* ===== KPI ================================================================ */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }

.kpi {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh);
    padding: 14px 16px;
}
.kpi-label { font-size: 12.5px; color: var(--muted); }
.kpi-value {
    font-family: var(--mono);
    font-size: 21px;
    line-height: 28px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin-top: 4px;
}
.kpi-value.is-warn { color: var(--warn); }
.kpi-value.is-dang { color: var(--dang); }
.kpi-value.is-ok { color: var(--ok); }
.kpi-note { font-size: 12px; color: var(--subtle); margin-top: 2px; }
.kpi-link { display: block; text-decoration: none; color: inherit; }
.kpi-link:hover { text-decoration: none; border-color: var(--subtle); }

/* ===== Miernik ============================================================
   Pasek zajetosci pod wartoscia w kafelku - procent musi byc widoczny takze
   bez czytania liczby. Tonu nie niesie sam kolor: liczba nad paskiem dostaje
   ten sam ton, wiec stan jest rozpoznawalny bez koloru (WCAG AA). */

.meter {
    height: 6px;
    margin-top: 8px;
    border-radius: 999px;
    background: var(--line-soft);
    overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 999px; background: var(--acc); }
.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-dang { background: var(--dang); }

/* ===== Wykres =============================================================
   Wlasny, inline SVG - bez biblioteki, tak jak reszta panelu. Wykres jest
   ozdoba (aria-hidden), dane stoja w tabeli pod nim. */

.chart-box { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line-soft); }
.chart-box:last-child { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }

.chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-title { font-size: 13.5px; font-weight: 500; }
.chart-meta { font-size: 12px; color: var(--subtle); }
.chart-ref { color: var(--warn); }

.chart { display: block; width: 100%; height: 110px; }

.chart-axis {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--subtle);
}

/* ===== Odpowiedz aktualizacji =============================================
   Tekst zwrocony przez skrypt instancji, w wierszu dopisanym pod jej wierszem.
   Tekstu nie formatujemy - ma byc widac dokladnie to, co przyszlo. */

.update-out td { padding-top: 0; }

.update-item-body {
    margin: 8px 0 0;
    padding: 8px 10px;
    background: #FCFCFD;
    border: 1px solid var(--line);
    border-radius: var(--r);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: #3F3F46;
}

/* ===== Taby =============================================================== */

.tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    padding: 0 10px;
    overflow-x: auto;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 11px;
    font-size: 13px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}
.tab:hover { color: var(--fg); text-decoration: none; }
.tab.is-active { color: var(--fg); font-weight: 500; border-bottom-color: var(--ink); }
.tab-count {
    font-family: var(--mono);
    font-size: 11.5px;
    background: var(--line-soft);
    border-radius: 999px;
    padding: 1px 6px;
}

/* ===== Filtry ============================================================= */

.filters {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.filters .field { margin-bottom: 0; }
.filters .field-grow { flex: 1 1 240px; }

/* ===== Paginacja ========================================================== */

.pager-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}
.pager-info { font-size: 12.5px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 4px; }

.pager-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    min-width: 30px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
    box-shadow: var(--sh);
    font-family: var(--mono);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--fg);
    text-decoration: none;
}
.pager-item:hover { background: var(--line-soft); color: var(--fg); text-decoration: none; }
.pager-item.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }
.pager-item.is-off { color: var(--subtle); cursor: not-allowed; pointer-events: none; }
.pager-gap { color: var(--subtle); padding: 0 2px; }

/* ===== Alert ============================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px 12px;
    border-radius: var(--r-lg);
    border: 1px solid var(--line);
    background: #fff;
    font-size: 13px;
    text-wrap: pretty;
}
.alert i { font-size: 15px; line-height: 20px; flex: 0 0 auto; }
.alert-info { background: var(--acc-soft); border-color: var(--acc-line); color: #1E40AF; }
.alert-ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.alert-dang { background: var(--dang-soft); border-color: var(--dang-line); color: var(--dang); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert code { font-size: 12px; }

/* ===== Stan pusty ========================================================= */

.empty {
    border: 1px dashed var(--line);
    border-radius: var(--r-lg);
    background: #fff;
    padding: 26px;
    text-align: center;
}
.empty i { font-size: 22px; color: var(--subtle); }
.empty-title { font-size: 14px; font-weight: 600; margin-top: 10px; }
.empty-text {
    font-size: 13px;
    color: var(--muted);
    max-width: 320px;
    margin: 4px auto 0;
    text-wrap: pretty;
}
.empty .btn { margin-top: 14px; }

/* ===== Blok kodu ========================================================== */

.code-box {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: #FAFAFA;
    padding: 11px 12px;
    overflow-x: auto;
}
.code-box pre { margin: 0; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }
.code-box.is-acc { border-color: var(--acc-line); background: var(--acc-soft); }

/* ===== Modal ============================================================== */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(9, 9, 11, .45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}
.modal.is-open { display: flex; }

.modal-box {
    width: 100%;
    max-width: 460px;
    background: #fff;
    border-radius: var(--r-lg);
    box-shadow: var(--sh-md);
    animation: fade .14s ease-out;
    overflow: hidden;
}

.modal-head {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.modal-head i { font-size: 17px; }
.modal-title { font-size: 15.5px; font-weight: 600; flex: 1; }
.modal-close {
    width: 28px;
    height: 28px;
    border: 0;
    background: transparent;
    color: var(--subtle);
    border-radius: var(--r);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.modal-close:hover { background: var(--line-soft); color: var(--fg); }

.modal-body { padding: 16px; font-size: 13.5px; line-height: 1.6; color: #3F3F46; }

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: #FCFCFD;
}

.modal-tone-dang i { color: var(--dang); }
.modal-tone-warn i { color: var(--warn); }
.modal-tone-acc i { color: var(--acc); }

/* ===== Loader ============================================================= */

.loader {
    position: fixed;
    inset: 0;
    background: rgba(250, 250, 250, .86);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 200;
}
.loader.is-on { display: flex; }
.loader i { font-size: 28px; color: var(--acc); animation: spin 1s linear infinite; }
.loader-text { font-size: 13.5px; font-weight: 500; }
.loader-note { font-size: 12.5px; color: var(--muted); }

/* ===== Ekran logowania ==================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--app);
}
.login-box { width: 100%; max-width: 380px; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head .logo-mark { margin: 0 auto 10px; width: 34px; height: 34px; flex: none; font-size: 16px; border-radius: 9px; }
.login-title { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.login-box .card-body { padding: 20px; }
.login-box .btn { width: 100%; }

/* ===== Pomocnicze ========================================================= */

.dsp-none { display: none !important; }
.dsp-inline { display: inline; }

.tx-muted { color: var(--muted); }
.tx-subtle { color: var(--subtle); }
.tx-dang { color: var(--dang); }
.tx-ok { color: var(--ok); }
.tx-warn { color: var(--warn); }
.tx-money { color: var(--money); }
.tx-12 { font-size: 12px; }
.tx-13 { font-size: 13px; }
.tx-right { text-align: right; }
.tx-center { text-align: center; }
.mono-sm { font-family: var(--mono); font-size: 12px; }
.mg-t-0 { margin-top: 0; }
.mg-t-10 { margin-top: 10px; }
.mg-t-16 { margin-top: 16px; }
.mg-b-0 { margin-bottom: 0; }
.mg-b-10 { margin-bottom: 10px; }
.mg-b-16 { margin-bottom: 16px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.dash { color: var(--subtle); }

/* dolna nawigacja i przyklejony CTA - tylko telefon */
.bottom-nav, .sticky-cta, .topbar-mobile { display: none; }

/* ===== Tablet: sidebar 64px, tylko ikony ================================== */

@media (max-width: 1279px) {
    .side { width: 64px; flex: 0 0 64px; }
    .side-head { padding: 0 19px; }
    .side-head-text, .nav-group-label, .nav-item-label, .nav-item-count,
    .side-foot-text, .topbar-search { display: none; }
    .side-nav { padding: 12px 8px; gap: 8px; }
    .nav-item { justify-content: center; padding: 0; }
    .nav-item i { font-size: 17px; }
    .side-foot { justify-content: center; padding: 10px 8px; gap: 6px; }
    .page { padding: 18px; }
    .topbar { padding: 0 18px; }
}

/* ===== Telefon: gorny pasek, dolna nawigacja, tabele jako karty =========== */

@media (max-width: 767px) {
    .side { display: none; }

    .topbar { padding: 0 12px; gap: 10px; }
    .topbar-mobile { display: flex; align-items: center; gap: 10px; }
    .crumb { display: none; }
    .topbar-title { font-size: 14px; font-weight: 600; }

    .page { padding: 14px 14px 20px; gap: 12px; }
    .page-title { font-size: 19px; }

    /* miejsce na dolna nawigacje (58px) i przyklejony CTA */
    .page { padding-bottom: 78px; }
    .page.has-cta { padding-bottom: 140px; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid var(--line);
        z-index: 50;
    }
    .bottom-nav a {
        flex: 1;
        height: 58px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 10.5px;
        font-weight: 500;
        color: var(--muted);
        text-decoration: none;
    }
    .bottom-nav a i { font-size: 18px; }
    .bottom-nav a.is-active { color: var(--acc); }

    .sticky-cta {
        display: block;
        position: fixed;
        bottom: 58px;
        left: 0;
        right: 0;
        padding: 8px 12px;
        background: #fff;
        border-top: 1px solid var(--line);
        z-index: 49;
    }
    .sticky-cta .btn { width: 100%; height: 46px; font-size: 14px; }

    /* dotykowe cele i pelna szerokosc akcji */
    .btn { height: 44px; padding: 0 16px; }
    .btn-sm { height: 38px; }
    .btn-icon { width: 40px; height: 40px; }
    .input, .select { height: 44px; }
    .page-actions .btn { flex: 1; }

    .form-row { grid-template-columns: 1fr; }
    .grid-2, .kpi-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }

    .filters { padding: 12px; }
    .filters .field { flex: 1 1 100%; }

    .data { grid-template-columns: 1fr; }
    .data > div { border-bottom: 0; padding: 2px 0; }
    .data > div:nth-child(odd) { padding-top: 10px; font-size: 12px; }
    .data > div:nth-child(even) { border-bottom: 1px solid var(--line-soft); padding-bottom: 10px; }

    .modal { align-items: flex-end; padding: 0; }
    .modal-box { max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; }
    .modal-foot .btn { flex: 1; height: 44px; }

    /* tabela zamienia sie w karty: naglowek kolumny wedruje przed wartosc
       (atrybut data-label w komorce), a wiersz staje sie kafelkiem */
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr {
        border: 1px solid var(--line);
        border-radius: var(--r-lg);
        background: #fff;
        box-shadow: var(--sh);
        padding: 12px;
        margin-bottom: 10px;
    }
    .table-cards tr:hover { background: #fff; }
    .table-cards td { border: 0; padding: 3px 0; }
    .table-cards td:first-child, .table-cards td:last-child { padding-left: 0; padding-right: 0; }
    .table-cards td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--muted);
        margin-bottom: 2px;
    }
    /* karta pomiaru pod godzina: wciecia nie ma czym pokazac, wiec zostaje
       obwodka z lewej - wiadomo, ze karta nalezy do godziny nad nia */
    .table-cards tr.is-sample {
        border-left: 3px solid var(--line);
        background: #FCFCFD;
        margin-left: 12px;
    }
    .table-cards tr.is-sample td:first-child { padding-left: 0; }

    .table-cards td.actions { text-align: left; margin-top: 8px; }
    .table-cards td.actions .btn-row { justify-content: flex-start; }
    .table-wrap { overflow-x: visible; }
}
