/* ===== CHAT PANEL ===== */
#chatPanel {
  position: fixed;
  top: 0; right: 0;
  width: 380px; height: 100vh;
  z-index: 50;
  display: flex; flex-direction: column;
  background: rgba(8,15,28,0.96);
  backdrop-filter: blur(20px);
  border-left: 1px solid rgba(99,179,237,0.2);
  box-shadow: -8px 0 40px rgba(0,0,0,0.6);
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
#chatPanel.open { transform: translateX(0); }

.chat-header {
  background: linear-gradient(135deg, rgba(15,30,60,0.95), rgba(20,40,80,0.9));
  border-bottom: 1px solid rgba(99,179,237,0.2);
  padding: 12px 16px;
  flex-shrink: 0;
}
.chat-header-img {
  width: 52px; height: 52px;
  border-radius: 50%;
  object-fit: cover; object-position: top;
  border: 2px solid rgba(99,179,237,0.5);
  background: rgba(20,30,50,0.8);
}

/* Messages */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column;
  gap: 10px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(99,179,237,0.3); border-radius: 2px; }

.msg-user {
  background: linear-gradient(135deg, #2b6cb0, #3182ce);
  border-radius: 16px 16px 3px 16px;
  padding: 9px 13px; color: white;
  font-size: 13px; line-height: 1.5;
  align-self: flex-end; max-width: 85%;
  box-shadow: 0 2px 8px rgba(49,130,206,0.3);
  animation: fadeInUp 0.3s ease;
}
.msg-agent {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px 16px 16px 3px;
  padding: 9px 13px; color: #e2e8f0;
  font-size: 13px; line-height: 1.5;
  align-self: flex-start; max-width: 90%;
  animation: fadeInUp 0.3s ease;
}
.msg-system {
  align-self: center;
  background: rgba(99,179,237,0.1);
  border: 1px solid rgba(99,179,237,0.2);
  border-radius: 20px;
  padding: 4px 12px; color: #90cdf4;
  font-size: 11px;
  animation: fadeInUp 0.3s ease;
}

/* Typing dots */
.typing-dot {
  width: 7px; height: 7px;
  background: #63b3ed; border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Quick buttons */
.quick-btn {
  background: rgba(99,179,237,0.08);
  border: 1px solid rgba(99,179,237,0.25);
  color: #90cdf4;
  padding: 5px 11px; border-radius: 16px;
  font-size: 11px; cursor: pointer;
  transition: all 0.2s ease; white-space: nowrap;
}
.quick-btn:hover {
  background: rgba(99,179,237,0.2);
  border-color: rgba(99,179,237,0.6); color: white;
}

/* Input */
.chat-input {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(99,179,237,0.25);
  border-radius: 20px; color: white;
  padding: 9px 14px; outline: none;
  font-size: 13px; font-family: 'Sarabun', sans-serif;
  transition: all 0.3s ease; resize: none;
}
.chat-input:focus {
  border-color: rgba(99,179,237,0.7);
  background: rgba(255,255,255,0.1);
  box-shadow: 0 0 0 3px rgba(99,179,237,0.08);
}
.chat-input::placeholder { color: rgba(255,255,255,0.3); }

.send-btn {
  background: linear-gradient(135deg, #2b6cb0, #3182ce);
  border-radius: 50%;
  width: 38px; height: 38px; flex-shrink: 0;
  border: none; color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.send-btn:hover { transform: scale(1.08); box-shadow: 0 3px 12px rgba(49,130,206,0.5); }

.close-chat-btn {
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all 0.2s ease;
}
.close-chat-btn:hover { background: rgba(245,101,101,0.3); color: white; border-color: rgba(245,101,101,0.5); }

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed rgba(99,179,237,0.25);
  border-radius: 10px; padding: 10px;
  text-align: center; cursor: pointer;
  transition: all 0.3s ease;
  color: rgba(99,179,237,0.5); font-size: 11px;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: rgba(99,179,237,0.7);
  background: rgba(99,179,237,0.05); color: #90cdf4;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: linear-gradient(135deg, #0f1f35, #0a1525);
  border: 1px solid rgba(99,179,237,0.35);
  border-radius: 20px; padding: 24px;
  max-width: 440px; width: 90%;
  animation: popIn 0.3s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}

/* ===== SPEECH BUBBLE ON MAP ===== */
.map-bubble {
  position: absolute;
  bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  color: #1a202c; border-radius: 10px;
  padding: 5px 9px; font-size: 10px; font-weight: 500;
  max-width: 140px; white-space: normal; text-align: center;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
  animation: bubbleIn 0.3s ease forwards;
  pointer-events: none; z-index: 20; line-height: 1.3;
}
.map-bubble::after {
  content: '';
  position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(255,255,255,0.95);
}

/* ===== HOVER TOOLTIP ===== */
.hover-tip {
  position: absolute;
  bottom: calc(100% + 10px); left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: rgba(10,15,30,0.94);
  border: 1px solid rgba(255,220,100,0.5);
  border-radius: 10px; padding: 7px 12px;
  white-space: nowrap; font-size: 11px; color: #f0e68c;
  text-align: center; pointer-events: none; z-index: 50;
  opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6); line-height: 1.6;
}
.hover-tip strong { color: #fff; font-size: 12px; }
.hover-tip span   { color: #90cdf4; font-size: 10px; }
.hover-tip em     { color: #68d391; font-size: 10px; font-style: normal; }
.hover-tip::after {
  content: '';
  position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(255,220,100,0.5);
}
.hover-tip.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== AGENT SETTINGS PANEL ===== */
#agentSettingsOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
#agentSettingsOverlay.hidden { display: none !important; }

#agentSettingsPanel {
  background: linear-gradient(135deg, #0f1f38, #0a1525);
  border: 1px solid rgba(99,179,237,0.3);
  border-radius: 18px;
  width: 520px; max-height: 88vh;
  overflow-y: auto; padding: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.8);
  font-size: 13px; color: #e2e8f0;
}
#agentSettingsPanel::-webkit-scrollbar { width: 4px; }
#agentSettingsPanel::-webkit-scrollbar-thumb { background: rgba(99,179,237,0.3); border-radius: 2px; }

.settings-title {
  font-size: 16px; font-weight: 700;
  color: #90cdf4; margin-bottom: 20px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid rgba(99,179,237,0.15);
  padding-bottom: 12px;
}
.settings-section { margin-bottom: 16px; }
.settings-label {
  font-size: 11px; color: #718096;
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 5px; font-weight: 600;
}
.settings-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 8px 12px;
  color: #e2e8f0; font-size: 12px;
  font-family: 'Sarabun', sans-serif;
  outline: none; transition: border-color 0.2s; resize: vertical;
}
.settings-input:focus { border-color: rgba(99,179,237,0.5); }
.settings-row { display: flex; gap: 10px; }
.settings-row .settings-section { flex: 1; }

.qa-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.qa-item {
  display: flex; align-items: center; gap: 4px;
  background: rgba(99,179,237,0.1);
  border: 1px solid rgba(99,179,237,0.25);
  border-radius: 6px; padding: 3px 4px 3px 10px;
  font-size: 11px; color: #90cdf4;
}
.qa-item input {
  background: none; border: none; outline: none;
  color: #90cdf4; font-size: 11px; width: 100px;
  font-family: 'Sarabun', sans-serif;
}
.qa-remove {
  background: none; border: none; cursor: pointer;
  color: #fc8181; font-size: 13px; padding: 0 2px; line-height: 1;
}
.qa-add-btn {
  background: rgba(99,179,237,0.1);
  border: 1px dashed rgba(99,179,237,0.35);
  color: #63b3ed; border-radius: 6px;
  padding: 3px 10px; font-size: 11px;
  cursor: pointer; font-family: 'Sarabun', sans-serif;
}
.qa-add-btn:hover { background: rgba(99,179,237,0.2); }

.settings-footer {
  display: flex; gap: 8px; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid rgba(99,179,237,0.1);
}
.btn-save {
  flex: 1; padding: 9px;
  background: linear-gradient(135deg,#2b6cb0,#3182ce);
  color: white; border: none; border-radius: 10px;
  font-size: 13px; cursor: pointer; font-family: 'Sarabun', sans-serif; font-weight: 600;
}
.btn-reset {
  padding: 9px 14px;
  background: rgba(245,101,101,0.12);
  color: #fc8181; border: 1px solid rgba(245,101,101,0.3);
  border-radius: 10px; font-size: 13px; cursor: pointer; font-family: 'Sarabun', sans-serif;
}
.btn-close-settings {
  padding: 9px 14px;
  background: rgba(255,255,255,0.06);
  color: #a0aec0; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; font-size: 13px; cursor: pointer; font-family: 'Sarabun', sans-serif;
}

/* ===== EDIT MODE ===== */
#editToolbar {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(10,15,30,0.96);
  border: 1px solid rgba(255,220,100,0.5);
  border-radius: 14px; padding: 10px 18px;
  display: none; align-items: center; gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  font-size: 12px; color: #f0e68c;
}
#editToolbar.show { display: flex; }
#editToolbar .tip { color: #90cdf4; font-size: 11px; }

.edit-save-btn {
  background: linear-gradient(135deg,#276749,#38a169);
  color: white; border: none;
  padding: 6px 16px; border-radius: 8px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.edit-cancel-btn {
  background: rgba(255,255,255,0.07);
  color: #e2e8f0; border: 1px solid rgba(255,255,255,0.15);
  padding: 6px 14px; border-radius: 8px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}

body.edit-mode .agent-on-map { cursor: grab !important; outline: 1px dashed rgba(255,220,100,0.5); border-radius: 4px; }
body.edit-mode .agent-on-map:active { cursor: grabbing !important; }
body.edit-mode .agent-on-map .sprite-wrap { animation: none !important; }
body.edit-mode .agent-on-map:hover .sprite-wrap { animation: none !important; }
body.edit-mode .agent-on-map:hover .sprite-img { filter: drop-shadow(0 0 12px rgba(255,220,100,0.9)) !important; animation: none !important; }

.edit-coord-badge {
  position: absolute; top: -18px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255,220,100,0.9); color: #1a1a00;
  font-size: 9px; font-family: monospace;
  padding: 1px 6px; border-radius: 4px;
  white-space: nowrap; pointer-events: none; display: none;
}
body.edit-mode .edit-coord-badge { display: block; }
