/* frontend/style.css */

/* --- CORRECTED FONT DEFINITIONS --- */
/* We define ONE font family 'Muni' and tell the browser which file to use for which weight. */
@font-face {
  font-family: "Muni";
  src: url("/fonts/Muni-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: "Muni";
  src: url("/fonts/Muni-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
}
@font-face {
  font-family: "Muni";
  src: url("/fonts/Muni-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
}
@font-face {
  font-family: "Muni";
  src: url("/fonts/Muni-Light.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
}
/* --- END OF CORRECTIONS --- */

body {
  /* This uses the system font, which is fine for the main text */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background-color: #f4f7f6;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  color: #333;
}

.chat-container {
  width: 100%;
  max-width: 800px;
  height: 90vh;
  max-height: 950px;
  background-color: #fff;
  border-radius: 8px; /* Slightly less rounded corners */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e0e0e0; /* Added a subtle border */
}

/* Modify chat-header to support flex layout */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left; /* Override previous center alignment */
  background-color: #fff;
  color: #000;
  padding: 20px;
  border-bottom: 1px solid #eee;
}

/* Header content container */
.header-content {
  flex: 1;
}

.chat-header h2 {
  margin: 0;
  font-size: 1.6rem; /* Made it larger */
  /* FIXED: Use the single 'Muni' family and specify the weight */
  font-family: "Muni", sans-serif;
  font-weight: 700; /* This tells the browser to use the bold woff2 file */
}

.chat-header p {
  margin: 4px 0 0;
  font-size: 1rem; /* Slightly larger */
  opacity: 0.7;
}

/* New styles for the language selector */
.lang-selector button {
  background: none;
  border: none;
  color: #555;
  padding: 4px 8px;
  margin-left: 5px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s, color 0.2s, background-color 0.2s;
  font-family: "Muni", sans-serif;
  font-size: 1rem;
}

.lang-selector button.active {
  opacity: 1;
  color: #0000dc;
  font-family: "Muni", sans-serif;
  font-weight: 700;
  background-color: transparent;
}

.lang-selector button:hover:not(.active) {
  background-color: #f5f5f5;
  opacity: 1;
}

.chat-box {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.message-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 95%; /* Adjust to make space for buttons */
}

.message-wrapper.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-wrapper.bot {
  align-self: flex-start;
}

.message {
  padding: 12px 18px;
  border-radius: 18px;
  max-width: 100%;
  line-height: 1.4;
  font-size: 1.05rem;
}

.message.user {
  background-color: #0000dc;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.bot {
  background-color: #e9ecef;
  color: #333;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.bot b,
.message.user b {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: #555;
}
.bot-text {
  display: inline-block;
}

.message.user b {
  color: #f0f0f0;
  opacity: 0.8;
}

.feedback-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feedback-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, transform 0.1s;
}

.feedback-btn:hover {
  background-color: #f0f0f0;
  transform: scale(1.1);
}

.feedback-container.feedback-sent .feedback-btn {
  pointer-events: none; /* Disable further clicks */
  border-color: #ddd;
}

.suggestions-box {
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid #eee;
}

.suggestions-box button {
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.suggestions-box button:hover {
  background-color: #f5f5f5;
  border-color: #0000dc;
}

.chat-input-area {
  display: flex;
  padding: 20px;
  border-top: 1px solid #eee;
  background-color: #fcfcfc;
}

#user-input {
  flex-grow: 1;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 12px 18px;
  font-size: 1.1rem;
  outline: none;
}
#user-input:focus {
  border-color: #0000dc;
}

#send-btn,
#suggest-btn {
  margin-left: 8px;
  padding: 0 22px;
  border: none;
  border-radius: 4px;
  background-color: #0000dc;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
  letter-spacing: 0.5px;
}
#send-btn {
  /* FIXED: Use the 'Muni' family. Since you don't have a 'muni-medium' file,
       a weight of 500 will use the regular font and ask the browser to make it slightly bolder. */
  font-family: "Muni", sans-serif;
  font-weight: 500;
  text-transform: uppercase;
}
#send-btn:hover {
  background-color: #0000b3;
}
#suggest-btn {
  background-color: #f0f0f0;
  color: #333;
  font-size: 1.3rem;
  padding: 0 16px;
}
#suggest-btn:hover {
  background-color: #e0e0e0;
}

/* Loading indicator styles */
.message.bot .typing-indicator {
  display: flex;
  align-items: center;
  padding: 5px 0;
}

.message.bot .typing-indicator span {
  height: 10px;
  width: 10px;
  background-color: #8e8e8e;
  border-radius: 50%;
  display: inline-block;
  margin: 0 2px;
  animation: bounce 1.2s infinite ease-in-out both;
}

.message.bot .typing-indicator span:nth-of-type(1) {
  animation-delay: -0.32s;
}

.message.bot .typing-indicator span:nth-of-type(2) {
  animation-delay: -0.16s;
}

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

/* Collapsible Metadata (Sources and Confidence) */
.metadata-details {
    margin-top: 15px;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.metadata-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: #555;
    list-style: none; /* Remove default arrow */
    padding: 5px 0;
}

.metadata-summary::-webkit-details-marker {
    display: none; /* Remove default arrow for Chrome */
}

.metadata-summary .header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.metadata-summary .chevron {
    transition: transform 0.2s;
    font-size: 0.8rem;
}

.metadata-details[open] .metadata-summary .chevron {
    transform: rotate(180deg);
}

.sources-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    padding-bottom: 5px;
}

.source-pill {
    padding: 6px 14px;
    border-radius: 20px;
    background-color: #eef2ff; /* Light blue background */
    color: #4338ca; /* Dark blue text */
    font-size: 0.85rem;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background-color 0.2s;
}

.source-pill:nth-child(even) {
    background-color: #fff;
    border: 1px solid #ddd;
    color: #666;
}

.source-pill:hover {
    background-color: #e0e7ff;
}

.confidence-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.confidence-label {
    font-weight: 500;
    color: #444;
}

.confidence-badge {
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 700;
}

.confidence-high {
    background-color: #d4edda;
    color: #155724;
}

.confidence-medium {
    background-color: #fff3cd;
    color: #856404;
}

.confidence-low {
    background-color: #f8d7da;
    color: #721c24;
}

/* Suggestion Bubbles below Message */
.suggestions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
    align-items: flex-start;
}

.suggestion-bubble {
    padding: 5px 11px;
    border-radius: 20px;
    background-color: #f0f7ff;
    color: #0000dc;
    font-size: 0.78rem;
    border: 1px solid #d0e7ff;
    cursor: pointer;
    text-align: left;
    max-width: 90%;
    transition: all 0.2s;
}

.suggestion-bubble:hover {
    background-color: #e0e7ff;
    border-color: #0000dc;
    transform: translateY(-1px);
}

.suggestion-bubble:active {
    transform: translateY(0);
}

/* ADD THESE STYLES AT THE END OF style.css */

.message-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 95%; /* Adjust to make space for buttons */
}

.message-wrapper.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-wrapper.bot {
  align-self: flex-start;
}

.message {
  /* max-width is now controlled by the wrapper, so we can set this to 100% or remove it */
  max-width: 100%;
}

.feedback-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feedback-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, transform 0.1s;
}

.feedback-btn:hover {
  background-color: #f0f0f0;
  transform: scale(1.1);
}

.feedback-container.feedback-sent .feedback-btn {
  pointer-events: none; /* Disable further clicks */
  border-color: #ddd;
}

/* In frontend/style.css, add these at the end */

/* Modify chat-header to support flex layout */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left; /* Override previous center alignment */
}

/* Header content styles */

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 600px) {
  .chat-container {
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: none;
  }

  .chat-header {
    padding: 15px;
  }

  .chat-header h2 {
    font-size: 1.3rem;
  }

  .chat-header p {
    font-size: 0.9rem;
  }

  .message {
    font-size: 1rem;
    padding: 10px 14px;
  }

  .chat-input-area {
    padding: 15px;
  }

  .suggestion-bubble {
    font-size: 0.75rem;
    padding: 4px 10px;
  }
}

/* Fix for Collapsible Metadata Rendering */
details.metadata-container {
    display: block;
    width: 100%;
}
summary.metadata-summary {
    display: list-item;
    cursor: pointer;
    outline: none;
}
