/* v9.0.2 */
/* =========================================================
   LOCATION MANAGER v8.5.8
   Soft UI / Glassmorphism
========================================================= */

#locm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-family: inherit;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#locm-overlay.locm-show {
  opacity: 1;
  visibility: visible;
}

#locm-dialog {
  width: min(860px, 100%);
  height: 90vh;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96) translateY(10px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#locm-overlay.locm-show #locm-dialog {
  transform: scale(1) translateY(0);
}

/* Header */
.locm-header {
  height: 60px;
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(248, 250, 252, 0.8));
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

.locm-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.locm-header-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #3b82f6, #0ea5e9);
  color: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.locm-header-text {
  display: flex;
  flex-direction: column;
}

.locm-ht-ja {
  font-weight: 800;
  font-size: 15px;
  color: #0f172a;
  line-height: 1.2;
}

.locm-ht-vi {
  font-weight: 600;
  font-size: 12px;
  color: #64748b;
  line-height: 1.2;
}

.locm-close-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #64748b;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.locm-close-btn:hover {
  background: rgba(226, 232, 240, 0.8);
  color: #0f172a;
}

/* Body / Layout */
.locm-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar - Rack List */
.locm-sidebar {
  width: 300px;
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(226, 232, 240, 0.8);
  background: rgba(248, 250, 252, 0.4);
}

.locm-sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}

.locm-search-input {
  flex: 1;
  height: 36px;
  padding: 0 12px 0 32px;
  border: 1px solid rgba(203, 213, 225, 0.6);
  border-radius: 12px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.7) url('data:image/svg+xml;utf8,<svg fill="%2394a3b8" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a8 8 0 015.293 13.707l5.414 5.414-1.414 1.414-5.414-5.414A8 8 0 1110 2zm0 2a6 6 0 100 12 6 6 0 000-12z"/></svg>') no-repeat 10px center / 14px;
  transition: all 0.2s ease;
}

.locm-search-input:focus {
  outline: none;
  border-color: #3b82f6;
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.locm-add-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(239, 246, 255, 0.8);
  color: #2563eb;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.locm-add-btn:hover {
  background: #3b82f6;
  color: #fff;
  transform: translateY(-1px);
}

.locm-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.locm-list::-webkit-scrollbar { width: 6px; }
.locm-list::-webkit-scrollbar-track { background: transparent; }
.locm-list::-webkit-scrollbar-thumb { background: rgba(203, 213, 225, 0.6); border-radius: 4px; }

.locm-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.locm-item:hover {
  background: rgba(241, 245, 249, 0.8);
}

.locm-item.active {
  background: #eff6ff;
  border-color: rgba(191, 219, 254, 0.8);
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.06);
}

.locm-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3b82f6;
  font-size: 14px;
  margin-right: 12px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.locm-item-icon.locm-sidebar-thumb {
  background: #f8fafc;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.8);
}
.locm-item-icon.locm-sidebar-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.locm-item.active .locm-item-icon {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.locm-item-info {
  flex: 1;
  min-width: 0;
}

.locm-item-name {
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.locm-item-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}

/* Main Content - Rack Details & Layers */
.locm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
}
.locm-main::-webkit-scrollbar { width: 6px; }
.locm-main::-webkit-scrollbar-track { background: transparent; }
.locm-main::-webkit-scrollbar-thumb { background: rgba(203, 213, 225, 0.6); border-radius: 4px; }

.locm-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  text-align: center;
  gap: 12px;
}
.locm-empty-state i {
  font-size: 48px;
  color: #cbd5e1;
}

/* Section styling */
.locm-section {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  border: 1px solid rgba(226, 232, 240, 0.6);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.locm-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed rgba(203, 213, 225, 0.6);
}

.locm-section-title {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
}

.locm-section-title i {
  color: #3b82f6;
}

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

.locm-form-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.locm-form-thumb-col {
  flex: 0 0 140px;
}

.locm-main-rack-thumb {
  width: 140px;
  height: 140px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px dashed rgba(203, 213, 225, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: #cbd5e1;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}
.locm-main-rack-thumb:hover {
  border-style: solid;
  border-color: #3b82f6;
  color: #3b82f6;
}
.locm-main-rack-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.locm-thumb-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 11px;
  text-align: center;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.locm-main-rack-thumb:hover .locm-thumb-overlay {
  opacity: 1;
}

.locm-form-grid-col {
  flex: 1;
  min-width: 0;
}

.locm-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.locm-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.locm-form-group.full {
  grid-column: 1 / -1;
}

.locm-label {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 4px;
}

.locm-input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(203, 213, 225, 0.6);
  border-radius: 10px;
  font-size: 14px;
  color: #1e293b;
  background: rgba(255, 255, 255, 0.8);
  transition: all 0.2s;
  font-family: inherit;
}
.locm-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.locm-textarea {
  padding: 10px 12px;
  border: 1px solid rgba(203, 213, 225, 0.6);
  border-radius: 10px;
  font-size: 14px;
  color: #1e293b;
  background: rgba(255, 255, 255, 0.8);
  transition: all 0.2s;
  resize: vertical;
  font-family: inherit;
  min-height: 80px;
}
.locm-textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Layer list inside Main */
.locm-layers-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.locm-layer-card {
  background: white;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
  transition: all 0.2s;
}
.locm-layer-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border-color: rgba(148, 163, 184, 0.4);
}

.locm-layer-thumb {
  width: 64px;
  height: 64px;
  background: #f8fafc;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #cbd5e1;
  border: 1px dashed rgba(203, 213, 225, 0.8);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: all 0.2s;
}
.locm-layer-thumb:hover {
  border-style: solid;
  border-color: #3b82f6;
  color: #3b82f6;
}
.locm-layer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.locm-layer-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.locm-layer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.locm-layer-name {
  font-weight: 800;
  font-size: 15px;
  color: #0f172a;
}
.locm-layer-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.4;
}

/* Buttons */
.locm-btn {
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.locm-btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.2);
}
.locm-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(59, 130, 246, 0.3);
}
.locm-btn-outline {
  background: white;
  border: 1px solid rgba(203, 213, 225, 0.8);
  color: #475569;
}
.locm-btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}
.locm-btn-ghost {
  background: transparent;
  color: #64748b;
  padding: 6px 12px;
}
.locm-btn-ghost:hover {
  background: rgba(241, 245, 249, 0.8);
  color: #0f172a;
}

.locm-btn-photo {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}
.locm-btn-photo:hover {
  background: rgba(16, 185, 129, 0.2);
}

.locm-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(226, 232, 240, 0.8);
  background: rgba(248, 250, 252, 0.6);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Mobile responsive — Legacy Modal Layout */
@media (max-width: 768px) {
  #locm-dialog {
    height: 100dvh;
    border-radius: 0;
    margin: 0;
    max-width: 100vw;
  }
  #locm-overlay { padding: 0; }
  
  .locm-body { flex-direction: row; }
  
  .locm-sidebar {
    width: 35%;
    flex: 0 0 35%;
    border-right: 1px solid rgba(226, 232, 240, 0.6);
    border-bottom: none;
  }
  .locm-main { flex: 1; padding: 10px; }
  
  /* Scale down components */
  .locm-header { height: 50px; flex: 0 0 50px; padding: 0 10px; }
  .locm-header-icon { width: 28px; height: 28px; font-size: 12px; }
  .locm-ht-ja { font-size: 13px; }
  .locm-ht-vi { font-size: 10px; }
  
  .locm-sidebar-header { flex-direction: column; padding: 8px; gap: 4px; }
  .locm-search-input { height: 32px; font-size: 12px; padding-left: 28px; background-position: 8px center; background-size: 12px;}
  .locm-add-btn { width: 100%; height: 32px; }
  
  .locm-item { padding: 8px; margin-bottom: 4px; border-radius: 8px; }
  .locm-item-icon { width: 24px; height: 24px; font-size: 11px; margin-right: 8px; }
  .locm-item-name { font-size: 11px; }
  .locm-item-sub { font-size: 10px; }
  
  
  .locm-section { padding: 12px; margin-bottom: 12px; border-radius: 12px; }
  .locm-section-title { font-size: 13px; }
  .locm-section-actions { flex-direction: column; gap: 4px; align-items: flex-end; }
  .locm-btn { padding: 6px 10px; font-size: 11px; }
  
  /* Make form stack on very narrow right col */
  .locm-form-layout { flex-direction: column; gap: 12px; align-items: center; }
  .locm-form-thumb-col { flex: 0 0 auto; width: 100px; height: 100px; }
  .locm-main-rack-thumb { width: 100px; height: 100px; font-size: 24px; }
  .locm-form-grid-col { width: 100%; }
  
  .locm-form-grid { grid-template-columns: 1fr; gap: 10px; }
  .locm-label { font-size: 11px; }
  .locm-input, .locm-textarea { font-size: 12px; padding: 6px 10px; height: 32px; }
  .locm-textarea { min-height: 60px; }
  
  .locm-layer-card { flex-direction: column; align-items: stretch; padding: 12px; gap: 10px; }
  .locm-layer-thumb { width: 100%; height: 100px; border-radius: 8px; }
  .locm-layer-name { font-size: 13px; }
  .locm-layer-desc { font-size: 11px; }
}

/* =========================================================
   Mobile responsive — V2 Full-Page Layout
   (.locm-v2-container generated by initDOM)
========================================================= */
@media (max-width: 768px) {
  /* Container: account for mobile navbar */
  .locm-v2-container {
    height: calc(100dvh - 56px) !important;
  }

  /* Dashboard Header: wrap KPIs + button */
  .locm-dashboard-header {
    flex-wrap: wrap !important;
    padding: 8px 12px !important;
    gap: 6px !important;
    min-height: unset !important;
  }
  .locm-dashboard-header .history-stats {
    gap: 6px !important;
    flex: 1 !important;
    min-width: 0 !important;
  }
  .locm-dashboard-header .history-stat-card {
    min-width: 80px !important;
    padding: 4px 8px !important;
  }
  .locm-dashboard-header .history-stat-value {
    font-size: 14px !important;
  }
  .locm-dashboard-header .history-stat-label {
    font-size: 9px !important;
  }
  .locm-dashboard-header .history-stat-icon {
    width: 20px !important;
    height: 20px !important;
    font-size: 9px !important;
  }
  #locm-add-rack-btn {
    padding: 4px 10px !important;
    font-size: 11px !important;
    white-space: nowrap;
  }

  /* Body: Flex container */
  .locm-dashboard-body {
    position: relative;
    overflow: hidden;
  }

  /* Mobile Drawer overlaps the whole screen */
  .locm-drawer {
    width: 100% !important;
    max-width: 100% !important;
    right: -100% !important;
  }
  .locm-v2-container.drawer-open .locm-drawer {
    right: 0 !important;
  }

  /* Right Pane → fill remaining */
  #locm-right-pane {
    flex: 1 !important;
    min-height: 0 !important;
  }

  /* Rack form photo compact */
  #locm-main-rack-thumb {
    height: 120px !important;
  }

  /* Layer Badges: compact chips */
  #locm-layer-badges-container {
    padding: 6px 10px !important;
    min-height: 38px !important;
    gap: 6px !important;
  }
  #locm-layer-badges-container .locm-tier-badge {
    min-width: 110px !important;
    padding: 6px 10px !important;
  }
  #locm-layer-badges-container .locm-tier-badge div[style*="font-size:15px"] {
    font-size: 13px !important;
  }
  #locm-layer-badges-container .locm-tier-badge .locm-tier-icon {
    width: 26px !important;
    height: 26px !important;
    font-size: 13px !important;
  }

  /* Grid Controls compact */
  #locm-layer-grid-controls {
    padding: 6px 10px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  #locm-selected-layer-title {
    font-size: 13px !important;
  }
  #locm-bulk-transfer-btn {
    font-size: 11px !important;
    padding: 4px 8px !important;
  }

  /* Layer grid padding */
  #locm-layer-grid {
    padding: 10px !important;
  }

  /* Top bar search compact: hide text labels on picker btn */
  #locm-rack-global-search {
    gap: 4px !important;
  }
  #locm-rack-global-search input {
    font-size: 13px !important;
    padding-left: 32px !important;
  }
  #locm-picker-trigger-btn .vi,
  #locm-picker-trigger-btn .ja {
    display: none !important;
  }
  #locm-picker-trigger-btn {
    padding: 0 10px !important;
  }

  /* Empty state grid (home dashboard / all layers) */
  #locm-layer-grid > div[style*="grid-template-columns"] {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 10px !important;
    padding: 10px !important;
  }

  /* Rack cards on home grid compact */
  .locm-rack-grid-thumb {
    width: 56px !important;
    height: 56px !important;
  }
}

/* Photo Preview Popup — consistent with Card Renderer style */
.locm-photo-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(0px);
  transition: background 0.3s ease, backdrop-filter 0.3s ease;
}
.locm-photo-popup.locm-photo-popup--active {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}
.locm-photo-popup-card {
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  position: relative;
  width: 80vw;
  max-width: 800px;
  height: 80vh;
  max-height: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.locm-photo-popup--active .locm-photo-popup-card {
  opacity: 1;
  transform: scale(1);
}
@media (max-width: 768px) {
  .locm-photo-popup-card {
    width: 94vw !important;
    height: 70vh !important;
    padding: 10px !important;
    border-radius: 10px !important;
  }
}
