:root {
  --bg: #f4f7ff;
  --panel: #ffffff;
  --panel2: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, .12);
  --primary: #2563eb;
  --danger: #ef4444;
  --ok: #16a34a;
  --shadow: 0 18px 60px rgba(2, 6, 23, .18);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans";
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.app {
  height: 100vh;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: 380px;
  min-width: 320px;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar__header {
  padding: 16px 16px 8px 16px;
  border-bottom: 1px solid var(--border);
}

.brand__title {
  font-weight: 800;
  letter-spacing: .2px;
  font-size: 18px;
}

.brand__sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.toolbar {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.gpsRow {
  display: flex;
  gap: 10px;
}

.filters {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filters__row {
  display: flex;
  gap: 10px;
}

.input,
.select {
  width: 100%;
  background: rgba(2, 6, 23, .03);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
}

.input::placeholder {
  color: rgba(15, 23, 42, .45);
}

.btn {
  background: rgba(2, 6, 23, .035);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: .15s;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(2, 6, 23, .06);
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: linear-gradient(180deg, rgba(37, 99, 235, 1), rgba(37, 99, 235, .85));
  border-color: rgba(37, 99, 235, .35);
  color: #fff;
}

.btn--primary:hover {
  background: linear-gradient(180deg, rgba(37, 99, 235, 1), rgba(37, 99, 235, .92));
}

.listHeader {
  padding: 12px 16px 6px 16px;
}

.listHeader__title {
  font-weight: 700;
}

.listHeader__hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.planList {
  padding: 0 12px 12px 12px;
  overflow: auto;
  flex: 1;
}

.planItem {
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  margin: 10px 4px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow: 0 10px 30px rgba(2, 6, 23, .06);
}

.planItem__left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 2px;
}

.planItem__main {
  flex: 1;
  min-width: 0;
}

.planTitle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(2, 6, 23, .03);
  color: var(--muted);
}

.planName {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.planFile {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.planActions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.smallBtn {
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(2, 6, 23, .035);
  color: var(--text);
  cursor: pointer;
}

.smallBtn:hover {
  background: rgba(2, 6, 23, .06);
  transform: translateY(-1px);
}

.smallBtn--danger {
  border-color: rgba(239, 68, 68, .35);
  background: rgba(239, 68, 68, .08);
  color: #991b1b;
}

.footerNote {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.main {
  flex: 1;
  position: relative;
}

.map {
  height: 100%;
  width: 100%;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 11000;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .45);
}

.modal__panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__title {
  font-weight: 900;
}

.iconBtn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(2, 6, 23, .03);
  color: var(--text);
  cursor: pointer;
}

.iconBtn:hover {
  background: rgba(2, 6, 23, .06);
}

.modal__body {
  padding: 14px 16px;
}

.modal__footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.modal__footerBtns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-left: auto;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.tableWrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

.table th {
  background: rgba(2, 6, 23, .03);
  font-weight: 800;
}

.table tr:last-child td {
  border-bottom: none;
}

.cellInput {
  width: 100%;
  background: rgba(2, 6, 23, .03);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  outline: none;
}

/* ✅ Upload progress */
.uploadProgress {
  min-width: 220px;
  max-width: 380px;
  flex: 1;
}

.uploadProgress__meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.uploadProgress__track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(2, 6, 23, .08);
  overflow: hidden;
  border: 1px solid var(--border);
}

.uploadProgress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(37, 99, 235, 1), rgba(37, 99, 235, .70));
  border-radius: 999px;
  transition: width .12s linear;
}

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 10px 14px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, .12);
  color: var(--text);
  font-size: 13px;
  max-width: min(720px, calc(100vw - 30px));
}

/* Mobile menu button */
.mobileMenuBtn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 9500;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .92);
  color: var(--text);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 35px rgba(2, 6, 23, .14);
  backdrop-filter: blur(8px);
}

.mobileMenuBtn:hover {
  background: rgba(255, 255, 255, 1);
  transform: translateY(-1px);
}

.sidebarBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .35);
  z-index: 9000;
}

/* =========================
   ✅ Leaflet controls stack top-right
   Order (add order): Layers btn -> Layers panel -> Zoom -> Opacity slider -> GPS/Tâm QH
   ========================= */
.leaflet-top.leaflet-right {
  margin-top: 12px;
  margin-right: 12px;
}

/* Base style for bars/buttons */
.leaflet-bar {
  border: none !important;
  box-shadow: 0 10px 26px rgba(2, 6, 23, .14);
  border-radius: 12px !important;
  overflow: hidden;
}

.leaflet-bar a,
.leaflet-bar button {
  width: 44px;
  height: 44px;
  line-height: 44px;
  border: 1px solid var(--border) !important;
  background: rgba(255, 255, 255, .92) !important;
  color: var(--text) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.leaflet-bar a:hover,
.leaflet-bar button:hover {
  background: rgba(255, 255, 255, 1) !important;
}

.leaflet-bar a+a,
.leaflet-bar button+button {
  border-top: none !important;
}

/* Custom Layers button */
.map-layers-btn.leaflet-bar button {
  width: 92px;
  padding: 0 10px;
  justify-content: center;
  font-weight: 900;
}

/* Hide default layers toggle (we use custom button) */
.leaflet-control-layers-toggle {
  display: none !important;
}

/* Show/hide layers panel cleanly */
.leaflet-control-layers {
  display: none;
}

.leaflet-control-layers.leaflet-control-layers-expanded {
  display: block;
  background: rgba(255, 255, 255, .97);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 26px rgba(2, 6, 23, .14);
  padding: 10px 10px;
  margin-top: 8px;
}

/* ✅ Opacity slider control (giống hình) */
.map-opacity.leaflet-bar {
  width: 44px;
  height: 178px;
  padding: 10px 6px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  border-radius: 12px !important;
}

.map-opacity .opacityLabel {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .98);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
  box-shadow: 0 10px 20px rgba(2, 6, 23, .12);
  user-select: none;
}

.map-opacity input[type="range"] {
    -webkit-appearance: none;
    appearance: none;

    position: relative;
    /* ✅ BẮT BUỘC để top hoạt động */
    top: -55px;
    /* ✅ tăng -> xuống | giảm/âm -> lên */

    width: 120px;
    height: 6px;
    background: rgba(2, 6, 23, .12);
    border-radius: 999px;
    outline: none;
    transform: rotate(-90deg);
}

.map-opacity input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 1);
  border: 2px solid rgba(255, 255, 255, 1);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .35);
  cursor: pointer;
}

.map-opacity input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 1);
  border: 2px solid rgba(255, 255, 255, 1);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .35);
  cursor: pointer;
}

/* Map actions: GPS + Tâm GPS + Tâm QH */
.map-actions.leaflet-bar {
  border-radius: 12px;
}

.map-actions.leaflet-bar button {
  width: 120px;
  padding: 0 10px;
  justify-content: center;
  font-weight: 900;
}

.map-actions .btnSub {
  font-weight: 800;
}

.map-actions button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* Desktop: hide map-actions + slider (sidebar already has GPS; slider optional)
   -> nếu bạn muốn slider luôn hiện desktop thì xóa 2 dòng display:none dưới */
.map-actions {
  display: none;
}

.map-opacity {
  display: none;
}

/* Responsive drawer + show controls on mobile */
@media (max-width: 900px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(86vw, 380px);
    z-index: 10000;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
  }

  .mobileMenuBtn {
    display: flex;
  }

  .main {
    width: 100%;
    height: 100vh;
  }

  .toolbar .gpsRow {
    display: none;
  }

  /* mobile dùng nút trên map */

  /* Mobile: show opacity + actions */
  .map-actions {
    display: block;
  }

  .map-opacity {
    display: block;
  }
}