:root {
  --bg: #F2F4F7; --surface: #FFFFFF; --ink: #14213D; --muted: #5B6478; --line: #D6DCE6;
  --accent: #1F3FA6; --accent-ink: #FFFFFF; --accent-soft: #E6EBFA;
  --seal: #B7791F; --seal-soft: #FBF3E3;
  --ok: #1E7F4F; --ok-soft: #E3F3EA; --warn: #B7791F; --warn-soft: #FBF3E3; --crit: #B42318; --crit-soft: #FBE7E4;
  --rail: #14213D; --rail-ink: #E6EAF2; --rail-muted: #9AA3B5; --rail-line: #24314F;
  --shadow: 0 1px 2px rgba(20,33,61,.06), 0 8px 24px rgba(20,33,61,.06);
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1420; --surface: #171D2B; --ink: #E6EAF2; --muted: #9AA3B5; --line: #2A3345;
    --accent: #8FA8FF; --accent-ink: #0F1420; --accent-soft: #1E2846;
    --seal: #E2B34A; --seal-soft: #2E2612;
    --ok: #4CC38A; --ok-soft: #12291D; --warn: #E2B34A; --warn-soft: #2E2612; --crit: #F0776A; --crit-soft: #33171A;
    --rail: #0B0F19; --rail-ink: #E6EAF2; --rail-muted: #8A93A6; --rail-line: #1C2333;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0F1420; --surface: #171D2B; --ink: #E6EAF2; --muted: #9AA3B5; --line: #2A3345;
  --accent: #8FA8FF; --accent-ink: #0F1420; --accent-soft: #1E2846;
  --seal: #E2B34A; --seal-soft: #2E2612;
  --ok: #4CC38A; --ok-soft: #12291D; --warn: #E2B34A; --warn-soft: #2E2612; --crit: #F0776A; --crit-soft: #33171A;
  --rail: #0B0F19; --rail-ink: #E6EAF2; --rail-muted: #8A93A6; --rail-line: #1C2333;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif; font-size: 15px; line-height: 1.55; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 22px 18px 28px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .04em; }
.brand-name { font-weight: 600; font-size: 16px; }
.brand-sub { color: var(--rail-muted); font-size: 12px; }

.steps { display: flex; flex-direction: column; gap: 4px; }
.step { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r); background: transparent; border: 0; color: var(--rail-ink); text-align: left; cursor: pointer; width: 100%; }
.step:hover { background: var(--rail-line); }
.step.active { background: var(--rail-line); }
.step:disabled { cursor: not-allowed; opacity: .5; }
.step-num { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--rail-muted); display: grid; place-items: center; font-size: 12px; font-variant-numeric: tabular-nums; }
.step.done .step-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.active .step-num { border-color: var(--accent); color: var(--accent); }
.step-name { font-size: 14px; }
.step-pct { font-size: 12px; color: var(--rail-muted); font-variant-numeric: tabular-nums; }

.tile { border: 1px solid var(--rail-line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.tile-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--rail-muted); }
.tile-value { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.tile-sub { font-size: 12px; color: var(--rail-muted); }
.meter { height: 6px; border-radius: 3px; background: var(--rail-line); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width .3s ease; }

.rail-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
#account { position: fixed; top: 14px; right: 18px; z-index: 30; }
.avatar { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--surface); background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px; cursor: pointer; box-shadow: var(--shadow); display: grid; place-items: center; }
.avatar:hover { filter: brightness(1.08); }
.acct-menu { position: absolute; right: 0; top: 46px; width: 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.acct-head { padding: 10px 12px 8px; }
.acct-name { font-weight: 600; font-size: 14px; }
.acct-mail { font-size: 13px; color: var(--muted); word-break: break-all; }
.acct-status { display: flex; align-items: center; gap: 8px; padding: 6px 12px 10px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.acct-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.acct-plan { font-size: 12.5px; color: var(--muted); padding: 0 12px 8px; }
.acct-item { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: transparent; color: var(--ink); border-radius: var(--r); cursor: pointer; text-decoration: none; font-size: 14px; }
.acct-item:hover { background: var(--accent-soft); color: var(--accent); }
.rail-note { font-size: 12px; color: var(--rail-muted); line-height: 1.45; }

.main { min-width: 0; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 860px; margin: 0 auto; padding: 32px 24px 120px; display: flex; flex-direction: column; gap: 28px; }
.pagehead { display: flex; flex-direction: column; gap: 8px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.intro { color: var(--muted); max-width: 62ch; }

.guest-banner { position: sticky; top: 0; z-index: 5; }
.guest #page input:disabled, .guest #page select:disabled, .guest #page textarea:disabled { opacity: 1; color: var(--ink); background: var(--surface); cursor: default; }
.guest #page .opt, .guest #page .chip, .guest #page .toggle, .guest #page .threat-head label { cursor: default; }
.guest #page button:disabled { opacity: .55; cursor: default; }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--r); background: var(--seal-soft); border: 1px solid var(--seal); color: var(--ink); font-size: 14px; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px 24px; display: flex; flex-direction: column; gap: 20px; box-shadow: var(--shadow); }
.section > h2 { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.note { padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--r) var(--r) 0; font-size: 14px; }

.q { display: flex; flex-direction: column; gap: 8px; }
.q-label { font-weight: 500; display: flex; gap: 6px; align-items: baseline; }
.req { color: var(--crit); font-size: 13px; }
.help { color: var(--muted); font-size: 13px; max-width: 70ch; }
.control input[type="text"], .control input[type="number"], .control select, .control textarea, .cell input, .cell select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); color: var(--ink);
}
.control textarea { min-height: 96px; resize: vertical; }
.control select, .cell select { appearance: auto; }
.inline-warn { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); background: var(--warn-soft); border: 1px solid var(--warn); font-size: 13px; }
.inline-warn b { color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 14px; user-select: none; }
.chip input { margin: 0; accent-color: var(--accent); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }

.opts { display: flex; flex-direction: column; gap: 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; background: var(--surface); font-size: 14px; }
.opt:hover { border-color: var(--muted); }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.opt-help { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sec-head h2 { padding: 0; border: 0; }
.rev { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 8px 18px; margin: 0; font-size: 14px; }
.rev dt { color: var(--muted); }
.rev dd { margin: 0; }
.missing { color: var(--crit); font-weight: 500; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { padding: 8px 18px; border: 0; background: var(--surface); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.tablewrap { overflow-x: auto; }
table.edit { width: 100%; border-collapse: collapse; font-size: 14px; }
table.edit th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; padding: 6px 8px 6px 0; }
table.edit td { padding: 4px 8px 4px 0; vertical-align: top; }
table.edit td.cell { min-width: 140px; }
.rowdel { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 8px 4px; }
.rowdel:hover { color: var(--crit); }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-rail { background: transparent; color: var(--rail-ink); border-color: var(--rail-line); }
.btn-rail:hover { border-color: var(--rail-muted); }
.btn.armed, .rowdel.armed { color: var(--crit); border-color: var(--crit); font-weight: 600; }
.btn-seal { background: var(--seal); color: #fff; border-color: var(--seal); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.sys-list { display: flex; flex-direction: column; gap: 14px; }
.sys-card { border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; background: var(--bg); }
.sys-card .q { gap: 5px; }
.sys-card .q-label { font-size: 13px; font-weight: 500; }
.sys-card .full { grid-column: 1 / -1; }
.sys-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sys-title { font-weight: 600; }
.crit-badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }

.risk-sys { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.risk-sys > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.risk-sys > header .help { font-size: 13px; }
.threats { display: flex; flex-direction: column; }
.threat { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.threat:last-child { border-bottom: 0; }
.threat-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.threat-head label { display: flex; align-items: center; gap: 8px; cursor: pointer; flex: 1; min-width: 200px; }
.threat-head input { accent-color: var(--accent); }
.lvl { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lvl.none { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.lvl.low { background: var(--ok-soft); color: var(--ok); }
.lvl.mid { background: var(--warn-soft); color: var(--warn); }
.lvl.high { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.lvl.crit { background: var(--crit-soft); color: var(--crit); border: 1px solid var(--crit); }
.threat-body { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.threat-body .full { grid-column: 1 / -1; }
.threat-body .q-label { font-size: 13px; }
.scale { display: flex; gap: 6px; flex-wrap: wrap; }
.scale button { padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); cursor: pointer; font-size: 13px; }
.scale button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.action-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }

.toggle-list { display: flex; flex-direction: column; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; background: var(--surface); }
.toggle.on { border-color: var(--accent); background: var(--accent-soft); }
.toggle input { accent-color: var(--accent); }
.toggle .crit-badge { margin-left: auto; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.stat-value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-value.crit { color: var(--crit); } .stat-value.warn { color: var(--warn); } .stat-value.ok { color: var(--ok); }
.stat-sub { font-size: 12px; color: var(--muted); }

.status-card { display: flex; gap: 16px; align-items: flex-start; padding: 16px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.status-card.ok-box { border-color: var(--ok); background: var(--ok-soft); }
.status-pill { padding: 4px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.status-pill.kluczowy { background: var(--crit-soft); color: var(--crit); }
.status-pill.wazny { background: var(--warn-soft); color: var(--warn); }
.status-pill.poza { background: var(--ok-soft); color: var(--ok); }
.status-pill.brak { background: var(--bg); color: var(--muted); }

.areas { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 24px; }
.area { display: flex; flex-direction: column; gap: 5px; }
.area-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.area-head b { display: inline-block; width: 16px; color: var(--muted); font-weight: 600; }
.area-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.area-val.ok { color: var(--ok); } .area-val.warn { color: var(--warn); } .area-val.crit { color: var(--crit); }
.area-meter { position: relative; background: var(--line); }
.area-meter > s { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--muted); text-decoration: none; }
.area-sub { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) { .areas { grid-template-columns: 1fr; } }
.findings { display: flex; flex-direction: column; gap: 8px; }
.finding { display: grid; grid-template-columns: 4px 1fr; gap: 14px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.finding > i { display: block; }
.finding.crit > i { background: var(--crit); } .finding.warn > i { background: var(--warn); } .finding.info > i { background: var(--accent); }
.finding-body { padding: 10px 14px 10px 0; display: flex; flex-direction: column; gap: 3px; }
.finding-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.finding-action { font-size: 13px; color: var(--muted); }
.finding-action b { color: var(--ink); font-weight: 500; }

.doc-tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.doc-tab { padding: 7px 12px; border-radius: var(--r); border: 1px solid transparent; background: transparent; cursor: pointer; font-size: 14px; }
.doc-tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.doc-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ai-meta { font-size: 13px; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.ai-status { font-size: 13px; padding: 8px 12px; border-radius: var(--r); background: var(--seal-soft); border: 1px solid var(--seal); }
.doc-preview { padding: 28px 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 14.5px; line-height: 1.6; }
.doc-preview h1 { font-size: 22px; margin-bottom: 10px; }
.doc-preview h2 { font-size: 16px; margin: 22px 0 8px; }
.doc-preview h3 { font-size: 14.5px; margin: 16px 0 6px; }
.doc-preview p { margin: 6px 0; max-width: 72ch; }
.doc-preview blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--seal); background: var(--seal-soft); font-size: 13.5px; }
.doc-preview ul { padding-left: 20px; margin: 6px 0; }
.doc-preview .tablewrap { margin: 8px 0; }
.doc-preview table { border-collapse: collapse; width: 100%; font-size: 13px; }
.doc-preview th, .doc-preview td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.doc-preview th { background: var(--bg); font-weight: 500; }
.doc-preview .todo { background: var(--warn-soft); color: var(--warn); padding: 0 4px; border-radius: 3px; font-weight: 500; }
/* wiersz szczegółów: scalona komórka pod pozycją tabeli, dla treści, które nie mieszczą się w kolumnie */
.doc-preview tr.det td { background: var(--bg); font-size: 12.5px; color: var(--muted); border-top: 0; }
.doc-preview tr.det b { color: var(--ink); font-weight: 500; }

.navbar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.nav-hint { font-size: 13px; color: var(--muted); }

.empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; padding: 16px; gap: 14px; }
  .steps { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .step { grid-template-columns: 22px auto; white-space: nowrap; }
  .step-pct { display: none; }
  .rail-actions { flex-direction: row; flex-wrap: wrap; }
  .tile-value { font-size: 22px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sys-card, .threat-body { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr; }
  .page { padding: 20px 16px 110px; }
  #account { top: 10px; right: 12px; }
  .pagehead { padding-right: 44px; }
  .doc-preview { padding: 18px 16px; }
  .navbar { padding: 10px 16px; }
}

@media print {
  body { background: #fff; color: #000; }
  .rail, .navbar, .doc-tabs, .doc-toolbar, .ai-status, .summary-top, .banner { display: none !important; }
  .page { padding: 0; max-width: none; }
  .section { border: 0; box-shadow: none; padding: 0; }
  .doc-preview { border: 0; padding: 0; }
}
