/* ============================================================
   In-Game Chat Panel — Game-styled overlay chat widget
   Designed for Diep.io-style tank game with Hermes AI mentor
   ============================================================ */

/* --- CSS Custom Properties (theme) --- */
:root {
  --chat-bg: rgba(10, 12, 18, 0.94);
  --chat-border: rgba(0, 200, 255, 0.25);
  --chat-accent: #00c8ff;
  --chat-accent-glow: rgba(0, 200, 255, 0.3);
  --chat-text: #d0d8e8;
  --chat-text-muted: #6a7a90;
  --chat-user-bubble: rgba(0, 180, 120, 0.18);
  --chat-user-bubble-border: rgba(0, 200, 120, 0.35);
  --chat-ai-bubble: rgba(40, 50, 80, 0.7);
  --chat-ai-bubble-border: rgba(80, 100, 160, 0.25);
  --chat-input-bg: rgba(20, 25, 40, 0.9);
  --chat-input-border: rgba(0, 200, 255, 0.2);
  --chat-scrollbar-thumb: rgba(0, 200, 255, 0.2);
  --chat-scrollbar-track: rgba(0, 0, 0, 0.3);
  --chat-shadow: 0 0 30px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 200, 255, 0.1);
  --chat-font: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
  --chat-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Panel container --- */
#chat-panel-container {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  width: 380px;
  max-width: 92vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--chat-transition);
  font-family: var(--chat-font);
  pointer-events: none;
}

#chat-panel-container.open {
  transform: translateX(0);
  pointer-events: auto;
}

/* --- Toggle button (always visible, bottom-right) --- */
#chat-toggle-btn {
  position: fixed;
  top: 24px;
  left: 24px;
  right: auto;
  bottom: auto;
  z-index: 10000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--chat-border);
  background: var(--chat-bg);
  color: var(--chat-accent);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chat-shadow);
  transition: all var(--chat-transition);
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

#chat-toggle-btn:hover {
  border-color: var(--chat-accent);
  box-shadow: 0 0 20px var(--chat-accent-glow);
  transform: scale(1.08);
}

#chat-toggle-btn:active {
  transform: scale(0.95);
}

/* Unread notification dot */
#chat-toggle-btn.has-unread::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff4040;
  border: 2px solid rgba(10, 12, 18, 0.9);
  animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 64, 64, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(255, 64, 64, 0); }
}

/* --- Main panel --- */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  border-right: 1.5px solid var(--chat-border);
  backdrop-filter: blur(16px);
  box-shadow: var(--chat-shadow);
  overflow: hidden;
}

/* --- Header --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(0, 200, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--chat-accent);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.chat-header-title .icon {
  font-size: 18px;
}

.chat-header-actions {
  display: flex;
  gap: 6px;
}

.chat-header-btn {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--chat-text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--chat-text);
  border-color: rgba(255, 255, 255, 0.25);
}

/* --- Messages area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--chat-scrollbar-track);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-scrollbar-thumb);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 200, 255, 0.4);
}

/* --- Individual messages --- */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: chat-fade-in 0.2s ease-out;
}

@keyframes chat-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
}

.chat-message.ai {
  align-self: flex-start;
}

.chat-message .sender-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 3px;
  padding: 0 4px;
  opacity: 0.7;
}

.chat-message.user .sender-label {
  color: #00c878;
}

.chat-message.ai .sender-label {
  color: var(--chat-accent);
}

.chat-message .bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  border: 1px solid transparent;
}

.chat-message.user .bubble {
  background: var(--chat-user-bubble);
  border-color: var(--chat-user-bubble-border);
  border-bottom-right-radius: 4px;
  color: #b8ecd0;
}

.chat-message.ai .bubble {
  background: var(--chat-ai-bubble);
  border-color: var(--chat-ai-bubble-border);
  border-bottom-left-radius: 4px;
  color: var(--chat-text);
}

.chat-message.system .bubble {
  background: rgba(255, 200, 40, 0.08);
  border-color: rgba(255, 200, 40, 0.2);
  color: #c8b060;
  font-style: italic;
  font-size: 12.5px;
  align-self: center;
  max-width: 100%;
  text-align: center;
  border-radius: 8px;
}

.chat-message.error .bubble {
  background: rgba(255, 60, 60, 0.12);
  border-color: rgba(255, 60, 60, 0.3);
  color: #ff8888;
  font-size: 12.5px;
}

.chat-message .timestamp {
  font-size: 10px;
  color: var(--chat-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.chat-message.user .timestamp {
  text-align: right;
}

/* Markdown in AI bubbles */
.chat-message .bubble p {
  margin: 0 0 6px 0;
}

.chat-message .bubble p:last-child {
  margin-bottom: 0;
}

.chat-message .bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Fira Code', 'Consolas', monospace;
  color: #e0c080;
}

.chat-message .bubble pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-message .bubble pre code {
  background: transparent;
  padding: 0;
}

.chat-message .bubble ul,
.chat-message .bubble ol {
  padding-left: 20px;
  margin: 4px 0;
}

.chat-message .bubble li {
  margin-bottom: 2px;
}

.chat-message .bubble a {
  color: var(--chat-accent);
  text-decoration: none;
}

.chat-message .bubble a:hover {
  text-decoration: underline;
}

.chat-message .bubble strong {
  color: #e8e0d0;
}

.chat-message .bubble blockquote {
  border-left: 2px solid var(--chat-accent);
  margin: 4px 0;
  padding: 2px 10px;
  opacity: 0.8;
  font-style: italic;
}

/* --- Typing indicator --- */
.chat-typing {
  display: none;
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--chat-ai-bubble);
  border: 1px solid var(--chat-ai-bubble-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  gap: 4px;
}

.chat-typing.visible {
  display: flex;
}

.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-accent);
  opacity: 0.4;
  animation: chat-typing-bounce 1.4s infinite;
}

.chat-typing .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chat-typing-bounce {
  0%, 60%, 100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* --- Input area --- */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid rgba(0, 200, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  background: var(--chat-input-bg);
  border: 1px solid var(--chat-input-border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--chat-text);
  font-family: var(--chat-font);
  font-size: 13.5px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.4;
  max-height: 100px;
}

.chat-input:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 12px rgba(0, 200, 255, 0.1);
}

.chat-input::placeholder {
  color: var(--chat-text-muted);
  opacity: 0.6;
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  background: rgba(0, 200, 255, 0.1);
  color: var(--chat-accent);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: rgba(0, 200, 255, 0.2);
  border-color: var(--chat-accent);
  box-shadow: 0 0 12px rgba(0, 200, 255, 0.2);
}

.chat-send-btn:active {
  transform: scale(0.95);
  background: rgba(0, 200, 255, 0.3);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Empty state --- */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  color: var(--chat-text-muted);
}

.chat-empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.chat-empty-state .title {
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 6px;
}

.chat-empty-state .subtitle {
  font-size: 12px;
  opacity: 0.7;
  line-height: 1.5;
}

/* --- Status indicator --- */
.chat-status {
  font-size: 12px;
  text-align: center;
  padding: 4px 8px;
  display: none;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.chat-status--visible {
  display: block;
}

.chat-status--thinking {
  color: var(--chat-accent);
  animation: chat-blink 1.5s infinite;
}

.chat-status--applied {
  color: #00e070;
}

.chat-status--error {
  color: #ff6060;
}

@keyframes chat-blink {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* --- Quick action buttons --- */
.chat-quick-actions {
  display: flex;
  gap: 6px;
  padding: 6px 0 0 0;
  justify-content: center;
}

.chat-quick-btn {
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--chat-text-muted);
  cursor: pointer;
  font-size: 11.5px;
  font-family: var(--chat-font);
  transition: all 0.15s;
  white-space: nowrap;
}

.chat-quick-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--chat-text);
  border-color: rgba(0, 200, 255, 0.3);
}

.chat-quick-btn:active {
  background: rgba(0, 200, 255, 0.15);
  transform: scale(0.96);
}

/* --- Responsive --- */
@media (max-width: 480px) {
  #chat-panel-container {
    width: 100vw;
    max-width: 100vw;
  }

  #chat-toggle-btn {
    top: 12px;
    left: 12px;
    right: auto;
    bottom: auto;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}
