/* VÙNG TỐI (MODAL OVERLAY) */
#modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999; /* Luôn nổi trên cùng */
    display: none; /* Mặc định ẩn */
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6); /* Vùng tối mờ */
    backdrop-filter: blur(8px); /* Làm mờ bản đồ bên dưới - hiệu ứng rất xịn */
    transition: all 0.3s ease;
}

/* KHUNG TRẮNG (MODAL CONTENT) */
#modal-content {
    /* Đảm bảo khung nội dung không bị dính sát mép */
    max-height: 90vh;
    overflow-y: auto;
}

/* Tùy chỉnh nút định vị */
.locate-btn {
  background: #2563eb;
  color: black;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  line-height: 40px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.locate-btn:hover { background: #1d4ed8; }

/* Tùy chỉnh Bản đồ */
#map { height: 100vh; z-index: 1; }
.leaflet-container { border-radius: 0; }
.custom-icon { background: 0 0; border: none; }
.leaflet-popup-content-wrapper {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,.1);
}
.dark .leaflet-popup-content-wrapper { background: #1f2937; color: #fff; }
.leaflet-popup-content { margin: 0; font-family: ui-sans-serif, system-ui, sans-serif; }
.leaflet-popup-tip { box-shadow: none; }

/* Hiệu ứng Spinner quay vòng */
.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #3b82f6;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }

/* Hiệu ứng Hover cho các nút và danh sách */
.location-item:hover { transform: translateY(-2px); transition: all .2s ease-in-out; }
.filter-btn:hover { transform: translateX(4px); transition: all .3s cubic-bezier(.4,0,.2,1); }

/* Thư viện ảnh (Gallery) trong Popup */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
}
.gallery img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: transform .2s;
}
.gallery img:hover { transform: scale(1.05); }

/* Các tùy chỉnh UI khác */
.picking-cursor { cursor: crosshair !important; }
.fa-location-dot {
  font-size: 32px;
  text-shadow: 1px 1px 3px rgba(0,0,0,.5);
  -webkit-text-stroke: 1px #fff;
  paint-order: stroke fill;
}
.leaflet-marker-icon.highlighted .fa-location-dot {
  animation: pulse 1.5s infinite ease-in-out;
}

/* Responsive cho Điện thoại */
@media (max-width: 768px) {
  .sidebar { width: 100%; height: auto; position: absolute; z-index: 50; transform: translateX(-100%); transition: transform 0.3s ease-in-out; }
  .sidebar.active { transform: translateX(0); }
  .map-container { margin-left: 0; }
  #toggle-sidebar {
    display: block;
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
    background: white;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  }
}

/* CKEditor và Video */
.ck-editor__editable { min-height: 250px; }
.modal-content { max-height: calc(90vh - 100px); overflow-y: auto; }
.video-iframe { aspect-ratio: 16/9; width: 100%; height: auto; }

/* Spinner của Chat AI */
.chat-spinner {
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 1s linear infinite;
}

/* --- GIAO DIỆN TRẮC NGHIỆM --- */
.quiz-option {
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid #e5e7eb;
    background: white;
    color: #374151;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}
.quiz-option:hover:not(:disabled) {
    border-color: #f59e0b;
    background: #fffbeb;
}
.quiz-option.correct {
    background: #10b981;
    color: white;
    border-color: #10b981;
}
.quiz-option.wrong {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    animation: shake 0.4s;
}
.quiz-option:disabled {
    cursor: not-allowed;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
}

/* --- STYLING CHO BẢNG HUY HIỆU --- */
.badge-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    border-radius: 20px;
    background: #f9fafb;
    border: 2px solid #f3f4f6;
    transition: all 0.3s ease;
}

.dark .badge-card { background: #374151; border-color: #4b5563; }

/* Trạng thái CHƯA ĐẠT (Đen trắng) */
.badge-card.locked {
    filter: grayscale(100%);
    opacity: 0.6;
}

/* Trạng thái ĐÃ ĐẠT (Rực rỡ) */
.badge-card.unlocked {
    background: white;
    border-color: #fbbf24;
    box-shadow: 0 10px 15px -3px rgba(251, 191, 36, 0.1);
    transform: translateY(-2px);
}

.dark .badge-card.unlocked { background: #1f2937; border-color: #d97706; }

.badge-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    border-radius: 15px;
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.badge-info h4 {
    margin: 0;
    font-weight: 700;
    font-size: 16px;
    color: #111827;
}
.dark .badge-info h4 { color: white; }

.badge-info p {
    margin: 2px 0 0;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
}
.dark .badge-info p { color: #9ca3af; }


/* --- HIỆU ỨNG THÀNH TỰU BAY RA VÀ XOAY --- */
@keyframes spin-pop {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    60% { transform: scale(1.3) rotate(20deg); opacity: 1; }
    80% { transform: scale(0.9) rotate(-10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.animate-spin-pop {
    animation: spin-pop 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Ép văn bản trong bong bóng chat không bao giờ tràn ra ngoài */
.break-words {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble{
    width: fit-content;
    max-width: 85%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    overflow: hidden;
}

#message-container *{
    min-width: 0;
}