:root {
  --green-900: #1f4d2b;
  --green-700: #2d6a3f;
  --green-600: #3d8c4e;
  --green-100: #e7f3ea;
  --orange-600: #e86b12;
  --orange-500: #f57c00;
  --orange-100: #fff1e4;
  --brown-600: #8d6e4f;
  --ink: #1c2a20;
  --muted: #5c6b61;
  --line: #d7e0d8;
  --bg: #f6f3ee;
  --card: #ffffff;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #17663a;
  --shadow: 0 8px 24px rgba(31, 77, 43, 0.08);
  --radius: 16px;
  --tap: 48px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
}

img { max-width: 100%; }
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; left: -999px;
}
.skip:focus { left: 8px; top: 8px; background: #fff; padding: 8px; z-index: 50; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { height: 46px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { color: var(--green-700); font-size: 1.05rem; }
.brand-text span { color: var(--muted); font-size: 0.78rem; }

.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lang-form { display: flex; gap: 4px; }
.lang-form button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 36px;
  cursor: pointer;
  color: var(--muted);
}
.lang-form button.active {
  background: var(--green-700);
  color: #fff;
  border-color: var(--green-700);
}

button.nav-toggle.btn { display: none; }

body.has-sidebar {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.has-sidebar .app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}
body.has-sidebar .page {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.sidebar {
  width: 15.5rem;
  flex: 0 0 15.5rem;
  min-height: 0;
  background: var(--green-700);
  overflow-y: auto;
  padding: 8px 10px 16px;
}
.nav-group { margin-bottom: 2px; }
.nav-label {
  margin: 10px 12px 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav-group:first-child .nav-label { margin-top: 2px; }
.sidebar a {
  display: block;
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
}
.sidebar a:hover,
.sidebar a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.16);
  text-decoration: none;
}
.nav-close {
  display: none;
  width: 100%;
  margin: 0 0 8px;
  min-height: var(--tap);
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.nav-backdrop { display: none; }

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

h1 { font-size: 1.6rem; margin: 0 0 8px; color: var(--green-900); }
h2 { font-size: 1.2rem; margin: 24px 0 8px; color: var(--green-900); }
.form-section {
  font-size: 1.05rem;
  margin: 22px 0 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
#chipping-estimate { color: var(--green-700); font-weight: 600; margin: 6px 0 0; }
.lede { color: var(--muted); margin-bottom: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.stat { background: var(--green-100); border-radius: 14px; padding: 14px; }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; color: var(--green-900); }
.stat.warn { background: var(--orange-100); }
.stat.warn .value { color: var(--orange-600); }

.btn, button.btn, input[type="submit"].btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  border: 0;
  background: var(--green-700);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--green-900); text-decoration: none; color: #fff; }
.btn-orange { background: var(--orange-600); }
.btn-orange:hover { background: #c45a0c; }
.btn-ghost {
  background: #fff;
  color: var(--green-700);
  border: 2px solid var(--green-700);
}
.btn-ghost:hover { background: var(--green-100); color: var(--green-900); }
.btn-danger { background: var(--danger); }
.btn:disabled,
.btn:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn:disabled:hover { background: var(--green-700); color: #fff; }
.btn-orange:disabled,
.btn-orange:disabled:hover { background: var(--orange-600); color: #fff; }
.btn-danger:disabled,
.btn-danger:disabled:hover { background: var(--danger); color: #fff; }
.btn-ghost:disabled,
.btn-ghost:disabled:hover { background: #fff; color: var(--green-700); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.input, .select, .textarea, .file {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #c3d0c6;
  font-size: 1rem;
  background: #fff;
}
.input-with-unit {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.input-with-unit .input { flex: 1; min-width: 0; }
.input-unit {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--green-100);
  color: var(--green-700);
  font-weight: 700;
  white-space: nowrap;
}
[hidden] { display: none !important; }
.input-unit[hidden] { display: none; }
.leaflet-interactive.pile-handle { cursor: nwse-resize; }
.input[readonly] { background: #f3f6f4; color: var(--muted); }
.field-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.field-check input.checkbox {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 2px;
  accent-color: var(--green-700);
  flex: 0 0 auto;
}
.field-check label { margin-bottom: 0; }
.textarea { min-height: 90px; }
.input-otp { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.help { color: var(--muted); font-size: 0.88rem; font-weight: 400; }
.errorlist { color: var(--danger); padding-left: 18px; }
.messages { list-style: none; padding: 0; }
.messages li {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--green-100);
}
.messages li.warning, .messages li.error { background: var(--orange-100); color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.85rem; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #eef2ef;
}
.badge-reported { background: var(--orange-100); color: var(--orange-600); }
.badge-measured { background: #e8f0fe; color: #1d4ed8; }
.badge-purchased { background: #e6f4ea; color: var(--ok); }
.badge-unpaid { background: #fde7e7; color: var(--danger); }
.badge-paid { background: #e6f4ea; color: var(--ok); }
.badge-cleared { background: #eee; color: var(--muted); }
.badge-active { background: var(--green-100); color: var(--green-700); }
.badge-dashed { border: 1px dashed var(--orange-600); background: var(--orange-100); color: var(--orange-600); }

.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; }

.location-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8.5rem;
  gap: 12px;
  margin-bottom: 14px;
  align-items: start;
}
.location-map { min-width: 0; }
.location-map .btn-row { margin-top: 0; }
.location-coords { min-width: 0; }
.location-coords .field { margin-bottom: 10px; }
.location-coords .field:last-child { margin-bottom: 0; }
.location-coords label { font-size: 0.78rem; margin-bottom: 4px; }
.location-coords .input {
  min-height: 36px;
  padding: 4px 8px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.photo-picker-label { display: block; font-weight: 600; margin-bottom: 6px; }
.photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.photo-camera-btn { flex: 1 1 14rem; }
.photo-file-btn { flex: 0 0 auto; min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.photo-actions .btn { position: relative; }
.photo-actions input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.photo-preview { margin-top: 10px; }
.photo-preview-item { position: relative; width: 120px; height: 120px; }
.photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: rgba(28, 42, 32, 0.72);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.plant-pin {
  background: #f57c00;
  border: 3px solid #2d6a3f;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff;
  cursor: grab;
}

.map { height: 420px; border-radius: 16px; border: 1px solid var(--line); }
.page:has(.map-screen) {
  display: flex;
  flex-direction: column;
}
.page:has(.map-screen) .wrap {
  max-width: none;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}
.page:has(.map-screen) .footer { padding: 8px 16px 12px; }
.map-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.map-screen .lede { margin-bottom: 12px; }
.map-screen .map { flex: 1 1 auto; height: auto; min-height: 420px; }
.map-filters .field { margin-bottom: 0; }
.map-filters .help { margin: 12px 0 0; }
.map-status { min-height: 1.2em; margin: 8px 0; }
.pile-shape { cursor: grab; }
.pile-label {
  background: rgba(255, 255, 255, 0.92);
  border: 0;
  border-radius: 6px;
  box-shadow: none;
  color: var(--ink);
  font-weight: 700;
  padding: 1px 6px;
}
.pile-label::before { display: none; }
.leaflet-control-layers-toggle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 7.5 12 3.5l9 4-9 4-9-4z' fill='%23fff' stroke='%23333' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 12.5l9 4 9-4' fill='none' stroke='%23333' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M3 17l9 4 9-4' fill='none' stroke='%23333' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-size: 22px 22px;
  background-repeat: no-repeat;
  background-position: center;
}
.muted { color: var(--muted); }
.small { font-size: 0.9rem; color: var(--muted); }
.lasts-min { color: var(--green-700); font-weight: 700; }
.lasts-max { color: var(--orange-600); font-weight: 700; }

.login-card { max-width: 420px; margin: 40px auto; }
.footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 24px; }

.chart {
  display: flex; align-items: flex-end; gap: 6px; height: 180px;
  padding: 8px; background: #fff; border-radius: 12px; overflow-x: auto;
}
.bar-group { display: flex; gap: 3px; align-items: flex-end; min-width: 28px; }
.bar { width: 10px; border-radius: 4px 4px 0 0; }
.bar.min { background: var(--green-600); }
.bar.max { background: var(--orange-500); }
.bar.reported { background: repeating-linear-gradient(135deg, var(--orange-500), var(--orange-500) 4px, #fff 4px, #fff 8px); }

.guide ol { padding-left: 20px; }
.guide li { margin-bottom: 10px; }

div.checkboxes { display: grid; gap: 8px; }
div.checkboxes label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  margin: 0;
  min-height: 1.6rem;
}
input.checkboxes {
  display: inline-block;
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  accent-color: var(--green-700);
  flex: 0 0 auto;
}

.dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  max-width: 28rem;
  width: calc(100% - 32px);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(28, 42, 32, 0.45); }
.dialog h2 { margin-top: 0; }
.dialog .btn-row { margin-bottom: 0; justify-content: flex-end; }
.camera-dialog { max-width: 40rem; }
.camera-dialog video {
  display: block;
  width: 100%;
  max-height: 60vh;
  margin-bottom: 12px;
  background: #111;
  border-radius: 12px;
  object-fit: contain;
}

@media (max-width: 700px) {
  .brand-text { display: none; }
  .brand img { height: 38px; }
  .topbar-inner { flex-wrap: wrap; row-gap: 8px; }
  .top-actions { width: 100%; justify-content: flex-end; }
  button.nav-toggle.btn { display: inline-flex; }
  .topbar { z-index: 45; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h, 4.5rem);
    left: 0;
    bottom: 0;
    width: min(18rem, 88vw);
    flex: none;
    height: auto;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .nav-close { display: block; }
  .nav-backdrop {
    display: block;
    position: fixed;
    top: var(--topbar-h, 4.5rem);
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(28, 42, 32, 0.45);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
  }
  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.nav-open .page { overflow: hidden; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 8px; }
  td { border: 0; padding: 4px 0; }
  td::before { content: attr(data-label); font-weight: 700; display: block; color: var(--muted); font-size: 0.78rem; }
  .location-layout { grid-template-columns: minmax(0, 1fr) 7.5rem; }
  .map { height: 320px; }
  .map-screen .map { min-height: 320px; }
}
