@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700&family=Roboto:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400&display=swap");

:root {
  /* Colors */
  --chat--color-primary: #363839;
  --chat--color-primary-shade-50: #2a2c2d;
  --chat--color-primary-shade-100: #1e1f20;
  --chat--color-secondary: #515658;
  --chat--color-secondary-shade-50: #363839;
  --chat--color-white: #ffffff;
  --chat--color-light: #f2f1f0;
  --chat--color-light-shade-50: #e8e7e6;
  --chat--color-light-shade-100: #dedcdb;
  --chat--color-medium: #8b8c8d;
  --chat--color-dark: #363839;
  --chat--color-disabled: #94a3b8;
  --chat--color-typing: #515658;

  /* Base Layout */
  --chat--spacing: 1rem;
  --chat--border-radius: 0.25rem;
  --chat--transition-duration: 0.15s;
  --chat--font-family:
    "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Oxygen-Sans,
    Ubuntu, Cantarell, "Helvetica Neue", sans-serif;

  /* Window Dimensions */
  --chat--window--width: 420px;
  --chat--window--height: 640px;

  /* Message Styles */
  --chat--message--font-size: 1rem;
  --chat--message--padding: 0.75rem 1rem;
  --chat--message--border-radius: 1rem;
  --chat--message-line-height: 1.5;
  --chat--message--margin-bottom: 0.5rem;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--chat--font-family) !important;
}

body {
  background: var(--chat--color-light);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.main-wrapper {
  width: 100%;
  max-width: 1000px;
  height: 90vh;
  display: flex;
  gap: 0;
  transition: all 0.4s ease;
}

.main-wrapper.iframe-visible {
  max-width: 100%;
  width: 100%;
  height: 100vh;
}

.history-sidebar {
  width: 260px;
  background: var(--chat--color-primary-shade-50);
  color: var(--chat--color-white);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border-right: 1px solid var(--chat--color-primary-shade-100);
  border-radius: 12px 0 0 12px;
  flex-shrink: 0;
  overflow-y: hidden;
  transition: width 0.3s ease, padding 0.3s ease;
}

.history-sidebar.collapsed {
  width: 60px;
  padding: 1rem 0.5rem;
  align-items: center;
}

.history-sidebar.collapsed .new-chat-btn span:not(.icon) {
  display: none;
}
.history-sidebar.collapsed .new-chat-btn {
  justify-content: center;
  padding: 10px;
}
.history-sidebar.collapsed .history-group-title,
.history-sidebar.collapsed .history-item {
  display: none;
}

.sidebar-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
  width: 100%;
}

.history-sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--chat--color-medium);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.sidebar-toggle:hover {
  color: var(--chat--color-white);
}

.new-chat-btn {
  background: transparent;
  color: var(--chat--color-white);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  transition: background 0.2s;
  margin-bottom: 20px;
  width: 100%;
  justify-content: flex-start;
}

.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px; /* Space for scrollbar */
}

.history-list::-webkit-scrollbar {
  width: 4px;
}
.history-list::-webkit-scrollbar-thumb {
  background-color: var(--chat--color-medium);
  border-radius: 4px;
}

.history-group-title {
  font-size: 11px;
  color: var(--chat--color-medium);
  margin: 16px 0 8px 0;
  padding-left: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-item {
  padding: 10px 12px;
  color: var(--chat--color-light);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  transition: background 0.2s;
  margin-bottom: 2px;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.1);
}
.history-item.active {
  background: rgba(255, 255, 255, 0.15);
  font-weight: 500;
}

.chat-container {
  width: 100%;
  height: 100%;
  background: var(--chat--color-white);
  border-radius: 0 12px 12px 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.4s ease;
  flex-shrink: 1;
}

.main-wrapper.iframe-visible .chat-container {
  width: 25%;
  min-width: 320px;
  border-radius: 0;
  box-shadow: none;
  border-right: 1px solid var(--chat--color-light-shade-100);
}



.iframe-panel {
  width: 0;
  height: 100vh;
  background: var(--chat--color-white);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.4s ease;
  flex-shrink: 0;
}

.main-wrapper.iframe-visible .iframe-panel {
  width: 75%;
  min-width: 900px;
}

.iframe-header {
  padding: 1rem;
  background: var(--chat--color-light);
  border-bottom: 1px solid var(--chat--color-light-shade-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.iframe-url {
  flex: 1;
  font-size: 13px;
  color: var(--chat--color-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iframe-actions {
  display: flex;
  gap: 8px;
}

.iframe-open-new {
  background: none;
  border: none;
  color: var(--chat--color-medium);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
  text-decoration: none;
}

.iframe-open-new:hover {
  color: var(--chat--color-primary);
}

.iframe-close {
  background: none;
  border: none;
  color: var(--chat--color-medium);
  cursor: pointer;
  font-size: 20px;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
}

.iframe-close:hover {
  color: var(--chat--color-dark);
}

.iframe-content {
  flex: 1;
  border: none;
  background: white;
}

.iframe-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background: #fff3cd;
  color: #856404;
}

.iframe-error h3 {
  margin-bottom: 1rem;
  font-size: 1.2rem;
}

.iframe-error p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

.iframe-error a {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: var(--chat--color-primary);
  color: white;
  text-decoration: none;
  border-radius: 24px;
  transition: transform 0.2s;
}

.iframe-error a:hover {
  transform: translateY(-2px);
}

.chat-header {
  padding: 1.25rem 1rem;
  background: linear-gradient(
    135deg,
    var(--chat--color-primary) 0%,
    var(--chat--color-secondary) 100%
  );
  color: var(--chat--color-white);
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-titles {
  display: flex;
  flex-direction: column;
}

.chat-header h1 {
  font-size: 0;
  line-height: 0;
  position: relative;
}

.chat-header h1::before {
  content: "Puccini";
  font-size: 2.2rem;
  line-height: normal;
  font-weight: 800;
  font-family: "Raleway", sans-serif;
}

.chat-header h1::after {
  content: "ONLINE";
  font-size: 1.2rem;
  line-height: normal;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  font-style: italic;
  vertical-align: baseline;
  margin-left: 0.3rem;
}

.chat-header p {
  font-size: 0;
  line-height: 0;
  margin-top: 0.5rem;
}

.chat-header p::after {
  content: "ArchiBot - Assistente digitale alla ricerca";
  font-size: 1rem;
  line-height: 1.5;
  font-family: "Roboto", sans-serif;
  font-weight: 100;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--chat--spacing);
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--chat--color-light);
}

.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: slideIn 0.3s ease-out;
}

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

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

.message.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

.user .message-avatar {
  background: linear-gradient(
    135deg,
    var(--chat--color-primary) 0%,
    var(--chat--color-secondary) 100%
  );
}

.assistant .message-avatar {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.message-content {
  background: var(--chat--color-white);
  padding: var(--chat--message--padding);
  border-radius: var(--chat--message--border-radius);
  line-height: var(--chat--message-line-height);
  border: 1px solid var(--chat--color-light-shade-100);
}
/* Styles specific to the Welcome Message */
.welcome-text {
  margin-bottom: 0.75rem;
}

.welcome-title {
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}

.welcome-subtitle {
  color: var(--chat--color-secondary);
  font-size: 0.95rem;
}

.welcome-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.welcome-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px; /* Space between checkmark and text */
  margin-bottom: 8px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.welcome-list li:last-child {
  margin-bottom: 0;
}

.welcome-icon {
  color: #27ae60; /* A nice friendly green for success/tips */
  flex-shrink: 0; /* Prevents icon from squishing */
  margin-top: 1px; /* Visual alignment with text top */
  font-weight: bold;
}

.user .message-content {
  background: linear-gradient(
    135deg,
    var(--chat--color-primary) 0%,
    var(--chat--color-secondary) 100%
  );
  color: var(--chat--color-white);
  border: none;
}

.assistant .message-content {
  background: var(--chat--color-white);
  color: var(--chat--color-dark);
}

.message-content a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
  cursor: pointer;
}

.user .message-content a {
  color: var(--chat--color-white);
}

.assistant .message-content a {
  color: var(--chat--color-primary);
}

.message-content a:hover {
  opacity: 0.8;
}

/* Styling per elementi markdown */
.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 0.8em 0 0.5em 0;
  font-weight: 600;
}

.message-content h1 {
  font-size: 1.5em;
}
.message-content h2 {
  font-size: 1.3em;
}
.message-content h3 {
  font-size: 1.1em;
}

.message-content strong {
  font-weight: 600;
}

.message-content em {
  font-style: italic;
}

.message-content ul,
.message-content ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.message-content li {
  margin: 0.3em 0;
}

.message-content p {
  margin: 0.5em 0;
}

.message-content blockquote {
  border-left: 3px solid var(--chat--color-medium);
  padding-left: 1em;
  margin: 0.5em 0;
  color: var(--chat--color-medium);
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999;
  animation: typing 1.4s ease-in-out infinite;
}

.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);
  }
}

.chat-input-container {
  padding: var(--chat--spacing);
  background: var(--chat--color-white);
  border-top: 1px solid var(--chat--color-light-shade-100);
  display: flex;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0;
  font-size: 14px;
  outline: none;
  background: var(--chat--color-light);
  transition: background-color 0.2s;
}

.chat-input:focus {
  background: var(--chat--color-light-shade-50);
}

.send-button {
  padding: 12px 24px;
  background: linear-gradient(
    135deg,
    var(--chat--color-primary) 0%,
    var(--chat--color-secondary) 100%
  );
  color: var(--chat--color-white);
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.send-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(54, 56, 57, 0.4);
}

.send-button:active {
  transform: translateY(0);
}

.send-button:disabled {
  background: var(--chat--color-disabled);
  cursor: not-allowed;
  transform: none;
}

.thinking-message {
  background: #e3f2fd;
  border-left: 4px solid #2196f3;
  padding: 12px 16px;
  border-radius: 8px;
  color: #1565c0;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Collapsible thinking panel */
.thinking-panel {
  background: #f8f9fa; /* Light gray */
  border-left: 4px solid #adb5bd; /* Medium gray */
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: #495057; /* Dark gray */
  overflow: hidden;
  animation: slideIn 0.3s ease-out;
}

.thinking-panel summary {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-style: italic;
  user-select: none;
  list-style: none;
}

.thinking-panel summary::-webkit-details-marker {
  display: none;
}

.thinking-panel summary::before {
  content: "▸";
  font-style: normal;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.thinking-panel[open] summary::before {
  transform: rotate(90deg);
}

.thinking-panel .thinking-ticker {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.thinking-panel .thinking-full {
  padding: 0 12px 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  border-top: 1px solid rgba(0, 0, 0, 0.05); /* very light gray separator */
}

.opac-filters {
  background: #f1f8e9;
  border-left: 4px solid #8bc34a;
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: 8px;
}

.opac-filters strong {
  color: #558b2f;
  display: block;
  margin-bottom: 8px;
}

.opac-filters a {
  display: inline-block;
  margin: 4px 8px 4px 0;
  padding: 4px 12px;
  background: var(--chat--color-white);
  border: 1px solid #8bc34a;
  border-radius: 16px;
  color: #558b2f;
  text-decoration: none;
  font-size: 13px;
  transition: all 0.2s;
}

.opac-filters a:hover {
  background: #8bc34a;
  color: var(--chat--color-white);
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(139, 195, 74, 0.3);
}

/* Resizer styles */
.resizer {
  width: 5px;
  background: var(--chat--color-light-shade-100);
  cursor: col-resize;
  display: none;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.resizer:hover {
  background: var(--chat--color-medium);
}

.main-wrapper.iframe-visible .resizer {
  display: block;
}

/* Disable transitions during resize for smoothness */
.main-wrapper.is-resizing .chat-container,
.main-wrapper.is-resizing .iframe-panel {
  transition: none;
}

/* DRAG OVERLAY - Critical for preventing iframe interference */
.drag-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  cursor: col-resize;
  background: transparent;
}

.drag-overlay.active {
  display: block;
}
