:root {
  --bg: #eef5ef;
  --panel: #ffffff;
  --text: #17211a;
  --muted: #66736a;
  --border: #cfd9d1;
  --accent: #24613b;
  --accent-dark: #17482b;
  --accent-soft: #e5f1e8;
  --danger: #a72e2e;
  --danger-soft: #f8e8e8;
  --shadow: 0 6px 20px rgba(22, 55, 34, 0.08);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button, .file-btn { min-height: 44px; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(36, 97, 59, 0.22);
  outline-offset: 2px;
}
.app-shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px 24px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; background: var(--accent); font-weight: 800; letter-spacing: -1px;
}
.brand-name { font-weight: 800; letter-spacing: .04em; }
.brand-sub { color: var(--muted); font-size: .86rem; margin-top: 2px; }
.view { padding-bottom: 16px; }
.hidden { display: none !important; }
h1, h2 { margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
h2 { font-size: 1.35rem; }
p { color: var(--muted); margin: 6px 0 0; line-height: 1.45; }
.section-head, .project-title-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  margin-bottom: 16px;
}
.section-head.compact { align-items: center; }
.eyebrow { font-size: .72rem; color: var(--muted); font-weight: 800; letter-spacing: .12em; margin-bottom: 4px; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 14px;
  font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
/* Update Tree stays visibly inactive until an editable field or photo changes. */
#saveTreeBtn:disabled { opacity: .42; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #e4b8b8; }
.btn-link { background: transparent; color: var(--accent); padding-inline: 6px; }
.btn-large { min-width: 150px; }
.summary-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px;
}
.summary-card {
  background: rgba(255,255,255,.8); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.summary-value { font-size: 1.45rem; font-weight: 800; line-height: 1; }
.summary-label { color: var(--muted); font-size: .8rem; margin-top: 6px; }
.project-chooser { display: grid; gap: 12px; }
.project-select-row { display: grid; grid-template-columns: minmax(0, 1fr) 48px; gap: 10px; align-items: end; }
.project-select-label { min-width: 0; }
.add-project-btn { width: 48px; padding-inline: 0; font-size: 1.45rem; line-height: 1; }
.project-preview { display: grid; gap: 12px; }
.project-preview .project-metrics { margin-top: 0; }
.accept-project-btn { width: 100%; min-height: 50px; }
.compact-btn { min-height: 40px; padding: 8px 11px; }
.empty-state .btn { margin-top: 14px; }
.project-list, .tree-list { display: grid; gap: 10px; }
.project-card, .tree-card, .form-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.project-card { padding: 14px; }
.project-card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.project-name { font-weight: 800; font-size: 1.1rem; }
.project-address { color: var(--text); font-size: .92rem; margin-top: 4px; line-height: 1.35; }
.project-acreage { color: var(--muted); font-size: .88rem; margin-top: 3px; font-weight: 700; }
.project-note { color: var(--muted); font-size: .86rem; margin-top: 5px; }
.project-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.metric { background: #f8faf8; border-radius: 9px; padding: 8px; }
.metric b { display: block; font-size: 1rem; }
.metric span { font-size: .72rem; color: var(--muted); }
.project-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.empty-state {
  border: 1px dashed #aab7ad; border-radius: 14px; padding: 30px 18px; text-align: center; color: var(--muted);
}
.empty-state strong { display: block; color: var(--text); margin-bottom: 5px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.search { flex: 1; }
.tree-card {
  display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; gap: 12px; padding: 10px; align-items: center;
}
.thumb {
  width: 82px; height: 82px; border-radius: 10px; object-fit: cover; background: #e7ece8;
}
.thumb-placeholder { width: 82px; height: 82px; border-radius: 10px; display: grid; place-items: center; background: #edf1ee; color: var(--muted); font-size: .78rem; text-align: center; }
.tree-title { font-weight: 800; }
.tree-meta { color: var(--muted); font-size: .87rem; margin-top: 4px; line-height: 1.4; }
.tag { display: inline-block; margin-top: 7px; padding: 3px 8px; border-radius: 999px; font-size: .76rem; font-weight: 800; background: #eef2ef; }
.tag.keep { background: #e2f2e7; color: #1c6336; }
.tag.maybe { background: #f5efd9; color: #745e15; }
.tag.remove { background: #f8e3e3; color: #8d2727; }
.form-card { padding: 14px; margin-bottom: 12px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-card label { display: block; }
.field-label { display: block; font-size: .82rem; font-weight: 800; margin-bottom: 6px; }
.hint, .muted { color: var(--muted); font-size: .84rem; }
.relative-head, .relative-row {
  display: grid; grid-template-columns: minmax(108px, 1.45fr) minmax(72px, .8fr) minmax(72px, .8fr); gap: 8px;
}
.relative-head { margin: 12px 0 5px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.relative-head span { min-width: 0; }
.relative-row { margin-bottom: 8px; align-items: center; }
.relative-row:last-child { margin-bottom: 0; }
.relative-row input, .relative-row select { min-width: 0; padding-inline: 8px; }
.card-headline { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.photo-card { text-align: center; }
.photo-wrap { display: grid; place-items: center; margin-bottom: 10px; }
.photo-preview, .photo-placeholder { width: min(100%, 420px); height: 230px; border-radius: 12px; }
.photo-preview { object-fit: cover; }
.photo-placeholder { display: grid; place-items: center; background: #edf1ee; color: var(--muted); }
.file-btn { display: inline-flex; align-items: center; justify-content: center; }
.file-btn input { display: none; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.tree-save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}
.tree-save-row .btn { width: 100%; min-width: 0; min-height: 48px; }
.tree-delete-row { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.tree-delete-row .btn { min-height: 44px; }

.form-message { min-height: 22px; margin: 4px 0 10px; color: var(--danger); font-weight: 700; }
dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100% - 28px)); box-shadow: 0 24px 70px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.32); }
.dialog-form { padding: 20px; display: grid; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.bearing-dialog { text-align: center; }
.bearing-live-value {
  font-size: clamp(3rem, 16vw, 5rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  padding: 8px 0 2px;
}
.bearing-status { margin: 0; min-height: 2.4em; }
.bearing-actions { justify-content: stretch; }
.bearing-actions .btn { flex: 1 1 0; min-height: 48px; }
.footer { width: min(920px, 100%); margin: 0 auto; padding: 0 14px max(18px, env(safe-area-inset-bottom)); color: var(--muted); font-size: .75rem; text-align: center; }
@media (max-width: 680px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-head, .project-title-row { align-items: stretch; }
  .section-head:not(.compact), .project-title-row { flex-direction: column; }
  .section-head:not(.compact) .btn, .project-title-row .btn { width: 100%; }
  .toolbar { flex-direction: column; }
  .toolbar .btn { width: 100%; }
  .tree-card { grid-template-columns: 68px minmax(0, 1fr); }
  .tree-card > .btn { grid-column: 1 / -1; width: 100%; }
  .thumb, .thumb-placeholder { width: 68px; height: 68px; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .card-headline { align-items: stretch; flex-direction: column; }
  .card-headline .btn { width: 100%; }
}

.project-title-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.map-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.map-mode-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.map-mode-btn { background: #fff; color: var(--text); border: 1px solid var(--border); }
.map-mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.map-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; }
.map-status { color: var(--muted); font-size: .84rem; margin-bottom: 10px; line-height: 1.4; }
.map-svg-wrap { width: 100%; overflow: auto; background: #fafcf9; border: 1px solid var(--border); border-radius: 12px; }
.map-svg { display: block; width: 100%; min-width: 520px; height: auto; aspect-ratio: 900 / 620; }
.map-grid-line { stroke: #dce5de; stroke-width: 1; }
.map-axis-line { stroke: #b7c5ba; stroke-width: 1.2; }
.map-scale-line { stroke: var(--text); stroke-width: 3; }
.map-scale-text, .map-north-text, .map-point-label { fill: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
.map-scale-text, .map-north-text { font-size: 16px; font-weight: 700; }
.map-point-label { font-size: 15px; font-weight: 800; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.map-point { cursor: pointer; }
.map-point-shape { stroke: #fff; stroke-width: 2.5; }
.map-point-shape.reference { fill: #374151; }
.map-point-shape.keep { fill: #2f7a48; }
.map-point-shape.maybe, .map-point-shape.unreviewed { fill: #b38a23; }
.map-point-shape.remove { fill: #b33a3a; }
.map-unplaced { margin-top: 10px; border: 1px dashed #b6c2b8; border-radius: 12px; padding: 10px 12px; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.map-legend { display: flex; flex-wrap: wrap; gap: 12px 16px; margin-top: 12px; color: var(--muted); font-size: .8rem; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-mark { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.legend-mark.reference { background: #374151; border-radius: 2px; transform: rotate(45deg); }
.legend-mark.keep { background: #2f7a48; }
.legend-mark.maybe { background: #b38a23; }
.legend-mark.remove { background: #b33a3a; }
.map-disclaimer { font-size: .76rem; margin-top: 10px; }
.survey-empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.survey-empty strong { display: block; color: var(--text); margin-bottom: 5px; }
.survey-file-btn { margin-top: 14px; }
.survey-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 10px; }
.survey-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.compact-file-btn { padding: 8px 11px; min-height: 40px; }
.survey-stage, .calibration-stage { position: relative; width: 100%; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #f4f6f4; }
.survey-view-controls { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.survey-view-controls .btn { min-height: 40px; }
.survey-zoom-btn { min-width: 46px; font-size: 1.2rem; line-height: 1; }
.survey-viewport { aspect-ratio: 900 / 620; min-height: 300px; touch-action: none; cursor: grab; background: #eef2ee; }
.survey-viewport.is-panning { cursor: grabbing; }
.survey-image-surface { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.survey-image { display: block; max-width: none; width: auto; height: auto; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.survey-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.survey-overlay .map-point { pointer-events: auto; }
.calibration-dialog { width: min(760px, calc(100vw - 32px)); }
.calibration-instruction { background: var(--accent-soft); color: var(--accent-dark); border-radius: 10px; padding: 10px 12px; font-weight: 800; }
.calibration-stage { height: min(48vh, 420px); min-height: 270px; cursor: crosshair; touch-action: none; background: #eef2ee; }
.calibration-view-controls { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.calibration-view-controls .btn { min-height: 40px; }
.calibration-view-controls .btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.calibration-view-controls .survey-zoom-btn { min-width: 42px; }
.calibration-crosshair { stroke: #fff; stroke-width: 2; paint-order: stroke; }
.calibration-marker { fill: var(--accent); stroke: #fff; stroke-width: 2; fill-opacity: .55; }
.calibration-label { fill: var(--text); font-size: 18px; font-weight: 900; paint-order: stroke; stroke: #fff; stroke-width: 5px; }
.calibration-actions { flex-wrap: wrap; }

@media (max-width: 680px) {
  .project-title-actions { width: 100%; display: grid; grid-template-columns: 1fr 1.45fr; }
  .map-head-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .map-head-actions .btn { width: 100%; }
  .project-title-actions .btn { width: 100%; }
  .map-mode-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .survey-toolbar { align-items: stretch; flex-direction: column; }
  .survey-actions { display: grid; grid-template-columns: repeat(3, 1fr); }
  .survey-actions .btn, .survey-actions .file-btn { width: 100%; min-width: 0; }
  .survey-view-controls { display: grid; grid-template-columns: 1fr 1fr 46px 46px; }
  .survey-viewport { min-height: 260px; }
  .calibration-actions .btn { flex: 1 1 120px; }
  .calibration-stage { height: min(43vh, 350px); min-height: 240px; }
  .calibration-view-controls .btn { padding: 8px; }
  .calibration-view-controls #calibrationAdjustABtn,
  .calibration-view-controls #calibrationAdjustBBtn { flex: 1 1 42%; }
}

.export-dialog { width: min(560px, calc(100vw - 28px)); }
.export-choice-group { display: grid; gap: 8px; }
.export-choice { width: 100%; justify-content: flex-start; text-align: left; min-height: 46px; }
.export-choice:disabled { opacity: .45; cursor: not-allowed; }
/* Calibration needs the full available dialog width, particularly for survey detail. */
#surveyCalibrationDialog { width: min(800px, calc(100vw - 24px)); max-height: 94dvh; overflow-y: auto; }
#surveyCalibrationDialog .calibration-dialog { width: 100%; }
