:root {
  --bg: #f3efe6;
  --surface: #fffdf8;
  --surface-2: #ebe6da;
  --ink: #1d211c;
  --ink-2: #5d6359;
  --line: #ddd6c7;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-soft: #d9eadf;
  --ok: #2f8a5c;
  --ok-soft: #d6efe1;
  --late: #8fbf74;
  --miss: #cf5a43;
  --miss-soft: #f6ddd5;
  --wait: #d79a2b;
  --wait-soft: #f7e8c9;
  --shadow: 0 1px 2px rgb(40 35 20 / .06), 0 8px 24px -12px rgb(40 35 20 / .18);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141613; --surface: #1d201c; --surface-2: #272b26; --ink: #ecefe8; --ink-2: #a3aa9e; --line: #333830;
    --accent: #6cc196; --accent-ink: #0f1a13; --accent-soft: #23382c;
    --ok: #5cc28d; --ok-soft: #1f3a2b; --late: #93c27b; --miss: #ec7c64; --miss-soft: #43251f; --wait: #e8b14c; --wait-soft: #3d311a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 30px -14px rgb(0 0 0 / .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
b { font-weight: 650; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.muted { color: var(--ink-2); font-size: .92rem; }
[hidden] { display: none !important; }

/* ---------- przyciski ---------- */
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 600;
  cursor: pointer; transition: transform .12s, background .2s, opacity .2s; min-height: 44px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }
.text-btn {
  appearance: none; background: none; border: 0; padding: 8px 4px; font: inherit; color: var(--accent);
  font-weight: 600; cursor: pointer; text-decoration: none; font-size: .95rem;
}
.danger { color: var(--miss) !important; }
.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); color: var(--ink); width: 40px; height: 40px;
  border-radius: 12px; font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row-end { justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .9rem; }
.badge.ok::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="err"] { background: var(--miss); color: #fff; }

.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.copy-row code {
  flex: 1; min-width: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 10px;
  overflow-x: auto; white-space: nowrap; user-select: all;
}
.steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: .94rem; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; color: var(--ink); }
details[open] summary { margin-bottom: 4px; }

/* ---------- ONA ---------- */
.patient .p-wrap {
  max-width: 440px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; gap: 22px;
  padding: calc(28px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}
.p-head { text-align: center; }
.p-date { color: var(--ink-2); font-size: .95rem; min-height: 1.4em; }
.p-med { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.p-center { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0; }

.dose {
  --size: min(68vw, 270px); --c: var(--accent); --c-soft: var(--accent-soft);
  position: relative; width: var(--size); height: var(--size); border-radius: 50%; border: 0; padding: 0;
  background: none; cursor: pointer; color: var(--accent-ink); font: inherit;
  transition: transform .18s cubic-bezier(.2, .8, .3, 1.2);
}
.dose:active { transform: scale(.95); }
.dose-ring { position: absolute; inset: -14px; border-radius: 50%; background: var(--c-soft); transition: background .4s; }
.dose-face {
  position: absolute; inset: 0; border-radius: 50%; background: var(--c);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-shadow: 0 18px 40px -18px color-mix(in srgb, var(--c) 80%, black), inset 0 -6px 0 rgb(0 0 0 / .08);
  transition: background .4s;
}
.dose-icon { width: 30%; height: auto; }
.dose-icon-check { display: none; }
.dose-label { font-size: 1.75rem; font-weight: 700; letter-spacing: -.01em; }
.dose-sub { font-size: .95rem; opacity: .85; }
.dose[data-state="pending"] .dose-ring { animation: breathe 2.6s ease-in-out infinite; }
.dose[data-state="saving"] { pointer-events: none; }
.dose[data-state="saving"] .dose-face { opacity: .7; }
.dose[data-state="loading"] .dose-face { background: var(--surface-2); color: var(--ink-2); box-shadow: none; }
.dose[data-state="loading"] .dose-icon { opacity: 0; }
.dose[data-state="taken"] { --c: var(--ok); --c-soft: var(--ok-soft); cursor: default; }
.dose[data-state="taken"]:active { transform: none; }
.dose[data-state="taken"] .dose-icon-pill { display: none; }
.dose[data-state="taken"] .dose-icon-check { display: block; animation: pop .45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes breathe { 50% { transform: scale(1.045); } }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dose-ring, .dose-icon-check { animation: none !important; } }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 14px 10px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.wd { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 4px 0; border-radius: 10px; }
.wd.is-today { background: var(--surface-2); }
.wd-name { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.wd-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.wd-dot.ok { background: var(--ok); }
.wd-dot.miss { background: transparent; box-shadow: inset 0 0 0 2.5px var(--miss); }
.wd-dot.wait { background: transparent; box-shadow: inset 0 0 0 2.5px var(--wait); }

.p-card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.p-card h2 { font-size: 1rem; }
.p-card .row { margin-top: 0; justify-content: space-between; }
.p-details summary { font-size: .95rem; color: var(--ink-2); }
.ios-share {
  display: inline-block; width: 14px; height: 17px; vertical-align: -2px;
  background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 18'%3E%3Cpath d='M7 0 3 4l1 1 2.3-2.3V11h1.4V2.7L10 5l1-1z M1 7h3v1.4H2.4v8.2h9.2V8.4H10V7h3v11H1z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 18'%3E%3Cpath d='M7 0 3 4l1 1 2.3-2.3V11h1.4V2.7L10 5l1-1z M1 7h3v1.4H2.4v8.2h9.2V8.4H10V7h3v11H1z'/%3E%3C/svg%3E") center/contain no-repeat;
}
.gone { margin: auto; text-align: center; color: var(--ink-2); font-size: 1.1rem; }

/* ---------- PANEL ---------- */
.admin .a-wrap {
  max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}
.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

/* menu: na telefonie pasek na dole, na szerokim ekranie zakładki pod nagłówkiem */
.tabs {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px;
  border-radius: 12px; color: var(--ink-2); text-decoration: none; font-size: .74rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current] { color: var(--accent); }
.tab[aria-current] svg { background: var(--accent-soft); border-radius: 99px; padding: 2px 14px; width: 56px; box-sizing: content-box; height: 22px; margin-top: -1px; }
.tab-dot { position: absolute; top: 5px; left: calc(50% + 12px); width: 8px; height: 8px; border-radius: 50%; background: var(--miss); box-shadow: 0 0 0 2px var(--surface); }
@media (min-width: 720px) {
  .admin .a-wrap { padding-bottom: 40px; }
  .tabs {
    position: static; padding: 4px; gap: 4px; border: 0; border-radius: 14px; background: var(--surface-2);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tab { flex-direction: row; justify-content: center; gap: 8px; font-size: .92rem; padding: 9px 10px; }
  .tab svg { width: 20px; height: 20px; }
  .tab[aria-current] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .tab[aria-current] svg { background: none; padding: 0; width: 20px; height: 20px; margin: 0; color: var(--accent); }
  .tab-dot { position: static; }
}
.csv-link { justify-self: center; }
.logout { justify-self: center; color: var(--ink-2); }
.push-end { margin-left: auto; }
.a-top { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px; }
.a-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.a-brand img { border-radius: 8px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }

.today { gap: 16px; }
.today-main { display: flex; gap: 14px; align-items: flex-start; }
.today-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; margin-top: 30px; background: var(--line); }
.today-main.ok .today-dot { background: var(--ok); box-shadow: 0 0 0 5px var(--ok-soft); }
.today-main.wait .today-dot { background: var(--wait); box-shadow: 0 0 0 5px var(--wait-soft); }
.today-main.miss .today-dot { background: var(--miss); box-shadow: 0 0 0 5px var(--miss-soft); animation: blink 1.6s infinite; }
@keyframes blink { 50% { box-shadow: 0 0 0 9px transparent; } }
.today-label { font-size: .85rem; color: var(--ink-2); text-transform: none; }
.today-big { font-size: 1.6rem; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; margin: 2px 0; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; display: grid; }
.stat b { font-size: 1.35rem; }
.stat span { font-size: .85rem; color: var(--ink-2); }

.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal-names span { text-align: center; font-size: .78rem; color: var(--ink-2); font-weight: 600; }
.day {
  appearance: none; border: 0; font: inherit; color: var(--ink); background: var(--surface-2);
  aspect-ratio: 1; max-height: 64px; width: 100%; border-radius: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; gap: 1px; position: relative;
}
.day-n { font-weight: 650; font-size: .95rem; }
.day-t { font-size: .64rem; opacity: .85; font-variant-numeric: tabular-nums; }
.day.ok { background: var(--ok); color: #fff; }
.day.late { background: var(--late); color: #13240f; }
.day.miss { background: var(--miss-soft); color: var(--miss); box-shadow: inset 0 0 0 2px var(--miss); }
.day.wait { background: var(--wait-soft); box-shadow: inset 0 0 0 2px var(--wait); }
.day.future { background: transparent; color: var(--ink-2); opacity: .5; cursor: default; }
.day.none { background: transparent; color: var(--ink-2); opacity: .6; }
.day.is-today::after { content: ""; position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.day.is-today:has(.day-t)::after { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 11px; height: 11px; border-radius: 4px; display: inline-block; }
.lg.ok { background: var(--ok); } .lg.late { background: var(--late); }
.lg.miss { background: var(--miss-soft); box-shadow: inset 0 0 0 2px var(--miss); }
.lg.wait { background: var(--wait-soft); box-shadow: inset 0 0 0 2px var(--wait); }

.dev-list { display: grid; gap: 4px; }
.dev { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.dev:last-child { border-bottom: 0; }

fieldset { border: 0; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; gap: 8px; }
legend { font-weight: 650; padding: 0; margin-bottom: 6px; float: left; width: 100%; }
fieldset > legend + * { clear: both; }
.field { display: grid; gap: 5px; min-width: 0; }
.field span { font-size: .82rem; color: var(--ink-2); font-weight: 600; }
.field input {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 1.5px solid transparent;
  border-radius: 11px; padding: 10px 12px; width: 100%; min-height: 44px; min-width: 0;
}
.field input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hint { font-size: .82rem; color: var(--ink-2); }
.form-err { color: var(--miss); font-size: .9rem; font-weight: 600; margin-right: auto; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; cursor: pointer; }
.switch {
  appearance: none; flex: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line);
  position: relative; cursor: pointer; transition: background .2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 340px); text-align: center; }
.login-logo { margin: 0 auto; border-radius: 14px; }
.login-card .field { text-align: left; }

.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink); border-radius: 22px;
  width: min(100% - 24px, 400px); box-shadow: 0 30px 80px -20px rgb(0 0 0 / .45);
}
.sheet::backdrop { background: rgb(15 18 14 / .45); backdrop-filter: blur(2px); }
.sheet-body { padding: 20px; display: grid; gap: 12px; }
.sheet-body .row { margin-top: 4px; }
.sheet-body .row .btn { flex: 1; }

@media (max-width: 340px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .day-t { display: none; }
}
