/* Wspólny wygląd aplikacji viCards (PWA) — ten sam układ co w projekcie `kosze`.
   Kolor przewodni ustawia każda aplikacja w swoim index.html (--primary, --primary-2, --primary-rgb). */
:root {
  --bg: #f3f7fb;
  --card: #ffffff;
  --text: #1d2a33;
  --muted: #6b7a86;
  --line: #e3eaf1;
  --primary: #14a37f;
  --primary-2: #1fb5c9;
  --primary-rgb: 20, 163, 127;
  --primary-ink: #ffffff;
  --shadow: 0 1px 2px rgba(29, 42, 51, .05), 0 6px 18px rgba(29, 42, 51, .07);
  --radius: 18px;

  --green: #16a34a;  --green-bg: #e8f8ee;
  --blue: #2f6fe4;   --blue-bg: #e9f0fe;
  --orange: #ea7a1a; --orange-bg: #fff1e3;
  --purple: #8b5cf6; --purple-bg: #f2edfe;
  --teal: #0f9fa8;   --teal-bg: #e3f7f8;
  --red: #dc3b3b;    --red-bg: #fdecec;
  --danger: #dc3b3b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* Pasek górny */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  color: var(--primary-ink);
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), .25);
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .01em; }
.badge { font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: rgba(255, 255, 255, .22); border: 0; color: inherit; font-family: inherit; cursor: pointer; }
.icon-btn {
  background: rgba(255, 255, 255, .2); border: 0; color: inherit; font-size: 1.2rem;
  width: 36px; height: 36px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}

main { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: flex; flex-direction: column; gap: 14px; }

/* Ekran startowy */
.welcome {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
  background-image: radial-gradient(circle at 100% 0, var(--teal-bg) 0, transparent 55%),
                    radial-gradient(circle at 0 100%, var(--green-bg) 0, transparent 50%);
}
.welcome h2 { margin: 0 0 4px; font-size: 1.3rem; }
.welcome p { margin: 0; color: var(--muted); line-height: 1.45; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats:empty { display: none; }
.stat { border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 1.5rem; line-height: 1; }
.stat span { font-size: .78rem; font-weight: 600; opacity: .85; }
.s-green { background: var(--green-bg); color: var(--green); }
.s-blue { background: var(--blue-bg); color: var(--blue); }
.s-orange { background: var(--orange-bg); color: var(--orange); }
.s-purple { background: var(--purple-bg); color: var(--purple); }
.section { margin: 6px 2px -4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.empty { text-align: center; color: var(--muted); font-size: 1rem; line-height: 1.5; margin: 18px 0; }

/* Przyciski */
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; font-size: 1rem; font-weight: 650; font-family: inherit;
  cursor: pointer; background: var(--line); color: var(--text); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s ease, box-shadow .2s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-primary {
  background: linear-gradient(120deg, var(--primary), var(--primary-2)); color: var(--primary-ink);
  box-shadow: 0 6px 16px rgba(var(--primary-rgb), .3);
}
.btn-soft-blue { background: var(--blue-bg); color: var(--blue); }
.btn-soft-orange { background: var(--orange-bg); color: var(--orange); }
.btn-soft-green { background: var(--green-bg); color: var(--green); }
.btn-soft-purple { background: var(--purple-bg); color: var(--purple); }
.btn-danger { background: none; color: var(--danger); border: 1.5px solid #f3c4c4; }
.btn-big { width: 100%; padding: 16px; font-size: 1.08rem; border-radius: 16px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.link-btn { background: var(--blue-bg); border: 0; color: var(--blue); font-weight: 650; cursor: pointer; font-size: .82rem; padding: 4px 10px; border-radius: 99px; margin-left: auto; font-family: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }

/* Panele i pola */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.panel-title { font-weight: 700; display: flex; align-items: center; gap: 10px; }
.dot { width: 30px; height: 30px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: .9rem; font-weight: 800; flex: none; }
.d-green { background: var(--green-bg); color: var(--green); }
.d-blue { background: var(--blue-bg); color: var(--blue); }
.d-orange { background: var(--orange-bg); color: var(--orange); }
.d-purple { background: var(--purple-bg); color: var(--purple); }
.d-teal { background: var(--teal-bg); color: var(--teal); }
.d-red { background: var(--red-bg); color: var(--red); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .86rem; font-weight: 650; color: var(--muted); }
.input, .field input, .field select, .field textarea {
  width: 100%; border: 2px solid var(--line); background: #fbfdff; color: var(--text);
  border-radius: 14px; padding: 11px 13px; font-family: inherit; font-size: 1rem; font-weight: 500;
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { min-height: 96px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .15); }
.input-number {
  width: 100%; border: 2px solid var(--line); background: #fbfdff; color: var(--text);
  border-radius: 14px; padding: 12px 14px; font-family: inherit;
  font-size: 1.6rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  transition: border-color .2s, box-shadow .2s;
}
.input-number:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .15); }
.input-number::placeholder { color: #b6c2cc; font-weight: 600; text-transform: none; letter-spacing: .02em; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .86rem; line-height: 1.4; }
.center { text-align: center; }
.err { color: var(--danger); font-size: .9rem; font-weight: 650; }

.photo-drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 120px; border: 2px dashed #b9dccf; border-radius: var(--radius);
  background: linear-gradient(160deg, var(--green-bg), var(--teal-bg));
  cursor: pointer; overflow: hidden; color: #2b7a63; font-weight: 600; line-height: 1.6; padding: 10px;
}
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.thumb .state { position: absolute; left: 0; right: 0; bottom: 0; font-size: .7rem; font-weight: 700; color: #fff; background: rgba(0, 0, 0, .5); padding: 2px 6px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .2s; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }
.chip { border: 0; background: var(--green-bg); color: var(--green); border-radius: 99px; padding: 7px 14px; font-weight: 700; cursor: pointer; font-size: .95rem; font-family: inherit; }
.chip.active { background: var(--green); color: #fff; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .76rem; font-weight: 700; background: var(--line); color: var(--muted); }
.t-green { background: var(--green-bg); color: var(--green); }
.t-blue { background: var(--blue-bg); color: var(--blue); }
.t-orange { background: var(--orange-bg); color: var(--orange); }
.t-red { background: var(--red-bg); color: var(--red); }
.t-purple { background: var(--purple-bg); color: var(--purple); }

/* Listy — kolor akcentu wg rodzaju */
.c-green { --acc: var(--green); --acc-bg: var(--green-bg); }
.c-blue { --acc: var(--blue); --acc-bg: var(--blue-bg); }
.c-orange { --acc: var(--orange); --acc-bg: var(--orange-bg); }
.c-purple { --acc: var(--purple); --acc-bg: var(--purple-bg); }
.c-teal { --acc: var(--teal); --acc-bg: var(--teal-bg); }
.c-red { --acc: var(--red); --acc-bg: var(--red-bg); }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; gap: 12px; align-items: center; background: var(--card); box-shadow: var(--shadow);
  border-radius: var(--radius); padding: 10px 12px 10px 10px; cursor: pointer;
  border-left: 5px solid var(--acc, var(--primary)); color: inherit; text-decoration: none;
  transition: transform .12s ease;
}
.card:active { transform: scale(.985); }
.card .noimg {
  width: 56px; height: 56px; border-radius: 12px; flex: none;
  background: var(--acc-bg); display: flex; align-items: center; justify-content: center;
}
.card .noimg .ic { width: 26px; height: 26px; color: var(--acc); }
.card .num {
  display: inline-block; font-weight: 800; font-size: 1.02rem; letter-spacing: .04em;
  color: var(--acc); background: var(--acc-bg); padding: 2px 10px; border-radius: 8px; margin-bottom: 4px;
}
.card .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { font-size: .82rem; color: var(--muted); }
.card .grow { flex: 1; min-width: 0; }
.card .go { color: var(--acc); display: flex; }
.card .go .ic { width: 22px; height: 22px; }
.card .pts { font-weight: 800; color: var(--acc); font-size: 1.1rem; text-align: right; line-height: 1.1; }
.card .pts small { display: block; font-size: .68rem; font-weight: 700; color: var(--muted); }

/* Szczegóły */
.hero { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-top: 5px solid var(--acc, var(--primary)); }
.hero-num { padding: 14px 16px 4px; font-size: 1.5rem; font-weight: 800; letter-spacing: .05em; color: var(--acc, var(--primary)); }
.hero-sub { padding: 0 16px 14px; color: var(--muted); }
.hero-points { display: flex; align-items: baseline; gap: 8px; padding: 0 16px 16px; }
.hero-points b { font-size: 2.4rem; line-height: 1; color: var(--acc, var(--primary)); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: .95rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; font-weight: 600; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; font-size: .9rem; }
.history li { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; border-bottom: 1px solid var(--line); padding: 9px 0; }
.history li:last-child { border-bottom: 0; }
.history .h-main { flex: 1; min-width: 0; }
.history .h-main div { word-break: break-word; }
.history .plus { color: var(--green); font-weight: 800; white-space: nowrap; }
.history .minus { color: var(--orange); font-weight: 800; white-space: nowrap; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--line); }
.qr-box { display: flex; justify-content: center; padding: 8px 0; }
.qr-box img, .qr-box canvas { width: 220px; height: 220px; image-rendering: pixelated; border-radius: 12px; background: #fff; padding: 10px; box-shadow: var(--shadow); }

/* Drzewo czynności wizyty */
.tree { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tree .tree { padding-left: 14px; border-left: 2px solid var(--line); margin-top: 8px; }
.tree-group { font-weight: 700; color: var(--muted); font-size: .86rem; text-transform: uppercase; letter-spacing: .05em; }
.task { background: #fbfdff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.task.done { border-color: #bfe8cf; background: var(--green-bg); }
.task.fail { border-color: #f3c4c4; background: var(--red-bg); }
.task-head { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.task-head span { flex: 1; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 0; border-radius: 99px; padding: 6px 12px; font-weight: 700; font-family: inherit; font-size: .85rem; cursor: pointer; background: var(--line); color: var(--text); }
.seg button.on-ok { background: var(--green); color: #fff; }
.seg button.on-fail { background: var(--red); color: #fff; }
.seg button.on-na { background: var(--muted); color: #fff; }

.footer { display: flex; justify-content: space-between; padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px); max-width: 640px; margin: 0 auto; width: 100%; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 11px 18px; border-radius: 99px; font-size: .95rem; z-index: 2000;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.tip { background: var(--orange-bg); color: #8a4a12; border-radius: var(--radius); padding: 12px 14px; font-size: .9rem; line-height: 1.45; }
.ok-box { background: var(--green-bg); color: #166534; border-radius: var(--radius); padding: 12px 14px; font-size: .95rem; line-height: 1.45; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Skaner kodu QR na pełnym ekranie */
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner-frame { position: absolute; left: 50%; top: 42%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); border: 3px solid rgba(255, 255, 255, .9); border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); pointer-events: none; }
.scanner-hint { position: absolute; top: calc(env(safe-area-inset-top) + 20px); left: 16px; right: 70px; color: #fff; font-weight: 650; }
.scanner-bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); }
.scanner-bar form { display: flex; gap: 8px; }
.scanner-bar input { flex: 1; min-width: 0; border: 0; border-radius: 14px; padding: 12px 14px; font: inherit; font-size: 1.1rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.scanner-close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .2); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

/* Pokaz zdjęcia na pełnym ekranie */
.viewer { position: fixed; inset: 0; z-index: 70; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .2); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

/* Okno dialogowe (zamiast alert/confirm) */
.sheet-back { position: fixed; inset: 0; z-index: 80; background: rgba(15, 25, 35, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 12px; max-height: 90dvh; overflow: auto; }
.sheet h3 { margin: 0; font-size: 1.15rem; }

/* Ikonki (zestaw SVG wstrzykiwany przez core.js) — kolor dziedziczą z tekstu */
.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; display: inline-block; }
.btn .ic { width: 1.25em; height: 1.25em; }
.ic-lg { width: 34px; height: 34px; }
.ic-xl { width: 46px; height: 46px; color: #b6c2cc; }
.icon-btn .ic { width: 22px; height: 22px; }
.dot .ic { width: 17px; height: 17px; }
.meta .ic { width: 14px; height: 14px; vertical-align: -2px; }

/* Ekran logowania */
html.locked body > *:not(#gate):not(svg):not(.toast) { display: none !important; }
.gate { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: var(--bg); overflow: auto; }
.gate-card { width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; background: #fff; padding: 28px 22px; border-radius: 18px; box-shadow: 0 8px 30px rgba(20, 40, 60, .12); }
.gate-card h2 { margin: 0; font-size: 1.25rem; }
.gate-card p { margin: 0; color: #5b6b78; font-size: .92rem; }
.gate-logo { width: 64px; height: 64px; margin: 0 auto; }
.gate-card input { font: inherit; font-size: 1.05rem; padding: 12px 14px; border: 1.5px solid #cfdbe6; border-radius: 12px; text-align: center; }
.gate-card input:focus { outline: none; border-color: var(--primary); }

/* Strona wyboru aplikacji */
.apps { display: flex; flex-direction: column; gap: 12px; }
.app-tile { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; color: inherit; text-decoration: none; border-left: 6px solid var(--acc); }
.app-tile img { width: 56px; height: 56px; border-radius: 14px; flex: none; }
.app-tile b { font-size: 1.08rem; }
.app-tile span { display: block; color: var(--muted); font-size: .88rem; margin-top: 2px; }
