html, body { height: 100%; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  background: #e8edf2;
  color: #1c2430;
}

#ui-panel {
  position: absolute;
  z-index: 1000;
  top: auto;
  left: auto;
  right: 14px;
  bottom: 14px;
  margin-left: 0;
  padding: 12px;
  background: rgba(17, 24, 34, 0.92);
  color: #e8eef6;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(8, 12, 20, 0.28);
  backdrop-filter: blur(16px);
  min-width: 300px;
  max-width: 440px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

#ui-panel label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 12px;
  color: #c5d0dc;
}

/* Chỉ ảnh hưởng input/button trực tiếp trong panel, KHÔNG áp cho nút trong danh sách */
#ui-panel > button,
#ui-panel > input:not([type="file"]) {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  box-sizing: border-box;
}

#ui-panel > input[type="file"],
#ui-panel input[hidden] {
  display: none !important;
}

#ui-panel label[for="brownFileInput"] {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px dashed rgba(148, 176, 210, 0.45);
  background: rgba(255, 255, 255, 0.04);
  color: #d7e3f0;
  font-weight: 650;
  cursor: pointer;
  box-sizing: border-box;
}

#ui-panel label[for="brownFileInput"]:hover {
  background: rgba(47, 111, 237, 0.16);
  border-color: rgba(96, 165, 250, 0.7);
  color: #fff;
}

#ui-panel #uploadProgress {
  height: 6px !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border-radius: 99px !important;
}

#ui-panel #uploadProgressBar {
  background: #3b82f6 !important;
  border-radius: 99px;
}

#ui-panel #uploadProgressText {
  color: #9aabbd;
  font-variant-numeric: tabular-nums;
}

#ui-panel .view-mode-row {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#status {
  display: none !important;
}

#map,
#map .leaflet-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.leaflet-control-attribution {
  font-size: 10px;
}

/* Zoom / scale sát lề phải, phía trên panel điều khiển */
.leaflet-top.leaflet-right {
  top: 12px;
  right: 12px;
  z-index: 900;
}

.leaflet-control-zoom a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 18px !important;
  color: #1c2430 !important;
}

.leaflet-bar,
.leaflet-pm-toolbar.leaflet-bar {
  border: none !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16) !important;
}

.leaflet-control-layers {
  border: none !important;
  border-radius: 12px !important;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16) !important;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  border-bottom-color: #eef2f6 !important;
}

.leaflet-bar a:hover,
.leaflet-pm-toolbar .button-container:hover {
  background: #f4f7fb !important;
}

.leaflet-pm-toolbar .button-container.active,
.leaflet-pm-toolbar .button-container.active .control-icon {
  background-color: #e7f0ff !important;
}

.leaflet-control-scale {
  margin-right: 12px !important;
  margin-bottom: 12px !important;
}

/* Geoman (công cụ vẽ) — đỉnh mép trái */
.leaflet-top.leaflet-left {
  top: 10px;
  transform: none;
  bottom: auto;
  --pm-toolbar-btn: 28px;
  --pm-toolbar-icon: 18px;
  min-width: calc(var(--pm-toolbar-btn) + 16px);
  max-height: calc(100vh - 16px);
  /* Khóa trục X: overflow-y:auto làm overflow-x thành auto → thanh kéo ngang dưới toolbar */
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.leaflet-top.leaflet-left .leaflet-pm-toolbar {
  margin-top: 0;
  margin-left: 8px;
}

/* Toolbar Geoman gọn — 1 cột, vừa màn hình */
.leaflet-top.leaflet-left .leaflet-control.leaflet-pm-toolbar {
  margin-bottom: 2px !important;
}

.leaflet-top.leaflet-left .leaflet-pm-toolbar .button-container,
.leaflet-top.leaflet-left .leaflet-pm-toolbar .control-icon,
.leaflet-top.leaflet-left .leaflet-pm-toolbar a.leaflet-buttons-control-button {
  width: var(--pm-toolbar-btn, 28px) !important;
  height: var(--pm-toolbar-btn, 28px) !important;
  min-width: var(--pm-toolbar-btn, 28px) !important;
  min-height: var(--pm-toolbar-btn, 28px) !important;
  box-sizing: border-box !important;
}

/* Căn giữa icon trong bbox từng nút toolbar */
.leaflet-top.leaflet-left .leaflet-pm-toolbar .button-container {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.leaflet-top.leaflet-left .leaflet-pm-toolbar .button-container > .control-icon,
.leaflet-top.leaflet-left .leaflet-pm-toolbar .button-container > a.leaflet-buttons-control-button,
.leaflet-top.leaflet-left .leaflet-pm-toolbar .control-icon,
.leaflet-top.leaflet-left .leaflet-pm-toolbar a.leaflet-buttons-control-button {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex: 0 0 var(--pm-toolbar-btn, 28px) !important;
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  text-align: center !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
  background-size: var(--pm-toolbar-icon, 18px) var(--pm-toolbar-icon, 18px) !important;
}

.leaflet-top.leaflet-left .attr-info-toolbar-host .control-icon,
.leaflet-top.leaflet-left .attr-info-toolbar-host #attr-info-toggle,
.leaflet-top.leaflet-left .polygon-qr-toolbar-host a,
.leaflet-top.leaflet-left .polygon-qr-toolbar-host #polygon-qr-toggle,
.leaflet-top.leaflet-left #polygon-qr-toggle {
  width: var(--pm-toolbar-btn, 28px) !important;
  height: var(--pm-toolbar-btn, 28px) !important;
  min-width: var(--pm-toolbar-btn, 28px) !important;
  min-height: var(--pm-toolbar-btn, 28px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  line-height: 1 !important;
  font-size: 10px !important;
  box-sizing: border-box !important;
}

.leaflet-top.leaflet-left #attr-info-toggle svg {
  display: block !important;
  width: var(--pm-toolbar-icon, 18px) !important;
  height: var(--pm-toolbar-icon, 18px) !important;
  margin: 0 !important;
}

.leaflet-pm-icon-measure-distance,
.leaflet-pm-icon-measure-area,
.leaflet-pm-icon-view-standard,
.leaflet-pm-icon-activate-table {
  background-size: var(--pm-toolbar-icon, 18px) var(--pm-toolbar-icon, 18px) !important;
  background-position: center center !important;
}

.leaflet-pm-icon-draw-circle-fixed,
.leaflet-pm-icon-create-area-from-markers,
.leaflet-pm-icon-measure-3d {
  position: relative !important;
}

.leaflet-pm-icon-draw-circle-fixed::before {
  width: 13px !important;
  height: 13px !important;
  inset: 0 !important;
  margin: auto !important;
}

.leaflet-pm-icon-create-area-from-markers::before {
  width: 16px !important;
  height: 16px !important;
  background-size: 18px 18px !important;
  background-position: center center !important;
  inset: 0 !important;
  margin: auto !important;
}

.leaflet-top.leaflet-left .leaflet-pm-toolbar .leaflet-pm-icon-measure-3d::before {
  content: "3D" !important;
  position: absolute !important;
  inset: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  font-size: 9px !important;
  font-weight: 800 !important;
  color: #0ea5e9 !important;
  letter-spacing: -0.02em !important;
  line-height: 1 !important;
}

/* Nút tùy chỉnh vẽ — cạnh toolbar, không bị clip */
.leaflet-top.leaflet-left .draw-style-toggle-control {
  top: 0 !important;
  left: calc(8px + var(--pm-toolbar-btn, 28px) + 8px) !important;
  z-index: 1200 !important;
  pointer-events: auto !important;
}

/* Vertex Geoman bám đúng tâm điểm trên line */
.leaflet-marker-icon.marker-icon {
  margin-left: -7px !important;
  margin-top: -7px !important;
}
.leaflet-marker-icon.marker-icon-middle {
  margin-left: -5px !important;
  margin-top: -5px !important;
}
#map.cut-split-flat-edit-active .marker-icon-middle,
.leaflet-container.cut-split-flat-edit-active .marker-icon-middle {
  opacity: 1 !important;
  background-color: #fff8e1 !important;
  border-color: #ff9800 !important;
  border-width: 2px !important;
  cursor: copy !important;
  z-index: 1000 !important;
}

/* Con trỏ Geoman phải xuyên click. Leaflet .leaflet-interactive ghi đè
   pointer-events:none của Geoman, nên click đúp kết thúc chữ nhật bị nuốt. */
.leaflet-marker-icon.cursor-marker,
.leaflet-marker-icon.cursor-marker.visible {
  pointer-events: none !important;
}

/* Nhãn số thứ tự đỉnh 1, 2, 3… (Kích hoạt / đang vẽ) — overlay HTML */
#draw-vertex-num-overlay {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none !important;
  z-index: 700;
}
.draw-vertex-num-overlay-item {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none !important;
  z-index: 701;
}
.draw-vertex-num-label {
  background: transparent !important;
  border: none !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
}
.draw-vertex-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 999px;
  background: #1565c0;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  pointer-events: none !important;
  user-select: none;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Nút toolbar: Đo khoảng cách — thước kẻ */
.leaflet-pm-icon-measure-distance {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Crect x='2.5' y='8' width='19' height='8' rx='1.2' fill='%23e3f2fd' stroke='%231565c0' stroke-width='1.7'/%3E%3Cpath d='M6 8 V12 M9 8 V10.5 M12 8 V12 M15 8 V10.5 M18 8 V12' stroke='%231565c0' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") !important;
  background-size: 18px 18px !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}
.leaflet-pm-icon-measure-distance::before,
.leaflet-pm-icon-measure-distance::after {
  content: none !important;
  display: none !important;
}

/* Nút toolbar: Đo chu vi / diện tích — đa giác + lưới diện tích */
.leaflet-pm-icon-measure-area {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M5 18 L4 9 L12 4 L20 8 L17 18 Z' fill='rgba(46,125,50,0.22)' stroke='%232e7d32' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M7.2 15.5 H14.8 M7.8 12.5 H15.6 M9 9.5 H16.2' stroke='%232e7d32' stroke-width='1.1' stroke-linecap='round' opacity='0.75'/%3E%3Ccircle cx='5' cy='18' r='1.5' fill='%23fff' stroke='%232e7d32' stroke-width='1.4'/%3E%3Ccircle cx='4' cy='9' r='1.5' fill='%23fff' stroke='%232e7d32' stroke-width='1.4'/%3E%3Ccircle cx='12' cy='4' r='1.5' fill='%23fff' stroke='%232e7d32' stroke-width='1.4'/%3E%3Ccircle cx='20' cy='8' r='1.5' fill='%23fff' stroke='%232e7d32' stroke-width='1.4'/%3E%3Ccircle cx='17' cy='18' r='1.5' fill='%23fff' stroke='%232e7d32' stroke-width='1.4'/%3E%3C/svg%3E") !important;
  background-size: 18px 18px !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}
.leaflet-pm-icon-measure-area::before,
.leaflet-pm-icon-measure-area::after {
  content: none !important;
  display: none !important;
}

/* Nút toolbar: Chế độ chuẩn — về góc nhìn ban đầu */
.leaflet-pm-icon-view-standard {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='8.2' stroke='%2337474f' stroke-width='1.7' fill='%23eceff1'/%3E%3Cpath d='M12 4.5 V7.2 M12 16.8 V19.5 M4.5 12 H7.2 M16.8 12 H19.5' stroke='%2337474f' stroke-width='1.6' stroke-linecap='round'/%3E%3Ccircle cx='12' cy='12' r='2.2' fill='%23c62828' stroke='%23b71c1c' stroke-width='1'/%3E%3Cpath d='M12 8.2 L13.1 11.1 L12 10.4 L10.9 11.1 Z' fill='%23c62828'/%3E%3C/svg%3E") !important;
  background-size: 18px 18px !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}
.leaflet-pm-icon-view-standard::before,
.leaflet-pm-icon-view-standard::after {
  content: none !important;
  display: none !important;
}

/* Nút toolbar: Kích hoạt — mũi tên chuột (pointer) */
.leaflet-pm-icon-activate-table {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M5.2 3.2 L5.2 18.2 L9.1 14.6 L11.6 20.8 L14.2 19.7 L11.7 13.6 L16.8 13.6 Z' fill='%231565c0' stroke='%230d47a1' stroke-width='1.2' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-size: 18px 18px !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}
.leaflet-pm-icon-activate-table::before,
.leaflet-pm-icon-activate-table::after {
  content: none !important;
  display: none !important;
}

#map.activate-table-mode-active,
#map.activate-table-mode-active.leaflet-container {
  cursor: pointer;
}

#measure-hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 10000;
  max-width: min(520px, calc(100vw - 24px));
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(18, 24, 32, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  white-space: pre-line;
}
#measure-hint[hidden] {
  display: none !important;
}

.leaflet-container.measure-mode-active {
  cursor: crosshair !important;
}
.leaflet-container.measure-mode-active .leaflet-overlay-pane,
.leaflet-container.measure-mode-active .leaflet-marker-pane {
  pointer-events: none;
}

.measure-tooltip {
  background: rgba(33, 33, 33, 0.92) !important;
  border: none !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  padding: 8px 14px !important;
  border-radius: 6px !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35) !important;
  /* Chỉ 2 dòng cố định — nới rộng, không wrap chữ */
  white-space: nowrap !important;
  max-width: none !important;
  width: max-content !important;
  min-width: 160px !important;
  line-height: 1.45 !important;
  text-align: left !important;
}
.leaflet-tooltip.measure-tooltip {
  max-width: none !important;
}
.measure-tooltip::before {
  border-top-color: rgba(33, 33, 33, 0.92) !important;
}

/* Nhãn đo tự động trên đường/vùng Geoman — chữ cùng màu nét, không hộp */
.draw-measure-label,
.draw-measure-text {
  background: transparent !important;
  border: none !important;
}
.draw-measure-label span,
.draw-measure-text div {
  display: inline-block;
  transform: translate(-50%, -50%);
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #ff0000;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: none;
  text-shadow: 0 0 2px #fff;
}
.draw-measure-label-edge span {
  /* Vị trí theo cạnh */
}
.draw-measure-label-area span,
.draw-measure-label-total span {
  padding: 0;
  background: transparent;
  transform: translate(-50%, -50%);
}

/* Nút toolbar: Xóa đỉnh (node) */
.leaflet-pm-icon-delete-vertex {
  background-image: none !important;
  position: relative;
}
.leaflet-pm-icon-delete-vertex::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2.5px solid #c62828;
  border-radius: 50%;
  background: #fff;
  box-sizing: border-box;
}
.leaflet-pm-icon-delete-vertex::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 3px;
  margin: -1.5px 0 0 -9px;
  background: #c62828;
  transform: rotate(-45deg);
  border-radius: 1px;
}

/* Chế độ xóa đỉnh */
.pm-vertex-delete-mode {
  cursor: crosshair;
}
.vd-delete-vertex-handle {
  background: transparent !important;
  border: none !important;
}
.vd-delete-vertex-dot {
  width: 18px;
  height: 18px;
  margin: 0;
  border-radius: 50%;
  background: #ff1744;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px #b71c1c, 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  box-sizing: border-box;
}
.vd-delete-vertex-dot:hover {
  background: #d50000;
  transform: scale(1.15);
}

body.mode-3d .nav3d-control {
  display: none !important;
}

body.mode-3d #stylePanelToggle,
body.mode-3d #draw-style-panel {
  display: none !important;
}

body.mode-3d #draw-node-coord-stack,
body.mode-3d #drawNodeCoordToggle,
body.mode-3d #draw-node-coord-panel {
  display: none !important;
}

.nav3d-control {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  background: #fff;
  margin-bottom: 12px !important;
  margin-left: 12px !important;
}
.nav3d-control a,
.nav3d-control button {
  width: 36px;
  height: 36px;
  line-height: 36px;
  display: block;
  border: none;
  background: #fff;
  cursor: pointer;
  padding: 0;
  text-align: center;
  font-size: 16px;
  color: #333;
}
.nav3d-control button:hover {
  background: #f4f4f4;
}
.nav3d-compass-needle {
  display: inline-block;
  transition: transform 0.05s linear;
  color: #c62828;
  font-size: 18px;
}
.nav3d-readout {
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  padding: 4px 2px;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  color: #444;
  user-select: none;
  min-width: 36px;
}
.nav3d-sep {
  opacity: 0.5;
  margin: 0 1px;
}

/* Khi nghiêng: làm mượt cạnh tile */
.nav3d-pitched .leaflet-map-pane {
  will-change: transform;
}


#view3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0b1a2b;
  z-index: 1;
}

#view3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#main_panel {
  position: fixed;
  top: 12px;
  left: 76px;
  z-index: 1100;
  max-width: calc(100vw - 96px);
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.24);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
  backdrop-filter: blur(10px);
  box-sizing: border-box;
}

.main-panel-title {
  display: none;
}

.view-mode-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin-top: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.view-mode-row::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.view-mode-btn {
  flex: 0 0 auto;
  width: auto !important;
  min-height: 30px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  margin: 0 !important;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #d5deea;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  box-sizing: border-box;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.view-mode-btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.view-mode-btn.is-active {
  border-color: #2f6fed;
  background: #2f6fed;
  color: #fff;
  box-shadow: none;
}

.view-mode-btn.recover-geotiff-btn {
  background: linear-gradient(180deg, #149a76 0%, #0f766e 100%);
  border-color: rgba(45, 212, 191, 0.35);
}

.view-mode-btn.recover-geotiff-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #16a34a 0%, #0f766e 100%);
  border-color: rgba(74, 222, 128, 0.45);
}

.view-mode-btn.recover-geotiff-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

@media (max-width: 960px) {
  #main_panel {
    left: 12px;
    top: 64px;
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 680px) {
  #main_panel {
    max-width: calc(100vw - 24px);
    top: 12px;
  }
}

/* ==========================================
   Popup Lưới mảnh địa chính (góc dưới-trái, cạnh Tọa độ nút)
   ========================================== */
#grid500-stack {
  position: fixed;
  left: 86px;
  bottom: 12px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  pointer-events: none;
}
#grid500-stack > * {
  pointer-events: auto;
}

#grid500Toggle {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  user-select: none;
  color: #333;
  line-height: 1;
  transition: all 0.2s ease;
  border-radius: 3px;
}
#grid500-stack:not(.grid500-stack-solo) #grid500Toggle {
  border-radius: 0 0 3px 3px;
  margin-top: -1px;
}
#grid500Toggle:hover {
  background: #f4f4f4;
}
#grid500Toggle .toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
#grid500Toggle .toggle-icon svg {
  display: block;
  width: 20px;
  height: 20px;
}
#grid500Toggle .toggle-label {
  position: absolute;
  left: 42px;
  top: 50%;
  transform: translateY(-50%) translateX(-10px);
  background: #ffffffee;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 3px 8px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  pointer-events: none;
}
#grid500Toggle:hover .toggle-label {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

.grid500-controls {
  position: relative;
  width: min(280px, calc(100vw - 100px));
  margin: 0;
  padding: 10px 10px 8px;
  border: 1px solid rgba(180, 200, 220, 0.28);
  border-radius: 8px 8px 0 0;
  background: rgba(18, 26, 36, 0.94);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  color: #e8eef4;
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}
.grid500-controls[hidden] {
  display: none !important;
}

body.mode-3d #grid500-stack {
  display: none !important;
}

.grid500-title {
  font-weight: 650;
  font-size: 13px;
  margin-bottom: 8px;
  color: #ffedd5;
}

.grid500-field {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #e2e8f0;
}

.grid500-field select,
.grid500-field input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  font: inherit;
}

.grid500-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.grid500-actions button {
  flex: 1 1 auto;
  min-height: 32px;
  border: 1px solid rgba(251, 146, 60, 0.45);
  border-radius: 8px;
  padding: 6px 8px;
  background: linear-gradient(180deg, #ea580c 0%, #c2410c 100%);
  color: #fff;
  font: 600 11px inherit;
  cursor: pointer;
}

.grid500-actions button:hover:not(:disabled) {
  filter: brightness(1.08);
}

.grid500-actions button:disabled {
  opacity: 0.65;
  cursor: wait;
}

#grid500ClearBtn,
#grid500DownloadBtn {
  background: linear-gradient(180deg, rgba(51, 65, 85, 0.96) 0%, rgba(30, 41, 59, 0.96) 100%);
  border-color: rgba(148, 163, 184, 0.35);
}

.grid500-visible-toggle {
  margin-top: 8px;
}

.grid500-status {
  margin-top: 6px;
  min-height: 16px;
  line-height: 1.35;
  color: #fdba74;
  word-break: break-word;
}

.grid500-status.is-error {
  color: #fca5a5;
}

.grid500-sheet-marker {
  background: none !important;
  border: none !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
}

.grid500-label {
  display: inline-block !important;
  width: max-content !important;
  max-width: none !important;
  box-sizing: border-box !important;
  background: rgba(15, 23, 42, 0.88) !important;
  border: 1px solid rgba(251, 146, 60, 0.75) !important;
  color: #ffedd5 !important;
  font: 600 10px/1.25 "Segoe UI", system-ui, sans-serif !important;
  padding: 3px 7px !important;
  border-radius: 4px !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35) !important;
  transform: translate(-50%, -50%);
  white-space: nowrap !important;
  pointer-events: none;
}

.grid500-label::before {
  display: none !important;
}

.dem3d-controls {
  margin-top: 8px;
  font-size: 12px;
}

.dem3d-exag-label {
  display: block;
  font-weight: 500;
}

.dem3d-exag-label input[type="range"] {
  width: 100%;
  margin-top: 4px;
}

.dem3d-layer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.dem3d-layer-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

#dtwControls .dtw-flood-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-top: 10px;
}

#dtwControls .dtw-solver-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
}

#dtwControls .dtw-solver-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

#dtwControls .dtw-solver-row input[type="radio"] {
  margin: 0;
  accent-color: #3d9cf0;
  cursor: pointer;
}

#dtwControls .dtw-flood-btn {
  display: block;
  width: 100% !important;
  min-height: 34px;
  margin: 0 !important;
  text-align: center;
}

.dem3d-hint {
  margin-top: 6px;
  opacity: 0.95;
  line-height: 1.35;
}

.dem3d-attrib {
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.75;
}

.dem3d-attrib a {
  color: inherit;
}

.dem3d-flow-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.dem3d-flow-btn {
  border: 1px solid rgba(61, 156, 240, 0.45);
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font: 600 12px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  cursor: pointer;
}

.dem3d-flow-btn.is-active {
  border-color: #38bdf8;
  background: rgba(29, 78, 216, 0.45);
}

.dem3d-flow-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.flow-run-panel {
  position: absolute;
  z-index: 1305;
  left: 14px;
  right: auto;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  width: max-content;
  max-width: calc(100vw - 28px);
  padding: 10px 12px 12px;
  background: rgba(12, 20, 32, 0.94);
  color: #e8f1fa;
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

#flowRunPanel .flow3d-panel-head {
  width: max-content;
  max-width: 100%;
  gap: 8px;
}

#flowRunPanel .flow3d-panel-head span {
  white-space: nowrap;
}

#flowRunPanel .flow3d-time-row {
  width: 100%;
  min-width: 0;
  margin-top: 8px;
}

#flowRunPanel .flow3d-time-row input[type="range"] {
  flex: 1 1 0;
  min-width: 0;
  width: 0;
}

body:not(.mode-3d) #flowRunPanel {
  display: none !important;
}

#flowRunTimeLabel {
  white-space: nowrap;
  color: #c5d0dc;
}

#svManningModal,
#rrParamsModal {
  position: fixed;
  inset: 0;
  z-index: 10070;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 16, 0.78);
  padding: 16px;
  box-sizing: border-box;
}

#svManningModal[hidden],
#rrParamsModal[hidden] {
  display: none !important;
}

.sv-manning-card {
  width: min(420px, 100%);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  background: #151c26;
  border: 1px solid rgba(61, 156, 240, 0.45);
  border-radius: 12px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
  color: #e8f1fa;
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}

.sv-manning-card h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.sv-manning-hint {
  margin: 4px 0 10px;
  font-size: 12px;
  opacity: 0.8;
}

.sv-manning-fill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.sv-manning-fill label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sv-manning-fill input {
  width: 64px;
  border: 1px solid rgba(61, 156, 240, 0.45);
  border-radius: 6px;
  padding: 4px 6px;
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font: inherit;
}

#svXsSpacing { width: 88px; }
#svDtHours { width: 72px; }

.sv-manning-fill button,
.sv-manning-actions button {
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

#svManningFillBtn {
  border: 1px solid rgba(61, 156, 240, 0.45);
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
}

.sv-manning-table-wrap {
  flex: 1;
  min-height: 180px;
  overflow: auto;
  border: 1px solid rgba(120, 150, 180, 0.28);
  border-radius: 8px;
}

.sv-manning-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.sv-manning-table th,
.sv-manning-table td {
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(120, 150, 180, 0.18);
}

.sv-manning-table th {
  position: sticky;
  top: 0;
  background: #1c2532;
  font-weight: 650;
}

.sv-manning-table input {
  width: 72px;
  border: 1px solid rgba(61, 156, 240, 0.4);
  border-radius: 6px;
  padding: 3px 6px;
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font: inherit;
}

.sv-manning-error {
  margin-top: 8px;
  color: #ffb4b4;
  font-size: 12px;
}

.sv-manning-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

#svManningCancel {
  background: transparent;
  color: #aeb9c6;
  border: 1px solid rgba(120, 150, 180, 0.35);
}

#svManningSave {
  border: 1px solid rgba(61, 156, 240, 0.55);
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font-weight: 600;
}

#svManningCalibrate {
  border: none;
  background: #2f7fc4;
  color: #fff;
  font-weight: 600;
}

#svManningCalibrate:hover {
  background: #3d9cf0;
}

#svManningSave:disabled,
#svManningCalibrate:disabled {
  opacity: 0.55;
  cursor: wait;
}

.rr-params-card {
  width: min(1100px, 96vw);
  max-height: min(90vh, 860px);
  min-height: min(72vh, 640px);
}

.rr-params-layout {
  display: flex;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.rr-params-body {
  flex: 0 0 min(360px, 42%);
  width: min(360px, 42%);
  min-height: 180px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}

.rr-hydro-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rr-hydro-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 650;
  color: #9ec7ef;
}

.rr-hydro-nse {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  background: rgba(120, 150, 180, 0.18);
  color: #e8f1fa;
}

.rr-hydro-nse.is-good {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
}

.rr-hydro-nse.is-ok {
  background: rgba(232, 197, 71, 0.2);
  color: #e8c547;
}

.rr-hydro-nse.is-poor {
  background: rgba(248, 113, 113, 0.2);
  color: #ffb4b4;
}

.rr-hydro-legend {
  display: inline-flex;
  gap: 12px;
  font-weight: 500;
  color: #c5d3e0;
}

.rr-hydro-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.rr-hydro-swatch {
  width: 16px;
  height: 0;
  border-top: 2px solid #e8c547;
  display: inline-block;
}

.rr-hydro-swatch.is-sim {
  border-top-color: #3d9cf0;
}

.rr-hydro-swatch.is-obs {
  border-top-color: #e8c547;
  border-top-style: dashed;
}

.rr-hydro-canvas-wrap {
  flex: 1;
  min-height: 280px;
  border: 1px solid rgba(120, 150, 180, 0.28);
  border-radius: 8px;
  overflow: hidden;
  background: #101820;
}

#rrHydroChart {
  display: block;
  width: 100%;
  height: 100%;
}

.rr-hydro-meta {
  margin: 0;
  font-size: 11px;
  color: #aeb9c6;
  min-height: 16px;
}

@media (max-width: 840px) {
  .rr-params-layout {
    flex-direction: column;
  }

  .rr-params-body {
    flex: none;
    width: 100%;
    max-height: 36vh;
  }

  .rr-hydro-canvas-wrap {
    min-height: 220px;
  }
}

.rr-params-group {
  margin: 0;
  border: 1px solid rgba(120, 150, 180, 0.28);
  border-radius: 8px;
  padding: 6px 10px 10px;
}

.rr-params-group legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 650;
  color: #9ec7ef;
}

.rr-params-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.rr-params-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #c5d3e0;
}

.rr-params-fields input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(61, 156, 240, 0.4);
  border-radius: 6px;
  padding: 4px 6px;
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font: inherit;
}

#rrParamsCancel {
  background: transparent;
  color: #aeb9c6;
  border: 1px solid rgba(120, 150, 180, 0.35);
}

#rrParamsInput {
  border: 1px solid rgba(61, 156, 240, 0.55);
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font-weight: 600;
}

#rrParamsInput:hover {
  border-color: rgba(61, 156, 240, 0.85);
  background: rgba(28, 39, 52, 0.95);
}

#rrParamsSave {
  border: 1px solid rgba(61, 156, 240, 0.55);
  background: rgba(18, 24, 32, 0.92);
  color: #e8f1fa;
  font-weight: 600;
}

#rrParamsSave:hover {
  border-color: rgba(61, 156, 240, 0.85);
  background: rgba(28, 39, 52, 0.95);
}

#rrParamsCalibrate {
  border: none;
  background: #2f7fc4;
  color: #fff;
  font-weight: 600;
}

#rrParamsCalibrate:hover {
  background: #3d9cf0;
}

#rrParamsSave:disabled,
#rrParamsCalibrate:disabled {
  opacity: 0.55;
  cursor: wait;
}

#hydro1dProgressModal,
#flood3dProgressModal {
  position: fixed;
  inset: 0;
  z-index: 10080;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 16, 0.78);
  padding: 16px;
  box-sizing: border-box;
}

#hydro1dProgressModal[hidden],
#flood3dProgressModal[hidden] {
  display: none !important;
}

.hydro1d-progress-card {
  width: min(560px, 100%);
  max-height: min(88vh, 640px);
  display: flex;
  flex-direction: column;
  background: #151c26;
  border: 1px solid rgba(61, 156, 240, 0.45);
  border-radius: 12px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
  color: #e8f1fa;
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}

.hydro1d-progress-card h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.hydro1d-progress-status {
  margin: 8px 0 2px;
  font-size: 13px;
  font-weight: 650;
}

.hydro1d-progress-status.is-running {
  color: #7ec8ff;
}

.hydro1d-progress-status.is-ok {
  color: #7ddea0;
}

.hydro1d-progress-status.is-error {
  color: #ffb4b4;
}

.hydro1d-progress-meta {
  margin: 0 0 8px;
  font-size: 12px;
  opacity: 0.8;
}

.hydro1d-progress-log {
  flex: 1;
  min-height: 180px;
  max-height: 360px;
  margin: 0;
  overflow: auto;
  border: 1px solid rgba(120, 150, 180, 0.28);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(8, 12, 18, 0.9);
  color: #d5e4f2;
  font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

#hydro1dProgressClose,
#flood3dProgressClose {
  background: #2f7fc4;
  color: #fff;
  border: none;
  font-weight: 600;
}

#hydro1dProgressClose:disabled,
#flood3dProgressClose:disabled {
  opacity: 0.5;
  cursor: wait;
}

#hydro1dProgressClose:not(:disabled):hover,
#flood3dProgressClose:not(:disabled):hover {
  background: #3d9cf0;
}

.flood3d-progress-bar {
  height: 6px;
  background: rgba(120, 150, 180, 0.22);
  border-radius: 99px;
  overflow: hidden;
  margin: 0 0 8px;
}

.flood3d-progress-bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: #3d9cf0;
  transition: width 0.12s linear;
}

.flow3d-panel {
  position: absolute;
  z-index: 1005;
  right: 12px;
  left: auto;
  bottom: 12px;
  width: min(560px, calc(100vw - 24px));
  padding: 10px 12px 8px;
  background: rgba(12, 18, 26, 0.92);
  color: #e8f1fa;
  border: 1px solid rgba(61, 156, 240, 0.4);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

body:not(.mode-3d) #flow3dPanel {
  display: none !important;
}

.flow3d-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 6px;
}

.flow3d-close-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(61, 156, 240, 0.4);
  border-radius: 6px;
  background: transparent;
  color: #dbe7f3;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.flow3d-close-btn:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(248, 113, 113, 0.7);
  color: #fecaca;
}

#flow3dChart {
  display: block;
  width: 100%;
  height: 210px;
  border-radius: 6px;
  background: #101820;
}

#flow3dQChart {
  display: block;
  width: 100%;
  height: 150px;
  margin-top: 8px;
  border-radius: 6px;
  background: #101820;
}

#flow3dQChart[hidden] {
  display: none !important;
}

.flow3d-time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
}

.flow3d-time-row button {
  border: 1px solid rgba(61, 156, 240, 0.45);
  border-radius: 7px;
  padding: 4px 10px;
  background: rgba(18, 24, 32, 0.95);
  color: #e8f1fa;
  cursor: pointer;
  font-weight: 600;
}

.flow3d-time-row input[type="range"] {
  flex: 1;
}

#flow3dTimeLabel,
#flow3dRainLabel {
  white-space: nowrap;
  color: #c5d0dc;
}

.flood3d-panel {
  position: absolute;
  z-index: 1300;
  right: 14px;
  bottom: 14px;
  width: min(420px, calc(100vw - 28px));
  padding: 10px 12px 12px;
  background: rgba(12, 20, 32, 0.94);
  color: #e8f1fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

body.mode-3d #flood3dPanel {
  z-index: 1300;
}

.flood3d-stats {
  font-size: 12px;
  line-height: 1.45;
  color: #c5d0dc;
  margin: 6px 0 4px;
}

.dem3d-legend {
  position: absolute;
  z-index: 1000;
  left: 12px;
  top: 12px;
  bottom: auto;
  padding: 10px 12px;
  background: rgba(12, 28, 48, 0.88);
  color: #f2f6fb;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
  min-width: 72px;
}

.dem3d-legend-title {
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.dem3d-legend-body {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.dem3d-legend-bar {
  width: 18px;
  height: 140px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  /* khớp giải màu DEM: xanh → cyan → xanh lá → vàng → cam → đỏ (thấp→cao từ dưới lên) */
  background: linear-gradient(
    to top,
    rgb(13, 51, 217) 0%,
    rgb(13, 191, 217) 20%,
    rgb(38, 217, 64) 40%,
    rgb(242, 230, 38) 60%,
    rgb(242, 115, 20) 80%,
    rgb(230, 26, 26) 100%
  );
}

.dem3d-legend-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 3.5em;
  font-variant-numeric: tabular-nums;
  font-family: Consolas, "Segoe UI Mono", monospace;
  font-size: 11px;
}

.dem3d-legend-hint {
  margin-top: 6px;
  opacity: 0.75;
  font-size: 10px;
}

.flood3d-legend {
  position: absolute;
  z-index: 1000;
  left: 60px;
  bottom: 50px;
  padding: 10px 12px;
  background: rgba(12, 28, 48, 0.88);
  color: #f2f6fb;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
  min-width: 108px;
}

.flood3d-legend-title {
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.flood3d-legend-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flood3d-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.flood3d-legend-swatch {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.flood3d-legend.is-dtw .flood3d-legend-swatch[data-flood-swatch="0"] { background: #8a8a8a !important; }
.flood3d-legend.is-dtw .flood3d-legend-swatch[data-flood-swatch="1"] { background: #5c5c5c !important; }
.flood3d-legend.is-dtw .flood3d-legend-swatch[data-flood-swatch="2"] { background: #3a3a3a !important; }
.flood3d-legend.is-dtw .flood3d-legend-swatch[data-flood-swatch="3"] { background: #1a1a1a !important; }
.flood3d-legend.is-dtw .flood3d-legend-swatch[data-flood-swatch="4"] { background: #000000 !important; }

#browseButton {
  background: #2f6fed;
  color: #fff;
  border: none;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  cursor: pointer;
  font: 650 13px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  letter-spacing: 0.01em;
}

#browseButton:hover {
  background: #3b82f6;
}

.geotiff-list {
  max-height: 220px;
  overflow-x: auto;
  overflow-y: auto;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 4px 0;
  contain: content;
}

.geotiff-list-item {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-sizing: border-box;
  width: 100%;
  cursor: pointer;
  contain: layout style;
  content-visibility: auto;
  contain-intrinsic-size: auto 36px;
}

.geotiff-list-item.is-opening {
  background: rgba(47, 111, 237, 0.16);
}

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

.geotiff-list-item.is-active {
  background: rgba(47, 111, 237, 0.22);
}

#ui-panel .geotiff-list-item input[type="checkbox"] {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
}

#ui-panel .geotiff-file-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Vùng 2 icon: luôn ngang, kích thước cố định */
#ui-panel .geotiff-icon-actions {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  flex: 0 0 62px;
  width: 62px;
  height: 28px;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
}

#ui-panel .geotiff-icon-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  line-height: 0;
  vertical-align: middle;
}

#ui-panel .geotiff-icon-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}

#ui-panel .geotiff-eye-btn .eye-open {
  display: none;
}

#ui-panel .geotiff-eye-btn.is-on .eye-open {
  display: block;
}

#ui-panel .geotiff-eye-btn.is-on .eye-closed {
  display: none;
}

#ui-panel .geotiff-icon-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

#ui-panel .geotiff-eye-btn.is-on,
.geotiff-list-item.is-active .geotiff-eye-btn {
  background: #d2f731;
}

#ui-panel .geotiff-locate-btn:hover {
  background: #d2f731;
}

#ui-panel .geotiff-delete-btn {
  display: inline-block;
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 2px 8px;
  font-size: 11px;
  background-color: #c0392b;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

#ui-panel .geotiff-delete-btn:disabled {
  background-color: #9aa0a6;
  color: #eee;
  cursor: not-allowed;
  opacity: 0.65;
}

/* Nhãn cao độ contour trên bản đồ 2D */
.contour-elev-label {
  background: transparent;
  border: none;
}
.contour-elev-label span {
  display: inline-block;
  padding: 1px 4px;
  font-size: 11px;
  font-weight: 700;
  color: #e30613;
  text-shadow:
    -1px -1px 0 #fff,
     1px -1px 0 #fff,
    -1px  1px 0 #fff,
     1px  1px 0 #fff;
  white-space: nowrap;
}

/* ==========================================
   Nút mở/đóng #ui-panel (góc dưới-phải)
   ========================================== */
#uiPanelToggle {
  position: fixed;
  bottom: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  background: rgba(17, 24, 34, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(8, 12, 20, 0.28);
  pointer-events: auto;
  user-select: none;
  color: #e8eef6;
  line-height: 1;
  transition: background 0.15s ease;
  z-index: 1001;
}
#uiPanelToggle:hover {
  background: rgba(32, 44, 60, 0.96);
}

#uiPanelToggle .toggle-label {
  position: absolute;
  right: 42px;
  top: 50%;
  transform: translateY(-50%) translateX(10px);
  background: #ffffffee;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 3px 8px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(255,255,255,0.6);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  pointer-events: none;
}
#uiPanelToggle:hover .toggle-label {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

/* Khi panel ẩn — dùng display none để giải phóng không gian */
#ui-panel.ui-panel-hidden {
  display: none !important;
}

/* ==========================================
   Khối bảng Tọa độ nút + nút bật/tắt (góc dưới-trái)
   ========================================== */
#draw-node-coord-stack {
  position: fixed;
  left: 40px;
  bottom: 12px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  pointer-events: none;
}
#draw-node-coord-stack > * {
  pointer-events: auto;
}

#drawNodeCoordToggle {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  background: #fff;
  border: 1.5px solid rgba(0,0,0,0.2);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  user-select: none;
  color: #333;
  line-height: 1;
  transition: all 0.2s ease;
  border-radius: 0 0 3px 3px;
  margin-top: -1px;
}
#drawNodeCoordToggle:hover {
  background: #f4f4f4;
}
#draw-node-coord-stack.draw-node-coord-stack-solo #drawNodeCoordToggle {
  border-radius: 3px;
  margin-top: 0;
}
#drawNodeCoordToggle .toggle-label {
  position: absolute;
  left: 42px;
  top: 50%;
  transform: translateY(-50%) translateX(-10px);
  background: #ffffffee;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 3px 8px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(255,255,255,0.6);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  pointer-events: none;
}
#drawNodeCoordToggle:hover .toggle-label {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

/* ==========================================
   Khung web GIS: thanh trên + bảng dữ liệu trái + bản đồ
   ========================================== */
body.gis-app {
  --gis-bar-h: 52px;
  --gis-dock-w: 320px;
  background: #dfe6ee;
}

body.gis-app.mesh-3d-page {
  --gis-dock-w: 280px;
  background: #0b1016;
}

.gis-appbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--gis-bar-h);
  z-index: 1400;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  box-sizing: border-box;
  background: #121a24;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.gis-brand {
  flex: 0 0 auto;
  color: #f4f7fb;
  font: 700 15px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-decoration: none;
  padding-right: 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.gis-appbar .view-mode-row {
  flex: 1 1 auto;
  min-width: 0;
}

.gis-project-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.gis-project-label {
  color: #9eb0c4;
  font: 600 12px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}

.gis-project-bar select,
.gis-project-create {
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #1c2836;
  color: #f4f7fb;
  font: 600 12px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}

.gis-project-bar select {
  max-width: 240px;
}

.gis-project-create {
  padding: 0 10px;
  cursor: pointer;
}

.gis-project-create:hover {
  background: #243447;
}

.gis-project-backdrop {
  position: fixed;
  inset: 0;
  z-index: 12050;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.gis-project-backdrop[hidden] {
  display: none !important;
}

.gis-project-modal {
  width: min(440px, 96vw);
  background: #fff;
  color: #0f172a;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
  padding: 16px;
}

.gis-project-modal h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.gis-project-modal p {
  margin: 0 0 12px;
  color: #64748b;
  font-size: 13px;
}

.gis-project-modal label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.gis-project-modal input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 10px;
  font: 14px "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
}

.gis-project-preview {
  margin-top: 8px;
  font-size: 13px;
  color: #0f172a;
}

.gis-project-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.gis-project-actions button {
  height: 34px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 0 12px;
  cursor: pointer;
}

.gis-project-actions button[type="submit"] {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
}

.gis-project-error {
  min-height: 18px;
  margin-top: 8px;
  color: #b91c1c;
  font-size: 12px;
}

.gis-dock-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8ea0b5;
}

body.gis-app:not(.mesh-3d-page) #map {
  top: var(--gis-bar-h);
  right: 0;
  bottom: 0;
  left: var(--gis-dock-w);
  width: auto;
  height: auto;
}

body.gis-app:not(.mesh-3d-page) #ui-panel.ui-panel-hidden ~ #map {
  left: 0;
}

body.gis-app #ui-panel {
  position: fixed;
  top: var(--gis-bar-h);
  left: 0;
  right: auto;
  bottom: 0;
  width: var(--gis-dock-w);
  min-width: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  box-sizing: border-box;
  border-radius: 0;
  border: none;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
  z-index: 1100;
}

body.gis-app #uiPanelToggle {
  top: calc(var(--gis-bar-h) + 8px);
  right: auto;
  left: calc(var(--gis-dock-w) - 42px);
  bottom: auto;
  z-index: 1200;
}

body.gis-app #ui-panel.ui-panel-hidden ~ #uiPanelToggle {
  left: 12px;
  right: auto;
}

body.gis-app #uiPanelToggle .toggle-label {
  right: auto;
  left: 42px;
  transform: translateY(-50%) translateX(-10px);
}

body.gis-app #uiPanelToggle:hover .toggle-label {
  transform: translateY(-50%) translateX(0);
}

body.gis-app:not(.mesh-3d-page) #draw-node-coord-stack {
  left: calc(var(--gis-dock-w) + 12px);
}

body.gis-app:not(.mesh-3d-page) #grid500-stack {
  left: calc(var(--gis-dock-w) + 58px);
}

body.gis-app:not(.mesh-3d-page) #ui-panel.ui-panel-hidden ~ #draw-node-coord-stack {
  left: 40px;
}

body.gis-app:not(.mesh-3d-page) #ui-panel.ui-panel-hidden ~ #grid500-stack {
  left: 86px;
}

body.gis-app.mesh-3d-page #draw-node-coord-stack {
  left: calc(var(--gis-dock-w) + 12px);
}

body.gis-app.mesh-3d-page #grid500-stack {
  left: calc(var(--gis-dock-w) + 58px);
}

body.gis-app .leaflet-top.leaflet-left {
  top: 8px;
  max-height: calc(100vh - var(--gis-bar-h) - 16px);
}

body.gis-app .leaflet-bottom.leaflet-right {
  margin-right: 8px;
}

@media (max-width: 860px) {
  body.gis-app {
    --gis-dock-w: min(280px, 86vw);
  }
  .gis-appbar {
    gap: 8px;
    padding: 0 8px;
  }
  .gis-brand {
    display: none;
  }
}
