/**
 * Chat Overlay CSS Styles
 * Mobile-optimized styles for Google Maps passenger chat interface
 */

/* CSS Variables for theming */
:root {
  --chat-primary: #2563EB;
  --chat-secondary: #1D4ED8;
  --passenger-bg: #2563EB;
  --operator-bg: #E8F5E8;
  --operator-border: #4CAF50;
  --driver-bg: #FFF3E0;
  --driver-border: #FF9800;
  --header-gradient: linear-gradient(135deg, #2563EB, #1D4ED8);
  --header-text-color: #ffffff;
  --connection-green: #34D399;
  --connection-red: #f44336;
}

/* Base Styles and Mobile Optimizations */
html, body, #map {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Mobile-specific optimizations */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f5f5f5;
}

#map {
  width: 100%;
  height: 100vh;
  height: -webkit-fill-available;
  position: relative;
}

/* Prevent zoom on double tap for mobile */
* {
  touch-action: manipulation;
}

/* Optimize for mobile Safari */
@supports (-webkit-touch-callout: none) {
  #map {
    height: -webkit-fill-available;
  }
}

/* Chat Overlay Container */
.chat-overlay {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 2000;
  pointer-events: none;
  padding: 8px;
}

/* Chat Toggle Button */
.chat-button {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--header-gradient);
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  touch-action: manipulation;
}

.chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.chat-button:active {
  transform: scale(0.95);
}

.chat-button svg {
  width: 24px;
  height: 24px;
  color: white;
}

/* Chat notification badge */
.chat-button.has-notification {
  animation: bounce 2s infinite;
}

.chat-button .notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #f44336;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

/* Chat Window */
.chat-window {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  height: 50vh;
  max-height: 600px;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  border: 2px solid var(--chat-primary);
  pointer-events: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-window.open {
  transform: translateY(0);
}

/* Hide chat window by default */
#chat-overlay.hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  background: var(--header-gradient);
  color: var(--header-text-color);
  padding: 12px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 16px 16px 0 0;
  position: relative;
  gap: 8px;
}

.chat-drag-indicator {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-details h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-details p {
  margin: 0;
  font-size: 12px;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-close {
  background: none;
  border: none;
  color: white;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  touch-action: manipulation;
}

.chat-close:hover {
  background: rgba(255,255,255,0.1);
}

/* PNR Badge */
.pnr-badge {
  background: rgba(255,255,255,0.2);
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* WiFi Signal Icon for Connection Status */
.connection-status {
  position: relative;
  width: 20px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

/* Use SVG-style WiFi icon similar to Lucide */
.connection-status::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h.01'/%3E%3Cpath d='M2 8.82a15 15 0 0 1 20 0'/%3E%3Cpath d='M5 12.859a10 10 0 0 1 14 0'/%3E%3Cpath d='M8.5 16.429a5 5 0 0 1 7 0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.connection-status.connected::before {
  filter: invert(64%) sepia(98%) saturate(1018%) hue-rotate(103deg) brightness(96%) contrast(89%);
}

.connection-status.disconnected::before {
  filter: invert(27%) sepia(93%) saturate(7471%) hue-rotate(3deg) brightness(91%) contrast(91%);
}

/* Chat Messages Container */
.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Individual Chat Messages */
.message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}

.message-content {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}

.message.passenger-message {
  align-self: flex-end;
}

.message.passenger-message .message-content {
  background: var(--passenger-bg);
  color: white;
  border-radius: 16px 16px 4px 16px;
}

.message.operator-message {
  align-self: flex-start;
}

.message.operator-message .message-content {
  background: var(--operator-bg);
  border: 1px solid var(--operator-border);
  border-radius: 16px 16px 16px 4px;
  color: #222;
}

.message.driver-message {
  align-self: flex-start;
}

.message.driver-message .message-content {
  background: var(--driver-bg);
  border: 1px solid var(--driver-border);
  border-radius: 16px 16px 16px 4px;
  color: #222;
}

.message-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.message.operator-message .message-time {
  justify-content: space-between;
}

.message-user-type {
  font-size: 10px;
  opacity: 0.6;
  font-weight: 500;
}

/* No Messages State */
.no-messages {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #666;
  text-align: center;
  padding: 20px;
}

.no-messages svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
  margin-bottom: 12px;
}

/* Chat Input Area */
.chat-input-area {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #e0e0e0;
}

/* Quick Chat Section */
.quick-chat-section {
  margin-bottom: 12px;
}

.quick-chat-label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-bottom: 8px;
  text-align: center;
}

.quick-chat-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.quick-chat-btn {
  padding: 10px 14px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  touch-action: manipulation;
}

.quick-chat-btn:hover {
  background: #f5f5f5;
  border-color: #1976d2;
}

.quick-chat-btn:active {
  transform: scale(0.98);
}

/* Message Input Container */
.chat-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 14px;
  resize: none;
  min-height: 20px;
  max-height: 80px;
  outline: none;
  font-family: inherit;
}

.chat-input:focus {
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.chat-send {
  width: 40px;
  height: 40px;
  background: #1976d2;
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  touch-action: manipulation;
}

.chat-send:hover {
  background: #1565c0;
}

.chat-send:active {
  transform: scale(0.95);
}

.chat-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* Connection Status Indicator */
.connection-status {
  position: absolute;
  top: 12px;
  right: 50px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

.connection-status.connected {
  color: #4caf50;
}

.connection-status.disconnected {
  color: #f44336;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
}

.connection-dot.disconnected {
  background: #f44336;
}

.connection-dot.connecting {
  background: #ff9800;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Loading Indicator */
.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e0e0e0;
  border-top: 2px solid #1976d2;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Typing Indicator */
.typing-indicator .message-content {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 16px 16px 16px 4px;
  animation: pulse 1.5s infinite;
}

/* Mobile Responsive Adjustments */
@media (max-width: 480px) {
  .chat-window {
    height: 60vh;
    max-height: 500px;
  }
  
  .chat-button {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
  
  .chat-overlay {
    padding: 4px;
  }
  
  .quick-chat-buttons {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  
  .quick-chat-btn {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
  }
  
  .message-content {
    font-size: 13px;
    padding: 6px 10px;
  }
}

/* iOS Safari specific fixes */
@supports (-webkit-appearance: none) {
  .chat-input {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 20px;
  }
}

/* High DPI screens */
@media (min-resolution: 2dppx) {
  .chat-button {
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  }
  
  .chat-window {
    box-shadow: 0 -2px 16px rgba(0,0,0,0.3);
  }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
  .chat-messages {
    background: #2d2d2d;
  }
  
  .message.operator-message .message-content {
    background: #3d3d3d;
    border-color: #555;
    color: #fff;
  }
  
  .chat-input-area {
    background: #3d3d3d;
    border-top-color: #555;
  }
  
  .chat-input {
    background: #2d2d2d;
    border-color: #555;
    color: #fff;
  }
  
  .quick-chat-btn {
    background: #3d3d3d;
    border-color: #555;
    color: #fff;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .chat-button,
  .quick-chat-btn, 
  .chat-send,
  .chat-window {
    transition: none;
  }
  
  .loading-spinner,
  .connection-dot.connecting,
  .typing-indicator .message-content {
    animation: none;
  }
}