:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #d7dde5;
  --accent: #2a7a4a;
  --accent-light: #bce2c8;
  --text: #24303f;
  --muted: #5b6a7c;
}

* {
  box-sizing: border-box;
}

span {
  color: #000000;
}

body.is-loading {
  overflow: hidden;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(245, 247, 250, 0.92);
  backdrop-filter: blur(2px);
  z-index: 1200;
  transition: opacity 0.2s ease;
}

body.is-loading .loading-overlay {
  display: flex;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem 2.5rem;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.18);
  color: #000000;
  font-size: 1.05rem;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(42, 122, 74, 0.2);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Kanit", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100%;
}

main.dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: stretch;
  flex: 0 0 auto;
}

.filters,
.summary {
  flex: 1 1 360px;
  display: flex;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.filters {
  align-items: flex-end;
}

.filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--muted);
  gap: 0.4rem;
  flex: 1 1 0;
  min-width: 140px;
}

.filters .clear-btn {
  align-self: stretch;
  margin-top: auto;
  padding: 0.6rem 1rem;
  border: 1px solid #4aa564;
  border-radius: 8px;
  background: #ddf7e4;
  color: #000000;
  font-family: "Kanit", "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, color 0.2s ease;
  min-width: 140px;
}

.filters .clear-btn:hover {
  background: #a9e9c0;
}

.filters .clear-btn:disabled {
  background: #e0e7e2;
  border-color: #d2d8d3;
  color: #7a867c;
  cursor: not-allowed;
}

.filters select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  width: 100%;
}

.summary {
  justify-content: space-between;
  gap: 1rem;
}

.card {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card:not(:last-child) {
  border-right: 1px solid var(--border);
  padding-right: 1rem;
}

.card-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #000000;
}

.card-value {
  font-size: 1.45rem;
  font-weight: 600;
  color: #000000;
}

.content {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  gap: 1rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

#map {
  flex: 1.4;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.data-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.table-wrapper {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.data-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-panel thead {
  position: sticky;
  top: 0;
  background: #f2f5f8;
  z-index: 1;
}

.data-panel th,
.data-panel td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-panel tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.data-panel tbody tr:hover {
  background: var(--accent-light);
}

.data-panel tbody tr.active {
  background: rgba(42, 122, 74, 0.16);
}

.leaflet-control-measure .leaflet-control-measure-toggle {
  width: 36px;
  height: 36px;
  line-height: 36px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease;
}

.leaflet-control-measure .leaflet-control-measure-toggle:hover {
  background: var(--accent);
  color: #fff;
}

.leaflet-control-measure-on .leaflet-control-measure-toggle {
  background: var(--accent);
  color: #fff;
}

.leaflet-control-measure {
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.18);
  border-radius: 10px;
}

.leaflet-control-measure .leaflet-control-measure-interaction {
  border-radius: 12px;
}

@media (max-width: 1100px) {
  .content {
    flex-direction: column;
    padding-right: 0;
  }

  #map {
    min-height: 440px;
  }
}

@media (max-width: 960px) {
  .top-bar {
    flex-direction: column;
  }

  .filters,
  .summary {
    flex: 1 1 auto;
    width: 100%;
    gap: 0.75rem;
  }
}

@media (max-width: 720px) {
  .dashboard {
    padding: 0.75rem;
  }

  .top-bar {
    gap: 0.75rem;
  }

  .filters,
  .summary {
    flex-direction: column;
    gap: 0.75rem;
  }

  .filters label {
    width: 100%;
  }

  .filters .clear-btn {
    width: 100%;
  }

  .card {
    width: 100%;
  }

  .card:not(:last-child) {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 0.75rem;
  }

  #map {
    min-height: 360px;
  }

  .table-wrapper {
    max-height: 45vh;
  }
}
