:root {
    --bg: #f5f6fc;
    --surface: #ffffff;
    --surface-2: #eef1f8;
    --text: #14162e;
    --muted: #646b82;
    --border: #e3e7f1;
    --brand: #191a48;
    --primary: #4f46e5;
    --primary-strong: #4338ca;
    --primary-soft: color-mix(in srgb, var(--primary) 12%, var(--surface));
    --danger: #d92d20;
    --success: #15803d;
    --warning: #b7791f;
    --shadow: 0 10px 30px -12px rgba(20, 22, 46, 0.22);
    --shadow-lg: 0 24px 60px -20px rgba(20, 22, 46, 0.32);
    --radius: 14px;
    --radius-sm: 9px;
    --ring: color-mix(in srgb, var(--primary) 32%, transparent);
    --sidebar-width: 270px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0d0f17;
    --surface: #151926;
    --surface-2: #1d2231;
    --text: #eef1f8;
    --muted: #9aa3b8;
    --border: #29303f;
    --brand: #c7ccf5;
    --primary: #7c83f4;
    --primary-strong: #9aa0f8;
    --primary-soft: color-mix(in srgb, var(--primary) 20%, var(--surface));
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow: 0 14px 40px -16px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 28px 70px -24px rgba(0, 0, 0, 0.65);
    --ring: color-mix(in srgb, var(--primary) 45%, transparent);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    letter-spacing: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    padding: 10px 11px;
    outline: none;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent);
    outline-offset: 2px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 650;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(140deg, rgba(15, 118, 110, 0.16), transparent 42%),
        var(--bg);
}

.auth-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.auth-card.wide {
    width: min(620px, 100%);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-weight: 850;
    letter-spacing: 0;
    margin-bottom: 18px;
}

.brand-mark.small {
    width: 36px;
    height: 36px;
    margin: 0;
    font-size: 0.82rem;
}

.stack {
    display: grid;
    gap: 16px;
}

.muted {
    color: var(--muted);
}

.alert {
    border-radius: 6px;
    border: 1px solid var(--border);
    padding: 11px 12px;
    margin: 14px 0;
}

.alert-error {
    background: color-mix(in srgb, var(--danger) 12%, var(--surface));
    color: var(--danger);
}

.alert-success {
    background: color-mix(in srgb, var(--success) 12%, var(--surface));
    color: var(--success);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 14px;
    overflow-y: auto;
    z-index: 20;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 820;
    font-size: 1.05rem;
    padding: 0 8px 18px;
}

.nav {
    display: grid;
    gap: 4px;
}

.nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    padding: 10px 11px;
    text-align: left;
}

.nav button:hover,
.nav button.active {
    background: var(--surface-2);
}

.nav .nav-icon {
    width: 22px;
    text-align: center;
}

.main-shell {
    min-width: 0;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    min-height: 68px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.menu-toggle {
    display: none;
}

.global-search {
    position: relative;
    flex: 1;
    max-width: 620px;
}

.global-search input {
    min-height: 42px;
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 40;
}

.search-results button {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 12px;
    text-align: left;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.92rem;
}

.content {
    padding: 24px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-title {
    margin: 0;
    font-size: clamp(1.45rem, 3vw, 2.1rem);
    line-height: 1.12;
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 16px;
}

.toolbar > * {
    width: auto;
}

.button,
.icon-button {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    min-height: 40px;
    padding: 9px 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.button:hover,
.icon-button:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.button.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

[data-theme="dark"] .button.primary {
    color: #06211e;
}

.button.danger {
    color: var(--danger);
}

.icon-button {
    width: 40px;
    padding: 0;
    font-size: 1.15rem;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid.cards {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.card,
.widget,
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.card,
.widget {
    padding: 15px;
}

.panel {
    padding: 18px;
}

.card-title {
    margin: 0 0 8px;
    font-size: 1rem;
    line-height: 1.3;
}

.card-meta,
.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 0.84rem;
}

.widget h2,
.panel h2 {
    margin: 0 0 12px;
    font-size: 1.05rem;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

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

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

th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0;
    background: var(--surface-2);
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 750;
    white-space: nowrap;
}

.priority-pilne,
.status-overdue {
    color: var(--danger);
}

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

.form-grid .full {
    grid-column: 1 / -1;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.48);
    padding: 20px;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(900px, 100%);
    max-height: min(86vh, 920px);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.18rem;
}

.modal-body {
    padding: 18px;
    overflow: auto;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 200;
    max-width: min(420px, calc(100vw - 40px));
    border-radius: 6px;
    background: var(--text);
    color: var(--surface);
    padding: 12px 14px;
    box-shadow: var(--shadow);
}

.empty {
    padding: 28px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.7fr);
    gap: 16px;
}

.definition-list {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 10px 16px;
}

.definition-list dt {
    color: var(--muted);
    font-weight: 700;
}

.definition-list dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.kanban {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 1fr);
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.kanban-column {
    min-height: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.kanban-column h2 {
    margin: 0 0 10px;
    font-size: 0.96rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.calendar-day {
    min-height: 116px;
    background: var(--surface);
    padding: 8px;
}

.calendar-day.outside {
    background: var(--surface-2);
    color: var(--muted);
}

.calendar-date {
    font-weight: 800;
    margin-bottom: 7px;
}

.calendar-item {
    display: block;
    width: 100%;
    border: 0;
    border-left: 4px solid var(--primary);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    margin: 4px 0;
    padding: 5px 6px;
    text-align: left;
    font-size: 0.78rem;
}

.report-bars {
    display: grid;
    gap: 8px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin: 12px 0 4px;
}

.summary-item {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    background: var(--surface-2);
}

.summary-item span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
}

.summary-item strong {
    display: block;
    font-size: 1.6rem;
    line-height: 1.2;
    margin-top: 4px;
}

.report-groups {
    display: grid;
    gap: 18px;
    margin-top: 18px;
}

.checklist-block {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 12px;
}

.checklist-block:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.checklist-block li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
}

.bar-row {
    display: grid;
    grid-template-columns: 180px 1fr 42px;
    gap: 10px;
    align-items: center;
}

.bar {
    height: 10px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.bar span {
    display: block;
    height: 100%;
    background: var(--primary);
}

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

.fieldset-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: grid;
    gap: 9px;
}

.fieldset-box legend {
    color: var(--muted);
    font-weight: 800;
    padding: 0 6px;
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        width: min(var(--sidebar-width), 86vw);
    }

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

    .menu-toggle {
        display: inline-flex;
    }

    .topbar {
        padding: 10px 14px;
    }

    .user-menu span {
        display: none;
    }

    .content {
        padding: 16px;
    }

    .page-header {
        display: grid;
    }

    .detail-layout,
    .split {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .definition-list {
        grid-template-columns: 1fr;
    }

    .calendar-grid {
        display: block;
        background: transparent;
        border: 0;
    }

    .calendar-day {
        min-height: auto;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 8px;
    }

    .calendar-day.empty-mobile {
        display: none;
    }
}

@media (max-width: 620px) {
    .topbar {
        flex-wrap: wrap;
    }

    .global-search {
        order: 5;
        flex-basis: 100%;
        max-width: none;
    }

    .toolbar > * {
        width: 100%;
    }

    .toolbar .button,
    .toolbar select,
    .toolbar input {
        width: 100%;
    }

    .table-wrap {
        border: 0;
        background: transparent;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 10px;
        margin-bottom: 10px;
    }

    td {
        border: 0;
        padding: 6px 0;
    }

    td::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 0.76rem;
        font-weight: 800;
        text-transform: uppercase;
        margin-bottom: 2px;
    }
}

/* ============================================================
   Odświeżenie wyglądu + logo BPiK
   ============================================================ */

body {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.button,
.icon-button,
.nav button,
.card,
.widget,
.panel,
.badge,
input,
select,
textarea {
    transition: background-color .16s ease, border-color .16s ease,
        color .16s ease, box-shadow .2s ease, transform .16s ease, filter .16s ease;
}

/* Spójniejsze zaokrąglenia */
input,
select,
textarea,
.button,
.icon-button,
.nav button,
.alert {
    border-radius: var(--radius-sm);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
    outline: none;
}

/* Logo / marka - oficjalny znak BPiK (inline SVG, dopasowany do motywu) */
.brand-logo-full {
    display: block;
    color: var(--brand);
    line-height: 0;
}

.brand-logo-full svg {
    display: block;
    width: 100%;
    height: auto;
}

.sidebar-brand {
    display: block;
    padding: 6px 6px 18px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-logo-full {
    max-width: 200px;
}

.auth-brand {
    margin-bottom: 24px;
}

.auth-brand .brand-logo-full {
    max-width: 250px;
}

/* Logowanie / konfiguracja */
.auth-page {
    background:
        radial-gradient(1100px 520px at 100% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 60%),
        radial-gradient(900px 520px at -10% 110%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 55%),
        var(--bg);
}

.auth-card {
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
}

/* Pasek boczny i nawigacja */
.nav button {
    position: relative;
    font-weight: 640;
}

.nav button:hover {
    background: var(--surface-2);
}

.nav button.active {
    background: var(--primary-soft);
    color: var(--primary-strong);
    font-weight: 760;
}

.nav button.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: 999px;
    background: var(--primary);
}

/* Przyciski */
.button.primary {
    background: linear-gradient(180deg, var(--primary), var(--primary-strong));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--primary) 75%, transparent);
}

.button.primary:hover {
    background: linear-gradient(180deg, var(--primary), var(--primary-strong));
    filter: brightness(1.06);
}

.button.primary:active {
    transform: translateY(1px);
}

[data-theme="dark"] .button.primary {
    color: #0b0d18;
}

/* Karty z subtelnym podniesieniem */
.grid.cards .card {
    cursor: default;
}

.grid.cards .card:hover {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

/* Górny pasek */
.topbar {
    background: color-mix(in srgb, var(--surface) 80%, transparent);
}

/* Akcent na nagłówkach stron */
.page-title {
    letter-spacing: -0.01em;
}

/* Ikony w menu (liniowe SVG) */
.nav .nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    flex: none;
}

.nav .nav-icon svg {
    width: 19px;
    height: 19px;
}
