* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #0f172a;
  background: #eef2f7;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
}

.topbar {
  background: #ffffff;
  border: 1px solid #d0d8e4;
  border-radius: 6px;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.topbar h1 .topbar-subtitle {
  font-weight: 400;
}

.topbar p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #475569;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: #f1f5f9;
}

.btn-primary {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #ffffff;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-active {
  background: #dbeafe;
  border-color: #93c5fd;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 6px;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel {
  background: #ffffff;
  border: 1px solid #d0d8e4;
  border-radius: 8px;
  padding: 8px;
  overflow: auto;
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 12px;
}

.panel p {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: #475569;
}

.layers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.layers-list li {
  border: 1px solid #dbe2ea;
  border-radius: 6px;
  background: #f8fafc;
  padding: 5px 6px;
  font-size: 11px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-row input[type="checkbox"] {
  margin: 0;
}

.layer-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zoom-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
}

.map-pane {
  border: 1px solid #d0d8e4;
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background: transparent;
  position: relative;
}

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

/* Map overlays */
.map-overlay {
  position: absolute;
  z-index: 1000;
  pointer-events: auto;
}

.map-dam-modal-wrap {
  top: 12px;
  left: 12px;
  z-index: 1001;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.map-dam-modal-wrap[hidden] {
  display: none !important;
}

.image-placeholder-box {
  position: absolute;
  top: 20px;
  left: 440px;
  /* Position to the right of sectors panel (300 + 120 + 20 margin) */
  min-width: 200px;
  width: 200px;
  min-height: 160px;
  background: #ffffff;
  border: 1px solid #d6dee9;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.image-placeholder-box[hidden] {
  display: none !important;
}

.image-placeholder-text {
  margin: 0;
  font-size: 13px;
  color: #64748b;
  text-align: center;
}

.dam-modal-card {
  min-width: 260px;
  max-width: 320px;
  background: #ffffff;
  border: 1px solid #d6dee9;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.dam-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #e2ecfb;
  border-bottom: 1px solid #d6dee9;
  padding: 8px 10px;
}

.dam-modal-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}

.dam-modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: #475569;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dam-modal-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0f172a;
}

.map-search-wrap {
  padding: 8px 10px;
  border-bottom: 1px solid #edf2f7;
  background: #f8fbff;
}

.dam-search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #0f172a;
  font-size: 13px;
  font-family: inherit;
}

.dam-search-input::placeholder {
  color: #94a3b8;
}

.dam-search-input:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
}

.dam-modal-body {
  max-height: 240px;
  overflow-y: auto;
  padding: 0;
}

.dam-list-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.dam-list-item {
  padding: 8px 10px;
  font-size: 12px;
  color: #0f172a;
  border-bottom: 1px solid #edf2f7;
  cursor: pointer;
  background: #ffffff;
  transition: background 0.15s;
}

.dam-list-item:last-child {
  border-bottom: none;
}

.dam-list-item:hover {
  background: #f1f5f9;
}

.dam-list-item.selected {
  background: #eff6ff;
  font-weight: 600;
}

.dam-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #edf2f7;
  background: #f8fbff;
}

.dam-action-btn {
  font-size: 12px;
  padding: 6px 12px;
}

/* Ruler modal */
.ruler-modal-wrap {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1002;
}

.ruler-modal-wrap[hidden] {
  display: none !important;
}

.ruler-modal-card {
  min-width: 300px;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #d6dee9;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.ruler-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #e2ecfb;
  border-bottom: 1px solid #d6dee9;
  padding: 10px 12px;
}

.ruler-modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.ruler-modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: #475569;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ruler-modal-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0f172a;
}

.ruler-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.ruler-tab {
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}

.ruler-tab:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.ruler-tab.active {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #ffffff;
}

.ruler-instruction {
  margin: 0;
  padding: 10px 12px;
  font-size: 12px;
  color: #475569;
  line-height: 1.4;
  border-bottom: 1px solid #edf2f7;
}

.ruler-measurements {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ruler-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ruler-row label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  min-width: 90px;
}

.ruler-value-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ruler-value-input {
  width: 100px;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  text-align: right;
}

.ruler-unit-select {
  padding: 6px 8px;
  font-size: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #0f172a;
}

.ruler-options {
  padding: 8px 12px;
  border-top: 1px solid #edf2f7;
  background: #f8fbff;
}

.ruler-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
}

.ruler-checkbox-label input {
  margin: 0;
}

.ruler-checkbox-hint {
  font-weight: 400;
  color: #64748b;
  font-size: 11px;
}

#map.ruler-drawing {
  cursor: crosshair;
}

#map.ruler-drawing .project-layer {
  pointer-events: none;
}

.ruler-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #edf2f7;
  background: #f8fbff;
}

.map-table-wrap {
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.map-types-control {
  position: relative;
}

.map-types-options {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 120px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1002;
}

.map-types-options[hidden] {
  display: none !important;
}

.map-type-option {
  border: none;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  color: #0f172a;
  font-size: 11px;
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
}

.map-type-option:last-child {
  border-bottom: none;
}

.map-type-option:hover {
  background: #eff6ff;
}

.map-type-option-active {
  font-weight: 700;
}

.map-kv-table {
  border-collapse: collapse;
  font-size: 11px;
  background: #ffffff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  border: 1px solid #cbd5e1;
}

.map-kv-table thead tr {
  background: #2563eb;
  color: #ffffff;
}

.map-kv-table th {
  padding: 4px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  border: 1px solid #1d4ed8;
}

.map-kv-table td {
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  color: #0f172a;
}

.map-kv-table tbody tr {
  background: #ffffff;
}

.map-kv-table tbody tr:hover:not(.kv-row-clickable) {
  background: #f8fafc;
}

.kv-row-clickable {
  cursor: pointer;
}

.kv-row-clickable:hover {
  background: #eff6ff !important;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 8px;
  background: #ffffff;
  border: 1px solid #d0d8e4;
  border-radius: 6px;
  font-size: 11px;
  color: #334155;
  flex-shrink: 0;
}

.statusbar-attribution {
  color: #64748b;
  font-size: 10px;
}

.leaflet-container {
  background: transparent;
}

.leaflet-container .leaflet-tile-pane,
.leaflet-container .leaflet-overlay-pane {
  background: transparent !important;
}

body.full-zoom .topbar,
body.full-zoom .sidebar,
body.full-zoom .statusbar {
  display: none;
}

body.full-zoom .app-shell {
  padding: 0;
  gap: 0;
}

body.full-zoom .workspace {
  display: block;
  height: 100vh;
}

body.full-zoom .map-pane {
  border: none;
  border-radius: 0;
  height: 100vh;
}

body.full-zoom .leaflet-control-container,
body.full-zoom .leaflet-control-attribution {
  display: none;
}

.exit-full-zoom-btn {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: none;
}

body.full-zoom .exit-full-zoom-btn {
  display: block;
}

.kv-popup .leaflet-popup-content-wrapper {
  border-radius: 8px;
  padding: 0;
}

.kv-popup .leaflet-popup-content {
  margin: 0;
}

.feature-popup {
  min-width: 240px;
  border: 1px solid #d6dee9;
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}

.feature-popup-title {
  background: #e2ecfb;
  border-bottom: 1px solid #d6dee9;
  font-weight: 700;
  padding: 8px 10px;
}

.feature-popup-table {
  width: 100%;
  border-collapse: collapse;
}

.feature-popup-table th,
.feature-popup-table td {
  border-bottom: 1px solid #edf2f7;
  padding: 6px 8px;
  vertical-align: top;
}

.feature-popup-table th {
  text-align: left;
  width: 42%;
  color: #475569;
  font-weight: 600;
  background: #f8fbff;
}

.feature-popup-table tr:last-child th,
.feature-popup-table tr:last-child td {
  border-bottom: none;
}

.feature-popup-actions {
  padding: 8px;
  border-top: 1px solid #edf2f7;
  background: #f8fbff;
  display: flex;
  justify-content: flex-end;
}

.popup-relocation-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
}

.popup-relocation-btn:hover {
  background: #eef2ff;
}

.popup-village-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
}

.popup-village-btn:hover {
  background: #eef2ff;
}

.popup-village-modal {
  position: absolute;
  right: -138px;
  bottom: 44px;
  width: 130px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  z-index: 2;
}

.popup-village-modal[hidden] {
  display: none !important;
}

.popup-village-title {
  background: #e2ecfb;
  border-bottom: 1px solid #d6dee9;
  color: #0f172a;
  font-weight: 700;
  padding: 6px 8px;
  font-size: 11px;
}

.popup-village-item {
  padding: 6px 8px;
  border-bottom: 1px solid #edf2f7;
  font-size: 11px;
  color: #0f172a;
}

.popup-village-item:last-child {
  border-bottom: none;
}

.popup-village-item-btn {
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: none;
  cursor: pointer;
}

.popup-village-item-btn:hover {
  background: #eff6ff;
}

.popup-gut-modal {
  position: absolute;
  right: -274px;
  bottom: 44px;
  width: 130px;
  height: 220px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  z-index: 2;
  display: flex;
  flex-direction: column;
}

.popup-gut-modal[hidden] {
  display: none !important;
}

.popup-gut-title {
  background: #e2ecfb;
  border-bottom: 1px solid #d6dee9;
  color: #0f172a;
  font-weight: 700;
  padding: 6px 8px;
  font-size: 11px;
}

.popup-gut-item {
  padding: 6px 8px;
  border-bottom: 1px solid #edf2f7;
  font-size: 11px;
  color: #0f172a;
}

.popup-gut-item:last-child {
  border-bottom: none;
}

.popup-gut-item-btn {
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: none;
  cursor: pointer;
}

.popup-gut-item-btn:hover {
  background: #eff6ff;
}

.popup-gut-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Land Ownership Styles */
.land-ownership-wrap {
  padding: 0;
  border-top: 1px solid #edf2f7;
  background: #f8fbff;
}

.land-ownership-wrap[hidden] {
  display: none !important;
}

.land-ownership-table {
  width: 100%;
  border-collapse: collapse;
}

.land-ownership-table th,
.land-ownership-table td {
  padding: 4px 8px;
  /* Reduced padding */
  font-size: 11px;
  /* Smaller font */
  text-align: left;
  border-bottom: 1px solid #edf2f7;
}

.land-ownership-table th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 600;
}

.land-btn {
  padding: 2px 8px;
  /* Smaller button padding */
  font-size: 10px;
  /* Smaller button font */
  border-radius: 4px;
  border: 1px solid transparent;
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
  /* Make buttons fill the cell for easier clicking despite small size */
  text-align: center;
}

.land-btn:hover {
  opacity: 0.9;
}

.land-private {
  background-color: #FFCC99;
  color: #0f172a;
}

.land-govt {
  background-color: #CC9966;
  color: #0f172a;
}

.land-forest {
  background-color: #006400;
  color: #ffffff;
}

.land-reset-btn {
  width: 100%;
  border-radius: 0;
  border: none;
  border-top: 1px solid #e2e8f0;
  color: #64748b;
  background: #f8fafc;
  padding: 4px;
  /* Reduced padding */
  font-size: 10px;
  /* Smaller font */
}

.land-reset-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* Sectors Panel Styles */
.sectors-panel-card {
  position: absolute;
  top: 20px;
  left: 300px;
  /* Position to the right of dam modal which is ~280px wide */
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 12px;
  width: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 80vh;
  z-index: 2000;
  pointer-events: auto;
}

.sectors-panel-card[hidden] {
  display: none !important;
}

.sectors-title {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 4px 0;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 4px;
}

.sectors-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sector-btn {
  width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  text-align: left;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s;
}

.sector-btn:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

.sector-btn.active {
  border-color: transparent;
  color: white;
}

.sector-private.active {
  background-color: #FFCC99;
  color: #0f172a;
}

.sector-govt.active {
  background-color: #CC9966;
  color: #0f172a;
}

.sector-forest.active {
  background-color: #006400;
  color: #fff;
}

.sector-reset-btn {
  padding: 4px;
  font-size: 10px;
  color: #94a3b8;
  background: transparent;
  border: none;
  cursor: pointer;
}

.sector-reset-btn:hover {
  color: #64748b;
  text-decoration: underline;
}


@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}