/* Support Chat - Styles principaux */

:root {
  /* Variables CSS personnalisables */
  --sc-bg: #ffffff;
  --sc-text: #333333;
  --sc-accent: #007cba;
  --sc-accent-hover: #005a87;
  --sc-bubble-user: #007cba;
  --sc-bubble-bot: #f1f1f1;
  --sc-border: #e1e1e1;
  --sc-radius: 12px;
  --sc-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --sc-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --sc-font-size: 14px;
  --sc-line-height: 1.5;
  --sc-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mode sombre automatique */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --sc-bg: #1a1a1a;
    --sc-text: #ffffff;
    --sc-accent: #4a9eff;
    --sc-accent-hover: #2d7dd2;
    --sc-bubble-user: #4a9eff;
    --sc-bubble-bot: #2a2a2a;
    --sc-border: #404040;
    --sc-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  }
}

/* Thème sombre forcé */
.support-chat-widget[data-theme="dark"] {
  --sc-bg: #1a1a1a;
  --sc-text: #ffffff;
  --sc-accent: #4a9eff;
  --sc-accent-hover: #2d7dd2;
  --sc-bubble-user: #4a9eff;
  --sc-bubble-bot: #2a2a2a;
  --sc-border: #404040;
  --sc-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Thème clair forcé */
.support-chat-widget[data-theme="light"] {
  --sc-bg: #ffffff;
  --sc-text: #333333;
  --sc-accent: #007cba;
  --sc-accent-hover: #005a87;
  --sc-bubble-user: #007cba;
  --sc-bubble-bot: #f1f1f1;
  --sc-border: #e1e1e1;
  --sc-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Transition fluide pour les changements de thème */
.support-chat-widget * {
  transition: background-color var(--sc-transition), 
              color var(--sc-transition), 
              border-color var(--sc-transition), 
              box-shadow var(--sc-transition);
}

/* Reset et base */
.support-chat-widget {
  font-family: var(--sc-font);
  font-size: var(--sc-font-size);
  line-height: var(--sc-line-height);
  color: var(--sc-text);
}

/* Widget flottant */
.support-chat-widget.floating {
  position: fixed;
  z-index: 999999;
}

.support-chat-widget.floating[data-position="bottom-right"] {
  bottom: 20px;
  right: 20px;
}

.support-chat-widget.floating[data-position="bottom-left"] {
  bottom: 20px;
  left: 20px;
}

/* Widget inline */
.support-chat-widget.inline {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 20px auto;
}

/* Launcher (bouton flottant) */
.support-chat-launcher {
  width: 60px;
  height: 60px;
  background: var(--sc-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--sc-shadow);
  transition: var(--sc-transition);
  color: white;
  border: none;
  outline: none;
}

.support-chat-launcher:hover,
.support-chat-launcher:focus {
  background: var(--sc-accent-hover);
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.support-chat-launcher:focus {
  outline: 2px solid var(--sc-accent);
  outline-offset: 2px;
}

/* Interface principale */
.support-chat-interface {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  max-height: 500px;
  background: var(--sc-bg);
  border-radius: var(--sc-radius);
  box-shadow: var(--sc-shadow);
  border: 1px solid var(--sc-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--sc-transition);
}

.support-chat-widget[data-position="bottom-left"] .support-chat-interface {
  right: auto;
  left: 0;
}

.support-chat-widget.inline .support-chat-interface {
  position: relative;
  bottom: auto;
  right: auto;
  left: auto;
  width: 100%;
  max-height: 600px;
}

/* Header */
.support-chat-header {
  background: var(--sc-accent);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--sc-radius) var(--sc-radius) 0 0;
}

.support-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.support-chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: var(--sc-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.support-chat-close:hover,
.support-chat-close:focus {
  background: rgba(255, 255, 255, 0.2);
  outline: none;
}

/* Zone des messages */
.support-chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  max-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.support-chat-widget.inline .support-chat-messages {
  max-height: 400px;
}

/* Message individuel */
.support-chat-message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

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

.support-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sc-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.support-chat-message.user .support-chat-avatar {
  background: var(--sc-bubble-user);
}

.support-chat-message.bot .support-chat-avatar {
  background: var(--sc-bubble-bot);
  color: var(--sc-text);
}

.support-chat-bubble {
  background: var(--sc-bubble-bot);
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 80%;
  word-wrap: break-word;
  line-height: 1.4;
}

.support-chat-message.user .support-chat-bubble {
  background: var(--sc-bubble-user);
  color: white;
}

/* Support Markdown dans les bulles */
.support-chat-bubble h1,
.support-chat-bubble h2,
.support-chat-bubble h3,
.support-chat-bubble h4,
.support-chat-bubble h5,
.support-chat-bubble h6 {
  margin: 0 0 8px 0;
  font-size: 1.1em;
  font-weight: 600;
}

.support-chat-bubble p {
  margin: 0 0 8px 0;
}

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

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

.support-chat-bubble li {
  margin: 4px 0;
}

.support-chat-bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9em;
}

.support-chat-bubble pre {
  background: rgba(0, 0, 0, 0.1);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.support-chat-bubble pre code {
  background: none;
  padding: 0;
}

.support-chat-bubble a {
  color: inherit;
  text-decoration: underline;
}

.support-chat-bubble blockquote {
  border-left: 3px solid var(--sc-accent);
  margin: 8px 0;
  padding-left: 12px;
  font-style: italic;
}

/* Sources */
.support-chat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--sc-border);
  font-size: 0.9em;
  opacity: 0.8;
}

.support-chat-sources-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.support-chat-source {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: 4px 0;
  border-radius: 4px;
  transition: var(--sc-transition);
}

.support-chat-source:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Timestamp */
.support-chat-timestamp {
  font-size: 0.8em;
  opacity: 0.6;
  margin-top: 4px;
  text-align: center;
}

/* Composer (zone de saisie) */
.support-chat-composer {
  padding: 20px;
  border-top: 1px solid var(--sc-border);
  background: var(--sc-bg);
}

/* Champ email */
.support-chat-email {
  margin-bottom: 12px;
}

.support-chat-email-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--sc-border);
  border-radius: 6px;
  background: var(--sc-bg);
  color: var(--sc-text);
  font-size: 14px;
  transition: var(--sc-transition);
}

.support-chat-email-input:focus {
  outline: none;
  border-color: var(--sc-accent);
  box-shadow: 0 0 0 3px rgba(0, 123, 186, 0.1);
}

/* Zone de saisie du message */
.support-chat-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.support-chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--sc-border);
  border-radius: 6px;
  background: var(--sc-bg);
  color: var(--sc-text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  transition: var(--sc-transition);
  line-height: 1.4;
}

.support-chat-input:focus {
  outline: none;
  border-color: var(--sc-accent);
  box-shadow: 0 0 0 3px rgba(0, 123, 186, 0.1);
}

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

/* Bouton d'envoi */
.support-chat-send {
  width: 40px;
  height: 40px;
  background: var(--sc-accent);
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--sc-transition);
  flex-shrink: 0;
}

.support-chat-send:hover,
.support-chat-send:focus {
  background: var(--sc-accent-hover);
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 123, 186, 0.1);
}

.support-chat-send:disabled {
  background: var(--sc-border);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Bouton d'escalade */
.support-chat-escalate {
  margin-top: 12px;
  text-align: center;
}

.support-chat-ticket-btn {
  background: none;
  border: 1px solid var(--sc-accent);
  color: var(--sc-accent);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: var(--sc-transition);
  text-decoration: none;
  display: inline-block;
}

.support-chat-ticket-btn:hover,
.support-chat-ticket-btn:focus {
  background: var(--sc-accent);
  color: white;
  outline: none;
}

/* États de chargement */
.support-chat-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.7;
}

.support-chat-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--sc-border);
  border-top: 2px solid var(--sc-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* États d'erreur */
.support-chat-error {
  background: #fee;
  color: #c33;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid #fcc;
  margin: 8px 0;
  font-size: 0.9em;
}

/* États de succès */
.support-chat-success {
  background: #d4edda;
  color: #155724;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid #c3e6cb;
  margin: 8px 0;
  font-size: 0.9em;
}

/* États d'information */
.support-chat-info {
    background: #d1ecf1;
    color: #0c5460;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #bee5eb;
    margin: 8px 0;
    font-size: 0.9em;
}

/* Styles pour l'interface admin */
.required {
    color: #dc3232;
    font-weight: bold;
}

.spinner.is-active {
    visibility: visible;
}

.spinner {
    visibility: hidden;
    float: none;
    margin-left: 10px;
}

/* Amélioration de l'accessibilité */
.support-chat-widget [role="button"]:focus,
.support-chat-widget button:focus,
.support-chat-widget input:focus,
.support-chat-widget textarea:focus {
    outline: 2px solid var(--sc-accent);
    outline-offset: 2px;
}

/* Support pour les lecteurs d'écran */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Amélioration des contrastes pour l'accessibilité */
.support-chat-bubble {
    background: var(--sc-bubble-bot);
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.4;
    /* Amélioration du contraste */
    border: 1px solid var(--sc-border);
}

.support-chat-message.user .support-chat-bubble {
    background: var(--sc-bubble-user);
    color: white;
    border: 1px solid var(--sc-bubble-user);
}

/* Amélioration de la lisibilité sur mobile */
@media (max-width: 480px) {
    .support-chat-bubble {
        font-size: 16px; /* Évite le zoom sur iOS */
        line-height: 1.5;
    }
    
    .support-chat-input {
        font-size: 16px; /* Évite le zoom sur iOS */
    }
}

/* Bouton stop pour le streaming */
.support-chat-stop {
  background: #dc3545;
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  margin-left: 8px;
}

.support-chat-stop:hover {
  background: #c82333;
}

/* Responsive */
@media (max-width: 480px) {
  .support-chat-widget.floating {
    bottom: 10px;
    right: 10px;
  }
  
  .support-chat-widget.floating[data-position="bottom-left"] {
    left: 10px;
  }
  
  .support-chat-interface {
    width: calc(100vw - 20px);
    max-width: 350px;
    bottom: 70px;
    right: 0;
    max-height: calc(100vh - 100px);
  }
  
  .support-chat-widget[data-position="bottom-left"] .support-chat-interface {
    left: 0;
    right: auto;
  }
  
  .support-chat-messages {
    max-height: 250px;
  }
  
  .support-chat-composer {
    padding: 15px;
  }
}

/* Accessibilité */
.support-chat-widget:focus-within {
  outline: 2px solid var(--sc-accent);
  outline-offset: 2px;
}

.support-chat-widget [role="button"]:focus,
.support-chat-widget button:focus {
  outline: 2px solid var(--sc-accent);
  outline-offset: 2px;
}

/* Animation d'entrée */
.support-chat-interface {
  animation: slideIn 0.3s ease-out;
}

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

/* Support pour les lecteurs d'écran */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* États offline */
.support-chat-offline {
  background: #fff3cd;
  color: #856404;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #ffeaa7;
  margin: 8px 0;
  font-size: 0.9em;
  text-align: center;
}

/* Copier dans le presse-papiers */
.support-chat-copy {
  background: none;
  border: none;
  color: var(--sc-accent);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-top: 4px;
  transition: var(--sc-transition);
}

.support-chat-copy:hover {
  background: rgba(0, 123, 186, 0.1);
}

/* Réédition de message */
.support-chat-reask {
  background: none;
  border: none;
  color: var(--sc-accent);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-top: 4px;
  transition: var(--sc-transition);
}

.support-chat-reask:hover {
  background: rgba(0, 123, 186, 0.1);
}
