* { box-sizing: border-box; }

:root {
  /* Giao diện SÁNG, tông xanh mát + xanh lá "hy vọng" làm điểm nhấn */
  --bg: #f1f7f4;          /* nền sáng hơi ngả xanh ngọc */
  --panel: #ffffff;       /* panel trắng */
  --border: #cfe0d9;
  --accent: #1fbf75;      /* xanh lá hy vọng */
  --accent-hover: #17a564;
  --text: #1b332c;        /* chữ xanh rêu đậm, đọc rõ trên nền sáng */
  --muted: #6b8a80;
  --danger: #d64545;
  --input-bg: #f4faf7;    /* nền ô nhập */
  --hover: #e4f1ea;       /* màu hover nhạt */
}

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  /* chặn double-tap-zoom + độ trễ 300ms của trình duyệt trên phần giao diện */
  touch-action: manipulation;
}

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

#sidebar {
  width: 360px;
  flex: 0 0 360px;
  background: var(--bg);
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
  transition: margin-left 0.28s ease;
}

#sidebar h1 {
  font-size: 18px;
  margin: 0 0 16px;
  padding-left: 46px;   /* chừa chỗ cho nút toggle ở góc trái-trên */
  line-height: 38px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* nút ghim sidebar */
.pin-btn {
  width: 30px;
  height: 30px;
  flex: none;
  margin-left: auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pin-btn:hover { background: var(--hover); color: var(--text); }
/* khi đã ghim: nút sáng màu accent */
#app.sidebar-pinned .pin-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ----- Nút mở/thu panel ----- */
#sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 300;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
#sidebar-toggle:hover { background: var(--hover); }

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 150;
}

/* ----- Thu gọn trên desktop: trượt panel ra khỏi màn hình ----- */
#app.sidebar-collapsed #sidebar {
  margin-left: -360px;
}

#map {
  flex: 1 1 auto;
  height: 100%;
  position: relative;
  touch-action: none; /* để OpenLayers tự xử lý cử chỉ, chặn double-tap zoom của trình duyệt */
}

#draw-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

/* Nhóm nút vẽ + nút bung. Trên desktop: nhóm hiện, nút bung ẩn. */
#draw-tools {
  display: flex;
  gap: 6px;
  align-items: center;
}
#draw-tools-toggle { display: none; }

/* ===== Cụm điều khiển góc phải-dưới (kiểu Google Maps) ===== */
#map-controls {
  position: absolute;
  right: 12px;
  bottom: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.ctrl-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: #3a4a44;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  font-size: 22px;
  line-height: 1;
}
.ctrl-btn:hover { background: var(--hover); }
.ctrl-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#locate-btn.loading { opacity: 0.6; }

/* cụm zoom: 2 nút dính liền */
#zoom-ctrl {
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
#zoom-ctrl .ctrl-btn {
  border-radius: 0;
  box-shadow: none;
  border-bottom: none;
}
#zoom-ctrl .ctrl-btn:last-child { border-bottom: 1px solid var(--border); }

/* menu chọn lớp bản đồ */
#layers-wrap { position: relative; }
#layers-menu {
  position: absolute;
  right: 0;
  bottom: 50px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  padding: 6px;
  min-width: 150px;
}
#layers-menu[hidden] { display: none; }
.layer-opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
}
.layer-opt:hover { background: var(--hover); }
.layer-opt.active {
  background: rgba(31, 191, 117, 0.16); /* nền xanh nhạt */
  border-color: var(--accent);
  color: var(--text);                   /* chữ đậm, rõ trên nền sáng */
  font-weight: 600;
}
/* dấu tick cho lựa chọn đang chọn */
.layer-opt.active::after {
  content: "✓";
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
}
.layer-sw {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex: none;
  border: 1px solid var(--border);
  background-size: cover;
  background-position: center;
}
.sw-simple {
  background: linear-gradient(135deg, #e8efe9 0%, #cfe0d9 100%);
}
.sw-sat {
  background: linear-gradient(135deg, #2f4a2a 0%, #5a7d3a 50%, #294b6e 100%);
}

/* Dời attribution của OpenLayers sang góc trái-dưới để không đè cụm điều khiển
   (nằm ở phải-dưới). */
.ol-attribution {
  right: auto !important;
  left: 0;
  bottom: 0;
}

/* Tooltip số đo (khoảng cách / diện tích) khi rê chuột */
#measure-tooltip {
  position: absolute;
  z-index: 250;
  pointer-events: none;
  background: rgba(20, 64, 58, 0.96);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  max-width: 240px;
  transform: translate(12px, 12px);
}
#measure-tooltip[hidden] { display: none; }
#measure-tooltip .mt-name { font-weight: 700; margin-bottom: 3px; color: #d7ffe9; }
#measure-tooltip .mt-head { margin: 1px 0; }
#measure-tooltip .mt-head b { color: #7dffc0; }
#measure-tooltip .mt-sub { margin-top: 5px; color: #b9d8cf; font-size: 11px; }
#measure-tooltip .mt-list {
  margin: 3px 0 0;
  padding-left: 16px;
  max-height: 160px;
  overflow-y: auto;
}
#measure-tooltip .mt-list li { font-size: 11px; }
#measure-tooltip .mt-list li.mt-active {
  font-weight: 700;
  color: #ffd400;              /* vàng, khớp màu đoạn tô đậm trên bản đồ */
  list-style: none;
  margin-left: -16px;
}
#measure-tooltip .mt-list li.mt-active::before { content: "▶ "; }

/* Dải hướng dẫn khi đang vẽ */
#draw-hint {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(90vw, 560px);
  background: #14403a;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  text-align: center;
}
#draw-hint[hidden] { display: none; }

#draw-toolbar .tool-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
}
#draw-toolbar .tool-btn:hover {
  background: var(--hover);
}
#draw-toolbar .tool-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.5;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.row > * { flex: 1; margin-bottom: 0; }

input, select, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 4px;
}
textarea { resize: vertical; font-family: "Consolas", monospace; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--hover);
  color: var(--text);
  padding: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #d4e9de; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
}
button.primary:hover { background: var(--accent-hover); }

button.ghost { background: transparent; }
button.ghost:hover { background: var(--hover); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: rgba(224, 90, 90, 0.12); }
button.active { background: var(--accent); border-color: var(--accent); }

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 8px;
}

#saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#saved-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}
#saved-list .name { flex: 1; cursor: pointer; }
#saved-list .name:hover { color: var(--accent); }
#saved-list .meta { font-size: 11px; color: var(--muted); }
#saved-list .mini {
  width: auto;
  padding: 3px 7px;
  font-size: 11px;
}

.footer {
  text-align: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  line-height: 1.5;
}
.footer-brand {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  letter-spacing: 0.2px;
}
.footer-by {
  font-size: 12px;
  margin-top: 2px;
}
.footer-by a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.footer-by a:hover { text-decoration: underline; }
.footer-copy {
  font-size: 11px;
  margin-top: 4px;
  color: var(--muted);
}

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #14403a;      /* pill xanh đậm cho nổi trên nền sáng */
  border: 1px solid #14403a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 1000;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); border-color: var(--danger); color: #fff; }

/* tooltip tên thửa trên bản đồ */
.feature-label {
  background: rgba(15, 46, 43, 0.85);
  color: #fff;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, -140%);
}

/* =========================================================================
 * RESPONSIVE / MOBILE
 * ========================================================================= */
@media (max-width: 768px) {
  /* Sidebar thành lớp phủ trượt từ trái, mặc định ẩn */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86vw;
    max-width: 360px;
    flex: none;
    z-index: 200;
    margin-left: 0;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.4);
  }

  /* Trên mobile, mặc định hiện bản đồ. Khi mở panel thì thêm class .sidebar-open */
  #app.sidebar-open #sidebar {
    transform: translateX(0);
  }
  #app.sidebar-open #sidebar-backdrop {
    display: block;
  }

  /* bỏ hiệu ứng margin của desktop trên mobile */
  #app.sidebar-collapsed #sidebar {
    margin-left: 0;
  }

  /* Bản đồ chiếm toàn màn hình phía dưới */
  #map { width: 100vw; }

  /* Mục tiêu chạm lớn hơn */
  #sidebar-toggle { width: 42px; height: 42px; }
  #draw-toolbar .tool-btn { width: 40px; height: 40px; }
  button { padding: 11px; }
  input, select, textarea { font-size: 16px; } /* tránh iOS tự zoom khi focus */

  /* Toolbar dời về góc PHẢI-trên để không bị nút 3 gạch (góc trái) đè lên. */
  #draw-toolbar {
    top: 10px;
    left: auto;
    right: 10px;
    transform: none;
  }

  /* Trên mobile: ẩn nhóm công cụ vẽ, chỉ hiện nút bung. */
  #draw-tools-toggle { display: flex; }
  #draw-tools { display: none; }
  #draw-toolbar.tools-open #draw-tools { display: flex; }

  /* Dải hướng dẫn vẽ cũng dời xuống chút cho thoáng */
  #draw-hint { top: 62px; }
}

@media (max-width: 380px) {
  #sidebar { width: 100vw; max-width: none; }
}

/* =========================================================================
 * Dấu phân cách trong toolbar + nút định vị
 * ========================================================================= */
.tool-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 2px 2px;
}

/* nút "?" cạnh tiêu đề */
.help-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  margin-left: auto;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  background: var(--hover);
  border: 1px solid var(--border);
  color: var(--text);
  flex: none;
}
.help-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

#vn2000-help-link {
  color: var(--accent);
  text-decoration: none;
}
#vn2000-help-link:hover { text-decoration: underline; }

/* =========================================================================
 * MODAL HƯỚNG DẪN
 * ========================================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: 100%;
  max-width: 620px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 26px 26px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal h2 { margin: 0 32px 16px 0; font-size: 20px; }
.modal h3 { font-size: 15px; margin: 18px 0 6px; color: var(--accent); }
.modal p, .modal li { font-size: 14px; line-height: 1.6; color: var(--text); }
.modal ul, .modal ol { margin: 6px 0; padding-left: 22px; }
.modal li { margin-bottom: 4px; }
.modal pre {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  overflow-x: auto;
  color: var(--text);
}
.modal .modal-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 7px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.modal-close:hover { background: var(--hover); }

/* =========================================================================
 * KẾT QUẢ TÌM ĐỊA CHỈ
 * ========================================================================= */
#search-results {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
#search-results li {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  background: var(--input-bg);
}
#search-results li:hover { background: var(--hover); border-color: var(--accent); }
#search-results li .sr-main { font-weight: 600; }
#search-results li .sr-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
#search-results li.sr-empty {
  cursor: default;
  background: transparent;
  color: var(--muted);
  text-align: center;
}
#search-results li.sr-empty:hover { border-color: var(--border); background: transparent; }
