/* ===== Tokeny ===== */
:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --ink: #1f2430;
    --ink-2: #4a5263;
    --muted: #7a8294;
    --line: #e4e8ef;
    --line-strong: #d3d9e3;
    --accent: #23408f;
    --accent-hover: #1a3174;
    --accent-soft: #e9eefb;
    --ok: #1f7a4d;
    --ok-soft: #e7f5ee;
    --err: #b3372f;
    --err-soft: #fbeceb;
    --warn-soft: #fff6e0;
    --warn: #8a5a00;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(25, 35, 60, .05), 0 4px 14px rgba(25, 35, 60, .05);
    --shadow-lg: 0 12px 40px rgba(20, 28, 50, .22);
    --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
    --sidebar-w: 248px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
    color: var(--ink); background: var(--bg);
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code { background: #eef1f6; padding: 1px 6px; border-radius: 5px; font-size: .9em; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ===== Układ ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: #fff;
    border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; z-index: 40;
}
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 12px;
    padding: 0 28px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar__title { font-size: .95rem; }
.topbar__app { color: var(--muted); }
.topbar__sep { color: var(--line-strong); margin: 0 8px; }
#topbarSection { font-weight: 600; }
.content { padding: 28px; max-width: 1280px; width: 100%; outline: none; }
.menu-btn { display: none; }
.sidebar-backdrop { display: none; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.02rem; padding: 4px 8px 18px; }
.brand__mark {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
    background: var(--accent); color: #fff; font-size: 1rem; flex: none;
}
.brand--large { justify-content: center; padding-bottom: 6px; font-size: 1.15rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: #f1f4f9; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav__ico { width: 20px; text-align: center; opacity: .8; }
.sidebar__foot { margin-top: auto; display: grid; gap: 8px; }
.whoami { display: flex; align-items: center; gap: 10px; padding: 8px; font-weight: 600; font-size: .9rem; }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .8rem; }

/* ===== Karty, nagłówki stron ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card__body { padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 20px; }
.stack { display: grid; gap: 20px; }
.stat { padding: 18px 20px; }
.stat__label { color: var(--muted); font-size: .85rem; }
.stat__value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat__sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }

/* ===== Przyciski ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
    border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f6f8fb; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn--danger:hover { background: #99302a; }
.btn--ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: #eef1f6; }
.btn--sm { min-height: 32px; padding: 0 11px; font-size: .88rem; }
.btn--block { width: 100%; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); cursor: pointer; font-size: 1.1rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===== Formularze ===== */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: #fff; color: var(--ink); font: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.is-invalid { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.toolbar > * { flex: 0 1 auto; }
.toolbar input[type=search], .toolbar input[type=text] { min-width: 220px; }
.toolbar select, .toolbar input[type=date] { width: auto; }

/* ===== Tabele ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .82rem; font-weight: 600; color: var(--muted); background: #fafbfd; white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfe; }
tfoot td { background: #f7f9fc; font-weight: 700; border-top: 2px solid var(--line-strong); }
td.actions { text-align: right; white-space: nowrap; }
.row-inactive td { color: var(--muted); }

/* Tabela rozliczenia */
.settle-table td { padding: 10px 12px; }
.settle-table tr.is-done td { background: var(--ok-soft); }
.settle-table tr.is-done td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.settle-table input.hours { width: 86px; text-align: right; }
.settle-table input.js-time, .settle-table input.js-courses { width: 78px; }
.settle-table input:disabled { background: #f1f3f7; color: var(--muted); }
.settle-table input.note { min-width: 160px; }
.settle-table .total { font-weight: 700; }
.settle-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px 20px; background: #f7f9fc; border-top: 1px solid var(--line); }
.sum-item small { display: block; color: var(--muted); font-size: .8rem; }
.sum-item strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.sum-item--grand strong { font-size: 1.5rem; color: var(--accent); }
.week-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.week-picker input[type=date] { width: auto; }
.week-label { font-weight: 700; font-size: 1.05rem; padding: 0 6px; font-variant-numeric: tabular-nums; }

/* ===== Etykiety, komunikaty ===== */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef1f6; color: var(--ink-2); }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--err { background: var(--err-soft); color: var(--err); }
.badge--accent { background: var(--accent-soft); color: var(--accent); }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .93rem; }
.alert--error { background: var(--err-soft); color: var(--err); border: 1px solid #f1cdca; }
.alert--success { background: var(--ok-soft); color: var(--ok); border: 1px solid #c8e8d6; }
.alert--warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0dca6; }
.alert--info { background: var(--accent-soft); color: var(--accent); border: 1px solid #cfd9f3; }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Modale i toasty ===== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100; background: rgba(20, 26, 40, .45); display: grid; place-items: center;
    padding: 16px; animation: fade .15s ease-out; overflow-y: auto;
}
.modal { background: #fff; width: 100%; max-width: 480px; border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal--wide { max-width: 1040px; }
.modal__head { padding: 18px 22px 0; }
.modal__body { padding: 12px 22px 8px; overflow-y: auto; }
.modal__foot { padding: 14px 22px 20px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast { background: #1f2430; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); animation: pop .2s ease-out; font-size: .93rem; }
.toast--success { background: #17603c; }
.toast--error { background: #9d2f28; }
.report-preview { background: #e9edf3; border-radius: 10px; padding: 10px; text-align: center; }
.report-preview canvas { max-width: 100%; max-height: 68vh; width: auto; height: auto; display: block; margin: 0 auto; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.15); }

/* ===== Logowanie ===== */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { background: #fff; width: 100%; max-width: 410px; border-radius: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 30px 28px; }
.auth-card h1 { font-size: 1.2rem; text-align: center; margin: 12px 0 22px; }

/* ===== Responsywność ===== */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(20, 26, 40, .4); z-index: 30; }
    .main { margin-left: 0; }
    .menu-btn { display: grid; }
    .topbar { padding: 0 16px; }
    .content { padding: 18px 14px; }
    .toolbar input[type=search], .toolbar input[type=text] { min-width: 0; flex: 1 1 100%; }
}
@media (max-width: 760px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
    .table-stack td { border: none; padding: 5px 0; display: flex; justify-content: space-between; gap: 12px; align-items: center; text-align: right; }
    .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; font-weight: 600; text-align: left; flex: none; }
    .table-stack td.actions { justify-content: flex-end; }
    .table-stack td.actions::before, .table-stack td[data-label=""]::before { display: none; }
    .table-stack tbody tr:hover td { background: transparent; }
    .settle-table tr.is-done { box-shadow: inset 4px 0 0 var(--ok); }
    .settle-table tr.is-done td:first-child { box-shadow: none; }
    .table-stack td.cell-name { font-weight: 700; font-size: 1.02rem; text-align: left; }
    .table-stack td.cell-name::before { display: none; }
    .settle-table input.note { min-width: 0; width: 60vw; }
    .page-head { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
