:root {
  --tfm-green: #1f6f43;
  --tfm-green-dark: #144d2e;
  --tfm-yellow: #ffcc00;
  --ink: #1b1b1b;
  --paper: #f7f6f2;
  --border: #d8d5cc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: 340px;
  min-width: 340px;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--border);
  padding: 16px;
}

#sidebar h1 {
  font-size: 1.1rem;
  line-height: 1.3;
  color: var(--tfm-green-dark);
  margin: 0 0 12px;
}
#sidebar h1 span {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: #555;
}

.panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tfm-green-dark);
  margin: 0 0 8px;
}

.layer-group {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.layer-group strong {
  font-size: 0.78rem;
  color: #555;
  margin-top: 4px;
}
.layer-group label, #sidebar label {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.note {
  font-size: 0.76rem;
  color: #666;
  line-height: 1.35;
}

.hero-area {
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  border: 1px solid var(--tfm-green);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.hero-number {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--tfm-green-dark);
}
.hero-sub {
  font-size: 0.8rem;
  color: #333;
}
.hero-src {
  font-size: 0.72rem;
  color: #555;
  margin-top: 4px;
}

.nudge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  margin: 6px 0;
}
.nudge-center {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
}
.nudge-btn, #sidebar button.nudge-btn {
  background: #eef2f0;
  color: var(--tfm-green-dark);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  padding: 6px 4px;
}
.nudge-btn:hover { background: #dff0e6; }
#scan-values {
  font-family: monospace;
  font-size: 0.7rem;
  white-space: pre-wrap;
}

#area-table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
}
#area-table td {
  padding: 2px 4px;
  border-bottom: 1px solid #eee;
}
#area-table tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--tfm-green);
  border-bottom: none;
}
#area-table td.unconfirmed {
  color: #b45309;
  font-style: italic;
}

#sidebar input[type=range] {
  width: 100%;
}
#sidebar button {
  background: var(--tfm-green);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 4px;
}
#sidebar button:hover { background: var(--tfm-green-dark); }

.sources {
  margin: 0;
  padding-left: 18px;
  font-size: 0.76rem;
  color: #666;
}

#building-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
}
#building-list li { margin-bottom: 4px; }

#map {
  flex: 1;
  height: 100%;
}

.leaflet-popup-content b { color: var(--tfm-green-dark); }
.leaflet-popup-content .flag {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.72rem;
  margin-top: 4px;
}

#sidebar-toggle {
  display: none;
}
#sidebar-close {
  display: none;
}

@media (max-width: 800px) {
  #app { position: relative; }
  #map { height: 100vh; width: 100vw; }

  #sidebar-toggle {
    display: flex;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 2100;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
    font-size: 1.3rem;
    cursor: pointer;
  }
  #sidebar-toggle.hidden {
    display: none;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 360px;
    height: 100%;
    max-height: none;
    z-index: 2000;
    box-shadow: 2px 0 12px rgba(0,0,0,.3);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }
  #sidebar.open {
    transform: translateX(0);
  }
  #sidebar-close {
    display: block;
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.8rem;
    line-height: 1;
    color: #666;
    cursor: pointer;
  }

  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 1900;
  }
  #sidebar-backdrop.open {
    display: block;
  }
}

.measuring-cursor,
.measuring-cursor .leaflet-interactive {
  cursor: crosshair !important;
}
