/* CSS Variables for Light Theme */
:root {
  --bg-primary: #f8fafc;         /* Slate 50 */
  --bg-secondary: #ffffff;       /* White */
  --bg-card: rgba(255, 255, 255, 0.92);
  --border-color: rgba(203, 213, 225, 0.6);
  
  --text-primary: #1e293b;       /* Slate 800 */
  --text-secondary: #64748b;     /* Slate 500 */
  --accent-color: #4f46e5;       /* Indigo 600 */
  --accent-hover: #4338ca;       /* Indigo 700 */
  
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Outfit', sans-serif;
  
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* Global Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body, html {
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* Layout container */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Sidebar Styling (Light Glassmorphism) */
.sidebar {
  width: 400px;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.06);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 28px 24px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-logo h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.icon-map {
  color: #4f46e5;
  filter: drop-shadow(0 0 4px rgba(79, 70, 229, 0.2));
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* Search Box Container */
.search-section {
  padding: 24px;
  position: relative;
}

.search-wrapper {
  display: flex;
  gap: 10px;
  width: 100%;
}

.search-input-container {
  display: flex;
  align-items: center;
  flex: 1;
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0 14px;
  height: 48px;
  transition: all 0.2s ease;
  position: relative;
}

.search-input-container:focus-within {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
  background-color: #ffffff;
}

.search-icon {
  color: var(--text-secondary);
  margin-right: 10px;
  flex-shrink: 0;
}

.search-input-container input {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 400;
  outline: none;
}

.search-input-container input::placeholder {
  color: #94a3b8;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.clear-btn:hover {
  background-color: rgba(148, 163, 184, 0.2);
  color: var(--text-primary);
}

.hidden {
  display: none !important;
}

#search-btn {
  background-color: var(--accent-color);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  height: 48px;
  font-family: var(--font-main);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

#search-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

#search-btn:active {
  transform: translateY(0);
}

/* Search Dropdown / Autocomplete Results */
.search-results {
  position: absolute;
  top: 76px;
  left: 24px;
  right: 24px;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1100;
  list-style: none;
  box-shadow: var(--shadow-lg);
}

.search-results li {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(203, 213, 225, 0.4);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
  color: var(--text-primary);
}

.search-results li:hover {
  background-color: rgba(79, 70, 229, 0.06);
  padding-left: 20px;
  color: #4f46e5;
}

.search-results li:last-child {
  border-bottom: none;
}

/* Custom Scrollbar for Dropdown */
.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 10px;
}

/* Info Details Card */
.details-card {
  margin: 0 24px 24px 24px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.details-header {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
}

.neighborhood-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.2);
  border-radius: 30px;
  padding: 6px 16px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: #312e81;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.color-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px currentColor;
}

.details-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(203, 213, 225, 0.4);
}

.info-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.info-value {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.4;
}

.text-mono {
  font-family: monospace, monospace;
  font-size: 13px;
  color: #4f46e5;
}

.status-success {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  background-color: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 10px;
  padding: 10px;
  margin-top: 6px;
}

.status-icon {
  color: #059669;
  display: flex;
  align-items: center;
}

.status-text {
  font-size: 13px;
  color: #047857;
  font-weight: 500;
}

/* Default / Idle Help Panel */
.default-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
}

.info-illustration {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(79, 70, 229, 0.02) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4f46e5;
  margin-bottom: 20px;
  border: 1px solid rgba(79, 70, 229, 0.15);
  animation: pulse 3s infinite;
}

.default-info h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.default-info p {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Footer Section */
.sidebar-footer {
  padding: 18px 24px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* Main Map container */
.map-container {
  flex: 1;
  height: 100%;
  position: relative;
  background-color: #e2e8f0;
}

/* Customize Leaflet Popup & Styles */
.leaflet-container {
  font-family: var(--font-main) !important;
}

.leaflet-popup-content-wrapper {
  background-color: #ffffff !important;
  color: #1e293b !important;
  border: 1px solid rgba(203, 213, 225, 0.6);
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 4px;
}

.leaflet-popup-tip {
  background-color: #ffffff !important;
  border: 1px solid rgba(203, 213, 225, 0.6);
}

.popup-info-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #1e293b;
  border-bottom: 1px solid rgba(203, 213, 225, 0.6);
  padding-bottom: 4px;
}

.popup-info-body {
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
}

.popup-tag {
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: rgba(79, 70, 229, 0.1);
  color: #4338ca;
}

/* Map Label Tooltips */
.map-polygon-tooltip {
  background-color: rgba(255, 255, 255, 0.92) !important;
  border: 1px solid rgba(100, 116, 139, 0.3) !important;
  border-radius: 6px !important;
  color: #1e293b !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1) !important;
  padding: 3px 8px !important;
  opacity: 0.95 !important;
}

/* Map Legend */
.map-legend {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  max-height: 500px;
  overflow-y: auto;
  min-width: 250px;
}

.legend-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 2px 10px;
}

.legend-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  letter-spacing: 0.3px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  cursor: default;
  transition: background-color 0.15s;
  border-radius: 4px;
  padding-left: 4px;
  padding-right: 4px;
}

.legend-item:hover {
  background-color: rgba(79, 70, 229, 0.06);
}

.legend-color {
  width: 18px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.legend-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.map-legend::-webkit-scrollbar {
  width: 4px;
}

.map-legend::-webkit-scrollbar-track {
  background: transparent;
}

.map-legend::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 10px;
}

/* Fade in Animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.25);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(79, 70, 229, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
  }
}

/* Responsive sidebar */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column-reverse;
  }
  .sidebar {
    width: 100%;
    height: 380px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    border-right: none;
    border-top: 1px solid var(--border-color);
  }
  .default-info {
    padding: 20px 32px;
  }
}

/* Boundary Editor Section */
.editor-section {
  padding: 0 24px 24px 24px;
  border-bottom: 1px solid var(--border-color);
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.editor-header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.editor-controls-wrapper {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

/* Custom Switch for Edit Mode */
.switch-container {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  width: 100%;
  gap: 12px;
}

.switch-container input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background-color: #cbd5e1;
  border-radius: 20px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.switch-container input:checked + .switch-slider {
  background-color: var(--accent-color);
}

.switch-container input:checked + .switch-slider:before {
  transform: translateX(20px);
}

.switch-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
}

/* Edit Controls Sub-panel */
.edit-controls {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(203, 213, 225, 0.5);
  animation: fadeIn 0.25s ease-out forwards;
}

.edit-help-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 12px;
}

#edit-khu-pho-select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: #f8fafc;
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 500;
  outline: none;
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color 0.2s;
  font-family: var(--font-main);
}

#edit-khu-pho-select:focus {
  border-color: var(--accent-color);
  background-color: #ffffff;
}

/* Button Groups */
.btn-group {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-main);
  text-align: center;
}

.btn-primary {
  background-color: var(--accent-color);
  color: white;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.15);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-primary:disabled {
  background-color: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background-color: #f1f5f9;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
  color: var(--text-primary);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 20px;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

.toast-message {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-info {
  border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Permanent Neighborhood Labels on Map */
.khu-pho-label {
  background: rgba(255, 255, 255, 0.88) !important;
  border: 1px solid rgba(15, 23, 42, 0.15) !important;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08) !important;
  color: #0f172a !important;
  font-family: var(--font-sans), system-ui, -apple-system, sans-serif !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
  text-align: center !important;
  white-space: nowrap !important;
  user-select: none !important;
}

/* Hide Default Tooltip Arrow */
.khu-pho-label::before {
  display: none !important;
}

/* Login Container styles */
.login-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.login-help-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}

.form-group {
  width: 100%;
}

.form-group input {
  width: 100%;
  height: 40px;
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.form-group input:focus {
  border-color: var(--accent-color);
  background-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.btn-block {
  width: 100%;
}

.error-msg {
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

.admin-info-container {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border-color);
}

.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-color);
  background-color: rgba(79, 70, 229, 0.08);
  padding: 4px 10px;
  border-radius: 6px;
}

.logout-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}

.logout-link:hover {
  color: #ef4444;
}

/* Header Login Trigger Button */
.login-trigger-btn {
  position: absolute;
  top: 26px;
  right: 24px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

.login-trigger-btn:hover {
  background-color: #e2e8f0;
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.login-trigger-btn.logged-in {
  background-color: rgba(16, 185, 129, 0.08);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.2);
}

.login-trigger-btn.logged-in:hover {
  background-color: rgba(16, 185, 129, 0.15);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.3);
}

.login-trigger-btn:active {
  transform: translateY(0);
}

/* Modal Overlay with Blur */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Modal Card with Scale animation */
.modal-card {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 1px 1px rgba(0, 0, 0, 0.05);
  transform: scale(0.92) translateY(15px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close-btn:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-help-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}

.input-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

/* Sidebar Editor Placeholder */
.editor-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px;
  background-color: rgba(248, 250, 252, 0.8);
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  animation: fadeIn 0.3s ease-out;
}

.placeholder-lock-icon {
  color: var(--text-secondary);
  margin-bottom: 12px;
  opacity: 0.6;
}

.editor-placeholder p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
  max-width: 255px;
}



