:root {
  --green: #2f6b2f;
  --green-d: #234f23;
  --green-l: #e7f1e4;
  --wheat: #e3a21a;
  --bg: #f4f3ee;
  --card: #fff;
  --text: #1f2421;
  --muted: #6b716c;
  --line: #dcdcd4;
  --red: #c0392b;
  --orange: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 17px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
a { color: var(--green); }
h1, h2 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.2rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.block { display: block; }
.hidden, [hidden] { display: none !important; }
.error { color: var(--red); }
.warn-text { color: var(--orange); }

/* ---------- układ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: .6rem;
  padding: calc(.6rem + env(safe-area-inset-top)) .9rem .6rem;
  background: var(--green); color: #fff;
}
.topbar h1 { margin: 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .logo { font-size: 1.4rem; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px;
  border: 0; border-radius: 12px; background: rgba(255,255,255,.15); color: inherit;
  font-size: 1.3rem; text-decoration: none; cursor: pointer;
}
.modal .icon-btn { background: #f0f0ea; color: var(--text); }
.page { max-width: 760px; margin: 0 auto; padding: 1rem .9rem calc(6rem + env(safe-area-inset-bottom)); }
.page.narrow { max-width: 440px; }
.page.wide { max-width: none; padding: .6rem; }
#app.full .page { padding: 0; max-width: none; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: 1rem;
}
.card.warn { background: #fff6e0; border: 1px solid #f0d189; }
.card.error { background: #fdecea; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-bottom: .6rem; }
.grow { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

/* ---------- przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: .35rem .7rem; font-size: .9rem; }
.btn.big { min-height: 64px; font-size: 1.15rem; border-radius: 16px; }
.btn.block { display: flex; width: 100%; }
.sticky-save { position: sticky; bottom: calc(.8rem + env(safe-area-inset-bottom)); box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* ---------- formularze ---------- */
.fld { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.fld > span { font-weight: 600; font-size: .9rem; }
.fld small { color: var(--muted); }
.input {
  width: 100%; min-height: 44px; padding: .55rem .7rem; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font: inherit; color: inherit;
}
.input.big { min-height: 54px; font-size: 1.15rem; }
.input:focus { outline: 3px solid rgba(47,107,47,.25); border-color: var(--green); }
.chk { display: flex; align-items: center; gap: .4rem; padding: .25rem 0; }
.chk input { width: 20px; height: 20px; }

/* ---------- logowanie ---------- */
.login { margin-top: 2rem; }
.brand { text-align: center; margin-bottom: 1rem; }
.brand-icon { font-size: 3rem; }

/* ---------- ekran główny ---------- */
.home-grid { display: grid; gap: .9rem; }
.home-btn {
  display: flex; align-items: center; gap: 1rem; min-height: 96px; padding: 1rem 1.2rem;
  border-radius: 20px; background: #fff; box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; font-size: 1.25rem; font-weight: 700;
}
.home-btn.primary { background: var(--green); color: #fff; min-height: 120px; }
.home-btn .ico { font-size: 2.4rem; }
.home-links { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.4rem; justify-content: center; }

/* ---------- praca ---------- */
.step h2 { display: flex; align-items: center; gap: .5rem; }
.stepnum { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--green); color: #fff; font-size: .9rem; }
.photo-row { display: flex; gap: .8rem; align-items: center; }
.photo-row > div { display: flex; flex-direction: column; gap: .35rem; }
.thumb { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; background: #ddd; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.tile, .pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; text-align: left;
  min-height: 64px; padding: .7rem .8rem; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; font: inherit; color: inherit; cursor: pointer;
}
.tile small, .pick small { color: var(--muted); }
.tile.on, .pick.on { border-color: var(--green); background: var(--green-l); }
.gauge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.gauge {
  min-height: 60px; border-radius: 12px; border: 2px solid var(--line); background: #fff;
  font: inherit; font-size: 1.15rem; font-weight: 700; cursor: pointer;
}
.gauge.on { border-color: var(--green); background: var(--green); color: #fff; }
.liters { font-size: 1.1rem; margin: .8rem 0 0; }
.hint { background: #eef6ff; border-radius: 10px; padding: .5rem .7rem; font-size: .9rem; }
.done { text-align: center; }
.big-ico { font-size: 4rem; }
.pick-list { display: grid; gap: .5rem; max-height: 60vh; overflow: auto; }
.pick { flex-direction: row; justify-content: space-between; align-items: center; width: 100%; }

/* ---------- segmenty ---------- */
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg button {
  flex: 1 1 auto; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
  border: 2px solid var(--line); background: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.seg button.on { border-color: var(--green); background: var(--green-l); }

/* ---------- mapa / nawigacja ---------- */
.map { width: 100%; height: 60vh; border-radius: var(--radius); }
.map.full { height: calc(100dvh - 56px - env(safe-area-inset-top)); border-radius: 0; }
.nav-info {
  position: fixed; left: .6rem; right: .6rem; top: calc(64px + env(safe-area-inset-top)); z-index: 1000;
  background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: .7rem .9rem; font-size: 1.1rem;
}
.nav-actions {
  position: fixed; left: .6rem; right: .6rem; bottom: calc(.8rem + env(safe-area-inset-bottom)); z-index: 1000;
  display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
}
.nav-actions .btn { min-height: 56px; box-shadow: var(--shadow); }
.pin { display: grid; place-items: center; font-size: 1.4rem; background: none; border: 0; }
.pin-me { width: 20px; height: 20px; border-radius: 50%; background: #1e6fd9; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(30,111,217,.25); }
.pin-entry { background: #fff; border-radius: 50%; border: 2px solid var(--green); font-size: .9rem; color: var(--green); font-weight: 700; }
.pin-vertex { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid #d35400; }
.field-label { background: rgba(255,255,255,.85); border: 0; box-shadow: none; font-weight: 700; padding: 1px 5px; }
.field-label::before { display: none; }
.crosshair, .crosshair .leaflet-interactive { cursor: crosshair !important; }

/* ---------- panel admina ---------- */
.tabs { display: flex; gap: .3rem; overflow-x: auto; padding: .5rem .6rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 56px; z-index: 999; }
.tabs a { white-space: nowrap; padding: .5rem .8rem; border-radius: 10px; text-decoration: none; color: var(--text); font-weight: 600; }
.tabs a.on { background: var(--green); color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.map-wrap { display: grid; grid-template-columns: 1fr 320px; gap: .6rem; }
.admin-map { height: calc(100dvh - 190px); min-height: 420px; }
.map-panel { margin: 0; max-height: calc(100dvh - 190px); overflow: auto; }
.map-panel ul { padding-left: 1.1rem; }
.legend { list-style: none; padding: 0 !important; }
.legend li { display: flex; align-items: center; gap: .5rem; margin: .3rem 0; font-size: .9rem; }
.lg { display: inline-block; width: 34px; height: 0; border-top: 3px solid; }
.lg.osm { border-color: #2c3e50; opacity: .5; }
.lg.custom { border-color: #7a4b1e; border-top-style: dashed; }
.lg.part { border-color: #e67e22; border-top-style: dashed; }
.lg.all { border-color: #c0392b; border-top-style: dotted; }
.popup { display: flex; flex-direction: column; gap: .35rem; min-width: 210px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; color: var(--muted); letter-spacing: .02em; }
.table .num { text-align: right; white-space: nowrap; }
.table.compact td, .table.compact th { padding: .4rem .45rem; }
.table tr.dim { opacity: .55; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover { background: var(--green-l); }
.table .actions { white-space: nowrap; display: flex; gap: .3rem; flex-wrap: wrap; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; align-items: end; }
.filters .fld { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stat { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: .7rem .9rem; display: flex; flex-direction: column; }
.stat small { color: var(--muted); }
.stat b { font-size: 1.25rem; }
.stat.neg b { color: var(--red); }
.stat.pos b { color: var(--green); }
.detail-photo { width: 100%; max-height: 50vh; object-fit: contain; background: #111; border-radius: 10px; margin-bottom: .6rem; }
.big-text { font-size: 1.3rem; }

/* ---------- historia ---------- */
.log { list-style: none; padding: 0; margin: 0; }
.log li { display: flex; gap: 1rem; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: .8rem 1rem; margin-bottom: .5rem; }
.log .when, .log .what { display: flex; flex-direction: column; }
.log .when { min-width: 96px; }
.log small { color: var(--muted); }

/* ---------- modal / toast ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.45); display: grid; place-items: end center; }
.modal {
  width: min(560px, 100%); max-height: 92dvh; overflow: auto; background: #fff;
  border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal-wrap { place-items: center; } .modal { border-radius: 18px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  z-index: 4000; max-width: 92vw; padding: .8rem 1.1rem; border-radius: 12px; background: #333; color: #fff;
  box-shadow: var(--shadow); transition: transform .25s; font-weight: 600;
}
.toast.show { transform: translate(-50%, 0); }
.toast.ok { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warn { background: var(--orange); }

@media (max-width: 820px) {
  .map-wrap { grid-template-columns: 1fr; }
  .admin-map { height: 62vh; }
  .map-panel { max-height: none; }
}
#app.full .leaflet-top { top: 70px; }
#app.full .leaflet-bottom { bottom: 80px; }

/* ---------- logowanie Google ---------- */
.btn.google { background: #fff; border: 1px solid #c9cdd2; color: #1f1f1f; gap: .7rem; }
.g-logo { display: inline-flex; }
.or { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9rem; margin: 1rem 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.role-badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: #eee; }
.role-badge.admin { background: #fde8c8; color: #8a4b00; }
.role-badge.rozliczenia { background: #dbeafe; color: #1e3a8a; }
.role-badge.operator { background: var(--green-l); color: var(--green-d); }

/* ---------- pola ---------- */
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: .4rem; vertical-align: -2px; }
.legend .swatch { width: 34px; height: 12px; opacity: .7; }
.group-h { font-size: .95rem; margin: 1rem 0 .3rem; display: flex; align-items: center; gap: .2rem; }
.parcel-list { list-style: none; padding: 0 !important; max-height: 260px; overflow: auto; }
.parcel-list li { display: flex; justify-content: space-between; align-items: center; gap: .4rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.icon-btn.small-x { min-width: 30px; min-height: 30px; font-size: .9rem; background: #f0f0ea; color: var(--text); }
code { background: #f0f0ea; padding: 0 .25rem; border-radius: 4px; font-size: .85em; }
textarea.input { resize: vertical; font-family: inherit; }
.map { position: relative; z-index: 0; isolation: isolate; }
