:root {
  --paper: #fafaf7;
  --card: #ffffff;
  --ink: #16201c;
  --ink-soft: #3f4a45;
  --line: #c9d1cd;
  --green: #1f5c45;
  --green-dark: #164634;
  --ok-bg: #e2f0e7;
  --amber-bg: #fff1cc;
  --amber-ink: #6b4a00;
  --amber-bar: #d99a00;
  --red-bg: #fbe4e1;
  --red-ink: #8e1f17;
  --red-bar: #c0392b;
  --focus: #1d4e89;
  --radius-s: 8px;
  --radius-l: 14px;
  font-size: 20px;
}
html.large { font-size: 24px; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Atkinson Hyperlegible', Verdana, Tahoma, sans-serif;
  line-height: 1.55;
}
.wrap { max-width: 44rem; margin: 0 auto; padding: 0 1rem; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: #fff; padding: .5rem; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Nagłówek */
.top { background: var(--green); color: #fff; padding: 1.4rem 0 1.6rem; }
.top-inner { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .4rem; }
.lead { margin: 0; font-size: 1.05rem; max-width: 32rem; }
.size-toggle { display: flex; gap: .3rem; flex-shrink: 0; }
.size-toggle button {
  min-width: 2.6rem; min-height: 2.6rem; border-radius: var(--radius-s);
  border: 2px solid rgba(255,255,255,.7); background: transparent; color: #fff;
  font: inherit; font-weight: 700; cursor: pointer;
}
.size-toggle .big-a { font-size: 1.3rem; }
.size-toggle button[aria-pressed="true"] { background: #fff; color: var(--green); }

/* Uwaga */
.notice {
  margin: 1.2rem 0; padding: .9rem 1.1rem; background: var(--amber-bg);
  border-left: 6px solid var(--amber-bar); border-radius: var(--radius-s); color: #3b2a00;
}
.notice p { margin: .2rem 0; }

/* Kroki */
.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.2rem 1.2rem 1.4rem; margin: 1.2rem 0; }
h2 { font-size: 1.3rem; line-height: 1.25; margin: 0 0 .5rem; display: flex; align-items: center; gap: .6rem; }
.num {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; flex-shrink: 0;
  border-radius: 50%; background: var(--green); color: #fff; font-size: 1.05rem;
}
.hint { color: var(--ink-soft); margin: 0 0 1rem; }
.soft { background: var(--paper); padding: .6rem .8rem; border-radius: var(--radius-s); }

.field-label, label[for] { display: block; font-weight: 700; margin: 1rem 0 .35rem; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 2px solid var(--line); border-radius: var(--radius-s); padding: .6rem .7rem; min-height: 2.8rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgba(29,78,137,.25); }

/* Przyciski */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 700; min-height: 3rem; padding: .6rem 1.2rem;
  border-radius: var(--radius-s); border: 2px solid var(--green); cursor: pointer;
  background: #fff; color: var(--green); text-decoration: none;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-outline:hover { background: var(--ok-bg); }
.btn-big { background: var(--green); color: #fff; min-height: 4rem; font-size: 1.1rem; flex: 1; }
.btn-big.btn-outline { background: #fff; color: var(--green); }
.btn-wide { width: 100%; margin-top: 1.3rem; min-height: 3.4rem; font-size: 1.1rem; }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn-remove {
  font: inherit; border: none; background: none; color: var(--red-ink); cursor: pointer;
  padding: .4rem .5rem; min-height: 2.6rem; text-decoration: underline;
}
.photo-buttons { display: flex; gap: .7rem; flex-wrap: wrap; }
.photo-buttons label { margin: 0; }
.photo-buttons label:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }

.thumbs { list-style: none; padding: 0; margin: .8rem 0 0; display: flex; gap: .6rem; flex-wrap: wrap; }
.thumbs li { position: relative; }
.thumbs img { width: 6rem; height: 6rem; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--line); display: block; }
.thumbs button {
  position: absolute; top: -.5rem; right: -.5rem; width: 2rem; height: 2rem; border-radius: 50%;
  border: 2px solid #fff; background: var(--red-bar); color: #fff; font-size: 1rem; cursor: pointer; line-height: 1;
}

.error { color: var(--red-ink); background: var(--red-bg); padding: .6rem .8rem; border-radius: var(--radius-s); margin-top: 1rem; font-weight: 700; }

/* Lista leków do poprawy */
.med-list { padding: 0; margin: 0 0 1rem; list-style: none; counter-reset: med; }
.med-list li {
  counter-increment: med; display: grid; grid-template-columns: 2rem 1fr auto; gap: .3rem .6rem;
  align-items: start; padding: .8rem 0; border-bottom: 1px solid var(--line);
}
.med-list li::before { content: counter(med) "."; font-weight: 700; padding-top: .6rem; }
.med-list li.low { background: var(--amber-bg); margin: 0 -.6rem; padding: .8rem .6rem; border-radius: var(--radius-s); }
.med-fields { display: grid; gap: .4rem; }
.med-fields input { min-height: 2.6rem; }
.med-fields .sub { font-size: .85rem; color: var(--ink-soft); margin: 0; }

/* Podpowiedzi leków */
.btn-second { margin-top: .7rem; min-height: 3rem; font-size: 1rem; }
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  max-height: min(60vh, 26rem); overflow-y: auto; overscroll-behavior: contain;
  background: #fff; border: 2px solid var(--focus); border-radius: var(--radius-s);
  box-shadow: 0 8px 24px rgba(22,32,28,.18);
}
.ac-group { padding: .55rem .7rem .65rem; border-top: 1px solid var(--line); }
.ac-group:first-child { border-top: none; }
.ac-head strong { display: block; line-height: 1.25; }
.ac-meta { display: block; font-size: .8rem; color: var(--ink-soft); line-height: 1.3; }
.ac-doses { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.ac-opt {
  cursor: pointer; font-size: .9rem; line-height: 1.2; padding: .45rem .7rem; min-height: 2.3rem;
  display: inline-flex; align-items: center; border: 2px solid var(--line); border-radius: 2rem; background: var(--paper);
}
.ac-opt:hover { border-color: var(--green); background: var(--ok-bg); }
.ac-opt.active { border-color: var(--focus); background: var(--focus); color: #fff; }

/* Choroby */
.checks { border: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .5rem; }
.checks label {
  display: flex; gap: .6rem; align-items: center; margin: 0; font-weight: 400;
  border: 2px solid var(--line); border-radius: var(--radius-s); padding: .55rem .7rem; cursor: pointer; min-height: 3rem;
}
.checks input { width: 1.4rem; height: 1.4rem; accent-color: var(--green); flex-shrink: 0; }
.checks label:has(input:checked) { border-color: var(--green); background: var(--ok-bg); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } .grid3 > div:last-child { grid-column: span 2; } }

/* Ładowanie */
.loading { text-align: center; padding: 2rem 1rem; }
.pill-anim { display: flex; justify-content: center; gap: .6rem; margin-bottom: 1rem; }
.pill-anim span { width: 2.4rem; height: 1rem; border-radius: 1rem; background: linear-gradient(90deg, var(--green) 50%, #fff 50%); border: 2px solid var(--green); animation: bob 1.4s ease-in-out infinite; }
.pill-anim span:nth-child(2) { animation-delay: .2s; }
.pill-anim span:nth-child(3) { animation-delay: .4s; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-.5rem) rotate(20deg); } }
@media (prefers-reduced-motion: reduce) { .pill-anim span { animation: none; } }

/* Wynik */
.result { margin: 1.5rem 0; outline: none; }
.result > h2 { font-size: 1.6rem; }
.print-date { color: var(--ink-soft); margin: 0 0 1rem; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.1rem 1.2rem; margin: 1rem 0; }
.block h3 { font-size: 1.15rem; margin: 0 0 .6rem; }
.block ul { margin: 0; padding-left: 1.2rem; }
.block li { margin: .35rem 0; }
.summary { font-size: 1.1rem; border-left: 6px solid var(--green); }
.urgent { background: var(--red-bg); border-color: var(--red-bar); border-left: 6px solid var(--red-bar); color: #4a0f0a; }

.item { border-top: 1px solid var(--line); padding: .8rem 0; }
.item:first-of-type { border-top: none; padding-top: 0; }
.item strong { display: block; }
.item p { margin: .25rem 0; }
.sev { display: inline-block; font-weight: 700; font-size: .85rem; padding: .1rem .55rem; border-radius: 1rem; margin-bottom: .3rem; }
.sev-high { background: var(--red-bg); color: var(--red-ink); }
.sev-moderate { background: var(--amber-bg); color: var(--amber-ink); }
.sev-low { background: var(--ok-bg); color: var(--green); }

/* Karta leku — kolorowy pasek jak naklejka apteczna */
.drug { display: grid; grid-template-columns: .5rem 1fr; gap: .9rem; padding: .9rem 0; border-top: 1px solid var(--line); }
.drug:first-of-type { border-top: none; }
.drug .bar { border-radius: 4px; }
.drug h4 { margin: 0; font-size: 1.1rem; }
.drug .subst { color: var(--ink-soft); margin: 0 0 .3rem; }
.drug .verdict { display: inline-block; font-weight: 700; padding: .15rem .6rem; border-radius: var(--radius-s); margin: .2rem 0 .4rem; }
.drug p { margin: .2rem 0; }
.drug .crit { font-size: .85rem; color: var(--ink-soft); }
.drug .taper { background: var(--amber-bg); padding: .4rem .6rem; border-radius: var(--radius-s); }
.v-keep .bar { background: var(--green); } .v-keep .verdict { background: var(--ok-bg); color: var(--green); }
.v-review .bar { background: var(--amber-bar); } .v-review .verdict { background: var(--amber-bg); color: var(--amber-ink); }
.v-consider_stop .bar, .v-duplicate .bar { background: var(--red-bar); }
.v-consider_stop .verdict, .v-duplicate .verdict { background: var(--red-bg); color: var(--red-ink); }

.sources a { color: var(--focus); word-break: break-word; }
.result-actions { display: flex; gap: .8rem; flex-wrap: wrap; margin: 1.4rem 0 2rem; }
.result-actions .btn { flex: 1; min-width: 12rem; }

.foot { color: var(--ink-soft); font-size: .85rem; padding-bottom: 2rem; }

/* Wydruk */
@media print {
  :root, html.large { font-size: 12pt; }
  body { background: #fff; }
  .top, .notice, .step, .loading, .result-actions, .foot, .skip { display: none !important; }
  .result { display: block !important; margin: 0; }
  .block { break-inside: avoid; border-color: #999; }
  .drug { break-inside: avoid; }
  a { color: #000; }
}

.key-points { border: 2px solid var(--green); border-left-width: 6px; background: var(--ok-bg); }
.key-points li { font-weight: 700; }
.sp-key { border: 1pt solid #000; padding: 2pt 4pt; }
@media print { .key-points { break-inside: avoid; } }

.disclaimer { background: var(--amber-bg); border-left: 6px solid var(--amber-bar); color: #3b2a00; }
@media print { .disclaimer { display: block !important; } }

/* Krótki PDF */
.pdf-panel { background: var(--card); border: 2px solid var(--green); border-radius: var(--radius-l); padding: 1rem 1.2rem 1.2rem; margin: 0 0 2rem; }
.pdf-panel p { margin: 0 0 .7rem; }
.pdf-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.pdf-actions .btn { flex: 1; min-width: 9rem; }
.pdf-frame { width: 100%; height: 80vh; margin-top: 1rem; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
@media print { .pdf-panel, #err-pdf { display: none !important; } }

/* Krótki wydruk — jedna kartka */
.short-print { display: none; }
.short-print.measure {
  display: block; position: absolute; left: -10000px; top: 0;
  width: calc(210mm - 20mm); font-size: 8.5pt; background: #fff;
}
.short-print { font-size: 8.5pt; line-height: 1.3; color: #000; }
.sp-head { display: flex; justify-content: space-between; gap: 1em; border-bottom: 1.5pt solid #000; padding-bottom: 2pt; margin-bottom: 3pt; font-size: 10.5pt; }
.sp-pat { margin: 0 0 4pt; }
.sp-sec { margin: 0 0 4pt; break-inside: avoid-page; }
.sp-sec h3 { font-size: 9pt; margin: 0 0 1pt; text-transform: uppercase; letter-spacing: .03em; border-bottom: .5pt solid #888; }
.sp-sec p { margin: 0 0 1.5pt; }
.sp-urgent { border: 1pt solid #000; padding: 2pt 4pt; }
.sp-foot { margin: 5pt 0 0; font-size: 7pt; font-style: italic; border-top: .5pt solid #888; padding-top: 2pt; }

@media print {
  html.print-short body > *:not(.short-print) { display: none !important; }
  html.print-short .short-print { display: block !important; }
}
@page { size: A4; margin: 10mm; }
