html, body {
  height: 100%;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background: #f2f2f0;
  color: #222;
}

* {
  box-sizing: border-box;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  width: 100vw;
}

.header {
  background: #202020;
  color: #f7f4ec;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 3px solid #a67c3d;
}

.header h1 {
  font-size: 1.05rem;
  line-height: 1.2;
  margin: 0;
  font-weight: bold;
}

.header .subtitle {
  font-size: 0.82rem;
  color: #d7d0c0;
  margin-top: 0.12rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-body {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px 1fr;
  transition: grid-template-columns 180ms ease;
}

.app-body.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid #cfc6b4;
  box-shadow: 2px 0 8px rgba(0,0,0,0.12);
  z-index: 600;
}

.app-body.sidebar-collapsed .sidebar {
  border-right: 0;
  box-shadow: none;
}

.panel-inner {
  width: 360px;
  padding: 0.85rem;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

#map {
  height: 100%;
  width: 100%;
  background: #e6e1d3;
}

button, select, input[type="number"], input[type="text"] {
  font: inherit;
}

button {
  border: 1px solid #8e8068;
  background: #fffaf0;
  color: #2d2a24;
  padding: 0.38rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background: #fff1cf;
}

button.primary {
  background: #1e4d6f;
  border-color: #183b55;
  color: white;
}

button.primary:hover {
  background: #163b56;
}

button.active {
  background: #5b3f1d;
  color: white;
}

.sidebar-toggle {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 800;
  background: white;
  box-shadow: 0 1px 7px rgba(0,0,0,0.28);
}

.app-body:not(.sidebar-collapsed) .sidebar-toggle {
  left: 370px;
}

fieldset {
  border: 1px solid #d7ceb9;
  border-radius: 6px;
  margin: 0 0 0.75rem 0;
  padding: 0.7rem 0.75rem;
  background: #fffdf8;
}

legend {
  font-weight: bold;
  color: #2b2b2b;
  padding: 0 0.3rem;
}

label {
  display: block;
  margin: 0.25rem 0;
}

.label-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: 0.5rem;
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  border: 1px solid #b8b1a2;
  border-radius: 4px;
  padding: 0.35rem 0.45rem;
  background: #fff;
}

input[type="range"] {
  width: 100%;
}

.small-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.15rem 0.4rem;
}

.status-box {
  margin: 0 0 0.75rem 0;
  padding: 0.55rem 0.65rem;
  background: #f3f5f7;
  border: 1px solid #d6dde5;
  border-radius: 5px;
  font-size: 0.9rem;
}

.warning {
  color: #7a3b00;
}

.good {
  color: #1f6a31;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.kpi {
  background: #fbf6ea;
  border: 1px solid #dfd2b9;
  border-radius: 6px;
  padding: 0.55rem;
}

.kpi .value {
  display: block;
  font-size: 1.25rem;
  font-weight: bold;
  color: #2a4053;
}

.kpi .label {
  display: block;
  font-size: 0.75rem;
  color: #5f584c;
}

.legend-list,
.top-list {
  margin: 0.35rem 0 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.legend-list li,
.top-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.16rem 0;
  border-bottom: 1px dotted #ddd3c0;
}

.swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
  border: 1px solid rgba(0,0,0,0.35);
  vertical-align: -0.12rem;
}

.note {
  font-size: 0.82rem;
  color: #615a50;
  margin: 0.4rem 0 0 0;
}

.popup-title {
  font-weight: bold;
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.popup-meta {
  font-size: 0.86rem;
  color: #333;
  margin-bottom: 0.35rem;
}

.popup-table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 0.35rem;
  font-size: 0.84rem;
}

.popup-table th,
.popup-table td {
  border-bottom: 1px solid #e0e0e0;
  padding: 0.12rem 0.2rem;
  text-align: left;
}

.popup-records {
  max-height: 210px;
  overflow: auto;
  margin-top: 0.35rem;
  border-top: 1px solid #ddd;
  padding-top: 0.25rem;
}

.record-line {
  margin: 0 0 0.22rem 0;
  font-size: 0.82rem;
  line-height: 1.25;
}

.leaflet-popup-content {
  min-width: 260px;
  max-width: 420px;
}

.leaflet-control-scale-line {
  font-family: Georgia, "Times New Roman", serif;
}

@media (max-width: 860px) {
  .app-body {
    grid-template-columns: 320px 1fr;
  }
  .panel-inner {
    width: 320px;
  }
  .app-body:not(.sidebar-collapsed) .sidebar-toggle {
    left: 330px;
  }
  .header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .app-body {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 88vw;
  }
  .panel-inner {
    width: 88vw;
  }
  .app-body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }
  .app-body:not(.sidebar-collapsed) .sidebar-toggle {
    left: calc(88vw + 10px);
  }
}
