:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #2c1a1d;
  --muted: #6b5d58;
  --line: #dcd4c6;
  --brand: #3f2327;
  --brand-ink: #ffffff;
  --gold: #b98f45;
  --gold-soft: #f4ead3;
  --danger: #a3261f;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf0d2;
  --ok: #1e6b34;
  --ok-soft: #e4f3e8;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 22px; line-height: 1.25; margin: 0; }
h2 { font-size: 17px; margin: 24px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 14px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--brand); color: var(--brand-ink); }
.topbar img { height: 32px; width: auto; border-radius: 4px; background: #fff; padding: 2px; }
.topbar strong { font-size: 16px; }
.page { max-width: 960px; margin: 0 auto; padding: 16px 16px 96px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }

.nav { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; color: var(--muted); font-size: 12px; text-decoration: none; }
.nav a.active { color: var(--brand); font-weight: 700; }
.nav a.camera svg { background: var(--brand); color: #fff; border-radius: 50%; padding: 5px; width: 34px; height: 34px; }
.nav svg { width: 24px; height: 24px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ok { color: var(--ok); border-color: var(--ok); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 2px solid var(--gold); }

label.field { display: block; margin: 12px 0 0; font-size: 14px; font-weight: 600; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], select, textarea { display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 9px 10px; border: 1px solid #b9ae9d; border-radius: var(--radius); background: #fff; color: var(--ink); font: inherit; font-weight: 400; }
textarea { min-height: 96px; resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 15px; }
input[type=checkbox] { width: 20px; height: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { min-height: 36px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 18px; background: var(--gold-soft); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; }

.map-scroll { overflow-x: auto; border-radius: var(--radius); background: #dfe6d4; -webkit-overflow-scrolling: touch; }
.map { position: relative; min-width: 760px; }
.map img { display: block; width: 100%; height: auto; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map polygon { fill: rgba(255, 255, 255, .12); stroke: rgba(255, 255, 255, .9); stroke-width: 3; cursor: pointer; }
.map polygon:hover, .map polygon:focus { fill: rgba(255, 255, 255, .4); outline: none; }
.map polygon.age-new { fill: rgba(255, 214, 0, .5); stroke: #a87f00; stroke-width: 4; }
.map polygon.age-mid { fill: rgba(222, 38, 28, .48); stroke: #8c1109; stroke-width: 4; }
.map polygon.age-old { fill: rgba(190, 12, 12, .62); stroke: #5f0505; stroke-width: 5; }
.map polygon.located { stroke: #0b6bcb; stroke-width: 12; }
.map .alert circle { fill: #a50b0b; stroke: #fff; stroke-width: 5; }
.map .alert text { fill: #fff; stroke: none; font-size: 40px; font-weight: 800; }
.map .action-marker .dot { fill: #2c1a1d; stroke: #fff; stroke-width: 5; }
.map .action-marker .ring { fill: none; stroke: #fff; stroke-width: 7; transform-box: fill-box; transform-origin: center; animation: action-ring 1.5s ease-out infinite; }
.map .action-marker .bell { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes action-ring { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(2.3); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .map .action-marker .ring { animation: none; } }
.legend .marker-sample { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin-right: 5px; border-radius: 50%; background: #2c1a1d; color: #fff; vertical-align: -5px; }
.legend .marker-sample svg { width: 13px; height: 13px; }
.house-chip.needs-action { border: 3px solid var(--ink); }
.chip-action { display: inline-flex; align-items: center; gap: 3px; margin-top: 2px; padding: 0 6px; border-radius: 9px; background: var(--ink); color: #fff !important; font-weight: 700; }
.chip-action svg { width: 11px; height: 11px; }
.action-line { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--ink); font-size: 14px; font-weight: 700; }
.action-line svg { flex: none; width: 16px; height: 16px; }
.notice.action { display: flex; align-items: center; gap: 10px; color: #fff; background: var(--ink); text-decoration: none; }
.notice.action svg { flex: none; width: 24px; height: 24px; }
.map text { font: 700 30px system-ui, sans-serif; fill: #fff; stroke: #2c1a1d; stroke-width: 7px; paint-order: stroke; text-anchor: middle; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; margin-right: 5px; border: 1px solid var(--muted); border-radius: 3px; vertical-align: -2px; }
.legend .l0 { background: #fff; }
.legend .l1 { background: #ffd600; }
.legend .l2 { background: #de261c; }
.legend .l3 { width: 18px; height: 18px; background: #a50b0b; border-radius: 50%; color: #fff; font-style: normal; font-weight: 800; font-size: 13px; line-height: 16px; text-align: center; vertical-align: -3px; }

.map-tools { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; margin: 12px 0; }
.map-tools label.field { flex: 1 1 200px; margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button { min-height: 44px; padding: 8px 12px; border: 0; background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.segmented button[aria-pressed=true] { background: var(--brand); color: var(--brand-ink); }
.house-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.house-chip { text-align: center; }
.bell { position: relative; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-left: auto; color: #fff; }
.bell svg { width: 26px; height: 26px; }
.bell-count { position: absolute; top: 2px; right: 0; min-width: 20px; padding: 0 5px; border-radius: 10px; background: #d9342b; color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.review-box { margin: 16px 0; padding: 12px; border: 2px solid var(--gold); border-radius: var(--radius); background: var(--surface); }
.description { white-space: pre-wrap; overflow-wrap: anywhere; }
.badge.do_akceptacji { background: var(--gold-soft); color: var(--warn); }
.badge.odmowa { background: var(--ink); color: #fff; }
.menu-card { display: flex; flex-direction: column; min-height: 60px; justify-content: center; }
.refuse { margin-top: 4px; }
.refuse summary { min-height: 36px; padding-top: 6px; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; }
.notification-link { display: block; color: inherit; text-decoration: none; }
.update-bar { position: fixed; z-index: 40; left: 12px; right: 12px; bottom: 70px; display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 520px; margin: 0 auto; padding: 8px 12px; border-radius: var(--radius); background: var(--ink); color: #fff; }
.update-bar .btn { min-height: 38px; padding: 4px 12px; }
.badge.odrzucone { background: var(--danger); color: #fff; }
.badge.usuniete { background: #e8e4dc; color: var(--muted); }
.thread { display: grid; gap: 8px; }
.comment { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.comment.from-contractor { border-left: 4px solid var(--gold); }
.comment.system { background: transparent; border-style: dashed; font-size: 14px; }
.comment.deleted { opacity: .65; }
.comment.deleted .comment-body { text-decoration: line-through; }
.comment-head { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.comment-body { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.link-btn { min-height: 36px; padding: 4px 0; border: 0; background: none; color: var(--brand); font: inherit; font-size: 14px; font-weight: 600; text-decoration: underline; cursor: pointer; }
.link-btn.danger { color: var(--danger); }
.link-row { display: flex; flex-wrap: wrap; gap: 0 16px; margin-top: 4px; }
.pick-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.house-pick-group { margin-top: 8px; }
.house-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px; }
.pick { display: block; cursor: pointer; }
.pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pick span { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-weight: 700; font-size: 14px; }
.pick input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.pick input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 1px; }
.fault-row { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.chip { display: inline-flex; align-items: center; text-decoration: none; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.card.notification.unread { border-left: 4px solid var(--gold); background: #fffdf6; }
.audit-details { font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
[hidden] { display: none !important; }
.house-chip { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 56px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-weight: 700; text-decoration: none; }
.house-chip small { font-weight: 500; font-size: 12px; color: var(--muted); }
.house-chip.age-new { background: #fff6bf; border-color: #d4ad00; }
.house-chip.age-new small { color: #6f5500; }
.house-chip.age-mid { background: var(--danger-soft); border-color: var(--danger); }
.house-chip.age-mid small { color: var(--danger); }
.house-chip.age-old { background: var(--danger); border-color: #5f0505; color: #fff; }
.house-chip.age-old small { color: #fff; }
.house-chip.located { outline: 3px solid #0b6bcb; outline-offset: 1px; }

.card { display: block; margin: 8px 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none; }
.card-title { font-weight: 700; overflow-wrap: anywhere; }
.card-meta { margin-top: 4px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.nowe { background: var(--danger-soft); color: var(--danger); }
.badge.przekazane { background: var(--warn-soft); color: var(--warn); }
.badge.wykonane { background: var(--ok-soft); color: var(--ok); }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumbs img { display: block; width: 72px; height: 72px; border-radius: 6px; object-fit: cover; background: var(--line); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
dialog.viewer { position: fixed; inset: 0; width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border-radius: 0; background: #111; color: #fff; overflow: hidden; }
dialog.viewer[open] { display: flex; flex-direction: column; }
dialog.viewer::backdrop { background: #111; }
.viewer-top, .viewer-bottom { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #111; }
.viewer-top { justify-content: space-between; }
.viewer-bottom { flex-direction: column; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.viewer-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: pan-y pinch-zoom; }
.viewer-stage img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer-status { position: absolute; color: #ddd; padding: 12px; text-align: center; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 72px; border: 0; border-radius: 10px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 34px; line-height: 1; cursor: pointer; }
.viewer-nav:disabled { opacity: .25; cursor: default; }
.viewer-nav.prev { left: 6px; }
.viewer-nav.next { right: 6px; }
.viewer-close { width: 44px; height: 44px; border: 0; border-radius: 8px; background: #333; color: #fff; font-size: 24px; cursor: pointer; }
.viewer-caption { max-width: 100%; font-size: 14px; color: #ddd; overflow-wrap: anywhere; text-align: center; }
.viewer-download { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 14px; border: 1px solid #777; border-radius: var(--radius); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
.viewer-download svg { width: 20px; height: 20px; }
.photo-cell { position: relative; }
.photo-cell img { display: block; width: 100%; aspect-ratio: 1; border-radius: 8px; object-fit: cover; background: var(--line); }
.photo-cell small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.photo-x { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(44, 26, 29, .8); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 10px; }
.notice { margin: 12px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--gold-soft); font-size: 15px; overflow-wrap: anywhere; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.empty { padding: 24px 12px; color: var(--muted); text-align: center; }
details.block { margin: 12px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
details.block summary { min-height: 28px; font-weight: 700; cursor: pointer; }

.login { max-width: 400px; margin: 0 auto; padding: 40px 16px; }
.login img { display: block; width: 180px; margin: 0 auto 16px; }

.toast { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: 74px; max-width: 480px; margin: 0 auto; padding: 12px 14px; border-radius: var(--radius); background: var(--ink); color: #fff; text-align: center; }
.toast.error { background: var(--danger); }
dialog { width: min(440px, calc(100vw - 32px)); padding: 16px; border: 0; border-radius: 12px; color: var(--ink); }
dialog::backdrop { background: rgba(44, 26, 29, .5); }
