/* =====================================================================
   HouseCRM - warstwa wizualna panelu
   Wszystkie animacje realizowane sa w CSS (transition / @keyframes).
   ===================================================================== */

/* --- Zmienne motywu --------------------------------------------------- */

:root {
    --bg:            #0f1420;
    --bg-elev:       #161d2c;
    --bg-elev-2:     #1c2537;
    --bg-hover:      #212c41;
    --line:          #253148;
    --line-soft:     #1e2839;

    --text:          #e8edf7;
    --text-dim:      #9aa8c2;
    --text-faint:    #64738f;

    --accent:        #4f8ef7;
    --accent-2:      #7c5cff;
    --accent-soft:   rgba(79, 142, 247, .14);
    --accent-line:   rgba(79, 142, 247, .35);

    --success:       #2fbf71;
    --success-soft:  rgba(47, 191, 113, .14);
    --warning:       #f0a92c;
    --warning-soft:  rgba(240, 169, 44, .14);
    --danger:        #ef4444;
    --danger-soft:   rgba(239, 68, 68, .14);
    --info:          #38bdf8;
    --info-soft:     rgba(56, 189, 248, .14);
    --violet:        #a78bfa;
    --violet-soft:   rgba(167, 139, 250, .14);

    --radius:        14px;
    --radius-sm:     10px;
    --radius-xs:     8px;
    --shadow:        0 12px 32px rgba(0, 0, 0, .35);
    --shadow-sm:     0 4px 14px rgba(0, 0, 0, .22);
    --sidebar-w:     262px;
    --topbar-h:      64px;
    --ease:          cubic-bezier(.22, .61, .36, 1);
}

[data-theme="light"] {
    --bg:            #f4f6fb;
    --bg-elev:       #ffffff;
    --bg-elev-2:     #f8fafc;
    --bg-hover:      #eef2f9;
    --line:          #e2e8f2;
    --line-soft:     #edf1f7;

    --text:          #16202f;
    --text-dim:      #5b6a83;
    --text-faint:    #8b9ab3;

    --accent-soft:   rgba(79, 142, 247, .10);
    --shadow:        0 12px 30px rgba(23, 43, 77, .10);
    --shadow-sm:     0 3px 10px rgba(23, 43, 77, .07);
}

/* --- Reset ------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, Arial, sans-serif;
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background .25s var(--ease), color .25s var(--ease);
}

h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .8em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    font-family: "Cascadia Mono", Consolas, monospace;
    background: var(--bg-elev-2);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 1px 5px;
    font-size: .88em;
}

.muted  { color: var(--text-dim); font-size: .9rem; }
.faint  { color: var(--text-faint); }
.mono   { font-family: "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.nowrap { white-space: nowrap; }
.right  { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Ikony: bez jawnego rozmiaru SVG rozlewa sie do 300x150, wiec ustalamy bazowy
   rozmiar tutaj. Reguly komponentow ponizej (np. .btn svg) nadpisuja te wartosci. */
.ic { display: inline-flex; align-items: center; justify-content: center; }
.ic svg { width: 1.05em; height: 1.05em; }
h1 svg, h2 svg, h3 svg { width: 1em; height: 1em; vertical-align: -.12em; }
svg { flex: 0 0 auto; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* --- Animacje --------------------------------------------------------- */

@keyframes fadeIn    { from { opacity: 0; }                        to { opacity: 1; } }
@keyframes slideUp   { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes slideLeft { from { opacity: 0; transform: translateX(28px); }  to { opacity: 1; transform: none; } }
@keyframes pop       { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin      { to { transform: rotate(360deg); } }
@keyframes shimmer   { 0% { background-position: -420px 0; } 100% { background-position: 420px 0; } }
@keyframes pulseDot  { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes grow      { from { transform: scaleY(0); } to { transform: scaleY(1); } }

.fade-in   { animation: fadeIn  .3s var(--ease) both; }
.slide-up  { animation: slideUp .34s var(--ease) both; }

/* Kaskadowe wejscie elementow listy */
.stagger > * { animation: slideUp .38s var(--ease) both; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .06s; }
.stagger > *:nth-child(3) { animation-delay: .10s; }
.stagger > *:nth-child(4) { animation-delay: .14s; }
.stagger > *:nth-child(5) { animation-delay: .18s; }
.stagger > *:nth-child(6) { animation-delay: .22s; }
.stagger > *:nth-child(7) { animation-delay: .26s; }
.stagger > *:nth-child(8) { animation-delay: .30s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* --- Szkielet aplikacji ----------------------------------------------- */

#app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--bg-elev);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .28s var(--ease);
}

.sidebar-head {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid var(--line-soft);
    flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
    width: 34px; height: 34px;
    flex: 0 0 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    display: grid; place-items: center;
    font-weight: 800; font-size: .8rem; letter-spacing: .02em;
    box-shadow: 0 4px 14px rgba(79, 142, 247, .38);
}

.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: .96rem; line-height: 1.2; }
.brand-text span {
    display: block; font-size: .74rem; color: var(--text-faint);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px 20px; }
.nav-group { margin-bottom: 18px; }
.nav-group > h6 {
    margin: 0 0 6px 10px;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-faint);
    font-weight: 700;
}

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: background .16s var(--ease), color .16s var(--ease), transform .16s var(--ease);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; transform: translateX(2px); }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
    content: "";
    position: absolute; left: -12px; top: 50%;
    width: 3px; height: 22px; margin-top: -11px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}
.nav-item .count {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: .68rem; font-weight: 700;
    padding: 1px 6px; border-radius: 20px;
    min-width: 19px; text-align: center;
}

.sidebar-foot { flex: 0 0 auto; border-top: 1px solid var(--line-soft); padding: 10px 12px; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    cursor: pointer; transition: background .16s var(--ease);
}
.user-chip:hover { background: var(--bg-hover); }
.avatar {
    width: 32px; height: 32px; flex: 0 0 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    color: #fff; display: grid; place-items: center;
    font-size: .74rem; font-weight: 700;
}
.user-chip div { min-width: 0; }
.user-chip strong { display: block; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip span { display: block; font-size: .72rem; color: var(--text-faint); }

/* --- Obszar glowny ---------------------------------------------------- */

.main {
    flex: 1 1 auto;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 22px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line-soft);
}

.topbar h1 { margin: 0; font-size: 1.12rem; }
.topbar .sub { font-size: .76rem; color: var(--text-faint); }
.topbar-spacer { flex: 1 1 auto; }

.icon-btn {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border: 1px solid var(--line);
    background: var(--bg-elev);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .16s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-line); background: var(--bg-hover); transform: translateY(-1px); }
.icon-btn svg { width: 17px; height: 17px; }

.menu-toggle { display: none; }

.view { padding: 22px; flex: 1 1 auto; max-width: 1560px; width: 100%; }

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

.card {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card + .card { margin-top: 18px; }

.card-head {
    display: flex; align-items: center; gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1 1 auto; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* --- Kafelki wskaznikow ----------------------------------------------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat {
    position: relative;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 15px 16px;
    overflow: hidden;
    transition: transform .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.stat:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--shadow); }
.stat::after {
    content: "";
    position: absolute; inset: 0 0 auto 0; height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transform: scaleX(0); transform-origin: left;
    transition: transform .3s var(--ease);
}
.stat:hover::after { transform: scaleX(1); }

.stat .label {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
    color: var(--text-faint); font-weight: 700; margin-bottom: 6px;
    display: flex; align-items: center; gap: 7px;
}
.stat .label svg { width: 14px; height: 14px; }
.stat .value { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.stat .value small { font-size: .8rem; font-weight: 600; color: var(--text-dim); margin-left: 3px; }
.stat .hint { font-size: .76rem; color: var(--text-dim); margin-top: 3px; }
.stat.is-danger  .value { color: var(--danger); }
.stat.is-success .value { color: var(--success); }
.stat.is-warning .value { color: var(--warning); }

.stat.clickable { cursor: pointer; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 8px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--bg-elev);
    color: var(--text);
    font: inherit; font-size: .88rem; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all .16s var(--ease);
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent-line); transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent; color: #fff;
    box-shadow: 0 4px 14px rgba(79, 142, 247, .30);
}
.btn-primary:hover { box-shadow: 0 7px 20px rgba(79, 142, 247, .42); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.btn-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, .3); }
.btn-success { background: var(--success-soft); color: var(--success); border-color: rgba(47, 191, 113, .3); }
.btn-ghost   { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* --- Znaczniki stanu -------------------------------------------------- */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: .74rem; font-weight: 650;
    line-height: 1.5;
    background: var(--bg-elev-2);
    color: var(--text-dim);
    border: 1px solid var(--line);
    white-space: nowrap;
}
.badge::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; flex: 0 0 6px;
}
.badge.no-dot::before { display: none; }

.badge.b-blue    { background: var(--accent-soft);  color: var(--accent);  border-color: var(--accent-line); }
.badge.b-green   { background: var(--success-soft); color: var(--success); border-color: rgba(47, 191, 113, .3); }
.badge.b-orange  { background: var(--warning-soft); color: var(--warning); border-color: rgba(240, 169, 44, .3); }
.badge.b-red     { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, .3); }
.badge.b-cyan    { background: var(--info-soft);    color: var(--info);    border-color: rgba(56, 189, 248, .3); }
.badge.b-violet  { background: var(--violet-soft);  color: var(--violet);  border-color: rgba(167, 139, 250, .3); }
.badge.b-live::before { animation: pulseDot 1.6s infinite; }

/* --- Tabela ----------------------------------------------------------- */

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

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}

table.data th {
    text-align: left;
    padding: 11px 14px;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-faint);
    font-weight: 700;
    border-bottom: 1px solid var(--line);
    background: var(--bg-elev-2);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}
table.data th.sortable { cursor: pointer; user-select: none; transition: color .15s var(--ease); }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { opacity: .45; font-size: .7em; margin-left: 3px; }
table.data th.sorted { color: var(--accent); }

table.data td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}
table.data tbody tr { transition: background .13s var(--ease); }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.actions .btn { opacity: .6; transition: opacity .15s var(--ease); }
table.data tr:hover td.actions .btn { opacity: 1; }

.cell-main { font-weight: 600; }
.cell-sub  { font-size: .78rem; color: var(--text-faint); }

/* --- Pasek narzedzi listy --------------------------------------------- */

.toolbar {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--line-soft);
    flex-wrap: wrap;
}
.toolbar .spacer { flex: 1 1 auto; }

.search {
    position: relative;
    flex: 0 1 280px;
    min-width: 180px;
}
.search input { padding-left: 34px; }
.search svg {
    position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: var(--text-faint); pointer-events: none;
}

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

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="month"], input[type="search"],
input[type="tel"], select, textarea {
    width: 100%;
    padding: 8px 11px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
    color: var(--text);
    font: inherit;
    font-size: .88rem;
    transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: #fff; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }
textarea { resize: vertical; min-height: 88px; line-height: 1.5; }
select { cursor: pointer; appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                      linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.field { display: block; margin-bottom: 14px; }
.field > span {
    display: block;
    font-size: .78rem; font-weight: 650;
    color: var(--text-dim);
    margin-bottom: 5px;
}
.field > span .req { color: var(--danger); margin-left: 2px; }
.field .err { display: block; color: var(--danger); font-size: .76rem; margin-top: 4px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field .help { display: block; font-size: .75rem; color: var(--text-faint); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.col-span-2 { grid-column: span 2; }

.check-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: .86rem; }
.check input { width: auto; }

input[type="checkbox"] {
    appearance: none;
    width: 17px; height: 17px;
    border: 1.5px solid var(--line);
    border-radius: 5px;
    background: var(--bg);
    cursor: pointer;
    position: relative;
    transition: all .15s var(--ease);
    flex: 0 0 17px;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
    content: "";
    position: absolute; left: 5px; top: 1px;
    width: 4px; height: 9px;
    border: solid #fff; border-width: 0 2px 2px 0;
    transform: rotate(43deg);
}

/* --- Zakladki --------------------------------------------------------- */

.tabs {
    display: flex; gap: 3px;
    border-bottom: 1px solid var(--line);
    padding: 0 18px;
    overflow-x: auto;
}
.tab {
    padding: 11px 14px;
    font-size: .87rem; font-weight: 600;
    color: var(--text-dim);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: color .16s var(--ease), border-color .16s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { font-size: .72rem; color: var(--text-faint); margin-left: 4px; }

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

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(6, 10, 18, .62);
    backdrop-filter: blur(4px);
    z-index: 90;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 4vh 16px;
    overflow-y: auto;
    animation: fadeIn .18s var(--ease) both;
}

.modal {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: min(680px, 100%);
    animation: pop .26s var(--ease) both;
    margin: auto 0;
}
.modal.wide { width: min(980px, 100%); }
.modal.narrow { width: min(460px, 100%); }

.modal-head {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-head .spacer { flex: 1 1 auto; }
.modal-body { padding: 20px; max-height: 68vh; overflow-y: auto; }
.modal-foot {
    display: flex; gap: 9px; justify-content: flex-end;
    padding: 14px 20px;
    border-top: 1px solid var(--line-soft);
    background: var(--bg-elev-2);
}

/* --- Powiadomienia ---------------------------------------------------- */

.toasts {
    position: fixed; right: 18px; bottom: 18px;
    z-index: 120;
    display: flex; flex-direction: column; gap: 9px;
    max-width: min(380px, calc(100vw - 36px));
}

.toast {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: .87rem;
    animation: slideLeft .28s var(--ease) both;
}
.toast.leaving { animation: fadeIn .2s var(--ease) reverse both; }
.toast.ok   { border-left-color: var(--success); }
.toast.err  { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
.toast svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.toast.ok svg   { color: var(--success); }
.toast.err svg  { color: var(--danger); }
.toast.warn svg { color: var(--warning); }
.toast strong { display: block; margin-bottom: 1px; }

/* --- Stany puste i ladowanie ------------------------------------------ */

.empty {
    padding: 52px 20px;
    text-align: center;
    color: var(--text-faint);
}
.empty svg { width: 42px; height: 42px; opacity: .35; margin-bottom: 12px; }
.empty h3 { color: var(--text-dim); margin-bottom: 4px; }

.skeleton {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--bg-elev-2) 25%, var(--bg-hover) 50%, var(--bg-elev-2) 75%);
    background-size: 420px 100%;
    animation: shimmer 1.25s infinite linear;
}
.skeleton + .skeleton { margin-top: 10px; }
.skeleton.w-60 { width: 60%; }
.skeleton.w-40 { width: 40%; }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}

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

.pager {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--line-soft);
    font-size: .83rem; color: var(--text-dim);
    flex-wrap: wrap;
}
.pager .spacer { flex: 1 1 auto; }
.pager .pages { display: flex; gap: 4px; }
.pager .page {
    min-width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: var(--radius-xs);
    border: 1px solid var(--line);
    background: var(--bg-elev);
    cursor: pointer; font-size: .82rem; font-weight: 600;
    transition: all .15s var(--ease);
}
.pager .page:hover { background: var(--bg-hover); border-color: var(--accent-line); }
.pager .page.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager .page:disabled { opacity: .4; cursor: not-allowed; }

/* --- Paski postepu i wykresy ------------------------------------------ */

.progress {
    height: 8px;
    background: var(--bg-elev-2);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
}
.progress > span {
    display: block; height: 100%;
    transition: width .5s var(--ease);
}
.progress .p-for   { background: linear-gradient(90deg, var(--success), #4ade80); }
.progress .p-against { background: linear-gradient(90deg, var(--danger), #f87171); }
.progress .p-abstain { background: var(--text-faint); }

.vote-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: .82rem; }
.vote-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 6px; }

.chart {
    display: flex; align-items: flex-end; gap: 8px;
    height: 190px; padding-top: 12px;
}
.chart .bar-group {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    height: 100%;
}
.chart .bars {
    flex: 1 1 auto;
    width: 100%;
    display: flex; align-items: flex-end; justify-content: center; gap: 3px;
}
.chart .bar {
    width: 46%; max-width: 22px;
    border-radius: 4px 4px 0 0;
    transform-origin: bottom;
    animation: grow .55s var(--ease) both;
    position: relative;
    transition: filter .16s var(--ease);
}
.chart .bar:hover { filter: brightness(1.2); }
.chart .bar.c { background: linear-gradient(180deg, var(--accent), rgba(79, 142, 247, .45)); }
.chart .bar.p { background: linear-gradient(180deg, var(--success), rgba(47, 191, 113, .45)); }
.chart .lbl { font-size: .68rem; color: var(--text-faint); white-space: nowrap; }

/* --- Kod odbioru ------------------------------------------------------ */

.pickup-code {
    font-family: "Cascadia Mono", Consolas, monospace;
    font-size: 1.7rem; font-weight: 700; letter-spacing: .22em;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px dashed var(--accent-line);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    text-align: center;
    user-select: all;
}

/* --- Lista definicji -------------------------------------------------- */

.dl {
    display: grid;
    grid-template-columns: minmax(120px, max-content) 1fr;
    gap: 9px 18px;
    font-size: .88rem;
}
.dl dt { color: var(--text-faint); font-size: .8rem; }
.dl dd { margin: 0; font-weight: 550; }

/* --- Os czasu (komentarze / historia) --------------------------------- */

.timeline { position: relative; padding-left: 26px; }
.timeline::before {
    content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px;
    width: 2px; background: var(--line);
}
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before {
    content: ""; position: absolute; left: -22px; top: 5px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent); border: 2px solid var(--bg-elev);
}
.tl-item.internal::before { background: var(--warning); }
.tl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.tl-head strong { font-size: .87rem; }
.tl-head time { font-size: .75rem; color: var(--text-faint); }
.tl-body { font-size: .88rem; white-space: pre-wrap; color: var(--text-dim); }

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

.login-wrap {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 24px 16px;
    background:
        radial-gradient(900px 500px at 15% -10%, rgba(79, 142, 247, .16), transparent 60%),
        radial-gradient(760px 460px at 95% 110%, rgba(124, 92, 255, .16), transparent 60%),
        var(--bg);
}

.login-card {
    width: min(410px, 100%);
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 32px 30px;
    animation: slideUp .4s var(--ease) both;
}
.login-card .brand { justify-content: center; margin-bottom: 22px; }
.login-card h1 { text-align: center; font-size: 1.2rem; margin-bottom: 2px; }
.login-card .lead { text-align: center; color: var(--text-dim); font-size: .87rem; margin-bottom: 22px; }
.login-error {
    background: var(--danger-soft); color: var(--danger);
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: var(--radius-xs);
    padding: 9px 12px; font-size: .84rem; margin-bottom: 14px;
    animation: slideDown .22s var(--ease) both;
}

/* --- Widok szczegolow ------------------------------------------------- */

.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.detail-grid .card + .card { margin-top: 18px; }

.crumbs { display: flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--text-faint); margin-bottom: 4px; }
.crumbs a { color: var(--text-dim); }

/* --- Responsywnosc ---------------------------------------------------- */

@media (max-width: 1180px) {
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
    .sidebar.open { transform: none; }
    .main { margin-left: 0; }
    .menu-toggle { display: grid; }
    .view { padding: 16px 14px; }
    .topbar { padding: 0 14px; gap: 10px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .col-span-2 { grid-column: auto; }

    .scrim {
        position: fixed; inset: 0;
        background: rgba(6, 10, 18, .55);
        z-index: 35;
        animation: fadeIn .2s var(--ease) both;
    }

    /* Tabela zamienia sie w liste kart */
    table.data thead { display: none; }
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data tr {
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        margin-bottom: 10px;
        padding: 4px 0;
        background: var(--bg-elev-2);
    }
    table.data td {
        display: flex; justify-content: space-between; align-items: center; gap: 14px;
        border-bottom: 1px solid var(--line-soft);
        padding: 8px 13px;
        text-align: right;
    }
    table.data td:last-child { border-bottom: 0; }
    table.data td::before {
        content: attr(data-label);
        font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
        color: var(--text-faint); font-weight: 700;
        text-align: left; flex: 0 0 auto;
    }
    table.data td.actions { justify-content: flex-end; }
    table.data td.hide-mobile { display: none; }

    .stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
    .stat .value { font-size: 1.35rem; }
    .modal-body { max-height: 74vh; }
    .toasts { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}

@media (max-width: 520px) {
    .toolbar { padding: 11px 13px; }
    .search { flex: 1 1 100%; }
    .card-head { padding: 13px 14px; flex-wrap: wrap; }
    .card-body { padding: 14px; }
    .chart { height: 150px; }
}

@media print {
    .sidebar, .topbar, .toolbar, .pager, .btn, .toasts { display: none !important; }
    .main { margin: 0; }
    .card { border: 1px solid #ccc; box-shadow: none; }
}
