:root {
    color-scheme: dark;
    --bg: #111316;
    --bg-elevated: #181c21;
    --bg-soft: #20262d;
    --border: #303741;
    --text: #f1f5f4;
    --muted: #a4afa9;
    --green: #39d59a;
    --green-dark: #12382c;
    --amber: #f4b84f;
    --rose: #ef6f7b;
    --blue: #6aa9ff;
    --danger: #ff5f6d;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    margin: 0;
    background: radial-gradient(circle at top left, rgba(57, 213, 154, 0.14), transparent 30%), var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
}

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

a:hover {
    color: #7ff0c5;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0f1215;
    color: var(--text);
    padding: 0.75rem 0.85rem;
}

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

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(57, 213, 154, 0.38);
    outline-offset: 2px;
    border-color: var(--green);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    color: #dfe7e3;
    font-weight: 700;
    background: #15191e;
    position: sticky;
    top: 0;
    z-index: 1;
}

tfoot th {
    background: #1c2425;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: rgba(18, 22, 26, 0.96);
    border-right: 1px solid var(--border);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
    z-index: 40;
}

.sidebar-backdrop {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--green), var(--amber));
    color: #07110e;
    display: grid;
    place-items: center;
    font-weight: 900;
}

.brand strong {
    display: block;
    font-size: 1.05rem;
}

.brand span {
    color: var(--muted);
    font-size: 0.9rem;
}

.nav-list {
    display: grid;
    gap: 0.35rem;
}

.nav-list a {
    color: #dfe6e2;
    padding: 0.78rem 0.85rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

.nav-list a:hover,
.nav-list a.active {
    background: var(--bg-soft);
    color: var(--text);
    border-color: var(--border);
}

.logout-form {
    margin-top: auto;
}

.content-shell {
    min-width: 0;
}

.topbar {
    min-height: 92px;
    border-bottom: 1px solid var(--border);
    background: rgba(17, 19, 22, 0.82);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.35rem, 2vw, 2rem);
    letter-spacing: 0;
}

.topbar-user {
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
}

.main-content {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 1.5rem;
    display: grid;
    gap: 1.2rem;
}

.eyebrow {
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    margin: 0 0 0.25rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card,
.panel-section,
.auth-card,
.summary-box {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015)), var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 1.1rem;
    min-height: 118px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-top: 3px solid var(--blue);
}

.stat-card span,
.muted,
.empty-state,
label small {
    color: var(--muted);
}

.stat-card strong {
    display: block;
    font-size: clamp(1.45rem, 2.4vw, 2.05rem);
    line-height: 1.1;
}

.accent-green {
    border-top-color: var(--green);
}

.accent-amber {
    border-top-color: var(--amber);
}

.accent-rose {
    border-top-color: var(--rose);
}

.panel-section {
    padding: 1.2rem;
}

.panel-section.narrow {
    max-width: 860px;
}

.section-heading,
.profile-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading h2,
.profile-heading h2 {
    margin: 0;
    font-size: 1.35rem;
    letter-spacing: 0;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.amount {
    font-weight: 800;
    color: #fbfffd;
    white-space: nowrap;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.actions form {
    margin: 0;
}

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.95rem;
    background: var(--bg-soft);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.button:hover {
    color: var(--text);
    border-color: #4a5561;
}

.button-primary {
    background: var(--green);
    color: #06110d;
    border-color: var(--green);
}

.button-primary:hover {
    color: #06110d;
    background: #63e8b4;
}

.button-secondary {
    background: #202b31;
    color: #eaf2ee;
}

.button-ghost {
    background: transparent;
}

.button-danger {
    background: rgba(255, 95, 109, 0.12);
    border-color: rgba(255, 95, 109, 0.35);
    color: #ffd9dd;
}

.button-small {
    min-height: 34px;
    padding: 0.45rem 0.65rem;
    font-size: 0.9rem;
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-stack,
.form-grid,
.filter-grid {
    display: grid;
    gap: 1rem;
}

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

.filter-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
}

label {
    display: grid;
    gap: 0.45rem;
    color: #eef6f2;
    font-weight: 700;
}

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

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    justify-content: flex-start;
}

.search-form {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    width: min(420px, 100%);
}

.input-with-unit {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #0f1215;
}

.input-with-unit input {
    border: 0;
    border-radius: 0;
    background: transparent;
}

.input-with-unit span {
    color: var(--muted);
    padding: 0 0.8rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.checkbox-row input,
.checkbox-card input {
    width: auto;
    min-height: auto;
}

.person-picker {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.person-picker legend {
    padding: 0 0.45rem;
    color: var(--green);
    font-weight: 800;
}

.person-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.85rem;
}

.checkbox-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
    padding: 0.8rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.3rem 0.65rem;
}

.checkbox-card small {
    grid-column: 2;
    font-size: 0.82rem;
    font-weight: 500;
}

.status {
    display: inline-flex;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.84rem;
    font-weight: 800;
}

.status-on {
    color: #98ffd2;
    background: rgba(57, 213, 154, 0.12);
}

.status-off {
    color: #ffd0d5;
    background: rgba(239, 111, 123, 0.12);
}

.flash {
    border-radius: 8px;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.flash-success {
    background: rgba(57, 213, 154, 0.12);
    border-color: rgba(57, 213, 154, 0.34);
}

.flash-error {
    background: rgba(255, 95, 109, 0.12);
    border-color: rgba(255, 95, 109, 0.34);
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-layout {
    width: min(440px, 100%);
}

.auth-card {
    padding: 1.35rem;
}

.auth-card h1 {
    margin: 1.2rem 0;
    font-size: 1.8rem;
}

.auth-brand {
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.auth-note {
    margin-top: 1rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.55rem;
}

.calendar-weekday {
    color: var(--muted);
    font-weight: 800;
    text-align: center;
    padding: 0.35rem;
}

.calendar-day {
    min-height: 112px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem;
    color: var(--text);
    background: #14181d;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.calendar-day:hover,
.calendar-day.selected {
    border-color: var(--green);
    background: #17231f;
}

.calendar-day.today {
    box-shadow: inset 0 0 0 2px rgba(244, 184, 79, 0.55);
}

.muted-day {
    opacity: 0.42;
}

.day-number {
    font-weight: 900;
}

.day-pill {
    width: fit-content;
    border-radius: 999px;
    background: var(--green-dark);
    color: #bfffe2;
    padding: 0.15rem 0.5rem;
    font-size: 0.82rem;
    font-weight: 800;
}

.calendar-day small {
    color: var(--muted);
}

.summary-box {
    padding: 1rem;
    margin-bottom: 1rem;
}

.summary-box p {
    margin: 0.25rem 0;
}

.person-print-page {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    box-shadow: var(--shadow);
}

.person-print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.person-print-header p {
    margin: 0 0 0.25rem;
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.person-print-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

.person-print-header span {
    display: block;
    margin-top: 0.25rem;
    color: var(--muted);
}

.person-print-header strong {
    font-size: 1.4rem;
    white-space: nowrap;
}

.person-print-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.person-print-summary div {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.025);
}

.person-print-summary span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.person-print-summary strong {
    font-size: 1.15rem;
}

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

.menu-button {
    display: none;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-soft);
    padding: 0.65rem;
}

.menu-button span {
    display: block;
    height: 2px;
    background: var(--text);
    margin: 4px 0;
}

.confirm-dialog {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-elevated);
    color: var(--text);
    width: min(420px, calc(100% - 2rem));
    box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
    background: rgba(0, 0, 0, 0.62);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

@media (max-width: 1180px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-grid,
    .person-checkbox-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    body {
        font-size: 15px;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(310px, 84vw);
        transform: translateX(-105%);
        transition: transform 180ms ease;
    }

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

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 30;
    }

    body.menu-open .sidebar-backdrop {
        display: block;
    }

    .menu-button {
        display: block;
        flex: 0 0 auto;
    }

    .topbar {
        align-items: center;
        padding: 0.9rem;
    }

    .topbar-user {
        display: none;
    }

    .main-content {
        padding: 0.75rem;
        gap: 0.85rem;
        width: 100%;
        overflow: hidden;
    }

    .panel-section,
    .auth-card,
    .person-print-page {
        padding: 0.85rem;
    }

    .section-heading,
    .profile-heading {
        flex-direction: column;
        gap: 0.75rem;
    }

    .section-heading h2,
    .profile-heading h2 {
        font-size: 1.15rem;
    }

    .search-form,
    .actions,
    .form-actions {
        width: 100%;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .form-grid,
    .filter-grid,
    .person-checkbox-grid {
        grid-template-columns: 1fr;
    }

    .button {
        width: 100%;
        white-space: normal;
        min-width: 0;
    }

    .actions {
        align-items: stretch;
        gap: 0.45rem;
    }

    .actions .button,
    .actions form {
        flex: 1 1 130px;
    }

    .actions form .button,
    .form-actions .button {
        width: 100%;
    }

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

    .stat-card {
        min-height: 92px;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        border-radius: 0;
    }

    .table-wrap table,
    .table-wrap thead,
    .table-wrap tbody,
    .table-wrap tfoot,
    .table-wrap tr,
    .table-wrap th,
    .table-wrap td {
        display: block;
        width: 100%;
    }

    .table-wrap table {
        min-width: 0;
        border-collapse: separate;
    }

    .table-wrap thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .table-wrap tbody,
    .table-wrap tfoot {
        display: grid;
        gap: 0.75rem;
    }

    .table-wrap tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #14181d;
        overflow: hidden;
    }

    .table-wrap td,
    .table-wrap tfoot th {
        display: grid;
        grid-template-columns: minmax(0, 42%) minmax(0, 58%);
        gap: 0.75rem;
        align-items: start;
        padding: 0.72rem 0.85rem;
        border-bottom: 1px solid var(--border);
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .table-wrap td:last-child,
    .table-wrap tfoot th:last-child {
        border-bottom: 0;
    }

    .table-wrap td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
        font-size: 0.82rem;
    }

    .table-wrap td.empty-state {
        display: block;
    }

    .table-wrap td.empty-state::before {
        content: none;
    }

    .table-wrap td.actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.45rem;
    }

    .table-wrap td.actions::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
        font-size: 0.82rem;
    }

    .table-wrap tfoot tr {
        background: #1c2425;
    }

    .table-wrap tfoot th {
        position: static;
        color: var(--text);
        background: transparent;
    }

    .table-wrap tfoot th::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
        font-size: 0.82rem;
    }

    .table-wrap tfoot th:first-child::before {
        content: "Podsumowanie";
    }

    .amount {
        white-space: normal;
    }

    .person-print-header {
        flex-direction: column;
    }

    .person-print-summary {
        grid-template-columns: 1fr;
    }

    .calendar-grid {
        gap: 0.35rem;
    }

    .calendar-day {
        min-height: 82px;
        padding: 0.45rem;
        font-size: 0.9rem;
    }

    .calendar-day small {
        display: none;
    }

    .day-pill {
        font-size: 0.74rem;
        padding: 0.1rem 0.35rem;
    }
}

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    body {
        background: #fff;
        color: #111;
        font-size: 10px;
        line-height: 1.22;
    }

    .sidebar,
    .topbar,
    .no-print,
    .button,
    .flash {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .main-content {
        width: 100%;
        padding: 0;
        display: block;
    }

    .panel-section,
    .stat-card,
    .report-header {
        box-shadow: none;
        border-color: #ccc;
        background: #fff;
    }

    .panel-section {
        padding: 4mm;
        margin: 0 0 3mm;
    }

    .section-heading {
        display: block;
        margin-bottom: 3mm;
    }

    .section-heading h2 {
        font-size: 14px;
        margin: 0;
    }

    .eyebrow,
    .muted {
        font-size: 9px;
        margin: 0 0 1mm;
    }

    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 2mm;
        margin: 0 0 3mm;
    }

    .stat-card {
        min-height: 0;
        padding: 2mm;
        border-top-width: 1px;
        page-break-inside: avoid;
    }

    .stat-card span {
        font-size: 8px;
    }

    .stat-card strong {
        font-size: 13px;
        line-height: 1.15;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
    }

    table {
        color: #111;
        min-width: 0;
        font-size: 9px;
    }

    th,
    td {
        padding: 1.6mm 2mm;
    }

    th {
        color: #111;
        background: #eee;
    }

    .person-report-header {
        padding-bottom: 2mm;
    }

    .person-report-table {
        padding-top: 2mm;
    }

    .person-print-page {
        display: block;
        break-after: page;
        page-break-after: always;
        color: #111;
    }

    .person-print-page:last-of-type {
        break-after: auto;
        page-break-after: auto;
    }

    .person-print-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 8mm;
        border: 1px solid #bbb;
        border-radius: 4px;
        padding: 4mm;
        margin-bottom: 3mm;
    }

    .person-print-header p {
        margin: 0 0 1mm;
        color: #008f62;
        font-size: 9px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .person-print-header h2 {
        margin: 0;
        font-size: 16px;
    }

    .person-print-header span {
        display: block;
        margin-top: 1mm;
        color: #555;
    }

    .person-print-header strong {
        font-size: 18px;
        white-space: nowrap;
    }

    .person-print-summary {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 2mm;
        margin-bottom: 3mm;
    }

    .person-print-summary div {
        border: 1px solid #c8c8c8;
        border-radius: 4px;
        padding: 2mm;
    }

    .person-print-summary span {
        display: block;
        color: #555;
        font-size: 8px;
        margin-bottom: 1mm;
    }

    .person-print-summary strong {
        font-size: 13px;
    }

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

    .person-print-table th,
    .person-print-table td {
        border-bottom: 1px solid #bbb;
        padding: 1.4mm 1.8mm;
    }

    .person-print-table th {
        background: #f0f0f0;
    }
}
