/* ========================================
   AI CHAT UTILAJE - STYLESHEET v1.2.1
   Fix scroll automat + responsive
   ======================================== */

/* Widget principal */
/* Ascundere inițială widget */
#ai-chat-widget[hidden] {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
#ai-chat-widget {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  overflow: hidden;
  z-index: 100001;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
  font-size: 14px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Header */
#chat-header {
  background: linear-gradient(135deg, #ef831e 0%, #d96f10 100%);
  color: #fff;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  flex-shrink: 0; /* Important: nu se comprimÄƒ */
}

/* Body - zona mesaje - FIX SCROLL */
#chat-body {
  flex: 1 1 auto; /* Important: permite creÈ™tere È™i scÄƒdere */
  padding: 16px;
  overflow-y: auto; /* Important: scroll vertical */
  overflow-x: hidden;
  background: #fafafa;
  scroll-behavior: smooth;
  min-height: 0; /* Important: permite shrink Ã®n flex */
  /* Fix pentru Safari */
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar custom (webkit) */
#chat-body::-webkit-scrollbar {
  width: 6px;
}
#chat-body::-webkit-scrollbar-track {
  background: #f1f1f1;
}
#chat-body::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
#chat-body::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Mesaje chat */
.chat-message {
  margin-bottom: 12px;
  line-height: 1.5;
  white-space: pre-line;
  word-wrap: break-word;
  word-break: break-word; /* Fix pentru cuvinte lungi */
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.bot {
  background: #fff;
  border: 1px solid #e5e5e5;
  padding: 12px 14px;
  border-radius: 12px 12px 12px 4px;
  max-width: 85%;
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
}

.chat-message.bot a {
  color: #ef831e;
  text-decoration: underline;
  word-break: break-all; /* Fix pentru link-uri lungi */
}

.chat-message.bot a:hover {
  color: #d96f10;
}

.chat-message.user {
  background: linear-gradient(135deg, #eaf4ff 0%, #d9ebff 100%);
  border: 1px solid #b8d9ff;
  padding: 12px 14px;
  border-radius: 12px 12px 4px 12px;
  max-width: 85%;
  margin-left: auto;
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
}

/* Indicator typing */
.typing {
  font-style: italic;
  color: #666;
  margin: 8px 0;
  font-size: 13px;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Buton toggle principal */
#chat-toggle-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #ef831e 0%, #d96f10 100%);
  color: #fff;
  border: 0;
  padding: 16px;
  border-radius: 50%;
  font-size: 24px;
  z-index: 100002;
  box-shadow: 0 6px 20px rgba(239, 131, 30, .4);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-toggle-button:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 24px rgba(239, 131, 30, .5);
}

#chat-toggle-button:active {
  transform: scale(0.95);
}

#chat-toggle-button:focus {
  outline: 3px solid #ef831e;
  outline-offset: 4px;
}

/* Sugestii */
.chat-suggestions {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5e5e5;
  background: #fff;
  flex-wrap: wrap;
  flex-shrink: 0; /* Important: nu se comprimÄƒ */
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.suggestion-btn {
  background: #f5f5f5;
  border: 1px solid #ddd;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.suggestion-btn:hover {
  background: #ef831e;
  color: #fff;
  border-color: #ef831e;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(239, 131, 30, .3);
}

.suggestion-btn:focus {
  outline: 2px solid #ef831e;
  outline-offset: 2px;
}

.suggestion-btn:active {
  transform: translateY(0);
}

/* Input wrap */
.chat-input-wrap {
  display: flex;
  align-items: center;
  border-top: 1px solid #e5e5e5;
  background: #fff;
  padding: 8px;
  flex-shrink: 0; /* Important: nu se comprimÄƒ */
}

#chat-input {
  flex: 1;
  border: 1px solid #e5e5e5;
  padding: 12px 14px;
  outline: 0;
  font-size: 14px;
  border-radius: 20px;
  margin-right: 8px;
  font-family: inherit;
  transition: border-color 0.2s ease;
  resize: none; /* Previne resize manual */
}

#chat-input:focus {
  border-color: #ef831e;
  box-shadow: 0 0 0 3px rgba(239, 131, 30, .1);
}

#chat-send-btn {
  background: linear-gradient(135deg, #ef831e 0%, #d96f10 100%);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(239, 131, 30, .3);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

#chat-send-btn:hover {
  background: linear-gradient(135deg, #d96f10 0%, #c25e0a 100%);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(239, 131, 30, .4);
}

#chat-send-btn:active {
  transform: scale(0.95);
}

#chat-send-btn:focus {
  outline: 2px solid #ef831e;
  outline-offset: 2px;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Mobile landscape și tablete mici */
@media (max-width: 768px) {
  #ai-chat-widget {
    bottom: 70px;
    right: 10px;
    width: calc(100vw - 20px);
    height: 500px;
    max-height: calc(100vh - 90px);
  }

  #chat-toggle-button {
    bottom: 10px;
    right: 10px;
    width: 56px;
    height: 56px;
    font-size: 22px;
  }

  .chat-suggestions {
    padding: 8px;
    gap: 6px;
  }

  .suggestion-btn {
    font-size: 12px;
    padding: 7px 12px;
  }

  #chat-input {
    font-size: 16px; /* Previne zoom pe iOS */
    padding: 12px 14px;
  }

  #chat-body {
    padding: 14px;
  }

  .chat-message {
    font-size: 14px;
  }
}


/* Mobile portrait mic */
@media (max-width: 480px) {
  #ai-chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height - iOS fix */
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  /* Ascunde butonul toggle când chatul e deschis pe mobile */
  #ai-chat-widget:not([hidden]) ~ #chat-toggle-button {
    display: none !important;
  }

  #chat-header {
    padding: 14px 16px;
    font-size: 15px;
  }

  #chat-body {
    padding: 10px;
  }

  .chat-message {
    font-size: 14px;
    margin-bottom: 10px;
  }

  .chat-message.bot,
  .chat-message.user {
    max-width: 92%;
    padding: 10px 12px;
  }

  /* Sugestii mai compacte pe mobile */
  .chat-suggestions {
    padding: 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .suggestion-btn {
    font-size: 11px;
    padding: 6px 10px;
    flex: 1 1 auto;
    min-width: calc(50% - 3px);
    text-align: center;
  }

  /* Input mai mare pentru touch */
  #chat-input {
    font-size: 16px !important; /* Previne zoom pe iOS */
    padding: 14px 16px;
  }

  #chat-send-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .chat-input-wrap {
    padding: 10px;
  }
}
/* Telefoane foarte mici (iPhone SE, etc) */
@media (max-width: 375px) {
  #chat-header {
    padding: 12px 14px;
    font-size: 14px;
  }

  .chat-message {
    font-size: 13px;
  }

  .suggestion-btn {
    font-size: 10px;
    padding: 5px 8px;
  }

  #chat-input {
    font-size: 16px;
    padding: 12px 14px;
  }

  #chat-send-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
  #ai-chat-widget {
    background: #1e1e1e;
    box-shadow: 0 10px 40px rgba(0,0,0,.6);
  }

  #chat-body {
    background: #2a2a2a;
  }

  .chat-message.bot {
    background: #333;
    border-color: #444;
    color: #e5e5e5;
  }

  .chat-message.user {
    background: linear-gradient(135deg, #2a4a6a 0%, #1e3a5a 100%);
    border-color: #3a5a7a;
    color: #e5e5e5;
  }

  .chat-suggestions {
    background: #1e1e1e;
    border-top-color: #444;
  }

  .suggestion-btn {
    background: #333;
    border-color: #444;
    color: #e5e5e5;
  }

  .chat-input-wrap {
    background: #1e1e1e;
    border-top-color: #444;
  }

  #chat-input {
    background: #333;
    border-color: #444;
    color: #e5e5e5;
  }

  #chat-input::placeholder {
    color: #999;
  }

  #chat-body::-webkit-scrollbar-track {
    background: #2a2a2a;
  }

  #chat-body::-webkit-scrollbar-thumb {
    background: #555;
  }
}

/* Reducere animaÈ›ii */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  #chat-body {
    scroll-behavior: auto;
  }
}

/* Print styles */
@media print {
  #ai-chat-widget,
  #chat-toggle-button {
    display: none !important;
  }
}
/* Mobile în landscape orientation */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #ai-chat-widget {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    width: 100%;
  }

  #ai-chat-widget:not([hidden]) ~ #chat-toggle-button {
    display: none !important;
  }

  #chat-body {
    padding: 8px;
  }

  .chat-suggestions {
    padding: 6px;
  }

  .suggestion-btn {
    font-size: 11px;
    padding: 5px 10px;
  }
}
/* Fix pentru iPhone notch */
/* Fix pentru iPhone notch și safe areas */
@supports (padding: max(0px)) {
  @media (max-width: 480px) {
    #ai-chat-widget {
      padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .chat-input-wrap {
      padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
  }
}