/**
 * Mobile Chat Interface - Optimized
 * Designed for better UX on phones & tablets
 */

/* ════════════════════════════════════════════════════════════
   MOBILE CHAT DOCK - IMPROVED LAYOUT
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock {
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  height: auto;
  padding: 0;
  background: transparent;
  display: none;
  flex-direction: column;
  gap: 0;
  z-index: 290;
}

.mobile-touch.mobile-chat-open #chat-dock {
  display: flex;
  pointer-events: auto;
}

/* ════════════════════════════════════════════════════════════
   MOBILE CHAT BOX - FULL SCREEN MODE
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-box {
  display: none;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  border-radius: 0;
  border: none;
  background: linear-gradient(135deg, rgba(10, 10, 20, 0.98), rgba(15, 12, 25, 0.98));
  box-shadow: none;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 290;
  padding-bottom: var(--safe-bottom);
}

.mobile-touch #chat-dock .chat-box.mobile-chat-active {
  display: flex;
  pointer-events: auto;
}

/* ════════════════════════════════════════════════════════════
   CHAT HEADER - IMPROVED MOBILE
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(20, 15, 30, 0.95), rgba(15, 12, 24, 0.85));
  border-bottom: 1px solid rgba(200, 151, 58, 0.15);
  flex-shrink: 0;
  gap: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.mobile-touch #chat-dock .chat-header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-touch #chat-dock .chat-header-title::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(200, 151, 58, 0.6);
  animation: chatHeaderPulse 2s ease-in-out infinite;
}

@keyframes chatHeaderPulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

.mobile-touch #chat-dock .chat-toggle-btn {
  background: rgba(200, 151, 58, 0.1);
  border: 1px solid rgba(200, 151, 58, 0.2);
  border-radius: 8px;
  color: var(--gold);
  font-size: 18px;
  padding: 6px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
}

.mobile-touch #chat-dock .chat-toggle-btn:active {
  background: rgba(200, 151, 58, 0.2);
  transform: scale(0.95);
}

/* ════════════════════════════════════════════════════════════
   CHANNEL TABS - HIDDEN (USING FAB INSTEAD)
   ════════════════════════════════════════════════════════════ */

.mobile-chat-channel-tabs {
  display: none !important;
}

.mobile-chat-tab {
  display: none !important;
}

.mobile-chat-tab-icon {
  display: none !important;
}

.mobile-chat-tab-label {
  display: none !important;
}

/* ════════════════════════════════════════════════════════════
   CHAT BODY & SCROLL - OPTIMIZED
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-body {
  display: grid;
  grid-template-rows: 1fr auto;
  flex: 1;
  min-height: 0;
  padding: 0;
  gap: 0;
  background: transparent;
}

.mobile-touch #chat-dock .chat-scroll {
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  margin: 0;
  max-height: none;
  -webkit-overflow-scrolling: touch;
  font-size: 14px;
  line-height: 1.4;
}

.mobile-touch #chat-dock .chat-scroll::-webkit-scrollbar {
  width: 4px;
}

.mobile-touch #chat-dock .chat-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.mobile-touch #chat-dock .chat-scroll::-webkit-scrollbar-thumb {
  background: rgba(200, 151, 58, 0.3);
  border-radius: 2px;
}

.mobile-touch #chat-dock .chat-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(200, 151, 58, 0.5);
}

/* ════════════════════════════════════════════════════════════
   CHAT INPUT - STICKY & OPTIMIZED
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 10px 10px;
  background: linear-gradient(180deg, rgba(10, 10, 20, 0.3), rgba(10, 10, 20, 0.9));
  border-top: 1px solid rgba(200, 151, 58, 0.1);
  flex-shrink: 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.mobile-touch #chat-dock .chat-input-row > div:not(:last-child) {
  display: flex;
  gap: 6px;
}

.mobile-touch #chat-dock .chat-inp {
  flex: 1;
  height: 40px;
  padding: 10px 14px;
  font-size: 15px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(200, 151, 58, 0.2);
  border-radius: 10px;
  color: var(--moon);
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.2s ease;
}

.mobile-touch #chat-dock .chat-inp:focus {
  background: rgba(0, 0, 0, 0.6);
  border-color: rgba(200, 151, 58, 0.5);
  box-shadow: 0 0 12px rgba(200, 151, 58, 0.2);
}

.mobile-touch #chat-dock .send-btn {
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(200, 151, 58, 0.2), rgba(200, 151, 58, 0.15));
  border: 1px solid rgba(200, 151, 58, 0.3);
  border-radius: 10px;
  color: var(--gold);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-touch #chat-dock .send-btn:active {
  background: linear-gradient(135deg, rgba(200, 151, 58, 0.35), rgba(200, 151, 58, 0.25));
  transform: scale(0.95);
}

/* Chat quote preview on mobile */
.mobile-touch #chat-dock .chat-quote-preview {
  padding: 8px 10px;
  margin: 0;
  border-left: 3px solid var(--gold);
  background: rgba(200, 151, 58, 0.08);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.mobile-touch #chat-dock .chat-quote-from {
  font-size: 11px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}

.mobile-touch #chat-dock .chat-quote-text {
  font-size: 12px;
  color: rgba(232, 220, 200, 0.8);
  margin-bottom: 4px;
}

/* ════════════════════════════════════════════════════════════
   CHAT MESSAGES - OPTIMIZED FOR MOBILE
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 6px 0;
  animation: chatRowFadeIn 0.3s ease-out;
}

@keyframes chatRowFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.mobile-touch #chat-dock .chat-avatar-wrapper {
  margin: 0;
  margin-top: 6px;
  flex-shrink: 0;
}

.mobile-touch #chat-dock .chat-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(200, 151, 58, 0.2);
}

.mobile-touch #chat-dock .chat-sender-info {
  margin-bottom: 2px;
}

.mobile-touch #chat-dock .chat-sender-name {
  font-size: 11px;
  font-weight: 600;
  color: rgba(232, 220, 200, 0.9);
  margin-bottom: 1px;
}

.mobile-touch #chat-dock .chat-sender-timestamp {
  font-size: 9px;
  color: rgba(154, 164, 184, 0.5);
}

.mobile-touch #chat-dock .chat-bubble {
  max-width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: break-word;
  border-radius: 14px;
  display: block;
}

.mobile-touch #chat-dock .chat-text {
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  display: block;
}

.mobile-touch #chat-dock .chat-bubble-container {
  max-width: 92%;
}

/* ════════════════════════════════════════════════════════════
   MOBILE CHAT FAB - BOTTOM FLOATING ACTION BUTTONS
   ════════════════════════════════════════════════════════════ */

/* FAB Container */
.mobile-touch .game-chat-fab-container {
  position: fixed;
  bottom: var(--safe-bottom);
  right: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 280;
  pointer-events: auto;
}

/* Individual FAB Button */
.mobile-touch .game-chat-fab {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(200, 151, 58, 0.9), rgba(200, 151, 58, 0.7));
  border: 2px solid rgba(200, 151, 58, 0.4);
  color: #fff;
  font-size: 24px;
  box-shadow: 0 8px 24px rgba(200, 151, 58, 0.3), 0 0 12px rgba(200, 151, 58, 0.2) inset;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  margin: 0 !important;
  padding: 0 !important;
  flex-shrink: 0;
}

.mobile-touch .game-chat-fab:active {
  transform: scale(0.92);
  box-shadow: 0 4px 12px rgba(200, 151, 58, 0.2), 0 0 8px rgba(200, 151, 58, 0.15) inset;
}

/* Show only the FAB for current channel */
.mobile-touch .game-chat-fab.mobile-fab-active {
  display: flex;
  animation: fabPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fabPop {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(20px);
  }
  70% {
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Unread badge on FAB */
.mobile-touch .game-chat-fab .fab-unread-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  min-width: 20px;
  background: linear-gradient(135deg, #FF4444, #FF6666);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(10, 10, 20, 0.9);
  box-shadow: 0 2px 8px rgba(255, 68, 68, 0.5);
  animation: fabBadgePulse 2s ease-in-out infinite;
  z-index: 2;
}

.mobile-touch .game-chat-fab .fab-unread-badge.show {
  display: flex;
}

@keyframes fabBadgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(255, 68, 68, 0.5); }
  50% { transform: scale(1.15); box-shadow: 0 2px 12px rgba(255, 68, 68, 0.7); }
}

/* FAB when chat is open - hide all FABs */
.mobile-touch.mobile-chat-open .game-chat-fab {
  display: none !important;
}

/* FAB when chat is open and closing - show animation */
.mobile-touch.mobile-chat-open .game-chat-fab.mobile-fab-active {
  display: none !important;
}

/* Closing FAB button inside chat (mini FAB to close) */
.mobile-touch .mobile-fab-close {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(200, 151, 58, 0.15);
  border: 1px solid rgba(200, 151, 58, 0.3);
  color: var(--gold);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.mobile-touch .mobile-fab-close:active {
  background: rgba(200, 151, 58, 0.25);
  transform: scale(0.95);
}

/* ════════════════════════════════════════════════════════════
   KEYBOARD HANDLING - IMPROVED
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock.keyboard-open {
  bottom: var(--kb-offset);
}

.mobile-touch #chat-dock.keyboard-open .chat-box {
  max-height: calc(100dvh - var(--kb-offset));
}

/* Safe area for notches and home indicators */
@supports (padding: max(0px)) {
  .mobile-touch #chat-dock {
    padding-bottom: max(0px, var(--safe-bottom));
  }
}

/* ════════════════════════════════════════════════════════════
   MENTION LIST - MOBILE OPTIMIZED
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .mention-list {
  position: fixed;
  bottom: auto;
  top: auto;
  left: 0;
  right: 0;
  max-height: 120px;
  border-radius: 8px 8px 0 0;
  background: var(--panel);
  border: 1px solid var(--border);
  display: none;
}

.mobile-touch #chat-dock .mention-list.show {
  display: flex;
  flex-direction: column;
}

.mobile-touch #chat-dock .mention-item {
  padding: 10px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.mobile-touch #chat-dock .mention-item:last-child {
  border-bottom: none;
}

/* ════════════════════════════════════════════════════════════
   SCROLL INDICATOR - DOWN ARROW
   ════════════════════════════════════════════════════════════ */

.mobile-touch #chat-dock .chat-scroll-to-latest-btn {
  position: absolute;
  bottom: 60px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(200, 151, 58, 0.15);
  border: 1px solid rgba(200, 151, 58, 0.3);
  color: var(--gold);
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 8;
  transition: all 0.2s ease;
}

.mobile-touch #chat-dock .chat-scroll-to-latest-btn.visible {
  display: flex;
  animation: scrollBtnPulse 0.6s ease-in-out infinite;
}

.mobile-touch #chat-dock .chat-scroll-to-latest-btn:active {
  background: rgba(200, 151, 58, 0.25);
  transform: scale(0.95);
}

@keyframes scrollBtnPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ════════════════════════════════════════════════════════════
   LANDSCAPE MODE - MOBILE LANDSCAPE
   ════════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
  .mobile-touch #chat-dock .chat-box {
    height: 100dvh;
  }

  .mobile-touch #chat-dock .chat-header {
    padding: 6px 12px;
    min-height: 36px;
  }

  .mobile-touch #chat-dock .chat-header-title {
    font-size: 14px;
  }

  .mobile-touch #chat-dock .chat-scroll {
    padding: 8px 10px;
  }

  .mobile-touch #chat-dock .chat-inp {
    height: 36px;
    font-size: 14px;
  }

  .mobile-touch #chat-dock .send-btn {
    height: 36px;
    font-size: 12px;
  }
}

/* ════════════════════════════════════════════════════════════
   UNREAD BADGE - IMPROVED
   ════════════════════════════════════════════════════════════ */

.mobile-chat-tab .chat-unread-badge {
  position: absolute;
  top: 0;
  right: 4px;
  width: 16px;
  height: 16px;
  min-width: 16px;
  background: linear-gradient(135deg, #FF4444, #FF6666);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(255, 68, 68, 0.4);
  animation: unreadPulse 2s ease-in-out infinite;
  z-index: 2;
}

.mobile-chat-tab .chat-unread-badge.show {
  display: flex;
}

@keyframes unreadPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 6px rgba(255, 68, 68, 0.4); }
  50% { transform: scale(1.1); box-shadow: 0 2px 10px rgba(255, 68, 68, 0.6); }
}

/* ════════════════════════════════════════════════════════════
   ACCESSIBILITY IMPROVEMENTS
   ════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .mobile-chat-tab,
  .mobile-touch #chat-dock .chat-row,
  .mobile-chat-channel-tabs,
  .chat-unread-badge {
    animation: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  .mobile-touch #chat-dock .chat-header {
    border-bottom: 2px solid rgba(200, 151, 58, 0.5);
  }

  .mobile-chat-tab {
    border-bottom: 2px solid transparent;
  }

  .mobile-chat-tab.active {
    border-bottom: 2px solid var(--gold);
  }
}
