/*
  Base styling for the Orange chatbot UI.
  The design takes inspiration from the orange.ma colour palette: a bold orange accent contrasted against
  dark neutrals. The layout is responsive and adapts gracefully to different screen sizes.
*/

/* CSS variables for easy theme adjustments */
:root {
  --orange-color: #ff7900; /* primary Orange brand colour */
  --orange-hover: #e06a00; /* slightly darker shade for hover states */
  --black-color: #000000;
  --assistant-bg: #f7f7f7; /* light grey for assistant bubbles */
  --user-bg: var(--orange-color);
  --border-radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Open Sans', sans-serif;
  background-color: #fafafa;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  color: #333;
}

.chat-app {
  width: 100%;
  max-width: 700px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid #ddd;
  border-radius: var(--border-radius);
  background-color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* Header styling */
.chat-header {
  background-color: var(--black-color);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
}

.chat-header .logo {
  width: 28px;
  height: 28px;
  margin-right: 12px;
  border-radius: 4px;
}

.chat-header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

/* Container that holds messages and input */
#chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* Messages scroll area */
#messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: #fff;
}

/* Individual message wrapper */
.message {
  margin-bottom: 12px;
  display: flex;
}

/* Align bubbles based on sender */
.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

/* Speech bubble styling */
.message .bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
  word-break: break-word;
}

.message.user .bubble {
  background-color: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 0;
}

.message.assistant .bubble {
  background-color: var(--assistant-bg);
  color: #222;
  border-bottom-left-radius: 0;
}

/* Styling pour les listes */
.message .bubble ul {
  list-style-type: disc;
  margin: 8px 0;
  padding-left: 20px;
}

.message .bubble li {
  margin: 4px 0;
  line-height: 1.6;
}

/* Styling pour les paragraphes */
.message .bubble p {
  margin: 8px 0;
  line-height: 1.6;
}

.message .bubble p:first-child {
  margin-top: 0;
}

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

/* Styling pour strong/bold */
.message .bubble strong {
  font-weight: 600;
  color: #000;
}

/* Styling pour les liens */
.message .bubble a {
  color: #ff7900;
  text-decoration: underline;
}

.message .bubble a:hover {
  color: #e06a00;
}

/* Input form styling */
#input-form {
  display: flex;
  border-top: 1px solid #eee;
  padding: 12px 16px;
  background-color: #fafafa;
}

#input-form input {
  flex: 1;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: var(--border-radius) 0 0 var(--border-radius);
  outline: none;
}

#input-form input::placeholder {
  color: #999;
}

#input-form button {
  background-color: var(--orange-color);
  color: #fff;
  border: none;
  padding: 0 20px;
  font-size: 1rem;
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#input-form button:hover {
  background-color: var(--orange-hover);
}

#input-form button:disabled {
  background-color: #d9d9d9;
  cursor: default;
}

/* Typing indicator animation */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  margin: 8px 0;
  justify-content: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background-color: var(--orange-color);
  border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

/* Typing indicator in message bubble */
.message.assistant .bubble span {
  width: 8px;
  height: 8px;
  background-color: var(--orange-color);
  border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s infinite ease-in-out;
  margin: 0 2px;
}

.message.assistant .bubble span:nth-child(1) {
  animation-delay: 0s;
}

.message.assistant .bubble span:nth-child(2) {
  animation-delay: 0.2s;
}

/* Streaming cursor animation */
.streaming-cursor {
  display: inline-block;
  animation: blink 1s infinite;
  font-weight: bold;
  color: var(--orange-color);
  margin-left: 2px;
}

@keyframes blink {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

/* Smooth streaming animation */
.message.assistant .bubble {
  transition: all 0.1s ease-out;
}

/* Streaming message specific styling */
#streaming-message .bubble {
  position: relative;
  overflow: hidden;
}

/* Pulse effect for streaming */
@keyframes streamPulse {
  0% { opacity: 0.8; }
  50% { opacity: 1; }
  100% { opacity: 0.8; }
}

.message.assistant.streaming .bubble {
  animation: streamPulse 2s infinite;
}

/* Bot message styling for streaming */
.message.bot .bubble {
  background-color: var(--assistant-bg);
  color: #222;
  border-bottom-left-radius: 0;
}

/* Text formatting - preserve line breaks and format lists */
.message .bubble {
  line-height: 1.6;
}

/* Only apply pre-wrap to raw text, not markdown-rendered content */
.message .bubble:not(.markdown-rendered) {
  white-space: pre-wrap;
}

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

.message .bubble li {
  margin: 4px 0;
  line-height: 1.5;
  display: list-item;
  padding: 1px 0;
}

.message .bubble p {
  margin: 8px 0;
  line-height: 1.5;
}

/* Force proper spacing for markdown content */
.message .bubble.markdown-rendered p {
  margin: 8px 0;
}

.message .bubble.markdown-rendered ul {
  margin: 8px 0;
}

.message .bubble.markdown-rendered li {
  margin: 4px 0;
  padding: 2px 0;
}

/* Better spacing for structured content */
.message .bubble h3, .message .bubble h4, .message .bubble h5, .message .bubble h6 {
  margin: 16px 0 8px 0;
  color: #333;
  font-weight: 600;
}

.message .bubble blockquote {
  margin: 12px 0;
  padding: 8px 16px;
  background-color: rgba(255, 121, 0, 0.1);
  border-left: 3px solid var(--orange-color);
  border-radius: 4px;
}

.message .bubble a {
  color: var(--orange-color);
  text-decoration: none;
}

.message .bubble a:hover {
  text-decoration: underline;
}

/* Additional list styling */
.message .bubble ul li {
  list-style-type: disc;
}

.message .bubble ol li {
  list-style-type: decimal;
}

.message .bubble strong {
  font-weight: 600;
  color: #333;
  display: block;
  margin: 8px 0 4px 0;
}

.message .bubble em {
  font-style: italic;
  color: #555;
}

/* Special spacing for question lists */
.message .bubble.markdown-rendered li strong {
  display: inline;
  margin: 0;
}

/* Styling pour les listes générées par marked.js */
.message .bubble ul {
    list-style-type: disc;
    margin: 10px 0;
    padding-left: 25px;
}

.message .bubble ol {
    list-style-type: decimal;
    margin: 10px 0;
    padding-left: 25px;
}

.message .bubble li {
    margin: 5px 0;
    line-height: 1.6;
}

/* Sous-listes (imbriquées) */
.message .bubble ul ul {
    list-style-type: circle;
    margin: 5px 0;
    padding-left: 25px;
}

.message .bubble ul ul ul {
    list-style-type: square;
    margin: 5px 0;
    padding-left: 25px;
}

/* Paragraphes dans les messages */
.message .bubble p {
    margin: 8px 0;
    line-height: 1.6;
}

.message .bubble p:first-child {
    margin-top: 0;
}

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

/* Strong (bold) */
.message .bubble strong {
    font-weight: 600;
    color: #000;
}

/* Liens */
.message .bubble a {
    color: #ff7900;
    text-decoration: underline;
}

.message .bubble a:hover {
    color: #e06a00;
}

/* Classes pour les listes personnalisées */
.message .bubble .main-list {
    list-style-type: disc;
    margin: 10px 0;
    padding-left: 20px;
}

.message .bubble .sub-list {
    list-style-type: circle;
    margin: 5px 0;
    padding-left: 25px;
}

.message .bubble .detail-list {
    list-style-type: square;
    margin: 3px 0;
    padding-left: 30px;
}

.message .bubble .numbered-list {
    list-style-type: decimal;
    margin: 10px 0;
    padding-left: 25px;
}

.message .bubble .main-item {
    margin: 8px 0;
    font-weight: 600;
    color: #000;
    line-height: 1.6;
}

.message .bubble .sub-item {
    margin: 4px 0;
    font-weight: 500;
    color: #ff7900;
    line-height: 1.5;
}

.message .bubble .detail-item {
    margin: 2px 0;
    font-weight: normal;
    color: #333;
    line-height: 1.4;
}

.message .bubble .numbered-item {
    margin: 6px 0;
    font-weight: 500;
    color: #000;
    line-height: 1.6;
}

/* Phrases de conclusion */
.message .bubble .conclusion-text {
    margin: 15px 0 8px 0;
    font-style: italic;
    color: #666;
    line-height: 1.5;
    border-left: 3px solid #ff7900;
    padding-left: 15px;
}

/* Liens dans les messages */
.message .bubble .chat-link {
    color: #ff7900;
    text-decoration: underline;
    font-weight: 500;
}

.message .bubble .chat-link:hover {
    color: #e06a00;
    text-decoration: none;
}

/* Typing dots inside message bubble */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dots .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #ff7900;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}