* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.45;
  user-select: none;
  touch-action: manipulation; /* blokuje double-tap zoom */
}

#app { height: 100%; display: flex; flex-direction: column; overflow-x: hidden; }

/* ikony SVG (styl Lucide) — cienka kreska, kolor dziedziczony z tekstu */
.ic { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-xs { width: 15px; height: 15px; stroke-width: 2.4; }
.ic-sm { width: 18px; height: 18px; stroke-width: 2.2; }
.ic-md { width: 22px; height: 22px; }

/* przejścia między ekranami — animowane tylko przy zmianie ekranu (nie przy re-renderze) */
.anim-fwd { animation: screenFwd .26s cubic-bezier(.2, .7, .3, 1) both; }
.anim-back { animation: screenBack .26s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes screenFwd { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes screenBack { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }

/* ---------- pasek statusu ---------- */
.statusbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-caption); color: var(--muted);
}
.statusbar .ward { font-weight: 700; color: var(--ink); font-size: 17px; }
/* Logotyp słowny, wariant "sticker" — "Med" jak biały nadruk na tealowej naklejce */
.logo-word {
  font-size: 58px; font-weight: 600; letter-spacing: .045em; line-height: 1;
  color: var(--ink); user-select: none; display: inline-flex; align-items: center;
}
.logo-word .med {
  color: #fff; background: var(--accent);
  border-radius: .22em; padding: .06em .18em .09em;
  margin-left: .14em; position: relative;
}
/* podwinięty rożek naklejki */
.logo-word .med::after {
  content: ""; position: absolute; top: 0; right: 0;
  width: .3em; height: .3em;
  background: linear-gradient(225deg, var(--bg) 0 50%, rgba(255,255,255,.9) 50% 100%);
  border-radius: 0 .2em 0 .12em;
}
.statusbar .logo-word { font-size: 19px; font-weight: 600; }
.statusbar .spacer { flex: 1; }
.statusbar .printer-ok { color: var(--cta); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.statusbar .printer-bad { color: var(--bad); font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.mode-toggle { display: inline-flex; align-items: center; justify-content: center; }
.user-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent-soft); color: var(--ink);
  font-size: 14px; font-weight: 600;
  padding: 6px 14px; border-radius: 99px; white-space: nowrap;
}
.user-chip .ic { color: var(--accent); }
.steps { display: flex; gap: 6px; }
.stepdot { width: 28px; height: 8px; border-radius: 4px; background: var(--border); }
.stepdot.on { background: var(--accent); }
.mode-toggle {
  border: 1px solid var(--border); background: var(--tile); color: var(--muted);
  border-radius: 8px; min-height: 44px; min-width: 44px; padding: 4px 12px;
  font-size: 15px; cursor: pointer;
}

/* ---------- ekran ---------- */
.screen { flex: 1; display: flex; flex-direction: column; padding: 22px 26px 24px; gap: var(--gap); overflow-y: auto; }
.stitle { font-size: var(--fs-title); font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.ssub { color: var(--muted); margin: -8px 0 0; font-size: 17px; }

/* ---------- kafle ---------- */
.tiles { display: grid; gap: var(--gap); align-content: start; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.section-label {
  grid-column: 1 / -1; margin-top: 6px;
  font-size: 14px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.tile {
  min-height: var(--touch-tile);
  background: var(--tile); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); font-size: var(--fs-tile); font-weight: 700; color: var(--ink);
  text-align: center; padding: 14px; cursor: pointer; position: relative;
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast), transform var(--t-fast);
}
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow-lift); }
.tile:active, .tile.pressed {
  background: var(--accent-soft); border-color: var(--accent);
  transform: scale(.985); box-shadow: var(--shadow);
}
.tile:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
.tile .sub { font-size: var(--fs-caption); font-weight: 500; color: var(--muted); }
.tile .icon { width: 46px; height: 46px; stroke: var(--accent); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Kafel z pełnym tłem (render Gemini): obiekt po prawej, tekst na ciemnej lewej stronie.
   Scrim gwarantuje kontrast >= 7:1 dla białego tekstu niezależnie od obrazu. */
.tile.tile-bg {
  min-height: 190px; padding: 0; overflow: hidden; border: none;
  background-size: cover; background-position: center right;
  align-items: flex-start; justify-content: flex-end;
  box-shadow: var(--shadow);
}
.tile.tile-bg::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(6, 34, 44, .68) 0%, rgba(6, 34, 44, .30) 45%, rgba(6, 34, 44, 0) 70%),
              linear-gradient(0deg, rgba(6, 34, 44, .45) 0%, rgba(6, 34, 44, 0) 40%);
  transition: background var(--t-fast);
}
.tile.tile-bg .bg-label {
  position: relative; z-index: 1;
  color: #fff; font-size: 27px; font-weight: 800; letter-spacing: .01em;
  text-align: left; text-wrap: balance; line-height: 1.15;
  padding: 0 22px 18px; text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  max-width: 62%;
}
.tile.tile-bg:hover { border: none; box-shadow: var(--shadow-lift); }
.tile.tile-bg:active, .tile.tile-bg.pressed {
  background-color: transparent; transform: scale(.985);
}
.tile.tile-bg:focus-visible { outline: 4px solid #fff; outline-offset: -6px; }
.tile.free { border-style: dashed; color: var(--muted); font-weight: 600; font-size: 19px; }
.tile .kg { font-family: ui-monospace, Menlo, monospace; font-size: 17px; font-weight: 700; color: var(--accent); }
.risk-stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: var(--warn); border-radius: var(--radius) 0 0 var(--radius); }
.tile.repeat { border-color: var(--accent); background: var(--accent-soft); }
.tile.repeat .sub { color: var(--ink); opacity: .75; }
.repeat-mark {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--tile);
  font-size: 14px; font-weight: 700; padding: 3px 12px; border-radius: 99px;
}
.lastprint { font-size: 14px; font-weight: 600; color: var(--accent); }

/* ---------- kafel pacjenta z paskiem powtórki ---------- */
.patient-tile { padding: 0; overflow: hidden; cursor: default; }
.patient-main {
  flex: 1; width: 100%; min-height: 118px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 6px;
  border: none; background: transparent; color: inherit; text-align: left;
  font-family: var(--font); cursor: pointer; padding: 48px 18px 14px;
  position: relative;
}
.patient-main:active { background: var(--accent-soft); }
/* zakładka narożna — równo ścięta z krawędziami kafla w lewym górnym rogu
   (kafel ma overflow:hidden, więc róg zakładki przycina się idealnie do promienia kafla) */
.bed-tab {
  position: absolute; top: 0; left: 0; z-index: 1;
  background: var(--accent); color: #fff;
  font-size: 12.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  padding: 8px 18px 9px; border-radius: 0 0 16px 0;
}
.dup-pill {
  position: absolute; top: 10px; right: 10px; z-index: 1;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 700;
  color: var(--warn); background: var(--warn-bg);
  padding: 4px 12px; border-radius: 99px; white-space: nowrap;
}
.pm-name { font-size: 22px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; }
.patient-main .kg { font-size: 15.5px; opacity: .9; }

.repeat-strip {
  width: 100%; min-height: 62px;
  border: none; border-top: 1px solid var(--border);
  background: var(--accent-soft); color: var(--ink);
  font-family: var(--font); cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  transition: background var(--t-fast), color var(--t-fast);
}
.rs-ico {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700;
}
.rs-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }
.rs-cap {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent);
}
.rs-drug {
  font-size: 15.5px; font-weight: 800; line-height: 1.2; text-align: left;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rs-time {
  flex: none; font-family: ui-monospace, Menlo, monospace;
  font-size: 14px; font-weight: 700; color: var(--accent);
  background: var(--tile); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 9px;
}
.repeat-strip:hover, .repeat-strip:active { background: var(--accent); color: #fff; }
.repeat-strip:hover .rs-cap, .repeat-strip:active .rs-cap { color: rgba(255, 255, 255, .8); }
.repeat-strip:hover .rs-ico, .repeat-strip:active .rs-ico { background: #fff; color: var(--accent); }
.repeat-strip:hover .rs-time, .repeat-strip:active .rs-time { background: transparent; border-color: rgba(255, 255, 255, .5); color: #fff; }
.repeat-strip:focus-visible { outline: 4px solid var(--accent); outline-offset: -4px; }

/* ---------- baner "etykieta wydrukowana" ---------- */
.success-banner {
  display: flex; align-items: center; gap: 14px;
  background: var(--cta); color: #fff;
  border-radius: var(--radius); padding: 14px 20px;
  box-shadow: 0 2px 6px rgba(21, 128, 61, .25), 0 10px 24px rgba(21, 128, 61, .18);
  animation: bannerIn .3s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes bannerIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
.sb-ico {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  display: flex; align-items: center; justify-content: center;
}
.sb-ico .ic { stroke-width: 3; }
.sb-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sb-txt b { font-size: 19px; font-weight: 800; letter-spacing: .01em; }
.sb-txt span { font-size: 15.5px; font-weight: 600; opacity: .92;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- pasek liter (filtrowanie pacjentów po nazwisku) ---------- */
.letter-rail { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  min-width: 56px; min-height: 56px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--tile); color: var(--ink);
  box-shadow: 0 1px 2px rgba(10, 40, 36, .06);
  font-family: var(--font); font-size: 21px; font-weight: 700; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.chip:active { transform: scale(.94); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }

/* ---------- klawiatura PIN ---------- */
.pin-dots { display: flex; gap: 18px; justify-content: center; margin: 8px 0 2px; }
.pin-dots span {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--tile);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.pin-dots span.filled { background: var(--accent); border-color: var(--accent); }
.pinpad {
  display: grid; grid-template-columns: repeat(3, minmax(96px, 132px));
  gap: 14px; justify-content: center; align-content: center; flex: 1;
}
.pinpad button {
  min-height: 80px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--tile); color: var(--ink); box-shadow: var(--shadow);
  font-family: var(--font); font-size: 30px; font-weight: 700; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.pinpad button:active { background: var(--accent-soft); border-color: var(--accent); transform: scale(.96); }
.pinpad button.fn { font-size: 22px; color: var(--muted); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--warn-bg); color: var(--warn);
  font-size: 13.5px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
}

/* ---------- pasek dolny ---------- */
.bottombar { display: flex; gap: var(--gap); align-items: stretch; margin-top: auto; padding-top: 6px; }
.btn-back {
  min-width: 160px; min-height: var(--touch-nav);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--tile); color: var(--ink); box-shadow: var(--shadow);
  font-family: var(--font); font-size: 19px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn-back:hover { border-color: var(--accent); box-shadow: var(--shadow-lift); }
.btn-back:active { transform: scale(.985); }
.btn-back svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn-back:focus-visible, .btn-cta:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
.btn-cta {
  flex: 1; min-height: var(--touch-cta);
  border: none; border-radius: var(--radius);
  background: var(--cta); color: var(--cta-ink);
  box-shadow: 0 2px 6px rgba(21, 128, 61, .25), 0 10px 24px rgba(21, 128, 61, .18);
  font-family: var(--font); font-size: 26px; font-weight: 800; letter-spacing: .01em; cursor: pointer;
  transition: filter var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn-cta:hover { filter: brightness(1.06); }
.btn-cta:active { transform: scale(.99); }
.btn-cta.warned {
  background: var(--warn); color: #fff;
  box-shadow: 0 2px 6px rgba(180, 83, 9, .25), 0 10px 24px rgba(180, 83, 9, .18);
}
.btn-cta:disabled { opacity: .55; cursor: default; box-shadow: none; }
.searchbar {
  flex: 1; display: flex; align-items: center; gap: 12px;
  min-height: var(--touch-nav);
  background: var(--tile); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0 18px; color: var(--muted); font-size: 19px; cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.searchbar:hover { border-color: var(--accent); box-shadow: var(--shadow-lift); }
.searchbar svg { width: 26px; height: 26px; stroke: var(--muted); fill: none; stroke-width: 2.2; stroke-linecap: round; }

/* ---------- podsumowanie ---------- */
.sumgrid { display: grid; grid-template-columns: 1.3fr 1fr; gap: var(--gap); align-content: start; }
.sumcard { background: var(--tile); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 22px; }
.sumcard .lbl { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.sumcard .big { font-size: var(--fs-drug); font-weight: 800; line-height: 1.12; margin-top: 2px; }
.sumcard .mid { font-size: 22px; font-weight: 700; margin-top: 2px; }
.sumcard .dim { color: var(--muted); font-size: 16.5px; }
.warnbanner {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 14px;
  background: var(--warn-bg); border: 1px solid var(--warn); border-left: 6px solid var(--warn);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 20px; color: var(--warn); font-weight: 800; font-size: 20px;
}
.warnbanner svg { width: 32px; height: 32px; stroke: var(--warn); fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.autopick {
  display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-left: 6px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 14px 18px; font-size: 18px; font-weight: 600;
}
.autopick svg { width: 26px; height: 26px; stroke: var(--accent); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- stany centralne (idle, druk, sukces, błąd) ---------- */
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.center .hero { font-size: 36px; font-weight: 800; letter-spacing: -0.01em; }
.center .sub { color: var(--muted); font-size: 19px; max-width: 46ch; }
.spinner {
  width: 68px; height: 68px; border-radius: 50%;
  border: 7px solid var(--border); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.result-ok, .result-err {
  width: 88px; height: 88px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.result-ok { background: var(--cta); }
.result-ok svg { width: 46px; height: 46px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.result-err { background: var(--bad-bg); border: 3px solid var(--bad); }
.result-err svg { width: 44px; height: 44px; stroke: var(--bad); fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- formularz pacjenta + klawiatura ekranowa ---------- */
.form-row { display: flex; gap: var(--gap); }
.field { flex: 1; }
.field label { display: block; font-size: 15px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 68px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--tile); color: var(--ink); box-shadow: var(--shadow);
  font-family: var(--font); font-size: 24px; font-weight: 700; padding: 0 16px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.field input.active { border-color: var(--accent); background: var(--accent-soft); }
.osk { display: grid; gap: 8px; margin-top: auto; }
.osk-row { display: flex; gap: 8px; justify-content: center; }
.osk button {
  min-width: 64px; min-height: 60px; flex: 1; max-width: 84px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--tile); color: var(--ink);
  box-shadow: 0 1px 2px rgba(10, 40, 36, .06);
  font-family: var(--font); font-size: 22px; font-weight: 700; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.osk button:active { background: var(--accent-soft); border-color: var(--accent); transform: scale(.96); }
.osk button.wide { max-width: none; flex: 2.5; font-size: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 14px 22px; border-radius: 10px; font-size: 17px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s; white-space: nowrap; z-index: 50;
}
.toast.show { opacity: .95; }
