* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
  height: 100vh;
  overflow: hidden;
}

/* Floating Chat Toggle Button */
.chat-toggle-btn {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  right: calc(20px + env(safe-area-inset-right, 0));
  background: none;
  border: none;
  cursor: pointer;
  padding: 12px;
  z-index: 1000;
  transition: transform 0.3s ease;
  filter: drop-shadow(0 2px 8px rgba(229, 57, 53, 0.3));
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-toggle-btn svg {
  transition: transform 0.3s ease;
}

.chat-toggle-btn .typing-dots {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chat-toggle-btn:hover {
  transform: scale(1.15);
  filter: drop-shadow(0 4px 12px rgba(229, 57, 53, 0.4));
}

.chat-toggle-btn:hover .typing-dots {
  opacity: 1;
}

.chat-toggle-btn:hover .speech-bubble {
  stroke: #C62828;
}

/* Typing Dots Animation */
.chat-toggle-btn .dot {
  opacity: 0;
  transform: scale(0);
}

.chat-toggle-btn:hover .dot-1 {
  animation: dot-appear 1.4s ease-in-out infinite;
  animation-delay: 0s;
}

.chat-toggle-btn:hover .dot-2 {
  animation: dot-appear 1.4s ease-in-out infinite;
  animation-delay: 0.2s;
}

.chat-toggle-btn:hover .dot-3 {
  animation: dot-appear 1.4s ease-in-out infinite;
  animation-delay: 0.4s;
}

@keyframes dot-appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  20% {
    opacity: 1;
    transform: scale(1);
  }
  80% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0);
  }
}

.chat-toggle-btn:active {
  transform: scale(1.1);
}

.chat-toggle-btn.hidden {
  display: none;
}

/* Chat Container */
.chat-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  right: calc(20px + env(safe-area-inset-right, 0));
  width: 400px;
  max-width: calc(100vw - 40px - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
  height: 600px;
  max-height: calc(100vh - 40px - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  animation: slideUp 0.3s ease-out;
}

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

.chat-container.hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, #FF6B35 0%, #FFA07A 100%);
  padding: 16px 20px;
  padding-left: calc(20px + env(safe-area-inset-left, 0));
  padding-right: calc(20px + env(safe-area-inset-right, 0));
  padding-top: calc(16px + env(safe-area-inset-top, 0));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
}

.header-avatar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-to-faq-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
  padding: 0;
  touch-action: manipulation;
}

.back-to-faq-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.back-to-faq-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.25);
}

.back-to-faq-btn svg {
  width: 20px;
  height: 20px;
}

.header-title {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.close-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Chat Window */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #FAFAFA;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-window::-webkit-scrollbar {
  width: 6px;
}

.chat-window::-webkit-scrollbar-track {
  background: transparent;
}

.chat-window::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chat-window::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* Messages */
.message {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: fadeIn 0.3s ease-in;
}

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

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}

.message-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  line-height: 1.4;
  font-size: 14px;
}

.message.agent .message-bubble {
  background: #F5D76E;
  color: #333;
  border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
  background: #E3F2FD;
  color: #333;
  border-bottom-right-radius: 4px;
}

/* FAQ Instant Answers */
.faq-instant-answers {
  padding: 20px;
  background: #FFFFFF;
  margin: 16px;
  margin-bottom: 24px;
}

.faq-instant-answers-title {
  font-size: 18px;
  font-weight: 600;
  color: #000;
  margin-bottom: 16px;
  margin-top: 0;
}

.faq-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faq-item-button {
  background: #FFFFFF;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 400;
  color: #000;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  min-height: 44px;
  display: flex;
  align-items: center;
  text-align: left;
  width: 100%;
  gap: 12px;
}

.faq-item-button:hover {
  background: #F5F5F5;
  border-color: #BDBDBD;
}

.faq-item-button:active {
  background: #EEEEEE;
  transform: scale(0.98);
}

.faq-direct-chat-button {
  border: 2px solid #2196F3;
  background: #2196F3;
  color: white;
  font-weight: 600;
}

.faq-direct-chat-button:hover {
  background: #1976D2;
  border-color: #1976D2;
}

.faq-direct-chat-button .faq-item-emoji {
  filter: brightness(0) invert(1);
}

.faq-direct-chat-button {
  border: 2px solid #2196F3;
  background: #2196F3;
  color: white;
  font-weight: 600;
}

.faq-direct-chat-button:hover {
  background: #1976D2;
  border-color: #1976D2;
}

.faq-direct-chat-button .faq-item-emoji {
  filter: brightness(0) invert(1);
}

.faq-item-emoji {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.faq-item-text {
  flex: 1;
  line-height: 1.4;
}

@media (max-width: 768px) {
  .faq-instant-answers {
    padding: 16px;
    margin: 12px;
    margin-bottom: 20px;
  }
  
  .faq-instant-answers-title {
    font-size: 16px;
    margin-bottom: 12px;
  }
  
  .faq-item-button {
    padding: 10px 14px;
    font-size: 14px;
    min-height: 44px;
  }
  
  .faq-item-emoji {
    font-size: 18px;
  }
}

.message-bubble a {
  color: #2196F3;
  text-decoration: underline;
  word-break: break-all;
}

.message-bubble a:hover {
  color: #1976D2;
  text-decoration: underline;
}

.message.agent .message-bubble a {
  color: #1976D2;
}

.message.agent .message-bubble a:hover {
  color: #1565C0;
}

/* Chat Input Area */
.chat-input-area {
  padding: 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0));
  padding-right: calc(12px + env(safe-area-inset-right, 0));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: #F5F5F5;
  border-top: 1px solid #E0E0E0;
  display: flex;
  gap: 8px;
  align-items: center;
}

.message-input {
  flex: 1;
  min-height: 44px;
  padding: 12px 16px;
  border: 1px solid #E0E0E0;
  border-radius: 24px;
  font-size: 16px; /* Prevent zoom on iOS */
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  touch-action: manipulation;
}

@media (min-width: 769px) {
  .message-input {
    font-size: 14px;
  }
}

.message-input:focus {
  border-color: #FF6B35;
}

.input-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.photo-upload-btn,
.send-btn {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background-color 0.2s;
  padding: 0;
  touch-action: manipulation; /* Prevent double-tap zoom on mobile */
}

.photo-upload-btn {
  background: #2196F3;
  color: white;
}

.photo-upload-btn:hover {
  background: #1976D2;
  transform: scale(1.1);
}

.photo-upload-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn {
  background: #5B4E9E;
  color: white;
}

.send-btn:hover {
  background: #4A3D7E;
  transform: scale(1.1);
}

.send-btn:active,
.photo-upload-btn:active {
  transform: scale(0.95);
}

/* Image messages in chat */
.message-image {
  padding: 0;
  background: transparent;
  max-width: 100%;
}

.chat-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 12px;
  display: block;
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.2s;
}

.chat-image:hover {
  transform: scale(1.02);
}

.message.user .chat-image {
  border: 1px solid #E0E0E0;
}

.message.agent .chat-image {
  border: 1px solid #F5D76E;
}

/* Customer Chat - Mobile First */
.chat-container {
  width: 100vw;
  width: calc(100vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
  height: 100vh;
  height: 100dvh;
  height: calc(100dvh - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  bottom: 0;
  right: 0;
  left: env(safe-area-inset-left, 0);
  border-radius: 0;
  /* iOS safe area */
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

.chat-toggle-btn {
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  right: calc(16px + env(safe-area-inset-right, 0));
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.chat-toggle-btn svg {
  width: 48px;
  height: 48px;
}

/* Desktop Customer Chat */
@media (min-width: 769px) {
  .chat-container {
    width: 400px;
    height: 600px;
    max-width: calc(100vw - 40px - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
    max-height: calc(100vh - 40px - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
    bottom: calc(20px + env(safe-area-inset-bottom, 0));
    right: calc(20px + env(safe-area-inset-right, 0));
    left: auto;
    border-radius: 16px;
    padding-bottom: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .chat-toggle-btn {
    bottom: calc(20px + env(safe-area-inset-bottom, 0));
    right: calc(20px + env(safe-area-inset-right, 0));
    padding: 12px;
  }
  
  .chat-toggle-btn:hover {
    transform: scale(1.15);
  }
}

/* PWA styles for iOS */
html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}

/* ============================================
   STAFF DASHBOARD STYLES - MOBILE FIRST
   ============================================ */

.staff-body {
  overflow: hidden;
  /* iOS safe area insets */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.staff-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  background: #F5F5F5;
  position: relative;
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0));
  left: calc(12px + env(safe-area-inset-left, 0));
  z-index: 1001;
  background: #2C2C2C;
  border: none;
  color: #FFFFFF;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: background-color 0.2s;
}

.mobile-menu-toggle:active {
  background: #3A3A3A;
}

/* Mobile Sidebar Overlay */
.mobile-sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  width: calc(100% + env(safe-area-inset-left, 0) + env(safe-area-inset-right, 0));
  height: 100%;
  height: calc(100% + env(safe-area-inset-top, 0) + env(safe-area-inset-bottom, 0));
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  margin-left: calc(-1 * env(safe-area-inset-left, 0));
  margin-top: calc(-1 * env(safe-area-inset-top, 0));
}

.mobile-sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Sidebar - Mobile First (Hidden by default, drawer on mobile) */
.staff-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: calc(85vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
  height: 100vh;
  height: 100dvh;
  height: calc(100dvh - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
  background: #2C2C2C;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #3A3A3A;
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  /* iOS safe area */
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  margin-top: env(safe-area-inset-top, 0);
}

.staff-sidebar.show {
  transform: translateX(0);
}

.sidebar-nav {
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid #3A3A3A;
}

.nav-icon {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  width: 48px;
  height: 48px;
  background: none;
  border: none;
  color: #B0B0B0;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  touch-action: manipulation;
}

.nav-icon:hover {
  background: #3A3A3A;
  color: #FFFFFF;
}

.nav-icon.active {
  background: #4A4A4A;
  color: #FFFFFF;
}

.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #FF4444;
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* Chat List Section */
.chat-list-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-list-section::-webkit-scrollbar {
  width: 6px;
}

.chat-list-section::-webkit-scrollbar-track {
  background: transparent;
}

.chat-list-section::-webkit-scrollbar-thumb {
  background: #4A4A4A;
  border-radius: 3px;
}

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid #3A3A3A;
  margin-bottom: 24px;
}

.chat-list-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #FFFFFF;
}

.menu-btn {
  background: none;
  border: none;
  color: #B0B0B0;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.menu-btn:hover {
  background: #3A3A3A;
}

.chat-category {
  margin-bottom: 32px;
}

.category-title {
  color: #B0B0B0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  color: #FFFFFF;
  touch-action: manipulation;
}

.chat-item:hover {
  background: #3A3A3A;
}

.chat-item.active {
  background: #4A90E2;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 12px;
  color: #B0B0B0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item.active .chat-preview {
  color: rgba(255, 255, 255, 0.9);
}

.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.chat-time {
  font-size: 11px;
  color: #888;
}

.chat-item.active .chat-time {
  color: rgba(255, 255, 255, 0.8);
}

.new-indicator {
  width: 8px;
  height: 8px;
  background: #FF4444;
  border-radius: 50%;
}

/* Sidebar Bottom */
.sidebar-bottom {
  padding: 16px 8px;
  border-top: 1px solid #3A3A3A;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #4A4A4A;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  margin-top: 8px;
}

/* Main Chat Panel */
.staff-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
  overflow: hidden;
  /* iOS safe area */
  padding-top: env(safe-area-inset-top, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.no-chat-selected {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 16px;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.no-chat-selected.hidden {
  display: none;
}

.active-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.active-chat.hidden {
  display: none;
}

.active-chat-header {
  padding: 12px 16px;
  padding-left: calc(12px + 44px + 12px + env(safe-area-inset-left, 0)); /* Account for menu button width + gap + safe area */
  padding-right: calc(16px + env(safe-area-inset-right, 0));
  padding-top: calc(12px + env(safe-area-inset-top, 0));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  border-bottom: 1px solid #E0E0E0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #FFFFFF;
  min-height: 44px;
}

@media (min-width: 769px) {
  .active-chat-header {
    padding: 16px 24px;
    padding-left: calc(24px + env(safe-area-inset-left, 0));
    padding-right: calc(24px + env(safe-area-inset-right, 0));
    padding-top: calc(16px + env(safe-area-inset-top, 0));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  }
}

.chat-header-info {
  flex: 1;
  min-width: 0; /* Allow text truncation */
}

.chat-header-info h2 {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .chat-header-info h2 {
    font-size: 16px;
  }
}

.chat-header-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header-info p {
  font-size: 12px;
  color: #999;
  margin: 0;
}

.chat-ip-address {
  font-size: 11px;
  color: #777;
  font-family: 'Courier New', monospace;
}

.chat-location {
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Metrics Modal */
.metrics-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  width: calc(100% + env(safe-area-inset-left, 0) + env(safe-area-inset-right, 0));
  height: 100%;
  height: calc(100% + env(safe-area-inset-top, 0) + env(safe-area-inset-bottom, 0));
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: calc(-1 * env(safe-area-inset-left, 0));
  margin-top: calc(-1 * env(safe-area-inset-top, 0));
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.metrics-overlay.show {
  opacity: 1;
  visibility: visible;
}

.metrics-modal {
  background: #FFFFFF;
  border-radius: 12px;
  width: 95%;
  max-width: calc(1000px - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
  max-height: calc(95vh - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
  max-height: calc(95dvh - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  transform: scale(0.9);
  transition: transform 0.3s ease;
  /* iOS safe area */
  margin: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

@media (min-width: 769px) {
  .metrics-modal {
    width: 90%;
  }
}

.metrics-overlay.show .metrics-modal {
  transform: scale(1);
}

.metrics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0));
  padding-right: calc(16px + env(safe-area-inset-right, 0));
  padding-top: calc(16px + env(safe-area-inset-top, 0));
  border-bottom: 1px solid #E0E0E0;
}

@media (min-width: 769px) {
  .metrics-header {
    padding: 24px;
    padding-left: calc(24px + env(safe-area-inset-left, 0));
    padding-right: calc(24px + env(safe-area-inset-right, 0));
    padding-top: calc(24px + env(safe-area-inset-top, 0));
  }
}

.metrics-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #333;
}

.metrics-close-btn {
  background: none;
  border: none;
  font-size: 32px;
  color: #999;
  cursor: pointer;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
  touch-action: manipulation;
}

.metrics-close-btn:hover {
  background: #F0F0F0;
  color: #333;
}

.metrics-content {
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0));
  padding-right: calc(16px + env(safe-area-inset-right, 0));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
}

@media (min-width: 769px) {
  .metrics-content {
    padding: 24px;
    padding-left: calc(24px + env(safe-area-inset-left, 0));
    padding-right: calc(24px + env(safe-area-inset-right, 0));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
  }
}

.metrics-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid #E0E0E0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 769px) {
  .metrics-tabs {
    gap: 8px;
    margin-bottom: 24px;
  }
}

.metric-tab {
  background: none;
  border: none;
  padding: 12px 16px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  touch-action: manipulation;
  white-space: nowrap;
}

@media (min-width: 769px) {
  .metric-tab {
    padding: 12px 24px;
  }
}

.metric-tab:hover {
  color: #333;
}

.metric-tab.active {
  color: #2196F3;
  border-bottom-color: #2196F3;
}

.metrics-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

@media (min-width: 481px) {
  .metrics-summary {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
  }
}

.metric-card {
  background: #F8F9FA;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
}

.metric-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 32px;
  font-weight: 700;
  color: #333;
}

.metrics-chart {
  margin-bottom: 32px;
}

.metrics-chart h3 {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
}

#metrics-chart-canvas {
  width: 100%;
  height: 300px;
  background: #FAFAFA;
  border-radius: 8px;
}

.metrics-locations {
  margin-top: 32px;
}

.metrics-locations h3 {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
}

.locations-list {
  background: #F8F9FA;
  border-radius: 8px;
  overflow: hidden;
}

.location-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #E0E0E0;
}

.location-item:last-child {
  border-bottom: none;
}

.location-name {
  font-size: 14px;
  color: #333;
}

.location-count {
  font-size: 14px;
  font-weight: 600;
  color: #2196F3;
  background: #E3F2FD;
  padding: 4px 12px;
  border-radius: 12px;
}

/* Staff Chat Window */
.staff-chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: #FAFAFA;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.staff-chat-window::-webkit-scrollbar {
  width: 6px;
}

.staff-chat-window::-webkit-scrollbar-track {
  background: transparent;
}

.staff-chat-window::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.staff-message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeIn 0.3s ease-in;
}

.staff-message.staff {
  flex-direction: row-reverse;
}

.staff-message-avatar {
  flex-shrink: 0;
}

.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.staff-message-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  line-height: 1.4;
  font-size: 14px;
  position: relative;
}

.staff-message.customer .staff-message-bubble {
  background: #E0E0E0;
  color: #333;
  border-bottom-left-radius: 4px;
}

.staff-message.staff .staff-message-bubble {
  background: #2196F3;
  color: white;
  border-bottom-right-radius: 4px;
}

.staff-message-bubble a {
  color: #2196F3;
  text-decoration: underline;
  word-break: break-all;
}

.staff-message-bubble a:hover {
  color: #1976D2;
  text-decoration: underline;
}

.staff-message.customer .staff-message-bubble a {
  color: #1976D2;
}

.staff-message.customer .staff-message-bubble a:hover {
  color: #1565C0;
}

.staff-message.staff .staff-message-bubble a {
  color: #E3F2FD;
  text-decoration: underline;
}

.staff-message.staff .staff-message-bubble a:hover {
  color: #BBDEFB;
  text-decoration: underline;
}

/* Image messages in staff chat */
.staff-message-image {
  padding: 0;
  background: transparent;
  max-width: 100%;
}

.staff-chat-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 12px;
  display: block;
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.2s;
}

.staff-chat-image:hover {
  transform: scale(1.02);
}

.staff-message.customer .staff-chat-image {
  border: 1px solid #E0E0E0;
}

.staff-message.staff .staff-chat-image {
  border: 1px solid #F5D76E;
}

.message-meta {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
  padding-left: 4px;
}

.staff-message.staff .message-meta {
  text-align: right;
  padding-right: 4px;
  padding-left: 0;
}

/* Staff Input Area */
.staff-input-area {
  padding: 12px 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0));
  padding-right: calc(16px + env(safe-area-inset-right, 0));
  padding-top: calc(12px + env(safe-area-inset-top, 0));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: #FFFFFF;
  border-top: 1px solid #E0E0E0;
  position: relative;
}

@media (min-width: 769px) {
  .staff-input-area {
    padding: 16px 24px;
    padding-left: calc(24px + env(safe-area-inset-left, 0));
    padding-right: calc(24px + env(safe-area-inset-right, 0));
    padding-top: calc(16px + env(safe-area-inset-top, 0));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  }
}

.staff-message-input {
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  font-size: 16px; /* Prevent zoom on iOS */
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 12px;
  touch-action: manipulation;
}

@media (min-width: 769px) {
  .staff-message-input {
    font-size: 14px;
  }
}

.staff-message-input:focus {
  border-color: #2196F3;
}

.input-options {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.private-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

.private-toggle input[type="checkbox"] {
  cursor: pointer;
}

.input-icon-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-icon-btn:hover {
  background: #F5F5F5;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.add-tag-btn {
  background: none;
  border: none;
  color: #2196F3;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.add-tag-btn:hover {
  background: #F5F5F5;
}

.input-hint {
  font-size: 12px;
  color: #999;
}

.staff-send-btn {
  position: absolute;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  right: 16px;
  background: #2196F3;
  color: white;
  border: none;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
  touch-action: manipulation;
}

.staff-send-btn:hover {
  background: #1976D2;
}

.staff-send-btn:active {
  transform: scale(0.98);
}

@media (min-width: 769px) {
  .staff-send-btn {
    bottom: 16px;
    right: 24px;
    padding: 10px 24px;
  }
}

/* Mobile-specific adjustments */
.chat-list-header h2 {
  font-size: 16px;
}

@media (min-width: 769px) {
  .chat-list-header h2 {
    font-size: 20px;
  }
}
