/* MAM ZAPISANE — arkusz stylów interfejsu panelu superadmina. */

:root {
    --bg:        #f4f6f9;
    --surface:   #ffffff;
    --border:    #e2e6ec;
    --text:      #1f2933;
    --muted:     #67707b;
    --danger:    #c8332b;
    --danger-d:  #a5271f;
    --ok:        #1f7a44;
    /* Kolor wiodący PANELU SUPERADMINA: bordo (jak w Przybył 2026). Panel
       firmy (mamzapisane.pl/{slug}, jeszcze niezbudowany) dostanie osobny,
       odróżniający kolor wiodący — deepskyblue — gdy powstanie. */
    --primary:       #7a1e2e;
    --primary-d:     #55141f;
    --accent:        #7a1e2e;
    --accent-d:      #55141f;
    --accent-border: #661a27;
    --radius:    9px;
    --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --control-h: 34px;
}

* { box-sizing: border-box; }

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

body {
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

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

code {
    font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: rgba(15, 23, 42, .06);
    padding: 1px 5px;
    border-radius: 4px;
}

.muted { color: var(--muted); }
.pre-wrap { white-space: pre-wrap; }

/* Podgląd treści e-maila (HTML z edytora WYSIWYG) w trybie widoku */
.email-preview {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 14px 16px;
}
.email-preview p { margin: 0 0 10px; }
.email-preview p:last-child { margin-bottom: 0; }

/* Edytor WYSIWYG (Quill) — dopasowanie do reszty formularzy, pełna szerokość karty */
#email-body-editor { background: #fff; border-radius: 7px; }
#email-body-editor .ql-toolbar.ql-snow { border-color: #cbd2db; border-radius: 7px 7px 0 0; }
#email-body-editor .ql-container.ql-snow { border-color: #cbd2db; border-radius: 0 0 7px 7px; }
#email-body-editor .ql-editor { min-height: 220px; font-size: 15px; }

/* ---------- Ekran logowania -------------------------------------- */

body.auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth__card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 26px 30px;
}

.auth__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 22px;
}

.auth__logo-img {
    display: block;
    max-width: 240px;
    max-height: 72px;
    width: auto;
    height: auto;
}

.auth__name { font-weight: 700; font-size: 17px; }
.auth__title { font-size: 16px; margin: 0 0 14px; }
.auth__foot { color: var(--muted); font-size: 13px; margin-top: 16px; }

/* ---------- Układ aplikacji ------------------------------------- */

.app__shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 234px;
    flex-shrink: 0;
    background: #222;
    color: #cdd7e4;
    display: flex;
    flex-direction: column;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px;
    min-height: 56px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar__logo-img {
    display: block;
    max-width: 100%;
    max-height: 46px;
    width: auto;
    height: auto;
}

.sidebar__name { font-weight: 700; color: #fff; font-size: 15px; }

.sidebar__nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }

.navitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 7px;
    color: #cdd7e4;
    text-decoration: none;
    font-size: 14px;
}

.navitem:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.navitem.is-active { background: var(--accent); color: #fff; }
.navitem__icon {
    width: 23px;
    height: 23px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: .75;
}
.navitem__icon svg { width: 100%; height: 100%; display: block; }
.navitem.is-active .navitem__icon { opacity: 1; }
.navitem--disabled { opacity: .5; cursor: default; }
.navitem__tag {
    margin-left: auto;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #8fa1b8;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.topbar__toggle {
    display: none;
    border: 0;
    background: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

.topbar__title { font-size: 17px; margin: 0; }

.topbar__user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar__username { font-size: 13px; color: var(--muted); }

@media (max-width: 560px) {
    .topbar__username { display: none; }
}

/* Pasek narzędzi zakładki — przyciski + pola wyszukiwania w jednym,
   segmentowym pasku u góry treści zakładki. */
.toolbar {
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    min-height: 42px;
    background: #dde1e7;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 18px;
}

.toolbar--card-top {
    margin: -20px -22px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
    border: none;
    border-bottom: 1px solid var(--border);
}

.toolbar__title {
    display: flex;
    align-items: center;
    padding: 0 16px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
}

.toolbar__actions { display: flex; align-items: stretch; margin-left: auto; }
.toolbar__group { display: flex; align-items: stretch; }

.toolbar__input {
    margin: 6px 4px;
    padding: 0 10px;
    border: none;
    border-left: 1px solid #c6ccd4;
    border-right: 1px solid #c6ccd4;
    border-radius: 5px;
    background: #fff;
    font: inherit;
    color: var(--text);
    width: 86px;
}
.toolbar__input:focus { outline: none; background: #eef4ff; }
.toolbar__input--wide { width: 200px; }

.toolbar__btn {
    display: inline-flex;
    align-items: center;
    height: 100%;
    margin: 0;
    padding: 0 16px;
    border: none;
    border-left: 1px solid #c6ccd4;
    border-right: 1px solid #c6ccd4;
    background: linear-gradient(to bottom, #e3e6eb, #d3d7dd);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: box-shadow .15s ease;
}
.toolbar__btn:hover { background: linear-gradient(to bottom, #aab1bd, #c7cdd6); box-shadow: inset 0 0 10px 1px rgba(170, 177, 189, .55); }
.toolbar__btn:active { background: linear-gradient(to bottom, #99a1ae, #b8bfc9); }

/* Klawisze funkcyjne (prowadzące do edycji/zapisu) — kolor wiodący. */
.toolbar__btn--accent {
    color: #fff;
    border-left: 1px solid var(--accent-border);
    border-right: 1px solid var(--accent-border);
    background: linear-gradient(to bottom, #98283a, var(--accent));
}
.toolbar__btn--accent:hover { background: linear-gradient(to bottom, #3d0e15, #551620); box-shadow: inset 0 0 12px 2px color-mix(in srgb, var(--accent) 70%, transparent); }
.toolbar__btn--accent:active { background: linear-gradient(to bottom, #2e0a10, var(--accent-d)); }

@media (max-width: 720px) {
    .toolbar,
    .toolbar__actions,
    .toolbar__group {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar__actions { margin-left: 0; width: 100%; }
    .toolbar__title { padding: 10px 16px; }

    .toolbar__input {
        width: auto;
        margin: 8px 10px;
        padding: 12px 10px;
        border: 1px solid #c6ccd4;
    }

    .toolbar__btn {
        width: 100%;
        justify-content: center;
        margin: 0;
        padding: 12px 16px;
        border-left: none;
        border-right: none;
        border-top: 1px solid #c6ccd4;
    }
    .toolbar__btn--accent { border-top-color: var(--accent-border); }
}

/* Zawartość modułu wypełnia całą dostępną szerokość; węższe bloki (np.
   formularze) ograniczamy klasą .card--narrow. */
.content { padding: 22px; width: 100%; }

/* ---------- Karty --------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
    margin-bottom: 18px;
}

.card--narrow { max-width: 480px; }
.card__title { font-size: 16px; margin: 0 0 12px; }
.card__lead { color: var(--muted); margin: 0 0 16px; }

/* ---------- Formularze ---------------------------------------- */

.form { display: flex; flex-direction: column; gap: 13px; }
.form__row { display: flex; flex-direction: column; gap: 5px; }
.form__label { font-size: 13px; font-weight: 600; }
.form__hint { font-weight: 400; color: var(--muted); }

.form__input {
    font: inherit;
    line-height: 1.4;
    padding: 8px 10px;
    border: 1px solid #cbd2db;
    border-radius: 7px;
    background: #fff;
    width: 100%;
    min-height: 39px;
}

.form__input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(122, 30, 46, .18);
}

.form__input.is-invalid,
.form__input:user-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(200, 51, 43, .15);
}

.form__check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.form__check.is-invalid { color: var(--danger-d); }
.form__check.is-invalid input { outline: 2px solid var(--danger); outline-offset: 2px; }

/* Grupa checkboxów pod jedną etykietą (np. Branża — kilka naraz) — pionowy
   stos zamiast pojedynczego .form__row, każdy wpis to własny .form__check. */
.form__check-group { display: flex; flex-direction: column; gap: 8px; }

/* Checkboxy i radio (checkboxy/"opcje" wyboru) w kolorze wiodącym wszędzie,
   2x większe niż domyślny rozmiar przeglądarki. */
input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--accent);
    width: 26px;
    height: 26px;
    cursor: pointer;
}

.form__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.form__actions--confirm { justify-content: space-between; }

.btn--right { margin-left: auto; }

/* Formularz w jednej linii (np. NIP + „Pobierz dane") */
.form-inline { display: flex; gap: 6px; align-items: center; }
.form__input--inline { width: auto; flex: 1 1 auto; min-width: 0; }

/* Pole + przycisk zrośnięte w jedną kontrolkę (np. NIP + „Pobierz dane") —
   bez odstępu, wspólna wysokość (align-items: stretch rozciąga przycisk do
   wysokości pola), zewnętrzne rogi zaokrąglone, wewnętrzne płaskie. */
.input-group { display: flex; align-items: stretch; }
.input-group .form__input {
    flex: 1 1 auto;
    min-width: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.input-group .btn {
    flex: 0 0 auto;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-left: -1px;
}

/* Śródtytuł sekcji w dłuższym formularzu */
.form__subhead {
    margin: 6px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
}

/* Dwie kolumny w formularzu (np. kod pocztowy + miasto) */
.form__grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form__grid2 > .form__row { margin: 0; }

@media (max-width: 520px) {
    .form__grid2 { grid-template-columns: 1fr; gap: 13px; }
}

/* Siatka pól formularza na pełnej szerokości karty — tyle kolumn po ~220px,
   ile się zmieści (zwykle 3-4 na desktopie), bez zmiany szerokości/wyglądu
   pojedynczego pola. Pole, które ma zająć cały wiersz mimo siatki (np. duży
   textarea) dostaje `.form__row--full` (grid-column: 1 / -1). */
.form__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 13px 16px;
}
.form__grid > .form__row,
.form__grid > .form__check { margin: 0; }
.form__row--full { grid-column: 1 / -1; }

/* ---------- Listy definicji -------------------------------- */

.deflist { margin: 0 0 16px; display: flex; flex-direction: column; gap: 6px; }
.deflist > div { display: flex; gap: 10px; font-size: 14px; }
.deflist dt { color: var(--muted); min-width: 90px; }
.deflist dd { margin: 0; font-weight: 600; }

.name { font-weight: 700; }
a.name { color: var(--text); text-decoration: none; }
a.name:hover { color: var(--primary); }

/* ---------- Przyciski ---------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 600;
    padding: 8px 15px;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    white-space: nowrap;
    transition: box-shadow .15s ease;
}

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-d); box-shadow: inset 0 0 12px 2px color-mix(in srgb, var(--primary) 70%, transparent); }
.btn--ghost { background: #fff; border-color: #cbd2db; color: var(--text); }
.btn--ghost:hover { background: #f1f3f6; box-shadow: inset 0 0 10px 1px rgba(170, 177, 189, .55); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger-d); box-shadow: inset 0 0 12px 2px color-mix(in srgb, var(--danger) 65%, transparent); }
.btn--accent { background: var(--accent); color: #fff; }
.btn--accent:hover { background: var(--accent-d); box-shadow: inset 0 0 12px 2px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn--sm { padding: 5px 10px; font-size: 13px; }
.btn--block { width: 100%; text-align: center; margin-top: 4px; }

/* ---------- Tabele ----------------------------------------- */

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

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th, .table td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: #eef0f3;
    color: var(--text);
    font-weight: 700;
    padding: 16px 12px;
}

.table tbody tr:hover { background: #f7f9fc; }
.table tbody tr[data-href] { cursor: pointer; }

.table th.col-actions,
.table td.col-actions {
    width: 1px;
    white-space: nowrap;
    text-align: right;
    padding-right: 0;
}

.table__actions { white-space: nowrap; }
.table__actions .btn + .btn,
.table__actions .inline-form + .btn { margin-left: 6px; }
.table__actions .inline-form { margin-left: 6px; }
.inline-form { display: inline; }

/* Etykieta statusu (pill) — wypełnione tło, biała czcionka. */
.tag {
    display: inline-block;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    background: rgba(15, 23, 42, .08);
    color: var(--muted);
    white-space: nowrap;
}

.tag--aktywny    { background: var(--ok); color: #fff; }
.tag--nieaktywny { background: var(--danger-d); color: #fff; }

/* ---------- Statystyki pulpitu ---------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stat {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat__value { font-size: 24px; font-weight: 700; }
.stat__label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* ---------- Komunikaty ---------------------------------- */

.alert {
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}

.alert--success { background: #e7f6ec; color: var(--ok); border-color: #b7e0c6; }
.alert--info { background: #e5f6fc; color: #0c6a94; border-color: #b9e4f2; }
.alert--error { background: #fdecec; color: var(--danger-d); border-color: #f3c2c2; }
.alert--muted { background: #eef0f3; color: var(--muted); border-color: #d3d8de; }

/* ---------- Zakładki (np. Ustawienia) ------------------ */

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

.tab {
    padding: 9px 14px;
    margin-bottom: -1px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
}

.tab:hover { color: var(--accent); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Przełącznik „widok → Edytuj" (data-edit-toggle) ---------- */
/* Domyślnie: widok tylko do odczytu (.js-view) widoczny, formularz (.js-edit)
   ukryty. Klik przycisku [data-edit-toggle] dodaje .is-editing na wskazanym
   zasięgu (jego JS-owa obsługa jest generyczna, patrz app.js) — wtedy się
   zamieniają. Ten sam wzorzec co w Przybył 2026 (tam po tabelach ustawień,
   tu też po całych sekcjach/formularzach jednego rekordu). */
.js-edit { display: none; }
.is-editing .js-view { display: none; }
.is-editing div.js-edit,
.is-editing section.js-edit { display: block; }
.is-editing form.js-edit,
.is-editing div.js-edit.form { display: flex; }

/* ---------- Paginacja ---------------------------------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    font-size: 13px;
    flex-wrap: wrap;
}

.pager__info { color: var(--muted); }
.pager__links { display: flex; gap: 4px; }

.pager__link {
    display: inline-block;
    min-width: 30px;
    text-align: center;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
}

.pager__link.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager__gap { padding: 5px 4px; color: var(--muted); }

/* ---------- Modal ------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 7vh 16px 16px;
}

.modal[hidden] { display: none; }

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .45);
}

.modal__dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 520px;
    max-height: 86vh;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 44px rgba(15, 23, 42, .28);
    overflow: hidden;
}

.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
}

.modal__title { margin: 0; font-size: 16px; font-weight: 600; }

.modal__x {
    background: none;
    border: 0;
    font-size: 22px;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    color: var(--muted);
}

.modal__x:hover { color: var(--text); }

/* Okno w kolorze wiodącym — nagłówek na deepskyblue, biały tytuł/X.
   Domyślne dla wszystkich okien modalnych (edycja/zapis/usuwanie). */
.modal--accent .modal__head { background: var(--accent); border-bottom-color: var(--accent-d); }
.modal--accent .modal__title { color: #fff; }
.modal--accent .modal__x { color: rgba(255, 255, 255, .8); }
.modal--accent .modal__x:hover { color: #fff; }

.modal__body { padding: 18px; overflow-y: auto; }
.modal__body > .card,
.modal__body > .card--narrow { border: 0; box-shadow: none; padding: 0; margin: 0; max-width: none; }

body.modal-open { overflow: hidden; }

/* ---------- Nakładka „przetwarzanie" ------------------ */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, .38);
}

.overlay[hidden] { display: none; }

.overlay__spinner {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: overlay-spin .75s linear infinite;
}

@keyframes overlay-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .overlay__spinner { animation-duration: 2s; }
}

/* ---------- Wąskie ekrany ----------------------------- */

@media (max-width: 820px) {
    .topbar__toggle { display: block; }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .18s ease;
    }

    .sidebar.is-open { transform: translateX(0); }
}
