:root {
  --forest: #244236;
  --forest-deep: #162b24;
  --moss: #5c7c4f;
  --spruce: #2f6f5e;
  --amber: #c58a2a;
  --clay: #a15743;
  --sky: #d7e7ea;
  --paper: #f7f5ef;
  --ink: #16201c;
  --muted: #65706b;
  --line: #d9d6cb;
  --white: #ffffff;
  --shadow: 0 18px 45px rgba(16, 32, 28, 0.18);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  background: var(--forest);
  color: var(--white);
}

.eyebrow {
  margin: 0 0 2px;
  color: #c5d8d0;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 6vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  min-height: 0;
}

.map-section {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid var(--line);
}

.map-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.stat {
  background: #fffaf0;
  padding: 13px 14px;
}

.stat span {
  display: block;
  color: var(--forest-deep);
  font-size: 1.35rem;
  font-weight: 850;
  line-height: 1;
}

.stat small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.map-wrap {
  position: relative;
  min-height: 420px;
  background: #c9dbd2;
}

.map {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
  background:
    linear-gradient(135deg, rgba(73, 117, 99, 0.2), rgba(209, 181, 125, 0.18)),
    #cbded2;
}

.map:active {
  cursor: grabbing;
}

.tile-layer,
.marker-layer,
.map-grid {
  position: absolute;
  inset: 0;
}

.tile-layer {
  z-index: 0;
}

.tile-layer img {
  position: absolute;
  width: 256px;
  height: 256px;
  object-fit: cover;
  pointer-events: none;
}

.map-grid {
  z-index: 1;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(36, 66, 54, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 66, 54, 0.22) 1px, transparent 1px);
  background-size: 80px 80px;
  pointer-events: none;
}

.marker-layer {
  z-index: 3;
}

.map-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(310px, calc(100% - 36px));
  transform: translate(-50%, -50%);
  padding: 16px;
  border: 1px solid rgba(22, 43, 36, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--forest-deep);
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.map-empty span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.marker {
  position: absolute;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 3px solid var(--white);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  background: var(--species-color);
  color: var(--white);
  font-weight: 900;
  font-size: 0.74rem;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(22, 32, 28, 0.28);
  cursor: pointer;
  overflow: hidden;
}

.marker.selected {
  width: 46px;
  height: 46px;
  outline: 4px solid rgba(197, 138, 42, 0.35);
}

.marker .tree-icon {
  width: 29px;
  height: 29px;
  object-fit: contain;
  object-position: center;
}

.marker.selected .tree-icon {
  width: 35px;
  height: 35px;
}

.marker.current {
  background: #2878bf;
  width: 18px;
  height: 18px;
  border-width: 4px;
  box-shadow: 0 0 0 14px rgba(40, 120, 191, 0.16);
  pointer-events: none;
}

.marker.pending {
  background: var(--amber);
  color: var(--forest-deep);
  font-size: 1.45rem;
  pointer-events: none;
  overflow: visible;
}

.tree-icon {
  width: 30px;
  height: 30px;
  display: block;
  object-fit: contain;
}

.map-controls {
  position: absolute;
  right: 14px;
  top: 14px;
  display: grid;
  gap: 8px;
  z-index: 4;
}

.attribution {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 4;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.78);
  color: #46534e;
  font-size: 0.68rem;
}

.panel {
  background: var(--white);
  min-width: 0;
  overflow: auto;
  max-height: calc(100svh - 70px);
  display: flex;
  flex-direction: column;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  position: sticky;
  top: 0;
  z-index: 7;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 15px 8px 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  border-color: var(--amber);
  color: var(--forest-deep);
}

.view {
  display: none;
  padding: 16px;
}

.view.active {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #44514c;
  font-size: 0.78rem;
  font-weight: 800;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.tree-list {
  display: grid;
  gap: 10px;
}

.tree-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: inherit;
  text-align: left;
}

.species-badge {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.12)),
    var(--species-color);
  color: var(--white);
}

.species-badge .tree-icon {
  width: 58px;
  height: 58px;
}

.tree-card.selected {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(197, 138, 42, 0.18);
}

.thumb {
  width: 72px;
  height: 72px;
  border-radius: 7px;
  object-fit: cover;
  background: linear-gradient(135deg, #496e5c, #d2b06b);
}

.tree-card h3,
.detail-panel h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.detail-panel h2 {
  display: flex;
  align-items: center;
  gap: 9px;
}

.detail-species-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--species-color);
  color: var(--white);
}

.detail-species-icon .tree-icon {
  width: 28px;
  height: 28px;
}

.meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.volume-pill {
  align-self: stretch;
  min-width: 68px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--forest);
  color: var(--white);
  font-weight: 900;
}

.tree-form {
  padding-bottom: 92px;
}

.form-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.form-mode strong {
  color: var(--forest-deep);
  font-size: 1rem;
}

.form-grid {
  display: grid;
  gap: 13px;
}

.measurement-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbf7;
}

.measurement-card > span {
  color: #44514c;
  font-size: 0.78rem;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.segment.active {
  background: var(--forest);
  color: var(--white);
}

.measurement-field.hidden {
  display: none;
}

.calc-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.photo-field input,
.import-field input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-preview {
  min-height: 190px;
  border: 1px dashed #a6aa9e;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--forest-deep);
  background:
    linear-gradient(rgba(255, 253, 248, 0.62), rgba(255, 253, 248, 0.75)),
    url("/assets/tree-placeholder.svg") center / cover;
  overflow: hidden;
}

.photo-preview.has-image {
  background-size: cover;
  background-position: center;
  color: var(--white);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.photo-preview svg {
  width: 38px;
  height: 38px;
}

.estimate-box {
  margin: 14px 0;
  padding: 14px;
  border-radius: 8px;
  background: #eef5f2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.estimate-box span {
  color: var(--muted);
  font-weight: 750;
}

.estimate-box strong {
  color: var(--forest-deep);
  font-size: 1.45rem;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button,
.danger-button,
.import-field span {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
  text-decoration: none;
}

.secondary-button.compact {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.primary-button {
  background: var(--forest);
  color: var(--white);
}

.secondary-button,
.import-field span {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--forest-deep);
}

.danger-button {
  background: #fff2ed;
  color: #8a3226;
}

.full {
  width: 100%;
}

.data-view {
  display: none;
  gap: 10px;
}

.data-view.active {
  display: grid;
}

.fineprint,
.status-line {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.11);
  color: var(--white);
}

.icon-button.small {
  width: 40px;
  height: 40px;
  background: rgba(22, 43, 36, 0.84);
}

.fab {
  position: fixed;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  display: none;
  place-items: center;
  background: var(--amber);
  color: var(--forest-deep);
  box-shadow: 0 12px 28px rgba(60, 42, 9, 0.28);
}

.detail-panel {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 8;
  width: min(410px, calc(100vw - 36px));
}

.detail-card {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.detail-close {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(22, 43, 36, 0.78);
  color: var(--white);
  box-shadow: 0 8px 18px rgba(22, 32, 28, 0.22);
}

.detail-close svg {
  width: 19px;
  height: 19px;
}

.detail-image {
  width: 100%;
  height: 170px;
  object-fit: cover;
  background: linear-gradient(135deg, #456a59, #c6a457);
}

.detail-body {
  padding: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.detail-metric {
  padding: 10px;
  border-radius: 8px;
  background: #f2f5f0;
}

.detail-metric b {
  display: block;
  color: var(--forest-deep);
}

.detail-metric span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 30;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--forest-deep);
  color: var(--white);
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty-list {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.app-version {
  margin-top: auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: #7a837e;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
  background: #fffdf8;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(390px, 52svh) auto;
  }

  .map-section {
    border-right: 0;
  }

  .map-wrap {
    min-height: 0;
  }

  .panel {
    max-height: none;
  }

  .fab {
    display: grid;
  }

  .detail-panel {
    left: 10px;
    bottom: 86px;
    width: calc(100vw - 20px);
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .map-toolbar {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat {
    padding: 10px 9px;
  }

  .stat span {
    font-size: 1.05rem;
  }

  .filters,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .tree-card {
    grid-template-columns: 62px 1fr;
  }

  .thumb,
  .species-badge {
    width: 62px;
    height: 62px;
  }

  .species-badge .tree-icon {
    width: 50px;
    height: 50px;
  }

  .volume-pill {
    grid-column: 1 / -1;
    min-height: 38px;
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }
}
