/* enc-style.css - tối ưu, gom các khai báo trùng lặp và chuẩn hóa selector
   Hỗ trợ panels kéo ra ngoài vùng chứa, nút ẩn/hiện nhỏ, responsive, accessibility */

/* Bản đồ chính */
#enc-map {
  height: 600px;
  width: 100%;
  border: 1px solid #ccc;
  box-sizing: border-box;
}

/* Container toàn cục cho shortcode / layout */
.enc-map-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* --- Quy tắc chung cho vùng điều khiển (gom lại, nhất quán) --- */
.enc-controls-region {
  position: absolute;
  z-index: 1050;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  font-family: sans-serif;
  font-size: 14px;
  max-width: 400px;
  max-height: 70vh;
  min-width: 200px;
  min-height: 80px;
  overflow-wrap: break-word;
  overflow: auto;
  pointer-events: auto;
  resize: both;
  cursor: move;
  box-sizing: border-box;
}

/* Floating ngoài wrapper */
.enc-controls-region.enc-floating {
  position: fixed;
  top: 80px; /* mặc định, có thể được JS đặt lại */
  right: 20px;
  left: auto;
  max-width: 420px;
  max-height: 80vh;
  z-index: 1400;
  /* resize / overflow / cursor đã có ở .enc-controls-region */
}

/* Collapsed state */
.enc-controls-region.enc-collapsed {
  height: 36px;
  min-height: 36px;
  overflow: visible;
  resize: none;
  cursor: default;
  white-space: nowrap;
}

/* Các vùng mặc định (sử dụng ID khi cần xác định vị trí cụ thể) */
#enc-toolbar-region {
  top: 10px;
  left: 10px;
  overflow: auto;
  z-index: 1050;
  position: absolute;
}
#enc-params-region {
  bottom: 60px;
  right: 10px;
  top: auto;
  left: auto;
  max-width: 300px;
  background: rgba(255, 255, 255, 0.95);
  z-index: 1050;
  position: absolute;
}
#enc-primary-controls {
  bottom: 10px;
  left: 10px;
  display: flex;
  gap: 8px;
  z-index: 1050;
  position: absolute;
}

/* Nút điều khiển - gom chung */
.enc-item,
.enc-control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px 0;
  padding: 6px 10px;
  background: #0073aa;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  box-sizing: border-box;
  text-decoration: none;
}
.enc-item:hover,
.enc-control-btn:hover {
  background: #005f8d;
}

/* Compact style cho nút icon nhỏ */
.enc-control-btn {
  padding: 6px;
  width: 36px;
  height: 36px;
  border-radius: 6px;
}

/* Toggle button cho việc show/hide panels */
.enc-panel-toggle {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 1600;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(0, 115, 170, 0.95);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
  border: none;
  font-size: 18px;
}

/* Hidden helper (dùng để ẩn hoàn toàn) */
.enc-hidden {
  display: none !important;
  visibility: hidden !important;
}

/* Chú giải (legend) */
#enc-legend {
  bottom: 10px;
  right: 10px;
  max-width: 180px;
  z-index: 1050;
  position: absolute;
}

/* Thông tin hành trình */
#enc-journey-details {
  top: 160px;
  left: 10px;
  right: auto;
  z-index: 1050;
  position: absolute;
}

/* Modal tìm kiếm, tải tuyến, cảnh báo, ETA, email (sử dụng class thống nhất) */
.enc-search-modal {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ccc;
  padding: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  z-index: 1200;
}
.enc-search-modal input[type="text"],
.enc-search-modal input[type="email"] {
  width: 100%;
  padding: 6px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.enc-search-modal button {
  margin-top: 6px;
  padding: 6px 10px;
  background: #0073aa;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.enc-search-modal button:hover {
  background: #005f8d;
}

/* Bảng ETA */
#enc-eta-table div {
  padding: 4px 0;
  border-bottom: 1px solid #eee;
}

/* Tooltip tọa độ: đặt z-index cao hơn controls để không bị che */
#enc-cursor-tooltip {
  position: absolute;
  background: #fff;
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  pointer-events: none;
  z-index: 1300;
}

/* Menu More */
.enc-more-menu {
  display: none;
  position: absolute;
  bottom: 50px;
  left: 10px;
  background: #fff;
  border: 1px solid #ccc;
  padding: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  z-index: 1100;
}
.enc-more-menu button {
  display: block;
  width: 100%;
  margin-bottom: 6px;
}

/* Accessibility helper */
.visually-hidden {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* Popups input usability */
.enc-popup input.static-popup-input {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}

/* Mobile bottom sheet (hidden on desktop) */
.enc-mobile-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 35vh;
  max-height: 70vh;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.2);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  transform: translateY(100%);
  transition: transform 240ms ease;
  z-index: 1600;
  overflow: auto;
}
.enc-mobile-sheet.open {
  transform: translateY(0%);
}
.enc-mobile-handle {
  width: 48px;
  height: 6px;
  background: #ccc;
  border-radius: 4px;
  margin: 8px auto;
}
.enc-mobile-content {
  padding: 12px;
}

/* Leaflet cursor helper */
.leaflet-container.cursor-crosshair {
  cursor: crosshair !important;
}

/* ----------------------------------------
   Responsive: gộp các thay đổi cho mobile
   breakpoint <= 768px
   ---------------------------------------- */
@media screen and (max-width: 768px) {
  /* Các vùng trong map trở thành flow content */
  #enc-toolbar-region,
  #enc-params-region,
  #enc-journey-details {
    position: static;
    margin: 10px 0;
    background: none;
    box-shadow: none;
    padding: 0;
    resize: none;
    cursor: default;
  }

  /* Primary controls */
  #enc-primary-controls {
    flex-wrap: wrap;
    justify-content: center;
    position: static;
    margin: 10px 0;
  }

  /* Controls region: ẩn in-map floating controls; JS sẽ đổ nội dung vào mobile sheet */
  .enc-controls-region {
    font-size: 13px;
    position: static;
    resize: none;
    cursor: default;
    max-width: 100%;
    min-width: auto;
    display: none; /* hide floating controls on small screens; JS may toggle */
    overflow: visible;
  }

  .enc-item,
  .enc-control-btn {
    font-size: 13px;
    padding: 5px 8px;
  }

  /* Search modal centered and above everything */
  .enc-search-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1400;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border-radius: 8px;
  }

  /* params region spacing */
  #enc-params-region {
    margin-top: 10px;
  }

  /* Make certain small components flow under map */
  #enc-eta-table,
  #enc-legend,
  #enc-journey-details {
    position: static;
    margin-top: 10px;
  }

  /* Split layout fallback: map ~2/3, controls ~1/3 stacked */
  .enc-map {
    height: 66vh !important;
  }
  .enc-controls-wrapper {
    height: 34vh;
    overflow: auto;
  }

  /* Hide desktop-only mobile sheet alternative */
  .enc-mobile-sheet {
    display: block;
  }
}

/* Small screen tweaks for very small devices */
@media screen and (max-width: 480px) {
  .enc-search-modal {
    width: 95%;
    padding: 12px;
    font-size: 14px;
  }
}

/* Desktop-specific rules */
@media screen and (min-width: 769px) {
  .enc-mobile-sheet {
    display: none;
  }
  .enc-controls-region {
    display: block;
  }
}
