:root {
  --navy: #0d2b4a;
  --navy-2: #123a63;
  --blue: #1a5f9e;
  --blue-light: #e8f1fa;
  --light: #eef4fa;
  --accent: #f0b429;
  --ok: #1e8a5a;
  --ok-bg: #e6f5ee;
  --err: #c0392b;
  --err-bg: #fdecea;
  --warn: #b9770a;
  --card: #ffffff;
  --border: #d3e0ee;
  --border-strong: #b9cde1;
  --text: #16283b;
  --muted: #607589;
  --radius: 12px;
  --radius-sm: 8px;
  --banner-h: 2.1rem;
  --shadow: 0 2px 14px rgba(13,43,74,.09);
  --shadow-lg: 0 12px 40px rgba(13,43,74,.28);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--light); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; font-size: 15px; }
a { color: var(--blue); }

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff; padding: .4rem 1.75rem; min-height: 150px;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 1.35rem; }
.brand h1 { font-size: 1.3rem; font-weight: 600; letter-spacing: .01em; }
.subtitle { font-size: .82rem; opacity: .85; margin-top: .1rem; }
.logo { height: 46px; max-width: 150px; object-fit: contain; background: #fff; border-radius: 6px; padding: 4px 8px; }
.logo-right { height: 50px; }
/* ParaMedica — logo na całą wysokość headera */
#logo-paramedica {
  height: 138px; max-width: 520px; flex: none;
  padding: 8px 16px; border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.24);
}
.topbar-right { display: flex; align-items: center; gap: 1rem; }

.version-badge {
  font-family: ui-monospace, monospace; font-size: .74rem; white-space: nowrap;
  background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.18);
  padding: .22rem .5rem; border-radius: 6px; opacity: .85;
}

.status-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
  padding: .3rem .7rem; border-radius: 999px; font-size: .78rem; white-space: nowrap;
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #9fb3c8; }
.status-pill.online .dot { background: #46d18a; box-shadow: 0 0 0 3px rgba(70,209,138,.25); }
.status-pill.offline .dot { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.25); }

/* ---------- Baner środowiska testowego ----------
   Wysokość jest STAŁA (--banner-h), bo od niej zależy `top` przyklejonych
   zakładek — baner ma zostać widoczny nad nimi przy każdym scrollu. */
.test-banner {
  height: var(--banner-h); line-height: var(--banner-h);
  background: var(--err); color: #fff; text-align: center;
  font-size: .82rem; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 .75rem; position: sticky; top: 0; z-index: 40;
  box-shadow: 0 2px 8px rgba(192,57,43,.35);
}

/* ---------- Kontekst placówki + konto w topbarze ---------- */
.ctx-switch { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; }
.ctx-switch .ctx-label { opacity: .8; text-transform: uppercase; letter-spacing: .04em; font-size: .68rem; }
.ctx-switch select {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px; padding: .28rem .6rem; font-size: .8rem; font-family: inherit; max-width: 240px;
}
.ctx-switch select option { color: var(--text); }
.user-chip {
  display: inline-flex; align-items: center; gap: .45rem; font-size: .8rem;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  padding: .22rem .3rem .22rem .7rem; border-radius: 999px; white-space: nowrap;
}
.user-chip .user-role {
  background: rgba(255,255,255,.18); border-radius: 999px; padding: .1rem .45rem; font-size: .68rem;
  text-transform: uppercase; letter-spacing: .03em;
}
.user-chip .btn { padding: .2rem .55rem; font-size: .72rem; color: #fff; border-color: rgba(255,255,255,.35); }
.ctx-list { gap: .5rem; }
.ctx-pick { justify-content: flex-start; text-align: left; }
.fac-role { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem; }
tr.row-current > td { background: var(--blue-light); }

/* ---------- Raporty ---------- */
.inline-field { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.inline-field input {
  padding: .35rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: inherit; font-size: .85rem;
}
td.day-ok { background: var(--ok-bg); text-align: center; }
td.day-low { background: var(--err-bg); color: var(--err); font-weight: 600; text-align: center; }
td.day-skip { color: var(--muted); text-align: center; }
tr.row-alert > td:first-child { box-shadow: inset 3px 0 0 var(--err); }
.verdict-ok { color: var(--ok); font-weight: 600; }
.verdict-bad { color: var(--err); font-weight: 600; }

/* ---------- Wykresy pacjenta ---------- */
.chart-box { margin-bottom: 1rem; }
.chart-head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; font-size: .88rem; color: var(--navy); }
.chart-stats { margin-left: auto; font-size: .74rem; color: var(--muted); }
.chart-svg { width: 100%; height: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ---------- Informacja "w przygotowaniu" ---------- */
.notice-wip {
  background: #fff8e6; border: 1px solid var(--accent); border-left-width: 4px;
  border-radius: var(--radius-sm); padding: .7rem .9rem; margin-bottom: 1rem;
  font-size: .86rem; color: #6b4c07;
}

/* ---------- Ekran logowania ---------- */
.login-body { background: linear-gradient(135deg, var(--navy), var(--blue)); }
.login-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.login-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 2rem; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .85rem;
}
.login-card h1 { font-size: 1.3rem; color: var(--navy); text-align: center; }
.login-logo { max-height: 64px; max-width: 100%; object-fit: contain; align-self: center; }
.login-sub { font-size: .82rem; color: var(--muted); text-align: center; margin-top: -.5rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .84rem; font-weight: 600; color: var(--navy); }
.login-card input {
  padding: .6rem .7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: .95rem; font-family: inherit;
}
.login-err { background: var(--err-bg); color: var(--err); border-radius: var(--radius-sm); padding: .55rem .7rem; font-size: .84rem; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: .25rem;
  background: #fff; border-bottom: 1px solid var(--border);
  padding: .5rem 1rem; position: sticky; top: var(--banner-h); z-index: 20;
  box-shadow: 0 1px 4px rgba(13,43,74,.04);
}
.tab {
  border: none; background: transparent; padding: .55rem 1.05rem;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--muted); font-size: .9rem; font-weight: 500;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--light); color: var(--navy); }
.tab.active { background: var(--blue); color: #fff; }

/* ---------- Layout ---------- */
main { flex: 1; padding: 1.5rem 1.75rem 2.5rem; max-width: 1320px; width: 100%; margin: 0 auto; }
.panel { display: none; animation: fade .18s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: .6rem; }
.toolbar-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
h2 { font-size: 1.25rem; color: var(--navy); }
h3 { font-size: 1.02rem; color: var(--navy); }
.section-h { margin: 1.75rem 0 .75rem; }
.box-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }

/* ---------- Cards / stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow); border-left: 4px solid var(--blue);
}
.card .num { font-size: 2rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.card .lbl { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: .2rem; }

.info-box { background: var(--card); padding: 1.15rem 1.35rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.proto-list { list-style: none; }
.proto-list li { padding: .5rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.proto-list li:last-child { border-bottom: none; }
.proto-list .tag { display: inline-block; font-family: ui-monospace, monospace; font-size: .78rem; background: var(--blue-light); color: var(--blue); padding: .05rem .4rem; border-radius: 4px; }

.info-box dl { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1.1rem; font-size: .9rem; }
.info-box dt { font-weight: 600; color: var(--navy); }

.mini-list { display: flex; flex-direction: column; }
.mini-row { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px dashed var(--border); font-size: .85rem; }
.mini-row:last-child { border-bottom: none; }
.mini-row .who { font-weight: 600; color: var(--navy); }
.mini-row .meas { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: .88rem; padding: .5rem 0; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border-strong); background: #fff; padding: .48rem .95rem;
  border-radius: var(--radius-sm); cursor: pointer; font-size: .875rem; font-weight: 500; color: var(--text);
  transition: border-color .15s, background .15s, color .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--err); border-color: #eab6b1; }
.btn.danger:hover { background: var(--err-bg); border-color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--blue); }
.btn.ghost:hover { background: var(--blue-light); }
.btn.sm { padding: .28rem .6rem; font-size: .8rem; }
.btn.icon { padding: .3rem .5rem; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label, .field-label { font-size: .82rem; color: var(--muted); font-weight: 600; display: flex; flex-direction: column; gap: .3rem; }
input, select, textarea {
  padding: .55rem .7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit; color: var(--text); background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,95,158,.14); }
.search { max-width: 320px; }
.chk-inline { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); font-weight: 500; }
.chk-inline input { width: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .4rem; max-height: 180px; overflow-y: auto; padding: .3rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--light); }
.chk-grid label { flex-direction: row; align-items: center; gap: .45rem; font-weight: 500; color: var(--text); font-size: .85rem; background: #fff; padding: .4rem .55rem; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.chk-grid label:hover { border-color: var(--blue); }
.chk-grid input { width: auto; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: .875rem; min-width: 560px; }
th { background: var(--navy); color: #fff; text-align: left; padding: .65rem .8rem; font-weight: 500; white-space: nowrap; }
td { padding: .58rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f4f9fd; }
.col-actions { text-align: right; }
td.actions { text-align: right; white-space: nowrap; display: flex; gap: .35rem; justify-content: flex-end; }
.mono { font-family: ui-monospace, SFMono-Regular, monospace; font-size: .82rem; color: var(--muted); }
.num-cell { font-variant-numeric: tabular-nums; }
.hexprev { font-family: ui-monospace, SFMono-Regular, monospace; font-size: .78rem; color: var(--muted); word-break: break-all; }
.sub { display: block; font-size: .74rem; color: var(--muted); }

.row-click { cursor: pointer; }
.detail-row td { background: #f0f6fc !important; padding: 0; }
.detail-inner { padding: 1rem 1.1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .55rem 1.4rem; }
.detail-inner .d { font-size: .84rem; }
.detail-inner .d span { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.detail-actions { grid-column: 1 / -1; padding-top: .4rem; }

/* ---------- Badges / tags ---------- */
.badge { display: inline-block; font-size: .7rem; padding: .15rem .5rem; border-radius: 999px; background: var(--blue-light); color: var(--blue); font-weight: 600; }
.badge.auto { background: var(--ok-bg); color: var(--ok); }
.badge.muted { background: #eceff3; color: var(--muted); }
.tag-ok { color: var(--ok); font-weight: 600; }
.tag-err { color: var(--err); font-weight: 600; }
.pill-src { font-size: .72rem; padding: .1rem .45rem; border-radius: 4px; background: #eceff3; color: var(--muted); }
.pill-src.vitals { background: var(--ok-bg); color: var(--ok); }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #c3cfdb; border-radius: 999px; transition: .18s; }
.switch .slider::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---------- List cards ---------- */
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.list-card { background: var(--card); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); border-top: 3px solid var(--blue); }
.list-card .lc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.list-card h4 { color: var(--navy); font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.list-card .desc { color: var(--muted); font-size: .84rem; margin: .35rem 0 .7rem; }
.member-list { list-style: none; margin: .4rem 0 .7rem; max-height: 200px; overflow-y: auto; }
.member-list li { display: flex; justify-content: space-between; align-items: center; padding: .35rem .1rem; border-bottom: 1px dashed var(--border); font-size: .86rem; }
.member-list li:last-child { border-bottom: none; }
.lc-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.x-btn { border: none; background: transparent; color: var(--err); cursor: pointer; font-size: .95rem; line-height: 1; padding: .1rem .35rem; border-radius: 4px; }
.x-btn:hover { background: var(--err-bg); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13,43,74,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; backdrop-filter: blur(2px); }
.modal-backdrop.hidden { display: none; }
.modal.wide { max-width: 780px; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; animation: pop .16s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.35rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 1.1rem; }
.modal-body { padding: 1.35rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.35rem; border-top: 1px solid var(--border); background: var(--light); border-radius: 0 0 var(--radius) var(--radius); }
.modal .close-x { border: none; background: transparent; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; }
.modal .close-x:hover { color: var(--err); }

/* ---------- Toasts ---------- */
.toast-wrap { position: fixed; bottom: 1.25rem; right: 1.25rem; display: flex; flex-direction: column; gap: .6rem; z-index: 200; max-width: 360px; }
.toast { background: var(--navy); color: #fff; padding: .8rem 1.1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: .875rem; display: flex; align-items: center; gap: .6rem; animation: slidein .2s ease; border-left: 4px solid var(--blue); }
.toast.ok { border-left-color: #46d18a; }
.toast.err { border-left-color: #ff6b6b; }
.toast.fade-out { animation: fadeout .3s ease forwards; }
@keyframes slidein { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes fadeout { to { opacity: 0; transform: translateX(30px); } }

.hint { font-size: .82rem; color: var(--muted); margin-bottom: .8rem; }
.hint code { background: #eceff3; padding: .05rem .35rem; border-radius: 4px; font-size: .82rem; }

footer { text-align: center; padding: 1rem; font-size: .76rem; color: var(--muted); border-top: 1px solid var(--border); background: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  #logo-paramedica { height: 88px; max-width: 320px; }
  .topbar { min-height: 0; }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; text-align: center; gap: .6rem; }
  .brand { flex-direction: column; gap: .5rem; }
  #logo-paramedica { height: 56px; max-width: 200px; }
  main { padding: 1rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search { max-width: none; }
  /* Na wąskim ekranie baner łamie się na kilka linii (cała treść musi być
     czytelna), więc przestaje być przyklejony — inaczej zasłaniałby zakładki. */
  .test-banner {
    position: static; height: auto; line-height: 1.25; white-space: normal;
    padding: .4rem .75rem;
  }
  .tabs { top: 0; }
}

/* Odciski połączeń (Diagnostyka) */
.hidden { display: none; }
.muted { color: var(--muted); }
.fp-frame { margin: .75rem 0; padding: .5rem .75rem; border: 1px solid var(--border, #e3e7ee); border-radius: 6px; }
.hexdump { font-family: ui-monospace, SFMono-Regular, monospace; font-size: .74rem; line-height: 1.45; overflow-x: auto; margin: .35rem 0 0; }
.hexdump mark { background: #ffd7d7; color: #b00020; font-weight: 700; padding: 0; }

/* Wskaźnik "żyje" na liście aparatów */
.live-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; cursor: help; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live-dot.off { background: var(--err); opacity: .65; }
