@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "IBM Plex Sans", sans-serif;
}

:root {
  /* Dark mode colors */
  --text-color: #FFFFFF;
  --subheading-color: #fff;
  --placeholder-color: #b5b5b5;
  --placeholder-secundary-color: #2a2d3d;
  --primary-color: #0a051a;
  --secondary-color: #171923cc;
  --secondary-hover-color: #171923;
  --brand-color: #d688ff;
  --user-bubble-background: rgba(214, 136, 255, 0.2); /* Light purple for User bubble in dark mode */
  --background-table-odd: #212330;
  --background-table-even: #2a2d3d;
  --table-header-background: #12141c; /* NEW: Darker header for tables */
  --error: #d0345c;
  --feedback-positive-color: #38a169; /* Verde para feedback positivo */
  --input-wrapper-background: rgba(42, 45, 61, 0.7); /* Dark semi-transparent background for input */
  --feedback-negative-color: #e53e3e; /* Rojo para feedback negativo */
}

.light_mode {
  /* Light mode colors */
  --text-color: #000000;
  --subheading-color: #fff;
  --placeholder-color: #6c6c6c;
  --placeholder-secundary-color: #dbdbdb;
  --primary-color: #fff;
  --secondary-color: rgba(225, 225, 227, 0.5); /* Más transparente para el experimento */
  --secondary-hover-color: #e1e1e3;
  --brand-color: #b34be9;
  --user-bubble-background: rgba(179, 75, 233, 0.15); /* Light purple for User bubble in light mode */
  --background-table-odd: #ededed;
  --background-table-even: #dbdbdb;
  --table-header-background: #d0d1d3; /* NEW: Darker header for tables */
  --error: #d0345c;
  --feedback-positive-color: #48bb78; /* Verde más brillante para modo claro */
  --input-wrapper-background: rgba(240, 242, 245, 0.8); /* Light semi-transparent background for input */
  --feedback-negative-color: #f56565; /* Rojo más brillante para modo claro */
}


/* --- NEW LAYOUT STYLES --- */
body {
  background: var(--primary-color);
  min-height: 100vh;
  overflow: hidden; /* El scroll se gestiona en los hijos */
}

/* NEW: Overlay for mobile sidebar */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999; /* Below sidebar, above content */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* NEW: Top right actions */
.top-right-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.top-right-actions .icon {
  color: var(--text-color);
  cursor: pointer;
  font-size: 1.5rem;
  border: none; /* Remove border from settings icon */
  background: transparent; /* Ensure no background box */
}

.user-initials {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--brand-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.sidebar {
  width: 260px;
  background-color: var(--secondary-color);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--placeholder-secundary-color);
  transition: width 0.3s ease;
  flex-shrink: 0;
  /* overflow: hidden; <-- REMOVED: This was hiding the project dropdown */
}

.sidebar-top {
  display: flex; /* Changed to flex */
  flex-direction: column; /* Stack logo and button */
  align-items: flex-start;
  padding: 1rem;
  text-align: center; /* Center the logo */
  flex-shrink: 0;
  gap: 1rem; /* Space between logo and button */
}

.sidebar-logo {
  font-family: 'IBM Plex Sans', sans-serif; /* Or a more specific font if you have one */
  font-weight: 300; /* Thin font */
  font-size: 1.8rem;
  color: var(--text-color);
  letter-spacing: 0.3em; /* Spaced out letters */
  margin: 0;
  width: 100%; /* Make it span the full width */
}

.sidebar-logo-collapsed {
  display: none; /* Hide by default */
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 300;
  font-size: 1.8rem;
  color: var(--text-color);
  margin: 0;
  width: 100%;
  text-align: center;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between; /* This will push the expand icon to the right */
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--placeholder-secundary-color);
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s ease;
  /* NEW: Rounded purple border like the image */
  border: 1px solid var(--brand-color);
  border-radius: 8px;
  margin: 0 1rem; /* Add horizontal margin */
}
.sidebar-header:hover, .sidebar-item:hover {
  background-color: var(--secondary-hover-color);
}

.project-selector-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
  flex-grow: 1; /* Allow it to take up space */
  overflow: hidden; /* Prevent content from overflowing */
}

.project-selector-wrapper:hover {
  background-color: var(--secondary-hover-color);
}

.project-selector-wrapper .expand-icon {
  margin-left: auto;
  transition: transform 0.3s ease;
}

.sidebar-header.open .expand-icon {
  transform: rotate(180deg);
}

.project-dropdown {
  display: none; /* Hidden by default */
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 100%;
  background-color: var(--secondary-hover-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 1001; /* Above sidebar overlay (999) and sidebar (1000) */
  max-height: 300px;
  overflow-y: auto;
}

.project-dropdown-item {
  padding: 0.8rem 1.5rem;
  color: var(--text-color);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-dropdown-item:hover {
  background-color: var(--brand-color);
}

.project-initial {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--brand-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
}

.project-name-sidebar {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-color);
  margin: 0;
}

/* --- NEW: Agent Selector Styles --- */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  color: var(--text-color);
  font-weight: 500;
}

.sidebar-item.active {
  color: var(--brand-color);
  font-weight: 600;
}

/* NEW: Fill the star icon when the favorites filter is active */
.sidebar-item.active#starred-conversations-btn .material-symbols-rounded {
  font-variation-settings: 'FILL' 1;
  color: var(--brand-color);
}

.sidebar-item .material-symbols-rounded {
  color: var(--placeholder-color);
}

.agent-dropdown {
  /* Reuses .project-dropdown styles */
  /* This is just a placeholder if you need specific overrides */
}

.agent-selector-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2400; /* Below agent editor, above everything else */
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.agent-selector-overlay.show {
  display: flex;
}

.agent-selector-modal {
  background-color: var(--secondary-hover-color);
  border: 1px solid var(--placeholder-secundary-color);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 80vh;
  animation: fadeInScaleUp 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.agent-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--placeholder-secundary-color);
  flex-shrink: 0;
}

.agent-selector-header #agent-search-input {
  background-color: var(--primary-color);
  border: 1px solid var(--placeholder-secundary-color);
  color: var(--text-color);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  outline: none;
  width: 300px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.agent-selector-header #agent-search-input:focus {
  border-color: var(--brand-color);
  box-shadow: 0 0 0 2px rgba(214, 136, 255, 0.3);
}

.agent-selector-header h3 {
  color: var(--text-color);
  margin: 0;
}

.agent-card-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
  overflow-y: auto;
}

.agent-category-title {
  color: var(--placeholder-color);
  font-size: 0.9rem;
  text-transform: uppercase;
  font-weight: 500;
  margin-bottom: 1rem;
  grid-column: 1 / -1; /* Span across all columns */
}

.agent-card {
  background-color: var(--primary-color);
  border: 1px solid var(--placeholder-secundary-color);
  border-radius: 10px;
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.agent-card:hover {
  transform: translateY(-5px);
  border-color: var(--brand-color);
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.agent-card-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.agent-card-description {
  font-size: 0.9rem;
  color: var(--placeholder-color);
  line-height: 1.4;
}

.agent-dropdown-divider {
  height: 1px;
  background-color: var(--placeholder-secundary-color);
  margin: 0.5rem 0;
}

.manage-agents-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  color: var(--placeholder-color);
}

.agent-selector-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--placeholder-secundary-color);
  display: flex;
  gap: 0.5rem; /* NEW: Add space between footer buttons */
  justify-content: flex-end;
}

.manage-agents-btn {
  background-color: transparent;
  border: 1px solid var(--placeholder-color);
  color: var(--placeholder-color);
  /* Re-uses styles from .new-conversation-btn */
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
}

/* --- NEW: Agent Editor Form Styles --- */
.agent-editor-form {
    display: flex;
    flex-direction: column;
    gap: 1rem; /* Space between form groups */
}

.agent-editor-form .form-label-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: -0.5rem; /* Pull the input closer */
}

.agent-editor-form label .required-asterisk {
    color: var(--error);
    margin-left: 4px;
    font-weight: bold;
}

.agent-editor-form .icon-button {
    background: none;
    border: none;
    color: var(--placeholder-color);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
}

.agent-editor-form .icon-button:not(:disabled):hover {
    background-color: var(--secondary-hover-color);
    color: var(--brand-color);
}


.agent-editor-form label {
    font-weight: 500;
    color: var(--placeholder-color);
    font-size: 0.9rem;
    margin-bottom: -0.5rem; /* Pull the input closer to the label */
}

.agent-editor-form input[type="text"],
.agent-editor-form textarea {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--placeholder-secundary-color);
    background-color: var(--primary-color);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.agent-editor-form input[type="text"]:focus,
.agent-editor-form textarea:focus {
    border-color: var(--brand-color);
    box-shadow: 0 0 0 2px rgba(214, 136, 255, 0.3);
}

.agent-editor-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
}

/* --- NEW: Agent Editor List Styles --- */
.agent-editor-content {
    overflow-y: auto;
    padding: 1rem;
    flex-grow: 1;
}

.agent-editor-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.agent-editor-item:not(:last-child) {
    border-bottom: 1px solid var(--placeholder-secundary-color);
}

.agent-editor-item:hover {
    background-color: var(--secondary-hover-color);
}

.agent-item-details {
    flex-grow: 1;
    overflow: hidden;
}

.agent-item-name {
    color: var(--text-color);
    font-weight: 500;
}

.agent-item-description {
    color: var(--placeholder-color);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-item-actions {
    display: flex;
    gap: 0.5rem;
}

.agent-action-btn {
    background: none;
    border: none;
    color: var(--placeholder-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
}

.agent-action-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

.agent-action-btn.delete:hover {
    color: var(--error);
}

/* Botón de toggle del menú (posición gestionada por JS) */
#toggle-sidebar-btn {
  margin-left: 0.5rem; /* Align with logo */
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 8px; /* Aumentado para un mejor área de clic */
  border-radius: 50%;
  display: flex;
  /* order: 2; /* No longer needed, position is handled by parent container */
}

.sidebar-header-btn:hover {
  background-color: var(--secondary-hover-color);
}

/* NEW: Wrapper for scrollable content */
.sidebar-scrollable-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Prevent this container from scrolling */
}

.sidebar-content {
  padding: 0.5rem 1rem; /* Adjust padding for alignment */
  flex-shrink: 0; /* Prevent this from shrinking */
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 1rem;
  border-top: 1px solid var(--placeholder-secundary-color);
}

.conversations-list-container {
  flex-grow: 1; /* This will take up the available space */
  overflow-y: auto; /* And only this will scroll */
  padding: 0 1rem; /* Horizontal padding */
}

/* NEW: Scrollbar styling for conversations list */
.conversations-list-container::-webkit-scrollbar {
  width: 8px;
}

.conversations-list-container::-webkit-scrollbar-track {
  background: transparent; /* Make track invisible */
}

.conversations-list-container::-webkit-scrollbar-thumb {
  background-color: var(--placeholder-secundary-color);
  border-radius: 10px;
  border: 2px solid var(--secondary-color); /* Creates padding around thumb */
}

.conversations-list-container::-webkit-scrollbar-thumb:hover {
  background-color: var(--placeholder-color);
}

/* For Firefox */
.conversations-list-container {
  scrollbar-width: thin;
  scrollbar-color: var(--placeholder-secundary-color) transparent;
}


.settings-popup {
  display: none; /* Hidden by default */
  position: fixed;
  top: 5rem; /* Position below the gear icon */
  right: 1.5rem;
  width: 300px;
  background-color: var(--secondary-hover-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 102;
  border: 1px solid var(--placeholder-secundary-color);
  overflow: hidden;
}

.settings-popup.show {
  display: block;
}

.settings-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--placeholder-secundary-color);
}

.settings-popup-header h4 {
  color: var(--text-color);
  margin: 0;
}

.settings-popup-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-popup-content .setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-color); /* Ensure text is readable in dark mode */
}
.settings-popup-content .setting-item label {
	color: var(--text-color);
}



.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none; /* Prevent text selection on click */
}

.settings-header:hover {
  background-color: var(--secondary-hover-color);
}

.settings-title {
  color: var(--placeholder-color);
  font-size: 0.9rem;
  margin: 0; /* Remove margin from title */
  text-transform: uppercase;
}

.settings-toggle-icon {
  transition: transform 0.3s ease;
  color: var(--placeholder-color); /* Ensure the icon is visible in both themes */
}

.sidebar-settings.open .settings-toggle-icon {
  transform: rotate(180deg);
}

.sidebar-settings.open .settings-content {
  max-height: 300px; /* Adjust as needed */
  padding-top: 1rem; /* Add padding when open */
}

.sidebar-settings .setting-item.response-length {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.response-length-options {
  display: flex;
  gap: 10px;
  align-items: center;
}

.response-length-options label {
  font-size: 0.85rem;
}

.sidebar-settings .setting-item label[for="usetable"] {
  flex-grow: 1; /* Allow label to take space */
}

/* NEW: Ensure theme label also takes available space */
.sidebar-settings .setting-item label[for="theme-toggle-button"] {
  flex-grow: 1;
}

.sidebar-settings #theme-toggle-button {
  cursor: pointer;
  font-size: 1.4rem;
  padding: 5px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

.sidebar-settings #theme-toggle-button:hover {
  background-color: var(--secondary-hover-color);
}

.sidebar.collapsed .sidebar-footer {
  display: none; /* Footer is hidden when collapsed */
}

.conversations-header {
  display: flex;
  align-items: center;
  padding: 1rem 1rem 0.5rem 1rem; /* Space from the elements above */
  margin-bottom: 0.5rem;
}
.conversations-header h4.active {
  color: var(--text-color);
  font-weight: 600;
}
.conversations-header h4 {
  cursor: pointer;
}

.conversations-header h4 {
  color: var(--placeholder-color);
  font-size: 0.8rem;
  text-transform: uppercase;
  margin: 0; /* Remove default margin */
  font-weight: 500;
}

/* NEW: Search input inside sidebar */
.search-wrapper {
  position: relative;
  padding: 0 1rem 0.5rem;
}
.search-wrapper .material-symbols-rounded {
  position: absolute;
  left: 1.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--placeholder-color);
  font-size: 1.2rem;
}
.search-wrapper input {
  width: 100%;
  padding-left: 2.2rem; /* Space for the icon */
}
.search-wrapper #close-search-btn {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px;
  color: var(--placeholder-color);
}

.sidebar.collapsed .conversations-header h4 {
  display: none;
}

/* NEW: Style for the "No conversations" message */
.no-conversations-message {
  color: var(--placeholder-color);
  padding: 0.5rem 0.2rem;
  font-style: italic;
}

/* NEW: Style for conversation list items */
.conversation-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.5rem 1rem; /* FIX: Align with sidebar-item horizontal padding */
  border-radius: 4px;
  position: relative;
  gap: 0.5rem;
}

.conversation-item:hover {
  background-color: var(--secondary-hover-color);
}

.conversation-item-title {
  color: var(--text-color);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1; /* Take available space */
}
.conversation-item .material-symbols-rounded {
  color: var(--placeholder-color);
  font-size: 1.2rem;
  cursor: pointer; /* Make icon clickable */
}
/* NEW: Style for favorite conversation icon */
.conversation-item .favorite-star {
  color: var(--text-color); /* Use default text color to be less prominent */
  font-variation-settings: 'FILL' 1; /* Filled star */
}


.conversation-menu-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto; /* Push to the far right */
  opacity: 0; /* Hidden by default */
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.conversation-item:hover .conversation-menu-btn {
  opacity: 1; /* Show on hover */
}

.conversation-menu-btn:hover {
  background-color: var(--secondary-color); /* A bit darker than the item hover */
}

/* NEW: Context menu for conversation items */
.conversation-context-menu {
  display: none; /* Hidden by default */
  position: absolute;
  right: 10px; /* Position near the menu button */
  top: 35px;   /* Position below the menu button */
  background-color: var(--secondary-hover-color); /* Same as dropdowns */
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 110; /* Below project dropdown but above most content */
  min-width: 180px;
  padding: 0.5rem 0;
  border: 1px solid var(--placeholder-secundary-color);
}

.conversation-context-menu.show {
  display: block;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  font-size: 1.4rem;
  width: 100%;
  text-align: left;
  font-size: 0.9rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.context-menu-item.delete {
  color: var(--error);
}

.context-menu-item.delete:hover {
  background-color: var(--error);
  color: #fff;
}

/* --- NEW: In-place Rename Input --- */
.rename-input {
  width: 100%;
  background-color: var(--secondary-hover-color);
  border: 1px solid var(--brand-color);
  border-radius: 4px;
  color: var(--text-color);
  font-family: "IBM Plex Sans", sans-serif;
  font-size: inherit; /* Inherit font size from the list item */
  padding: 2px 6px;
  outline: none;
  box-shadow: 0 0 5px rgba(214, 136, 255, 0.5);
  /* Ensure it takes up the same space as the title */
  margin: 0;
  flex-grow: 1;
}


/* --- NEW CONVERSATION BUTTON --- */
.new-conversation-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background-color: var(--brand-color);
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 2rem; /* Fully rounded */
  padding: 0.75rem 1rem;
  margin: 0 1rem 1rem 1rem; /* Margin around the button */
  margin-top: 1rem; /* FIX: Add top margin to separate from project selector */
  transition: background-color 0.2s ease;
  text-decoration: none;
}

.new-conversation-btn:hover {
  background-color: #b34be9; /* Darker purple on hover */
}

.sidebar.open .new-conversation-btn {
    justify-content: flex-start;
}


/* Collapsed state for sidebar */
.sidebar.collapsed {
  width: 90px;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .project-name-sidebar,
.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .expand-icon {
  display: none;
}
.sidebar.collapsed .sidebar-header {
  display: none;
}

.sidebar.collapsed .sidebar-logo-collapsed {
  display: block; /* Show the 'H' when collapsed */
}

/* NEW: Adjust new conversation button size when collapsed */
.sidebar.collapsed .new-conversation-btn {
  width: 48px; /* Make it a square-ish button */
  height: 48px;
  padding: 0; /* Remove padding to center the icon */
  margin: 1rem auto; /* Center it horizontally */
}

/* NEW: Hide text on all sidebar items when collapsed */
.sidebar.collapsed .sidebar-item span:not(.material-symbols-rounded) {
  display: none;
}

.sidebar.collapsed .sidebar-item {
  justify-content: center;
}

.sidebar.collapsed .new-conv-text {
  display: none;
}

/* NEW: Styles for collapsed agent icons */
.collapsed-agent-wrapper {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0.5rem 0;
}
.sidebar.collapsed .collapsed-agent-wrapper {
  display: flex;
}
.collapsed-agent-wrapper .sidebar-item {
  justify-content: center;
  width: 100%;
}
.sidebar.collapsed .new-conversation-btn .new-conv-text {
  display: none;
}

/* NEW: Styles for the collapsed project icon */
.collapsed-project-icon-wrapper {
  display: none; /* Hidden by default */
  padding: 0.5rem 1rem; /* Match header padding */
  cursor: pointer;
  justify-content: center; /* Align icon to the center */
}
.sidebar.collapsed .collapsed-project-icon-wrapper {
  display: flex; /* Shown only when sidebar is collapsed */
}

.main-content {
  display: flex;
  width: 100%;  
  z-index: 1; /* FIX: Ensure main content is below fixed elements like top-right-actions */
  height: 100vh; /* Take full viewport height */
}

.chat-area-wrapper {
  flex-grow: 1;
  display: flex; /* This is key for vertical centering */
  flex-direction: column;
  padding-top: 60px;  /* FIX: Apply padding here to always reserve space for the top-bar */
}

/* FIX: Apply max-width and centering to the containers, not individual messages */
/* When a conversation is active, the header disappears and the chat list grows */
.header,
.chat-list,
.typing-form {
  max-width: 1080px;
  width: 100%; /* <-- AÑADIDO: Esta es la corrección clave */
  margin: 0 auto; /* This centers the containers horizontally */
}
body.hide-header .header {
  display: none;
}
/* The padding is now on chat-area-wrapper, so this is no longer needed */


/* NEW: Wrapper to center header content vertically and horizontally */
.header-center-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* NEW: Styles for the simplified header */
.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end; /* Align content to the bottom */
  padding: 2rem 2rem 0; /* Remove bottom padding to get closer to input */
  flex-shrink: 0;
  position: relative; /* For the pseudo-element */
  color: var(--text-color);
  min-height: 300px; /* Give it some space */
  /* NEW: This makes the header take up the available space, pushing the typing-area down */
  flex-grow: 1;
  justify-content: center; /* This centers the content vertically */
}

/* NEW: Blurred radial background effect */
.header::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 300px; /* Made it a bit taller */
  background: radial-gradient(circle, rgba(214, 136, 255, 0.15) 0%, rgba(214, 136, 255, 0) 70%);
  filter: blur(50px);
  z-index: -1;
}

.header .title {
  text-align: center;
  width: 100%;
}

.header .subtitle {
  color: var(--placeholder-color);
  font-size: 1rem;
  margin-top: 0.5rem;
}

.suggestion-list {
  position: relative;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  z-index: 1; /* Changed from 10 */
  margin-top: 2rem; /* Space below the subtitle */
  padding: 20px;
}

/* NEW: Chip style for suggestions */
.suggestion-list .suggestion {
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 20px;
  background-color: var(--secondary-color);
  border: 1px solid var(--placeholder-secundary-color);
  color: var(--text-color);
  font-size: 0.9rem;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.suggestion-list .suggestion:hover {
  background: var(--secondary-hover-color);
  border-color: var(--brand-color);
}

.chat-list {
  padding: 1rem;
  flex-grow: 1; /* Make chat list take available space */
  overflow-y: auto;
  scrollbar-color: #999 transparent;
}

/* FIX: Make incoming messages a flex container to align avatar, text, and action buttons */
.chat-list .message.incoming {
  display: flex;
  align-items: flex-start; /* Align items to the top (avatar, text, buttons) */
  gap: 1.5rem; /* Space between avatar/text and action buttons */
  margin-top: 1.5rem;
  width: 100%;
  /* No specific padding-left here, it's handled by .chat-list padding */
}

.chat-list .message.incoming .ai-response-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  flex-grow: 1;
  max-width: calc(100% - 40px - 1.5rem);
}

.chat-list .message.incoming .ai-response-body {
  display: flex;
  flex-direction: column; /* Stack text/charts and actions vertically */
  flex-grow: 1; /* Take available horizontal space */
  background-color: var(--secondary-color); /* AI bubble background */
  padding: 10px 15px;
  border-radius: 15px;
  position: relative; /* For the triangle pseudo-element */
  width: 100%;
}

/* Triangle for AI message bubble */
.chat-list .message.incoming .ai-response-wrapper .ai-response-body::before {
  content: "";
  position: absolute;
  left: -10px; /* Position to the left of the bubble */
  top: 15px;
  border: 8px solid transparent;
  border-right: 10px solid var(--secondary-color); /* Color of the bubble */
}

.chat-list .message.outgoing {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  margin-top: 1.5rem;
  align-items: flex-start;
  gap: 0.5rem;
}

/* Action buttons on outgoing messages */
.outgoing-message-actions {
    display: flex;
    flex-direction: row; /* Position icons horizontally */
    align-items: center;
    gap: 0.25rem; /* Small gap between them */
}

.outgoing-message-actions .icon {
    visibility: hidden; /* Hide icons by default */
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.chat-list .message.outgoing:hover .outgoing-message-actions .icon {
    visibility: visible; /* Show on message hover */
}

.outgoing-message-actions .icon:hover {
    opacity: 1;
}

.chat-list .message .message-content {
  /* This class is for outgoing messages. It makes the bubble shrink to fit the text. */
  /* For incoming messages, .ai-response-body handles the layout */
  max-width: 85%; /* The bubble won't exceed 85% of the container width */
  width: fit-content;
}

.chat-list .message .text {
  color: var(--text-color);
}

.chat-list .message.outgoing .message-content .text {
  background-color: var(--user-bubble-background);
  padding: 10px 15px;
  border-radius: 15px;
  position: relative;
  text-align: left; /* The text inside the bubble aligns left, but the bubble itself is on the right */
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-list .message.outgoing .text::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 15px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 10px solid var(--user-bubble-background);
}

.chat-list .message.error .text {
  color: var(--error);
}

.chat-list .message.loading .text {
  display: none;
}

.chat-list .message .avatar {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 50%;
  align-self: flex-start;
}

.chat-list .message.loading .avatar {
  animation: rotate 3s linear infinite;
}

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

/* NEW: Styles for the "Show More" button to match the wireframe */
#show-more-conversations-btn {
  background: none;
  border: none;
  color: var(--placeholder-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  width: 100%;
  justify-content: flex-start; /* Align to the left */
}

#show-more-conversations-btn:hover {
  color: var(--text-color);
}

/* NEW: Styles for the li container of the show more button */
#show-more-li {
  list-style-type: none; /* Remove bullet point */
  padding: 0;
}

/* FIX: Vertically align the expand icon with the text */
#show-more-conversations-btn .material-symbols-rounded {
  font-size: 1.2rem; /* Match other icons */
}


.icon-button {
    background: none;
    border: none;
    color: var(--placeholder-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
}

.chat-list .message .icon {
  color: var(--text-color);
  cursor: pointer;
  height: 35px;
  width: 35px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  font-size: 1.25rem;
  flex-shrink: 0; /* Prevent icons from shrinking */ /* Visibility handled by specific rules */
}

/* Specific styles for outgoing message icons */
.chat-list .message.outcoming .icon {
  margin: 0; /* Spacing is now handled by 'gap' on the parent */
}

/* FIX: Ensure the actions wrapper and its contents are visible in incoming messages */
/* NEW: Styles for the actions container within AI response body */
.chat-list .message.incoming .ai-message-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: flex-start; /* Align buttons to the left */
  padding-left: 5px;
}

/* Ensure icons within ai-message-actions and outgoing copy button are visible */
.chat-list .message.incoming .ai-message-actions .icon,
.chat-list .message.incoming .ai-message-actions .feedback-controls,
.chat-list .message.outgoing .icon { /* This now targets the dynamically added copy button for outgoing messages */
  visibility: visible;
}

.chat-list .message .icon.hide {
  visibility: hidden;
}
.chat-list .message .loading-indicator {
  display: none;
  gap: 0.8rem;
  width: 100%;
  flex-direction: column;
}

.chat-list .message.loading .loading-indicator {
  display: flex;
}

.chat-list .message .loading-indicator .loading-bar {
  height: 11px;
  width: 100%;
  border-radius: 0.135rem;
  background-position: -800px 0;
  background: linear-gradient(to right, #9f4fd9, var(--primary-color), #9f4fd9);
  animation: loading 3s linear infinite;
}

.chat-list .message .loading-indicator .loading-bar:last-child {
  width: 70%;
}

@keyframes loading {
  0% {
    background-position: -800px 0;
  }
  100% {
    background-position: 800px 0;
  }
}

/* === SECCIÓN MODIFICADA PARA SOLUCIONAR EL OVERLAP Y PERMITIR MULTILÍNEA === */

.typing-area {
  position: relative; /* Cambiado de fixed a relative */
  flex-shrink: 0; /* Evita que se encoja */
  padding: 1rem;
  margin: 0 auto 1rem; /* Center the typing area and add bottom margin */
  background: var(--primary-color);
  z-index: 20;
}

.typing-area :where(.typing-form, .action-buttons) {
  display: flex;
  gap: 0.75rem;
}

/* Contenedor principal que envuelve toda la barra de entrada */
.typing-form .input-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column; /* Apila las previsualizaciones y la fila del input */
  position: relative;
  background: var(--input-wrapper-background);
  backdrop-filter: blur(10px); /* Blurred background effect */
  -webkit-backdrop-filter: blur(10px); /* For Safari */
  border-radius: 12px; /* Redondeo como en el diseño */
  padding: 0; /* No padding on the main wrapper */
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  max-width: 800px; /* Widen the input box */
  margin: 0 auto; /* Center the input box */
  border: 1px solid var(--placeholder-secundary-color);
}


/* Contenedor para previsualización de archivos */
#file-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px 10px;
  width: 100%;
  max-height: 100px;
  overflow-y: auto;
}

#file-preview-container:not(:empty) {
    margin-bottom: 5px; /* Add margin only when there are files */
}

/* FIX: Añadir los estilos para los elementos de previsualización de archivos */
.file-preview-item {
  border: 1px solid var(--placeholder-color);
  border-radius: 5px;
  padding: 3px 8px;
  margin: 2px;
  display: flex;
  align-items: center;
  font-size: 0.75em;
  background-color: var(--secondary-color);
  max-width: calc(50% - 10px);
  color: var(--text-color);
}

.file-preview-thumbnail {
  width: 30px;
  height: 30px;
  object-fit: cover;
  margin-right: 10px;
  cursor: pointer;
}

.file-preview-name {
  margin-right: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  cursor: pointer;
}

.file-preview-remove {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  font-size: 1.2em;
  line-height: 1;
  padding: 0 5px;
}

#file-preview-container > div {
  border: 1px solid var(--placeholder-color);
  border-radius: 5px;
  padding: 3px 8px;
  margin: 2px;
  display: flex;
  align-items: center;
  font-size: 0.75em;
  background-color: var(--secondary-color);
  max-width: calc(50% - 10px);
  color: var(--text-color); /* Make text color adapt to theme */
}
#file-preview-container > div span {
  max-width: 100px;
}

/* Fila que contiene el textarea y los botones, ahora usa flexbox */
.typing-form .main-input-row {
  display: flex; /* Alinea los botones con la base del textarea */
  align-items: center;
  width: 100%;
  min-height: 52px; /* Altura mínima de la fila */
  background-color: transparent; /* Fondo ya está en input-wrapper */
  border-radius: 12px; /* Redondear internamente */
  padding: 0 8px; /* Padding for icons */
}

.typing-form .input-wrapper:focus-within {
  box-shadow: 0 0 0 2px var(--brand-color);
}

/* Estilos para el TEXTAREA que admite múltiples líneas */
.typing-form .typing-input {
  flex-grow: 1; /* Ocupa el espacio disponible */
  height: auto; /* La altura se gestiona con JS y min-height de la fila */
  border: none;
  outline: none;
  resize: none; /* Desactiva el redimensionado manual */
  font-size: 1rem;
  color: var(--text-color);
  padding: 12px 5px; /* Padding interno para el texto */
  background: transparent;
  line-height: 1.5; /* Espaciado entre líneas */
  max-height: 200px; /* Altura máxima antes de que aparezca el scroll */
  overflow-y: auto;
}

.typing-form .typing-input::placeholder {
  color: var(--placeholder-color);
}

/* NEW: File counter style */
.typing-form #file-counter {
  color: var(--placeholder-color);
  font-size: 0.85rem;
  margin: 0 8px;
  white-space: nowrap;
  background-color: var(--primary-color);
  padding: 4px 8px;
  border-radius: 6px;
}

/* Estilos específicos para los botones DENTRO de la barra de input */
.typing-form .attach-file-btn,
.typing-form #copy-conversation-button,
.typing-form #stop-button,
.typing-form #send-message-button, .typing-form #copy-conversation-button {
  flex-shrink: 0; /* Evita que los botones se encojan */
  position: static; /* Importante: quitamos el posicionamiento absoluto */
  width: 40px;
  height: 40px;
  border: none;
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  margin: 0 2px;
  border-radius: 50%;
}

.typing-form .bottom-actions-row .icon:hover {
  color: var(--text-color);
  background-color: var(--secondary-hover-color);
}

.typing-form .attach-file-btn:hover,
.typing-form #copy-conversation-button:hover,
.typing-form #stop-button:hover,
.typing-form #send-message-button:hover {
    background-color: var(--secondary-hover-color);
}

.typing-form #copy-conversation-button,
.typing-form #stop-button,
.typing-form .attach-file-btn {
  background: transparent;
}

.typing-form #stop-button {
  background-color: var(--text-color); /* Fondo blanco en modo oscuro, negro en modo claro */
  color: var(--primary-color); /* Icono negro en modo oscuro, blanco en modo claro */
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.typing-form #stop-button:hover {
  opacity: 1;
  background-color: var(--text-color); /* Mantenemos el fondo al pasar el ratón */
}

.typing-form #stop-button .material-symbols-rounded {
  font-variation-settings: 'FILL' 1; /* Asegura que el icono esté relleno */
}

.typing-form #send-message-button {
  width: 36px; /* Slightly smaller */
  height: 36px;
  outline: none;
  display: none; /* Oculto por defecto para que no ocupe espacio */
  background-color: var(--brand-color);
  color: white;
  transition: opacity 0.2s ease, transform 0.2s ease;
  opacity: 0;
}

/* La clase .input-valid (gestionada por JS) muestra el botón de enviar */
.typing-form .main-input-row.input-valid #send-message-button {
    display: flex;
    transform: scale(1);
    opacity: 1; 
}
.typing-form .main-input-row.input-valid #send-message-button:hover {
    background-color: #b34be9;
}

/* --- Visibilidad de botones de acción --- */

/* Por defecto, el botón de parar está oculto */
.typing-form #stop-button {
    display: none;
}

/* Cuando se está generando respuesta, mostramos 'parar' y ocultamos los otros */
.typing-form.is-generating #stop-button {
    display: flex;
}

.typing-form.is-generating #copy-conversation-button,
.typing-form.is-generating .attach-file-btn {
    display: none;
}
/* --- Feedback UI --- */
.feedback-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem; /* Espacio reducido entre pulgares */
}

.feedback-btn {
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-size: 1.25rem; /* Mismo tamaño que el de copiar */
    color: var(--text-color);
}

.feedback-btn:hover {
    background-color: var(--secondary-hover-color);
}

/* Estilo para cuando un botón de feedback está activo */
.feedback-btn.thumb-up-btn.selected {
    color: var(--feedback-positive-color);
}

.feedback-btn.thumb-down-btn.selected {
    color: var(--feedback-negative-color);
}

.feedback-btn.selected .material-symbols-rounded {
    font-variation-settings: 'FILL' 1; /* Icono relleno */
}

/* Contenedor para el input de texto del feedback negativo */
.feedback-input-container {
    display: none; /* Oculto por defecto */
    position: absolute;
    bottom: calc(100% + 15px); /* Posicionado encima de los botones de feedback con un margen de 15px */
    left: 50%;
    transform: translateX(-50%); /* Centrado horizontalmente respecto a su padre */
    width: 350px;
    max-width: 90vw;
    background-color: var(--secondary-hover-color);
    border: 1px solid var(--placeholder-secundary-color);
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    z-index: 150;
    padding: 1rem;
    animation: fadeInScaleUp 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes fadeInScaleUp {
    from { opacity: 0; transform: translateX(-50%) scale(0.9); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* Flecha que apunta hacia abajo */
.feedback-input-container::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px;
    border-style: solid;
    border-color: var(--secondary-hover-color) transparent transparent transparent;
}

.feedback-input-container textarea {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--placeholder-secundary-color);
    background-color: var(--secondary-color);
    color: var(--text-color);
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.feedback-input-container textarea:focus {
    border-color: var(--brand-color);
    box-shadow: 0 0 0 2px rgba(214, 136, 255, 0.3);
}

.feedback-popup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.feedback-popup-btn {
    background-color: transparent;
    color: var(--text-color);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.feedback-popup-btn:hover {
    background-color: var(--secondary-color);
}

/* === FIN DE LA SECCIÓN MODIFICADA === */

.typing-area .disclaimer-text {
  text-align: center;
  font-size: 0.85rem;
  margin-top: 1rem;
  color: var(--placeholder-color);
}

.link {
  color: var(--text-color);
  text-decoration: none;
}
.link:hover {
  color: var(--brand-color);
  text-decoration: none;
}

strong {
  font-size: 1.1em; /* Un poco más grande que el texto normal */
  display: inline-block; /* Permite aplicar padding vertical */
  padding-top: 0.3em; /* Espacio superior dentro de la línea */
  padding-bottom: 0.3em; /* Espacio inferior dentro de la línea */
  /* NEW: Prevent long words in strong tags from overflowing */
  overflow-wrap: break-word;
  max-width: 100%;
}

hr {
  border: 0;
  border-top: 1px solid var(--placeholder-secundary-color);
  margin: 2em 0;
  padding: 0;
}

input[type="checkbox"] {
  accent-color: var(--brand-color);
}

.form-control {
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  padding: 1.1rem 1.5rem;
  border-radius: 50px;
  cursor: pointer;
  appearance: auto;
}

.form-control option {
  background-color: var(--secondary-hover-color);
}

/* Responsive media query code for small screen */
@media (max-width: 1240px) {
  .hide-if-mobile {
      display: none;
  }

  #scroll-to-bottom-btn {
    right: 20px;
    width: 40px;
    height: 40px;
  }

  .header :is(.title, .subtitle) {
    font-size: 2rem;
    line-height: 2.6rem;
  }

  .header .subtitle {
    font-size: 1.7rem;
  }

  .typing-area :where(.typing-form, .action-buttons) {
    gap: 0.4rem;
  }

  .typing-area .disclaimer-text {
    font-size: 0.75rem;
    margin-top: 0.5rem;
  }

}

@media (max-height: 1000px) {
  .suggestion-list {
    margin-top: -120px;
    padding: 10px;
    gap: 10px;
  }
}
@media (max-height: 780px) {
  .suggestion-list {
    display: none;
  }
}

@media (max-width: 989px) {
  .suggestion-list {
    display: none;
  }
}

/* --- MOBILE OPTIMIZATIONS (768px and below) --- */
@media (max-width: 768px) {
  /* NEW: Reduce base font size for smaller screens */
  html {
    font-size: 14px;
  }

  /* NEW: Allow body to scroll on mobile, which also fixes dev tools scrolling */
  body {
    overflow-y: auto;
  }

  .sidebar {
    position: fixed;
    left: -260px; /* Hidden by default */
    top: 0;
    height: 100%;
    z-index: 1000;
    transition: left 0.3s ease;
    /* FIX: Remove transparency from mobile sidebar by using a solid background color */
    background-color: var(--secondary-hover-color);
    border-right: 1px solid var(--placeholder-secundary-color);
  }

  .sidebar.open {
    left: 0; /* Shown when .open class is added */
  }

  .main-content {
    height: auto; /* Let the content flow naturally on mobile */
    flex-direction: column; /* Stack chat area below the header */
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .chat-area-wrapper {
    padding-top: 50px; /* Space for the fixed mobile top-bar */
  }

  /* En móvil, el botón está en la top-bar */
  .top-bar #toggle-sidebar-btn {
    order: -1; /* Lo coloca al principio de la top-bar */
    margin-right: 10px;
  }

  /* FIX: Use the body class to strongly override desktop styles for mobile view */
  body.mobile-view .top-bar {
    left: 0;
    width: 100%;
    padding: 10px 15px; /* Adjust padding for mobile */
  } 
  /* NEW: Adjust chat text and spacing for mobile */
  .chat-list .message .text {
    font-size: 0.95rem; /* Slightly smaller text in bubbles */
  }

  .chat-list .message.incoming,
  .chat-list .message.outgoing {
    margin-top: 1rem; /* Less space between messages */
  }

  .chat-list .message.incoming {
    gap: 0.75rem; /* Less space between avatar and bubble */
  }

  .typing-form .typing-input {
    font-size: 0.95rem; /* Slightly smaller text for the input area */
  }
}

/* NEW: Scroll to bottom button */
#scroll-to-bottom-btn {
  position: fixed;
  /* 'bottom' is set dynamically by JavaScript to stay above the typing area */
  right: 30px;
  z-index: 50;
  
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background-color: var(--secondary-color);
  color: var(--text-color);
  border: 1px solid var(--placeholder-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;

  /* Visibility & Animation */
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  /* Also transition the 'bottom' property for smooth repositioning */
  transition: opacity 0.3s ease, transform 0.3s ease, bottom 0.2s ease;
}

#scroll-to-bottom-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#scroll-to-bottom-btn:hover {
  background-color: var(--secondary-hover-color);
  border-color: var(--brand-color);
}
/* END: Scroll to bottom button */


.table-container {
  max-width: 90%; /* Aumentado para que sea más ancho y adaptable */
  overflow-x: auto;
  margin: 1em auto 1em; /* AÑADIDO: Margen superior para separar del texto, centrado horizontalmente y con margen inferior */
  scrollbar-color: #999 transparent;
  text-align: right; /* Aligns the inline-block export button to the right */
}

table {
  width: 100%;
  border-collapse: separate;
  background-color: var(--primary-color);
  border-spacing: 0 6px;
}

th, td {
  padding: 8px;
  text-align: left;
  color: var(--text-color);
  border: none;
  font-size: 14px;
  font-weight: 400;
}

tr {
  background-color: var(--background-table-odd);
}

tr:nth-child(even) {
  background-color: var(--background-table-even);
}

tr td:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

tr td:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

th {
  background-color: var(--table-header-background);
  color: var(--text-color);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

th:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

th:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

tbody tr:hover { 
  background-color: var(--secondary-hover-color);
  cursor: pointer; 
}

/* Specific styles for tables within chat messages to handle overflow */
.chat-list .message .text-and-chart-wrapper  {
  display: block;
  max-width: 100%; /* Override generic max-width to fit container */

  margin-left: 0; /* Reset margin for chat context */
  margin-right: 0;
  /* NEW: Allow long words to break to prevent overflow */
  overflow-wrap: break-word;
}
.chat-list .message .text-and-chart-wrapper .table-container {
  text-align: right; /* Align the export button to the right */
}


.chat-list .message .text-and-chart-wrapper td,
.chat-list .message .text-and-chart-wrapper th {
  white-space: nowrap; /* Prevent content from wrapping to force scroll */
}

.conversation-title-container {
  display: flex;
  flex-grow: 1;
  align-items: center;
  /* NEW: Prevent the container from shrinking and ensure it can be centered */
  min-width: 0;
}

.conversation-title-container p {
  color: var(--text-color);
  font-size: 1rem;
  font-weight: bold;
  width: 100%;
  margin: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;  
}

.message .suggestions-wrapper-inline {
  /* Estilo de "bocadillo" similar a la respuesta de la IA */
  background-color: var(--secondary-color);
  padding: 10px 15px;
  border-radius: 15px;
  position: relative;
  margin-top: 1rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px; /* Espacio entre el título y las sugerencias */
}
/* Triángulo para el bocadillo de sugerencias */
.message .suggestions-wrapper-inline::before {
    content: "";
    display: none; /* Desactivado por ahora para un look más limpio, puedes activarlo si lo prefieres */
}

.message .suggestions-title-inline {
  width: 100%;
  font-size: 0.85em;
  color: var(--placeholder-color);
  margin-bottom: 5px;
  font-style: italic;
  font-weight: bold;
}
.chat-list .message .text-and-chart-wrapper ul ul,
.chat-list .message .text-and-chart-wrapper ol ol {
  margin-top: 0.25em;
  margin-bottom: 0.25em;  
  padding-left: 25px;
}

.chat-list .message .text-and-chart-wrapper li {
  margin-bottom: 1.25em;
  margin-left: 20px;
  margin-top: 10px;
}

.chat-list .message .text-and-chart-wrapper ul ul,
.chat-list .message .text-and-chart-wrapper ol ol,
.chat-list .message .text-and-chart-wrapper ul ol,
.chat-list .message .text-and-chart-wrapper ol ul {
  margin-top: 1.25em;
  margin-bottom: 1.25em;
  padding-left: 20px;
}

.message .clickable-suggestion-inline {
  display: flex; /* Usamos flex para alinear el icono y el texto */
  align-items: center;
  gap: 10px; /* Espacio entre el icono y el texto */
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-color);
  font-size: 0.85em;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  width: 100%;
  border: 1px solid transparent; /* Borde transparente para mantener el tamaño en hover */
}

.message .clickable-suggestion-inline .suggestion-icon {
  color: var(--brand-color); /* Color morado para la lupa */
  font-size: 1.2rem;
}

.message .clickable-suggestion-inline:hover {
  background-color: var(--secondary-hover-color);
  border-color: var(--brand-color);
}


/* FIX: Correctly target the chart wrapper and ensure it has flex properties to grow */
/* This combination of styles ensures the container has a defined space for Chart.js to render into. */
.chat-list .message.incoming .text-and-chart-wrapper {
  display: flex;          /* Re-establish flex context like in the working version */
  flex-direction: column;   /* Stack chart elements vertically */
  width: 100%;            /* Take full width */
}

.message-content .text-and-chart-wrapper .text {
  width: 100%;
  word-wrap: break-word;
  margin-bottom: 1.25em;
}

.chat-list .message .text-and-chart-wrapper,
.chat-list .message .text-and-chart-wrapper p {
  color: var(--text-color);
}

.chat-list .message .text-and-chart-wrapper h2,
.chat-list .message .text-and-chart-wrapper h3,
.chat-list .message .text-and-chart-wrapper h4 {
  color: var(--text-color);
  font-weight: 600;
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--placeholder-secundary-color);
  font-size: 1.2em; /* Aumenta el tamaño para que destaque más */
}

.chat-list .message .text-and-chart-wrapper code {
  background-color: var(--secondary-color); /* Un fondo sutil que ya usas */
  color: var(--text-color); /* El color de texto normal */  
  padding: 0.2em 0.5em;
  border-radius: 5px;
  font-size: 0.85em;
  white-space: nowrap;
  border: 1px solid var(--placeholder-secundary-color); /* Un borde ligero para definirlo */
}

.message-content .text-and-chart-wrapper .ai-chart {
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.message-content .text-and-chart-wrapper .loading-indicator {
  width: 100%;
}

.export-chart-button {
  background-color: var(--brand-color);
  color: #FFFFFF;
  border: none;
  padding: 8px 15px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 0.8em;
  margin-top: 8px;
  margin-left: 55px;
  cursor: pointer;
  border-radius: 4px;
  transition: opacity 0.3s ease;
}

.export-chart-button:hover {
  opacity: 0.8;
}

.export-table-button {
  background-color: var(--brand-color);
  color: #FFFFFF;
  border: none;
  padding: 6px 12px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 0.8em;
  margin-top: 8px; /* Space between table and button */
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}

.export-table-button:hover {
  opacity: 0.8;
}

.export-table-button:disabled {
  background-color: #4cae4c; /* A green color for success */
  opacity: 1;
  cursor: default;
}

/* Hide export buttons when printing or copying rich content */
@media print {
  .export-table-button,
  .export-chart-button {
    display: none !important;
  }
}

.message-content .text-and-chart-wrapper > div > .export-chart-button {
    margin-left: 0;
}

/* NEW: Placeholder for chart rendering */
.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  width: 100%;
  background-color: var(--primary-color);
  border: 1px dashed var(--placeholder-secundary-color);
  border-radius: 8px;
  color: var(--placeholder-color);
  font-style: italic;
  margin: 10px 0;
}

/* NEW: Styles for the chart rendering error message */
.text.error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 100px;
    width: 100%;
    background-color: var(--primary-color);
    border: 1px dashed var(--error);
    border-radius: 8px;
    color: var(--error);
    font-style: italic;
    margin: 10px 0;
    padding: 1rem;
    text-align: center;
}

/* --- NEW: File Preview Modal Styles --- */
.file-preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 2000; /* High z-index to be on top of everything */
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.file-preview-overlay.show {
  display: flex;
}

.file-preview-modal {
  background-color: var(--secondary-color);
  border: 1px solid var(--placeholder-secundary-color);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  width: 90%;
  height: 90%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--placeholder-secundary-color);
  flex-shrink: 0;
}

.preview-filename {
  color: var(--text-color);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

.preview-actions .icon {
  color: var(--text-color);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  background: none;
  border: none;
}

.preview-content {
  flex-grow: 1;
  overflow: auto; /* Allow scrolling for large content */
  padding: 1rem;
  background-color: var(--primary-color); /* Slightly different background for content */
}

.preview-content img,
.preview-content embed,
.preview-content iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.preview-content pre {
  white-space: pre-wrap; /* Wrap text content */
  word-wrap: break-word;
  color: var(--text-color);
  font-size: 0.9rem;
}

.top-bar {
  position: fixed;
  top: 0;
  right: 0; /* Pin to the right edge */
  color: var(--text-color);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  /* NEW: Use space-between to push menu/title and right-actions apart */
  justify-content: space-between;
  gap: 1rem; /* Add space between items */
  z-index: 100; /* Keep it above other content */
  /* NEW: Ensure it has a background on mobile to cover content scrolling underneath */
  background-color: var(--primary-color);
  /* NEW: Define a fixed height for mobile layout consistency */
  height: 50px;
  /* --- DESKTOP LAYOUT --- */
  left: 260px; /* Start where the sidebar ends */
  width: auto; /* Let left/right positioning define the width */
  transition: left 0.3s ease; /* Animate the left position on sidebar collapse */
}

/* NEW: Adjust top-bar when sidebar is collapsed */
body.sidebar-collapsed .top-bar {
  left: 90px; /* Match the collapsed sidebar width */
}

/* --- NEW: Generated File Chips --- */
.generated-files-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 5px 0;
}

.generated-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 16px;
  background-color: var(--secondary-color);
  border: 1px solid var(--placeholder-secundary-color);
  color: var(--text-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  max-width: 250px;
}

.generated-file-chip:hover {
  background-color: var(--secondary-hover-color);
  border-color: var(--brand-color);
}

.generated-file-chip .material-symbols-rounded {
  font-size: 1.2rem;
  color: var(--placeholder-color);
}

.generated-file-chip .file-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* --- NEW: Collapsible Status Steps Styles --- */
.status-steps-container {
  /* The container itself is now transparent */
  border-radius: 8px;
  margin-top: 0.75rem; /* NEW: Space between the bubble and the status steps */
  overflow: hidden;
  width: 100%; /* Take full width of the wrapper */
}

.status-steps-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease;
}

.status-steps-header:hover {
  background-color: var(--secondary-hover-color);
}

/* NEW: Ensure text inside the header (like .status-text) is always visible */
.status-steps-header .status-text {
    color: var(--text-color);
    font-style: normal; /* Remove italics from the header view */
}

.status-steps-header::after {
  content: 'expand_more';
  font-family: 'Material Symbols Rounded';
  margin-left: auto;
  transition: transform 0.3s ease;
}

.status-steps-container.open .status-steps-header::after {
  transform: rotate(180deg);
}

.status-steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out;
  background-color: var(--primary-color);
  border-top: 1px solid transparent;
}

.status-steps-container.open .status-steps-list {
  max-height: 500px; /* Allow space for the list to expand */
  padding: 10px 15px;
  border-top-color: var(--placeholder-secundary-color);
}

.status-step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--placeholder-color);
  font-style: italic;
}

.status-step-item .status-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-step-item .status-icon .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--placeholder-color);
  border-top-color: var(--brand-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.status-step-item .status-icon .material-symbols-rounded {
  font-size: 18px;
  color: var(--feedback-positive-color); /* Green checkmark */
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
