/* Modern WP Chat Widget Styles */
:root {
  --wpchat-primary: #2563eb;
  --wpchat-primary-hover: #1d4ed8;
  --wpchat-primary-light: #dbeafe;
  --wpchat-white: #ffffff;
  --wpchat-gray-50: #f9fafb;
  --wpchat-gray-100: #f3f4f6;
  --wpchat-gray-200: #e5e7eb;
  --wpchat-gray-300: #d1d5db;
  --wpchat-gray-500: #6b7280;
  --wpchat-gray-600: #4b5563;
  --wpchat-gray-800: #1f2937;
  --wpchat-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --wpchat-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --wpchat-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --wpchat-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Widget Container */
.wpchat-widget { 
  position: fixed; 
  right: 20px; 
  bottom: 20px; 
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Modern Toggle Button */
.wpchat-toggle { 
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--wpchat-primary);
  color: var(--wpchat-white);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--wpchat-shadow-lg);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(0);
}

.wpchat-toggle:hover {
  background: var(--wpchat-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--wpchat-shadow-xl);
}

.wpchat-toggle-icon {
  color: var(--wpchat-white);
}

.wpchat-toggle-text {
  white-space: nowrap;
}

.wpchat-toggle.hidden {
  display: none !important;
}

/* Modern Chat Panel */
.wpchat-panel { 
  width: 380px; 
  height: 600px; 
  background: var(--wpchat-white);
  border: 1px solid var(--wpchat-gray-200);
  border-radius: 16px;
  box-shadow: var(--wpchat-shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  max-height: 600px;
  min-height: 400px;
}

.wpchat-panel[hidden] { 
  display: none !important; 
}

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

/* Header with Gradient */
.wpchat-header { 
  background: linear-gradient(135deg, var(--wpchat-primary) 0%, var(--wpchat-primary-hover) 100%);
  color: var(--wpchat-white);
  padding: 16px;
  flex-shrink: 0; /* Prevent header from shrinking */
  position: relative;
  z-index: 2;
}

.wpchat-header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wpchat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wpchat-header-icon {
  color: var(--wpchat-white);
  opacity: 0.9;
}

.wpchat-header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.wpchat-header-subtitle {
  margin: 0;
  font-size: 12px;
  opacity: 0.8;
  line-height: 1.2;
}

.wpchat-close {
  background: none;
  border: none;
  color: var(--wpchat-white);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Messages Container - Ensure proper height distribution */
.wpchat-messages-container {
  flex: 1;
  position: relative;
  background: var(--wpchat-gray-50);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.wpchat-messages {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
  box-sizing: border-box;
  flex: 1;
  min-height: 0; /* Critical for proper scrolling in flex containers */
}

.wpchat-messages::-webkit-scrollbar {
  width: 4px;
}

.wpchat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.wpchat-messages::-webkit-scrollbar-thumb {
  background: var(--wpchat-gray-300);
  border-radius: 2px;
}

/* Loading Skeleton */
.wpchat-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--wpchat-gray-50);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.wpchat-loader.hidden {
  display: none;
}

.wpchat-skeleton {
  width: 100%;
  max-width: 320px;
  margin-bottom: 20px;
}

.wpchat-skeleton-message {
  display: flex;
  margin-bottom: 16px;
  gap: 8px;
}

.wpchat-skeleton-agent {
  justify-content: flex-start;
}

.wpchat-skeleton-user {
  justify-content: flex-end;
}

.wpchat-skeleton-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--wpchat-gray-200) 25%, var(--wpchat-gray-100) 50%, var(--wpchat-gray-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.wpchat-skeleton-bubble {
  height: 40px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--wpchat-gray-200) 25%, var(--wpchat-gray-100) 50%, var(--wpchat-gray-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.wpchat-skeleton-agent .wpchat-skeleton-bubble {
  width: 180px;
}

.wpchat-skeleton-user .wpchat-skeleton-bubble {
  width: 140px;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.wpchat-loading-text {
  color: var(--wpchat-gray-500);
  font-size: 14px;
  margin: 0;
  text-align: center;
}

/* Message Styles */
.wpchat-msg { 
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: messageAppear 0.3s ease-out;
}

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

.wpchat-msg.user { 
  align-self: flex-end;
}

.wpchat-msg.agent { 
  align-self: flex-start;
}

.wpchat-msg .bubble { 
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.wpchat-msg.user .bubble {
  background: var(--wpchat-primary);
  color: var(--wpchat-white);
  border-bottom-right-radius: 4px;
}

.wpchat-msg.agent .bubble { 
  background: var(--wpchat-white) !important;
  color: var(--wpchat-gray-800);
  border: 1px solid var(--wpchat-gray-200);
  border-bottom-left-radius: 4px;
}

.wpchat-msg .meta { 
  font-size: 11px;
  color: var(--wpchat-gray-500);
  margin-top: 4px;
  padding: 0 4px;
}

.wpchat-msg.sending {
  opacity: 0.5;
}

/* Modern Composer */
.wpchat-composer { 
  padding: 16px;
  border-top: 1px solid var(--wpchat-gray-200);
  background: var(--wpchat-white);
  flex-shrink: 0; /* Prevent composer from shrinking */
  position: relative;
  z-index: 1;
}

.wpchat-input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  background: var(--wpchat-gray-50);
  border: 1px solid var(--wpchat-gray-200);
  border-radius: 24px;
  transition: border-color 0.2s ease;
}

.wpchat-input-container:focus-within {
  border-color: var(--wpchat-primary);
  box-shadow: 0 0 0 3px var(--wpchat-primary-light);
}

.wpchat-composer textarea { 
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  font-family: inherit;
}

.wpchat-send-btn {
  background: var(--wpchat-primary) !important;
  color: var(--wpchat-white) !important;
  border: none !important;
  border-radius: 50% !important;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
  flex-shrink: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  text-decoration: none !important;
  font-size: 14px !important;
  line-height: 1 !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
}

.wpchat-send-btn:hover {
  background: var(--wpchat-primary-hover);
  transform: scale(1.05);
}

.wpchat-send-btn:disabled {
  background: var(--wpchat-gray-300);
  cursor: not-allowed;
  transform: none;
}

/* Modern Modal */
.wpchat-modal { 
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: modalAppear 0.3s ease-out;
}

.wpchat-modal[hidden] { 
  display: none !important; 
}

@keyframes modalAppear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.wpchat-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.wpchat-modal-dialog { 
  position: relative;
  background: var(--wpchat-white);
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--wpchat-shadow-xl);
  animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.wpchat-modal-header {
  text-align: center;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--wpchat-gray-100);
}

.wpchat-modal-icon {
  color: var(--wpchat-primary);
  margin-bottom: 12px;
}

.wpchat-modal-header h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  color: var(--wpchat-gray-800);
}

.wpchat-modal-subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--wpchat-gray-500);
}

.wpchat-guest-form {
  padding: 24px;
}

.wpchat-form-group { 
  margin-bottom: 20px;
}

.wpchat-form-group label { 
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--wpchat-gray-600);
}

.wpchat-form-group svg {
  color: var(--wpchat-gray-500);
}

.wpchat-form-group input { 
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--wpchat-gray-200);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.wpchat-form-group input:focus {
  outline: none;
  border-color: var(--wpchat-primary);
  box-shadow: 0 0 0 3px var(--wpchat-primary-light);
}

.wpchat-modal-actions {
  margin-top: 24px;
}

.wpchat-btn-primary { 
  width: 100%;
  background: var(--wpchat-primary);
  color: var(--wpchat-white);
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.2s ease;
}

.wpchat-btn-primary:hover {
  background: var(--wpchat-primary-hover);
}

/* Admin Inbox Styles */
.wpchat-inbox { 
  display: flex;
  gap: 16px;
  min-height: 600px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.wpchat-inbox-list { 
  width: 350px;
  border: 1px solid var(--wpchat-gray-200);
  border-radius: 8px;
  overflow: hidden;
  background: var(--wpchat-white);
}

.wpchat-inbox-row { 
  padding: 16px;
  border-bottom: 1px solid var(--wpchat-gray-100);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.wpchat-inbox-row:hover { 
  background: var(--wpchat-gray-50);
}

.wpchat-inbox-row:last-child {
  border-bottom: none;
}

.wpchat-inbox-thread { 
  flex: 1;
  border: 1px solid var(--wpchat-gray-200);
  border-radius: 8px;
  background: var(--wpchat-white);
  display: flex;
  flex-direction: column;
}

/* Toolbar buttons common styles (moved from inline PHP) */
.wpchat-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 8px;
  padding: 0 8px;
  flex-shrink: 0;
  border-top: 1px solid var(--wpchat-gray-200);
  padding: 8px 16px;
  background: var(--wpchat-white);
}

.wp-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--wpchat-white);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
  font-size: 13px;
}
.wp-btn svg { display: block; }
.wp-btn:hover { transform: translateY(-1px); }

/* Optional primary modifier for actions that should use brand color */
.wp-btn.primary { background: var(--wpchat-primary); color: var(--wpchat-white); border-color: var(--wpchat-primary); }
.wp-btn.primary:hover { background: var(--wpchat-primary-hover); }

/* Enhanced responsive behavior */
@media (max-width: 480px) {
  .wpchat-widget {
    right: 16px;
    bottom: 16px;
  }
  
  .wpchat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    max-width: 380px;
    min-height: 300px;
    max-height: calc(100vh - 120px);
  }
  
  .wpchat-toggle-text {
    display: none;
  }
  
  .wpchat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
  }
  
  .wpchat-messages {
    padding: 12px;
  }
  
  .wpchat-composer {
    padding: 12px;
  }
}

@media (max-height: 600px) {
  .wpchat-panel {
    height: calc(100vh - 100px);
    max-height: 500px;
  }
}
