:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #172033;
  --muted: #667085;
  --line: #d7dde8;
  --accent: #0b7fab;
  --accent-2: #0f9f7a;
  --danger: #c93c4a;
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(18, 31, 53, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
p { color: var(--muted); line-height: 1.5; }
h1, h2, h3 { margin: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, textarea, select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
textarea { min-height: 98px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,127,171,.12); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.logo { width: 48px; height: 48px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; display: grid; place-items: center; font-weight: 900; }
.brand-logo {
  width: 112px;
  height: 70px;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}
.sidebar-logo {
  width: 124px;
  height: 78px;
}
.brand h1 { font-size: 24px; }

.app-shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar { background: #172033; color: #fff; padding: 22px; position: sticky; top: 0; height: 100vh; }
.sidebar p, .sidebar .muted { color: #aeb8ca; }
.user-box { margin: 22px 0; padding: 14px; border-radius: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); }
.user-box strong { display: block; }
.user-box span { color: #c4ccda; font-size: 13px; }
.nav { display: grid; gap: 8px; }
.nav button { text-align: left; background: transparent; color: #c4ccda; padding: 11px 12px; border-radius: 8px; }
.nav button.active, .nav button:hover { color: #fff; background: rgba(255,255,255,.12); }
.sidebar-credit { margin-top: 22px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); color: #8b95a7; font-size: 12px; }
.notif-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 800; }

.status-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; vertical-align: middle; }
.status-dot.online { background: #16a34a; }
.status-dot.recent { background: #d97706; }

.staff-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.staff-head h3 { font-size: 18px; }
.staff-legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); }

.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.staff-card { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px; background: var(--surface-2); transition: transform .12s ease, box-shadow .12s ease; }
.staff-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.staff-card.online { border-left-color: #16a34a; }
.staff-card.recent { border-left-color: #d97706; }

.avatar { position: relative; width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); letter-spacing: .5px; }
.staff-card.recent .avatar { background: linear-gradient(135deg, #e08a16, #b45309); }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid var(--surface); }
.avatar .dot.online { background: #16a34a; }
.avatar .dot.recent { background: #d97706; }
.staff-card.online .avatar .dot.online { animation: statusPulse 1.8s ease-out infinite; }
@keyframes statusPulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .55); }
  70% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.staff-info { min-width: 0; flex: 1; }
.staff-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-chip { font-size: 12px; color: var(--muted); }
.staff-when { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; flex: none; }
.staff-card.online .staff-when { color: #16a34a; }
.notif-unread { border-left: 4px solid var(--accent); }

.content { padding: 28px; max-width: 1440px; width: 100%; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.topbar h2 { font-size: 28px; }
.topbar p { margin: 6px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  background: var(--accent);
  color: #fff;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 700;
  border: 1px solid transparent;
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: #fff3f4; color: var(--danger); border-color: #f0b9bf; }
.btn.ok { background: #eefbf6; color: #08765a; border-color: #b9e8d9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 32px; }
.stat span, .muted { color: var(--muted); }

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:hover td { background: #fbfcfe; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; border: 1px solid var(--line); background: #f5f7fb; color: var(--text); margin-right: 6px; }
.badge.red { background: #fff0f1; color: #9f2a35; border-color: #f1b8bf; }
.badge.orange { background: #fff4ec; color: #9a4a11; border-color: #f3c4a4; }
.badge.yellow { background: #fff8df; color: #846000; border-color: #ebd483; }
.badge.green { background: #ecfdf4; color: #087246; border-color: #a8dfc2; }
.badge.blue { background: #edf7ff; color: #0b5f8c; border-color: #a6d5f2; }
.badge.black { background: #202536; color: #fff; border-color: #202536; }

.error, .success { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; }
.error { color: #9f2a35; background: #fff0f1; border: 1px solid #f1b8bf; }
.success { color: #087246; background: #ecfdf4; border: 1px solid #a8dfc2; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(13, 21, 36, .55); display: grid; place-items: center; padding: 24px; z-index: 20; }
.modal { width: min(820px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: 0 24px 70px rgba(10,20,35,.25); }
.notification-popup-backdrop { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(13, 21, 36, .64); z-index: 35; }
.notification-popup { width: min(520px, 100%); background: #fff; border: 2px solid var(--accent); border-radius: 8px; padding: 22px; box-shadow: 0 26px 80px rgba(10,20,35,.34); }
.notification-popup-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.notification-popup p { color: var(--text); font-size: 17px; font-weight: 700; margin: 0 0 18px; }
.notification-popup-actions { justify-content: flex-end; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.profile-head { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.record-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface-2); margin-bottom: 12px; }
.record-card p { margin: 8px 0; }
.record-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px; margin: 8px 0; }
.kv.mini { grid-template-columns: 1fr; gap: 2px; padding: 8px 0; }
.kv span:first-child { color: var(--muted); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* Zwijane panele (details/summary) */
.panel-collapse { padding: 0; overflow: hidden; }
.panel-head { list-style: none; display: flex; align-items: center; gap: 10px; padding: 16px 18px; user-select: none; }
.panel-head::-webkit-details-marker { display: none; }
.panel-head h3 { font-size: 18px; }
.panel-head::after { content: "›"; margin-left: auto; font-size: 22px; line-height: 1; color: var(--muted); transition: transform .15s ease; }
.panel-collapse[open] > .panel-head::after { transform: rotate(90deg); }
.panel-head:hover { background: var(--surface-2); }
.panel-body { padding: 0 18px 16px; }
.count-badge { background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 800; padding: 2px 9px; border-radius: 999px; min-width: 24px; text-align: center; }
.panel-filter { margin-bottom: 12px; }

/* Akordeon pozycji (wpisy, dokumenty, archiwum) */
.acc { border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); margin-bottom: 8px; overflow: hidden; }
.acc-sum { list-style: none; display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; flex-wrap: wrap; user-select: none; }
.acc-sum::-webkit-details-marker { display: none; }
.acc-sum::after { content: "›"; margin-left: auto; font-size: 20px; line-height: 1; color: var(--muted); transition: transform .15s ease; }
.acc[open] > .acc-sum::after { transform: rotate(90deg); }
.acc[open] > .acc-sum { border-bottom: 1px solid var(--line); background: var(--surface); }
.acc-sum:hover { background: var(--surface); }
.acc-date { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-tag { font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.acc-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 120px; min-width: 0; }
.acc-body { padding: 12px 14px; }
.acc-body p { margin: 8px 0; }
.acc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.document-a4 { position: relative; display: flex; flex-direction: column; min-height: 1120px; background: white; color: #111; width: min(840px, 100%); margin: 0 auto; padding: 46px; border-radius: 8px; box-shadow: var(--shadow); }
.document-a4 h1 { text-align: center; margin-bottom: 28px; font-size: 24px; }
.document-a4 p, .document-a4 .muted { color: #333; }
.doc-brand { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 20px; }
.doc-brand img { width: 90px; height: 56px; object-fit: contain; }
.doc-brand strong { display: block; }
.doc-brand span { color: #555; font-size: 13px; }
.doc-watermark { position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg); font-size: 84px; font-weight: 900; color: rgba(201, 60, 74, .16); letter-spacing: 6px; pointer-events: none; white-space: nowrap; }
.doc-line { display: grid; grid-template-columns: 190px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px solid #ddd; }
.doc-content { white-space: pre-wrap; line-height: 1.6; color: #111; padding: 6px 0; }
.doc-sign { margin-top: 60px; display: flex; justify-content: flex-end; }
.doc-sign div { width: min(420px, 100%); text-align: center; border-top: 1px solid #111; padding-top: 8px; font-size: 13px; color: #111; }
.doc-stamp { display: block; max-width: 100%; max-height: 220px; object-fit: contain; margin: 0 auto 10px; }
.stamp-preview { display: block; max-width: 420px; max-height: 240px; object-fit: contain; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; }

.sor-section-header {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 4px;
  margin-bottom: 10px;
}

.btn.sor-paramedic { background: #0b5f8c; color: #fff; }
.btn.sor-nurse { background: #0f9f7a; color: #fff; }

.activation-code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 30px; font-weight: 800; letter-spacing: 6px; text-align: center; padding: 16px; margin: 12px 0; background: var(--surface-2); border: 2px dashed var(--accent); border-radius: 10px; color: var(--accent); user-select: all; }
.info-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 14px 0 0; }
.reset-pass { display: flex; align-items: center; gap: 8px; margin-top: 16px; }

.form-divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 13px; margin: 18px 0 6px; }
.form-divider::before, .form-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); margin: 0 10px; }
.clinic-search-results { margin-top: 8px; display: grid; gap: 6px; }
.clinic-search-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }

.sample-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.sample-field label { display: flex; align-items: center; gap: 8px; margin-top: 0; }
.sample-letter { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: #fff; font-weight: 800; font-size: 12px; flex: none; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.board-card { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.board-card h3 { margin: 10px 0 2px; }
.board-card p { margin: 6px 0; }
.board-card-top { display: flex; align-items: center; justify-content: space-between; }
.board-wait { font-size: 13px; color: var(--muted); font-weight: 700; }
.board-status { font-weight: 700; color: var(--text); }
.board-card.triage-red { border-left-color: #c93c4a; }
.board-card.triage-orange { border-left-color: #d3791f; }
.board-card.triage-yellow { border-left-color: #c9a400; }
.board-card.triage-green { border-left-color: #0f9f7a; }
.board-card.triage-blue { border-left-color: #0b7fab; }
.board-card.triage-black { border-left-color: #202536; }
.board-card.overdue { box-shadow: 0 0 0 2px #c93c4a inset, var(--shadow); }
.board-wait.over { color: #c93c4a; }
.board-overdue { color: #c93c4a; font-weight: 800; font-size: 12px; margin-top: 6px; }

.triage-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.legend-item { font-size: 12px; padding: 6px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); border-left-width: 5px; }
.legend-item.triage-red { border-left-color: #c93c4a; }
.legend-item.triage-orange { border-left-color: #d3791f; }
.legend-item.triage-yellow { border-left-color: #c9a400; }
.legend-item.triage-green { border-left-color: #0f9f7a; }
.legend-item.triage-blue { border-left-color: #0b7fab; }
.legend-item.triage-black { border-left-color: #202536; }

.board-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.board-filters label { margin-top: 0; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .topbar { display: block; }
  .actions { justify-content: flex-start; margin-top: 12px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .profile-head { grid-template-columns: 1fr; }
  .form-row, .form-row.three, .form-row.four { grid-template-columns: 1fr; }
  .board-filters, .sample-grid { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}

@page { margin: 14mm; }

@media print {
  body { background: white; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  .document-a4 { box-shadow: none; width: 100%; min-height: calc(297mm - 28mm); border-radius: 0; padding: 0; }
  .doc-watermark { color: rgba(201, 60, 74, .22); }
}
