:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --primary: #1f5eff;
  --primary-ink: #ffffff;
  --weekend: #fff4e0;
  --holiday: #ffe6e6;
  --ok: #e7f6ec;
  --ok-ink: #17643a;
  --err: #fdecec;
  --err-ink: #9b1c1c;
  --info: #e8f0ff;
  --info-ink: #1d3f8f;
  --warn: #b45309;
  --radius: 8px;
  --sidebar: 220px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85em; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.strong { font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
ul.plain { list-style: none; padding: 0; margin: 0; line-height: 1.8; }

/* Layout */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 52px; z-index: 20;
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand span { color: var(--primary); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.topbar-user form { margin: 0; }
.nav-toggle { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; }
.sidebar {
  position: fixed; top: 52px; bottom: 0; left: 0; width: var(--sidebar); z-index: 10;
  background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .5rem; overflow-y: auto;
}
.sidebar a { display: block; padding: .55rem .8rem; border-radius: 6px; color: var(--text); }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--info); color: var(--info-ink); font-weight: 600; }
.content { margin-left: var(--sidebar); padding: 72px 1.5rem 2rem; max-width: 1600px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.narrow-card { max-width: 640px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.tile-label { color: var(--muted); font-size: .85rem; }
.tile-value { font-size: 1.35rem; font-weight: 700; margin-top: .25rem; font-variant-numeric: tabular-nums; }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--text); }
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: normal; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.row > label { flex: 1 1 160px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; display: flex; flex-direction: column; gap: .75rem; }
legend { font-weight: 600; padding: 0 .3rem; }
input.money { text-align: right; min-width: 80px; }
input.narrow, .narrow { max-width: 110px; }

.btn {
  display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 85%, black); }
.btn-warn { background: #fff7ed; border-color: #fdba74; color: var(--warn); }
.btn-ghost { background: transparent; }
.btn-small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; }
button.link.danger { color: var(--err-ink); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }
.actions form { margin: 0; }
details > summary { cursor: pointer; list-style: none; margin-bottom: .5rem; }
details > summary::-webkit-details-marker { display: none; }
details.card > summary { font-weight: 600; }

/* Period picker */
.period { display: flex; gap: .4rem; align-items: center; margin: 0; }
.period select { width: auto; }
.period input[type=number] { width: 90px; }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-success { background: var(--ok); color: var(--ok-ink); }
.alert-error { background: var(--err); color: var(--err-ink); }
.alert-info { background: var(--info); color: var(--info-ink); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th.num, .table td.num { text-align: right; }
.table thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tfoot th { border-top: 2px solid var(--border); border-bottom: 0; }
.table.compact td, .table.compact th { padding: .3rem .4rem; }
.table tr.inactive td { opacity: .55; }
.table tr.new-row td { background: var(--bg); }

.timesheet td { padding: .2rem .35rem; }
.timesheet input[type=time] { width: 110px; }
.timesheet select { min-width: 90px; }
.timesheet tr.weekend td { background: var(--weekend); }
.timesheet tr.holiday td { background: var(--holiday); }
.timesheet .t-dur { font-weight: 600; min-width: 60px; }
.tag { font-size: .7rem; background: #fff; border: 1px solid #f5b5b5; color: var(--err-ink); border-radius: 4px; padding: 0 .25rem; }
.payroll input { padding: .25rem .35rem; }
.payroll td { white-space: nowrap; }

.sticky-actions {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: .75rem 0; margin-top: .5rem; display: flex; gap: 1rem; align-items: center;
}

.badge { display: inline-block; font-size: .75rem; padding: .1rem .45rem; border-radius: 999px; font-weight: 600; }
.badge-uop { background: var(--info); color: var(--info-ink); }
.badge-zlecenie { background: #f3e8ff; color: #6b21a8; }

.tabs, .emp-tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem; }
.tabs a, .emp-tabs a { padding: .4rem .8rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.tabs a.active, .emp-tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Zmiana szerokości kolumn */
.table thead th { position: relative; }
.col-resizer { position: absolute; top: 0; right: -4px; width: 9px; height: 100%; cursor: col-resize; z-index: 2; touch-action: none; }
.col-resizer::after { content: ""; position: absolute; top: 20%; bottom: 20%; left: 4px; width: 1px; background: var(--border); }
.col-resizer:hover::after, .col-resizing .col-resizer::after { background: var(--primary); width: 2px; }
body.col-resizing { cursor: col-resize; user-select: none; }
.table.resized { table-layout: fixed; }
.table.resized td, .table.resized th { overflow: hidden; text-overflow: ellipsis; }
.table.resized input, .table.resized select { min-width: 0; }
.card { overflow-x: auto; }

/* Sprzedaż */
.sales-tiles .tile-value { font-size: 1.25rem; }
.tile-sub { color: var(--muted); font-size: .8rem; margin-top: .3rem; }
.tile-accent { border-color: var(--primary); background: var(--info); }
.tile-accent .tile-value { color: var(--info-ink); }
.bar { height: 6px; background: var(--bg); border-radius: 3px; margin-top: .5rem; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); transition: width .2s; }
.target-rate { align-self: center; }
.planned-form { margin-top: .75rem; }
.planned-form .grow { flex: 3 1 260px; }

/* Kalendarz sprzedaży */
.cal-card { overflow-x: auto; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: .75rem; align-items: center; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)) minmax(110px, .8fr); gap: 4px; min-width: 980px; }
.cal-head { font-size: .75rem; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: .25rem .4rem; }
.cal-day { border: 1px solid var(--border); border-radius: 6px; padding: .35rem .45rem; min-height: 112px; background: var(--surface); display: flex; flex-direction: column; gap: .15rem; }
.cal-day.weekend { background: var(--weekend); }
.cal-day.holiday { background: var(--holiday); }
.cal-day.today { border: 2px solid var(--primary); }
.cal-empty { background: transparent; border-style: dashed; opacity: .4; }
.cal-week { background: var(--bg); justify-content: center; }
.cal-top { display: flex; align-items: center; gap: .3rem; }
.cal-num { font-weight: 700; }
.cal-add { margin-left: auto; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; width: 22px; height: 22px; line-height: 1; cursor: pointer; color: var(--primary); font-weight: 700; }
.cal-add:hover { background: var(--info); }
.cal-hours { font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-amount { font-size: .85rem; font-variant-numeric: tabular-nums; }
.cal-wp { list-style: none; margin: 0; padding: 0; font-size: .75rem; color: var(--muted); }
.cal-wp li.no-rate { color: var(--warn); }
.cal-cum { margin-top: auto; font-variant-numeric: tabular-nums; }
.chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .72rem; border-radius: 4px; padding: .05rem .35rem; font-style: normal; }
.chip form { margin: 0; display: inline; }
.chip-plan { background: #f3e8ff; color: #6b21a8; }
.chip-x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 .1rem; font-weight: 700; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-ok { background: #16a34a; }
.dot-bad { background: #dc2626; }

/* Zgłoszenia godzin */
.status { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; }
.status-ok { background: var(--ok); color: var(--ok-ink); }
.status-pending { background: #fff7ed; color: var(--warn); }
.status-rejected { background: var(--err); color: var(--err-ink); }
.timesheet tr.is-pending td { box-shadow: inset 0 0 0 9999px rgba(251, 191, 36, .08); }
.nav-badge { display: inline-block; min-width: 1.4em; text-align: center; font-size: .72rem; font-weight: 700; background: var(--warn); color: #fff; border-radius: 999px; padding: 0 .35rem; margin-left: .25rem; }
.actions .reason { flex: 1 1 260px; }
.section-gap { margin-top: 1.5rem; }

/* Tabela jako karty na telefonie (Moja ewidencja) */
@media (max-width: 760px) {
  .stack-mobile thead { display: none; }
  .stack-mobile, .stack-mobile tbody, .stack-mobile tr, .stack-mobile td { display: block; width: 100% !important; }
  .stack-mobile tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .6rem; padding: .4rem .6rem; }
  .stack-mobile td { border: 0; display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: .5rem; padding: .2rem 0; }
  .stack-mobile td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  .stack-mobile td.center, .stack-mobile td.num { text-align: left; }
  .stack-mobile tfoot { display: block; }
  .stack-mobile tfoot tr { display: flex; flex-wrap: wrap; gap: .5rem; }
  .stack-mobile tfoot th { display: inline; border: 0; }
  .selfreport .table-wrap { overflow: visible; }
}

/* Role */
.perm-matrix .group-row th { background: var(--bg); text-transform: none; font-size: .9rem; color: var(--text); }
.perm-matrix td.center input { width: 18px; height: 18px; }
.inline-form { display: flex; gap: .4rem; align-items: center; margin: 0; }

.emp-picker { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; padding: .75rem 1rem; }
.emp-picker .emp-search { flex: 0 1 220px; }
.emp-picker .emp-select { flex: 1 1 280px; max-width: 420px; }
.emp-picker .emp-nav { display: flex; gap: .4rem; }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }

dl.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin: 0 0 1rem; }
dl.summary dt { color: var(--muted); font-size: .85rem; }
dl.summary dd { margin: .15rem 0 0; font-size: 1.1rem; font-weight: 600; }

/* Auth */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.auth-box h1 { margin-bottom: 1.25rem; }

/* Mobile */
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.15); }
  .content { margin-left: 0; padding: 68px 16px 2rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-user a { display: none; }
}

@media print {
  .topbar, .sidebar, .no-print, .period, .tabs, .alert { display: none !important; }
  .content { margin: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
  input { border: 0 !important; padding: 0 !important; }
}

/* Licencja (CRM Entevo) */
.license-details { display: grid; grid-template-columns: 170px 1fr; gap: .5rem 1rem; margin: 0; }
.license-details dt { color: var(--muted); }
.license-details dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .license-details { grid-template-columns: 1fr; gap: .15rem; } .license-details dd { margin-bottom: .5rem; } }
.license-state { display: inline-block; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; }
.license-ok { background: var(--ok); color: var(--ok-ink); }
.license-warn { background: #fff7ed; color: var(--warn); }
.license-err { background: var(--err); color: var(--err-ink); }
.text-err { color: var(--err-ink); }

/* Weryfikacja dwuetapowa */
.qr { display: flex; justify-content: center; margin: .75rem 0; }
.qr svg { width: 220px; height: 220px; max-width: 100%; border-radius: 8px; background: #fff; }
.secret-key { text-align: center; padding: .5rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow-wrap: anywhere; }
.secret-key code, .recovery-codes code { font: 600 15px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .04em; }
.code-input { font: 600 20px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .15em; text-align: center; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1.5rem; margin: 1rem 0; padding-left: 1.5rem; }
