:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e3e6eb;
    --text: #1a1d22;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --tag-bg: #eef2ff;
    --tag-text: #4338ca;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
}

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav a {
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
}

.nav a:hover { background: var(--bg); }
.nav a.active {
    background: var(--primary);
    color: white;
}

.userbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
}

h1, h2, h3 { margin: 0 0 16px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.1s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
}

tr:hover td { background: #fafbfc; }

.tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--tag-bg);
    color: var(--tag-text);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.badge-otwarte    { background: #dbeafe; color: #1e40af; }
.badge-wstrzymane { background: #fef3c7; color: #92400e; }
.badge-zamkniete  { background: #e5e7eb; color: #374151; }
.badge-nowy       { background: #dbeafe; color: #1e40af; }
.badge-rozmowa    { background: #fef3c7; color: #92400e; }
.badge-pracuje    { background: #d1fae5; color: #065f46; }
.badge-zakonczony { background: #e5e7eb; color: #374151; }
.badge-odrzucony  { background: #fee2e2; color: #991b1b; }
.badge-zrezygnowal{ background: #fee2e2; color: #991b1b; }
.badge-aktywny    { background: #d1fae5; color: #065f46; }
.badge-wstrzymany { background: #fef3c7; color: #92400e; }
.badge-archiwum   { background: #e5e7eb; color: #374151; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--card);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

.field {
    margin-bottom: 12px;
}
.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
}

.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 12px;
}
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}

.toolbar .spacer { flex: 1; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* Nie lamia sie wartosci jednoliniowe (telefon, daty, dokumenty, imie) */
td.mono,
td[data-col="imie"],
td[data-col="telefon"],
td[data-col="data_urodzenia"],
td[data-col="paszport"],
td[data-col="pesel"],
td[data-col="narodowosc"],
td[data-col="wiek"],
td[data-col="plec"],
td[data-col="stawka"],
td[data-col="__stawka_match"],
td[data-col="__zmiana"] {
    white-space: nowrap;
}

/* Login screen */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}
.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.login-card h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 24px;
}

/* Przypisania - 2 kolumny */
.kolumny {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
}
.lista-pracownikow .pracownik {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.lista-pracownikow .pracownik:last-child { border-bottom: none; }

.firma-row {
    border-left: 4px solid var(--primary);
    padding-left: 12px;
    margin-bottom: 12px;
}
.firma-row.full { border-left-color: var(--success); }
.firma-row.empty { border-left-color: var(--warning); }

.licznik {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-weight: 700;
    font-size: 13px;
}

details.firma-details summary {
    cursor: pointer;
    padding: 8px 0;
    list-style: none;
}
details.firma-details summary::-webkit-details-marker { display: none; }
details.firma-details summary::before {
    content: '\25B6';
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.1s;
    font-size: 10px;
    color: var(--muted);
}
details.firma-details[open] summary::before { transform: rotate(90deg); }

.actions { display: flex; gap: 4px; }

/* ============ Klikalne wiersze ============ */
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #eef2ff; }
tr.row-link:hover { box-shadow: inset 4px 0 0 var(--primary); }

/* ============ Sortowalne naglowki ============ */
th.sortable a {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
th.sortable a:hover { color: var(--primary); }
th.sortable .sort-arrow {
    font-size: 10px;
    opacity: 0.4;
}
th.sortable.active .sort-arrow { opacity: 1; color: var(--primary); }
th.sortable.active a { color: var(--primary); font-weight: 700; }

/* ============ Modal/dialog ============ */
dialog.modal {
    border: none;
    border-radius: 10px;
    padding: 0;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    max-width: 500px;
    width: 90vw;
    background: var(--card);
}
dialog.modal::backdrop {
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
}
dialog.modal[open] {
    animation: modalIn 0.15s ease-out;
}
@keyframes modalIn {
    from { transform: translateY(-10px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
dialog.modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
dialog.modal .modal-header h2 { margin: 0; font-size: 16px; }
dialog.modal .modal-close {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    color: var(--muted);
    padding: 0;
    width: 32px;
    height: 32px;
}
dialog.modal .modal-close:hover { color: var(--text); }
dialog.modal .modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}
dialog.modal .modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 10px 10px;
}

/* ============ Aktywne filtry - chipy ============ */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--tag-bg);
    color: var(--tag-text);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.filter-chip a {
    color: inherit;
    text-decoration: none;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
}
.filter-chip a:hover { opacity: 1; }

/* ============ Karta detalu ============ */
.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}
.detail-header h1 { margin: 0; flex: 1; }
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.detail-row {
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 6px;
}
.detail-row .label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}
.detail-row .value { font-weight: 500; }
.breadcrumb {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
