:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #dfe3e8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #c77700;
  --crit: #c5352b;
  --warn-bg: #fff6e0;
  --crit-bg: #fdecea;
  --ok-bg: #e7f6ec;
  --row: #f8f9fb;
  --top: #172133;
  --top-text: #e8ecf3;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --text: #e4e8ee;
    --muted: #9aa5b5;
    --line: #2c3542;
    --accent: #6ea8ff;
    --accent-text: #0d1522;
    --ok: #4cc27f;
    --warn: #e5a93b;
    --crit: #f0766c;
    --warn-bg: #3a2f14;
    --crit-bg: #3d1e1c;
    --ok-bg: #173323;
    --row: #1f2631;
    --top: #0d1118;
    --top-text: #e4e8ee;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
code, .mono, pre { font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: 13px; }
code { background: var(--row); padding: 1px 4px; border-radius: 3px; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 24px; }

.top { background: var(--top); color: var(--top-text); }
.top-in { display: flex; align-items: center; gap: 0 20px; flex-wrap: wrap; min-height: 52px; }
.brand { color: var(--top-text); font-weight: 600; font-size: 16px; padding: 12px 0; }
/* Nazwa systemu i wylogowanie w pierwszym wierszu, menu w drugim – długa nazwa nie łamie wtedy menu. */
.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 0 0 100%; order: 3; margin: 0 -12px; }
.top nav a { color: var(--top-text); opacity: .8; padding: 9px 12px; border-bottom: 3px solid transparent; }
.top nav a:hover { opacity: 1; text-decoration: none; }
.top nav a.on { opacity: 1; border-bottom-color: #6ea8ff; }
.logout { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { opacity: .75; }
.badge { background: var(--crit); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 12px; font-weight: 600; }
.foot { color: var(--muted); font-size: 12px; padding-bottom: 24px; }

.btn {
  display: inline-block; padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-ghost { background: transparent; }
.top .btn-ghost { color: var(--top-text); border-color: rgba(255, 255, 255, .25); }

input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; max-width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.card.danger { border-color: var(--crit); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.cols > .card { margin-bottom: 0; }
.cols { margin-bottom: 16px; }

.tiles { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 18px;
  min-width: 190px; color: var(--text); display: block;
}
.tile b { display: block; font-size: 26px; line-height: 1.2; }
.tile span { color: var(--muted); }
.tile-warn b { color: var(--crit); }
a.tile:hover { text-decoration: none; border-color: var(--accent); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.search { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.search input[type=search] { flex: 1; min-width: 220px; max-width: 460px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin-bottom: 8px; }
.table-wrap.scroll { max-height: 520px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid thead th { background: var(--row); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.grid thead th a { color: var(--text); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--row); }
.grid.plain { border: 1px solid var(--line); }
.grid tr:has(+ tr.sub-row) td { border-bottom: 0; }
.grid tr.sub-row td { padding-top: 0; color: var(--muted); }
.grid tr.sub-row td b { color: var(--text); }
.grid tr.sub-row td .err { color: var(--crit); }
.num { text-align: right !important; white-space: nowrap; }
.c-dot { width: 44px; padding-right: 0 !important; }
.c-date { white-space: nowrap; width: 140px; }
.c-cat { white-space: nowrap; width: 130px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }

.kv th { text-align: left; font-weight: 400; color: var(--muted); padding: 5px 14px 5px 0; width: 42%; vertical-align: top; }
.kv td { padding: 5px 0; word-break: break-word; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.dot-ok { background: var(--ok); }
.dot-idle { background: var(--warn); }
.dot-off { background: var(--crit); }
.warn-ico {
  display: inline-block; width: 17px; height: 17px; line-height: 17px; text-align: center; border-radius: 50%;
  background: var(--crit); color: #fff; font-size: 12px; font-weight: 700; margin-left: 4px; cursor: help;
}

.bar { width: 120px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar-block { display: block; margin: 5px 0 3px; }
.bar-warn i { background: var(--warn); }
.bar-crit i { background: var(--crit); }

.tag { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 10px; margin-right: 4px; }
.tag-add { background: var(--ok-bg); color: var(--ok); }
.tag-del { background: var(--crit-bg); color: var(--crit); }
.tag-chg { background: var(--warn-bg); color: var(--warn); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 4px 12px; color: var(--text); }
.chip b { margin-left: 4px; }
a.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

.notice { background: var(--ok-bg); border: 1px solid var(--ok); border-radius: 6px; padding: 9px 12px; margin-bottom: 14px; }
.notice-warn { background: var(--warn-bg); border-color: var(--warn); }
.notice-err { background: var(--crit-bg); border-color: var(--crit); }
.notice p { margin: 0 0 8px; }
.notice p:last-child { margin-bottom: 0; }
.token-new { font-size: 22px; letter-spacing: 1px; font-weight: 600; user-select: all; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin: 12px 0 14px; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.inline-form input[type=text] { min-width: 220px; }

.crumbs { color: var(--muted); margin: 0 0 6px; }
.head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { margin: 0; }

.form label { display: block; margin-bottom: 12px; color: var(--muted); }
.form label input, .form label textarea, .form label select { display: block; width: 100%; margin-top: 4px; }
.form.narrow { max-width: 380px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: block; margin-bottom: 10px; }

.login-box { max-width: 360px; margin: 48px auto; }
.login-box label { display: block; margin-bottom: 12px; color: var(--muted); }
.login-box input { display: block; width: 100%; margin-top: 4px; }
.btn-wide { display: block; width: 100%; text-align: center; padding-top: 9px; padding-bottom: 9px; }
.local-login { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.local-login summary { cursor: pointer; color: var(--muted); margin-bottom: 12px; }
/* Rola „tylko podgląd”: formularze zmieniające dane są ukryte (serwer i tak odrzuca takie żądania). */
body.role-viewer main form[method="post"], body.role-viewer main .bulkbar, body.role-viewer main input.bulk-id { display: none !important; }
body.role-viewer main .keybox { display: none !important; }
.install { max-width: 620px; margin: 24px auto; }
.install h2 { margin-top: 18px; }

.code { background: var(--row); border: 1px solid var(--line); border-radius: 6px; padding: 12px; white-space: pre-wrap; word-break: break-all; margin: 0 0 10px; }
.code-area { width: 100%; font-family: Consolas, Menlo, monospace; font-size: 13px; }
.pager { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

@media (max-width: 700px) {
  .cols { grid-template-columns: 1fr; }
  .form .two { grid-template-columns: 1fr; }
  .logout { margin-left: 0; }
}

.btn-small { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
form.inline { display: inline; }
.row-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 8px; }
.row-form label { color: var(--muted); }
.row-form label input[type=text] { display: block; margin-top: 4px; min-width: 240px; }
.row-form .check { margin-bottom: 8px; }
.form.narrow-wide { max-width: 640px; }
.form p { margin-top: -6px; }
.form label.check, .row-form label.check { color: var(--text); }
.form label.check input, .row-form label.check input { display: inline; width: auto; margin: 0 6px 0 0; vertical-align: middle; }
.kv .dot { margin-right: 4px; }

details summary { cursor: pointer; color: var(--accent); }
pre.code.small { font-size: 12px; margin: 6px 0 0; max-height: 220px; overflow: auto; }
.toolbar h2 { margin: 0; }
.bulkbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.c-dot input { vertical-align: middle; margin: 0 4px 0 0; }
.head form.inline { margin-left: auto; }
.card > .row-gap { margin-top: 12px; }

/* ---------- Wersja 1.4: bezpieczeństwo, incydenty, wgrywanie pakietów, raport do wydruku ---------- */
input[type=date], input[type=datetime-local], input[type=file] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; max-width: 100%;
}
.chips.sub { margin-bottom: 14px; }
.wrap-text, .mono.wrap, td .wrap { word-break: break-all; }
.pre { white-space: pre-wrap; word-break: break-word; }
tr.dim td { color: var(--muted); }
.cols.inner { margin-bottom: 0; gap: 8px 28px; }
.err { color: var(--crit); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
.keybox { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 12px 0; background: var(--row); }
.keybox .row-form { margin-bottom: 4px; }
.keybox .row-form label input { display: block; margin-top: 4px; }
.keybox p { margin: 6px 0 0; }
.key-text { -webkit-text-security: disc; }
.sign-grid input[type=text], .sign-grid input[type=number], .sign-grid select { width: 100%; min-width: 70px; padding: 3px 6px; }
.sign-grid td { vertical-align: top; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
.row-form label select, .row-form label input[type=datetime-local], .row-form label input[type=date] { display: block; margin-top: 4px; }
progress { width: 100%; height: 14px; margin-top: 10px; accent-color: var(--accent); }
.pending { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; background: var(--row); }
.steps { margin: 10px 0; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.steps .row-form { margin: 6px 0 0; }
.steps code { word-break: break-all; }
.report h1 { margin-bottom: 4px; }
.checklist td.blank { width: 34%; height: 44px; }
.signatures { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 28px; }
.signatures div { flex: 1; min-width: 200px; color: var(--muted); }
.signatures span { display: block; border-bottom: 1px solid var(--text); height: 34px; }

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --line: #999; --row: #fff; --ok-bg: #fff; --warn-bg: #fff; --crit-bg: #fff; }
  body { font-size: 11pt; }
  .top, .foot, .no-print, .notice:not(.notice-warn):not(.notice-err) { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; margin-bottom: 14pt; break-inside: avoid; }
  .cols { display: block; }
  .cols > .card { margin-bottom: 14pt; }
  .grid thead th { position: static; }
  .tag { border: 1px solid #999; }
  a { color: #000; text-decoration: none; }
  textarea, input[type=text], input[type=datetime-local], select { border: 0; padding: 0; background: transparent; resize: none; appearance: none; -webkit-appearance: none; }
  textarea { field-sizing: content; width: 100%; }
}
.c-state { min-width: 130px; }
.c-state .tag { white-space: nowrap; }

.step { display: flex; gap: 10px; align-items: flex-start; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.step:hover { background: var(--row); }
.step input { margin-top: 3px; flex: none; }
.step.done .step-title { color: var(--muted); text-decoration: line-through; }
.step.next { background: var(--warn-bg); }
.step-title { font-weight: 600; }
.step-hint { display: block; color: var(--muted); font-size: 13px; }
.next-step { font-size: 15px; }
.hint { margin-top: 4px; padding: 4px 8px; border-left: 3px solid var(--warn); background: var(--warn-bg); border-radius: 0 4px 4px 0; }
.card .notice { margin-top: 10px; }
.row-form.compact { margin: 0; gap: 6px; align-items: center; }
.row-form.compact input[type=password] { width: 150px; padding: 3px 8px; }
.changelog { background: var(--row); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; max-height: 360px; overflow: auto; }
[hidden] { display: none !important; }

/* Konta i uprawnienia */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 16px; margin: 4px 0 4px 24px; }
.perm-grid .check { margin-bottom: 6px; }
.person .head { margin-bottom: 4px; }
.search label { display: flex; align-items: center; gap: 6px; }

/* Wykresy pomiarów czujników (assets/chart.js) */
.chart { position: relative; margin: 6px 0 18px; }
.chart h3 { margin: 0 0 4px; font-size: 15px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.chart-legend i, .chart-tip i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.chart-plot { position: relative; width: 100%; overflow: hidden; }
.chart-plot svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 11px; }
.chart-hair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-tip { position: absolute; top: 34px; z-index: 5; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; }
.chart-tip-head { color: var(--muted); margin-bottom: 3px; }
.chart-tip b { display: inline-block; min-width: 58px; }
.chart-empty { color: var(--muted); padding: 18px 0; }
/* Wąski ekran: szerokie tabele przewijają się w poziomie zamiast rozpychać stronę. */
@media (max-width: 700px) {
  .cols > *, .card { min-width: 0; }
  table.grid.plain { display: block; overflow-x: auto; }
}
