:root {
  --bg: #0f172a; --panel: #1e293b; --panel2: #273449; --text: #e2e8f0; --muted: #94a3b8;
  --green: #22c55e; --red: #ef4444; --yellow: #eab308; --orange: #f97316; --blue: #3b82f6; --line: #334155;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px); min-height: 100vh; }
main { max-width: 560px; margin: 0 auto; }
h1 { font-size: 22px; margin: 18px 0 12px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 40px 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

.card { background: var(--panel); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; }
.topbar .who { font-size: 14px; color: var(--muted); }

button, .btn {
  appearance: none; border: 0; border-radius: 12px; padding: 14px 16px; font-size: 16px; font-weight: 600;
  background: var(--panel2); color: var(--text); cursor: pointer; text-align: center; text-decoration: none; display: inline-block;
}
button:disabled { opacity: .5; }
button.primary { background: var(--blue); color: #fff; }
button.green { background: var(--green); color: #052e16; }
button.red { background: var(--red); color: #fff; }
button.orange { background: var(--orange); color: #fff; }
button.link { background: none; padding: 6px 4px; color: var(--blue); font-weight: 500; }
button.small { padding: 8px 12px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big { width: 100%; padding: 22px; font-size: 20px; border-radius: 18px; }

input, select, textarea {
  width: 100%; padding: 13px 12px; font-size: 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #0b1222; color: var(--text); margin: 6px 0 12px;
}
label { font-size: 14px; color: var(--muted); }
input.code { font-size: 30px; letter-spacing: 8px; text-align: center; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; }
.tabs button { padding: 10px 14px; font-size: 15px; background: transparent; color: var(--muted); }
.tabs button.on { background: var(--panel2); color: var(--text); }

.gate { display: flex; flex-direction: column; align-items: center; padding: 22px 0 8px; }
.dot { width: 150px; height: 150px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 48px; border: 6px solid var(--line); background: var(--panel2); transition: all .3s; }
.dot.closed { border-color: var(--green); }
.dot.open { border-color: var(--red); }
.dot.opening, .dot.closing { border-color: var(--yellow); animation: pulse 1s infinite; }
.dot.stopped { border-color: var(--orange); }
.gate .label { font-size: 26px; font-weight: 700; margin-top: 14px; }
.gate .sub { color: var(--muted); margin-top: 4px; min-height: 22px; text-align: center; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.badge { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.badge.active, .badge.online { background: #14532d; color: #bbf7d0; }
.badge.expired, .badge.blocked, .badge.offline { background: #450a0a; color: #fecaca; }
.badge.pending { background: #422006; color: #fde68a; }

.list .item { border-top: 1px solid var(--line); padding: 12px 0; }
.list .item:first-child { border-top: 0; }
.log .item { font-size: 14px; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 18px); max-width: 520px; margin: 0 auto;
  background: #f8fafc; color: #0f172a; padding: 14px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 6px 24px #0008; z-index: 10; }
.toast.err { background: var(--red); color: #fff; }

.modal-bg { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-end; justify-content: center; z-index: 5; }
.modal { background: var(--panel); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px); max-height: 90vh; overflow: auto; }
.share-box { background: #0b1222; border-radius: 10px; padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; white-space: pre-wrap; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.presets button { padding: 8px 10px; font-size: 14px; }
.hint { background: #172554; color: #bfdbfe; border-radius: 10px; padding: 12px; font-size: 14px; }

/* v2: ogrod, uzytkownicy, moduly, QR */
.zones { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 12px 0; }
.zone { background: var(--panel); border-radius: var(--radius); padding: 14px; border: 2px solid transparent; }
.zone.on { border-color: var(--yellow); }
.zone .row.wrap { margin-top: 10px; }
.zone input[type=range] { margin: 12px 0 0; padding: 0; accent-color: var(--yellow); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #0b1222; padding: 4px; border-radius: 12px; margin: 6px 0 12px; }
.seg button { background: transparent; color: var(--muted); padding: 10px; }
.seg button.on { background: var(--blue); color: #fff; }
.checks { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 12px; }
.checks.days { flex-direction: row; flex-wrap: wrap; }
.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 15px; }
.check input { width: auto; margin: 0; }
.check.day { background: var(--panel2); padding: 8px 10px; border-radius: 10px; }
.bits { display: flex; gap: 4px; flex-wrap: wrap; }
.bit { min-width: 26px; text-align: center; padding: 3px 0; border-radius: 6px; background: var(--panel2); color: var(--muted); font-size: 12px; }
.bit.on { background: var(--yellow); color: #1c1917; font-weight: 700; }
.item form.row input { margin: 6px 0; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.grid3 button { padding: 14px 6px; }
.qr-print { text-align: center; }
.qr { width: 240px; max-width: 80vw; height: auto; background: #fff; border-radius: 10px; padding: 0; display: block; margin: 6px auto; image-rendering: pixelated; }
.qr-name { font-size: 20px; font-weight: 700; margin-top: 6px; }
.center-code { text-align: center; margin: 8px 0; font-size: 18px; }
.center-code b { letter-spacing: 4px; }

/* druk: tylko QR + nazwa + waznosc */
@media print {
  html, body { background: #fff !important; color: #000 !important; }
  body.print-qr > *:not(.modal-bg) { display: none !important; }
  body.print-qr .modal-bg { position: static; background: none; display: block; }
  body.print-qr .modal { background: #fff; color: #000; max-height: none; overflow: visible; box-shadow: none; }
  body.print-qr .no-print { display: none !important; }
  body.print-qr .qr { width: 9cm; max-width: none; }
  body.print-qr .muted { color: #000; }
}
