/* optichat.css — styles for OptiChat page */

* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}

.optichat-page {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - 18px);  /* Fill viewport — aligned with sidebar Logout */
}

.optichat-title {
  color: #000;
  font-size: 28px;
  font-weight: 800;
  margin: 0;
}

.optichat-response {
  white-space: pre-wrap;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: #000;
  flex: 1 1 auto;  /* Fill remaining vertical space */
  min-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;  /* Prevent horizontal scroll on response area — tables scroll internally */
}

/* Add subtle opacity during loading instead of blur for better UX */
.optichat-response[data-dash-is-loading="true"] {
  opacity: 0.95;
  /* filter: blur(3px); */ /* Removed: blur makes screen hard to read */
}

/* Keep spinner overlay transparent so content stays visible underneath */
.optichat-page .dash-spinner { background-color: transparent !important; }
/* Dash versions may use an overlay element; ensure it's transparent and non-blocking */
.optichat-page .dash-loading-overlay { background-color: transparent !important; pointer-events: none; }
.optichat-page .dash-loading .dash-loading-overlay { background-color: transparent !important; pointer-events: none; }

.optichat-input {
  flex: 0 0 auto;  /* Don't grow, don't shrink — fixed at bottom */
  background: #fff;
  padding: 4px 10px 0 10px;
  border-radius: 8px;
}

.optichat-textarea {
  width: 100%;
  height: 68px;
  margin-bottom: 4px;
  resize: vertical;
}

/* Reuse global .btn */
.btn { border: none; border-radius: 20px; padding: 10px 18px; cursor: pointer; font-weight: 600; font-size: 14px; transition: background .2s, transform .15s, box-shadow .2s; }
.btn-teal { background-color: #3DC6C3; color: #fff; }
.btn-teal:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.15); transform: translateY(-2px); }
.btn-teal:active { transform: translateY(1px); }
.btn-clear-chat { background-color: #fef2f2; color: #7f1d1d; border: 1px solid #fecaca; }
.btn-clear-chat:hover { background-color: #fee2e2; color: #991b1b; border-color: #fca5a5; box-shadow: 0 2px 4px rgba(220,38,38,0.12); transform: translateY(-1px); }
.btn-clear-chat:active { transform: translateY(1px); }
.btn-clear-chat i { margin-right: 4px; color: #dc2626; }

/* Chat bubbles */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 16px;  /* Increased gap to prevent overlap */
}

.chat-item {
  position: relative;
  display: flex;
  flex-direction: column;  /* Stack bubble and meta vertically */
  gap: 4px;  /* Small gap between bubble and timestamp */
}

.chat-item.user {
  align-items: flex-end;  /* Align to right */
}

.chat-item.bot {
  align-items: flex-start;  /* Align to left */
}

.bubble-container {
  position: relative;
  max-width: 70%;  /* Limit width to 70% of chat area */
  min-width: 150px;  /* Ensure minimum readable width */
  display: inline-flex;  /* Changed from flex to inline-flex to shrink to content */
  flex-direction: column;
  width: fit-content;  /* Shrink to actual content width */
}

/* Responsive sizing for smaller screens */
@media (max-width: 768px) {
  .bubble-container {
    max-width: 85%;  /* Use more width on mobile */
  }
}

.bubble {
  width: 100%;
  padding: 12px 14px;
  padding-bottom: 8px;  /* Reduced bottom padding since meta-row is inside */
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;  /* Ensure long text wraps */
  overflow-wrap: break-word;
}

/* Prompt (user) bubble */
.user .bubble {
  background: #f5f5f5;
  border: 2px solid #f5f5f5;
  color: #000;
  max-width: 100%;  /* Fill container width */
}

/* Response (bot) bubble */
.bot .bubble {
  background: #e0f8f7;
  border: 1px solid #e0f8f7;
  color: #000;
  max-width: 100%;  /* Fill container width */
}

.bot.error .bubble {
  background: #f4dcdc;
  border: 2px solid #f4dcdc;
}

/* Copy button */
.copy-btn {
  background: #e0f8f7;
  color: #000;
  border: 1px solid #b3e5e3;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  white-space: nowrap;
}

.copy-btn:hover {
  background: #c7f2f0;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

.copy-btn:active {
  transform: translateY(0);
}

.copy-btn.copied {
  background: #10b981;
}

.copy-btn i {
  font-size: 11px;
}

.tail {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  display: none;  /* Hide tails to prevent overlap issues */
}

.meta {
  font-size: 11px;
  color: #666;
  font-style: italic;
  padding: 0 4px;
  margin-top: 2px;
  z-index: 1;  /* Ensure timestamp is above other elements */
}

.user .meta {
  text-align: right;
  align-self: flex-end;
}

.bot .meta {
  text-align: left;
  align-self: flex-start;
}

/* Meta row container for timestamp and copy button */
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;  /* Match the actual bubble width */
  margin-top: 8px;
  padding-top: 8px;
  padding-left: 4px;
  padding-right: 4px;
  border-top: 1px solid rgba(0,0,0,0.05);  /* Subtle separator line */
  gap: 10px;
  box-sizing: border-box;  /* Include padding in width calculation */
}

/* Processing state with spinner */
.chat-item.processing {
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.processing-text {
  color: #666;
  font-style: italic;
  margin-left: 10px;
}

/* Markdown rendering styles for chat bubbles */
.bubble h1, .bubble h2, .bubble h3 {
  color: #000;
  margin-top: 12px;
  margin-bottom: 8px;
  font-weight: 700;
}

.bubble h1 {
  font-size: 20px;
}

.bubble h2 {
  font-size: 18px;
}

.bubble h3 {
  font-size: 16px;
}

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

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

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

/* Bot bubbles containing tables get wider to avoid cramped columns */
.bot .bubble-container:has(table) {
  max-width: 95%;
}

/* Table scroll wrapper — added by JS to wrap each table for horizontal scroll */
.table-scroll-wrapper {
  overflow-x: auto;
  margin: 12px 0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Markdown table styles — normal table display for aligned columns */
.bubble table {
  border-collapse: collapse;
  font-size: 14px;
  background-color: #fff;
  width: max-content;
  min-width: 100%;
}

.bubble table thead {
  background-color: #3DC6C3;
}

.bubble table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #fff;
  border: 1px solid #2BA8A5;
  white-space: nowrap;  /* Prevent header text wrapping */
}

.bubble table td {
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  background-color: #fff;
  white-space: nowrap;  /* Keep cell data on one line for readability */
}

.bubble table tbody tr:nth-child(even) td {
  background-color: #f9fafb;
}

.bubble table tbody tr:hover td {
  background-color: #f3f4f6;
}

.bubble strong {
  font-weight: 600;
  color: #000;
}

.bubble em {
  font-style: italic;
}

.bubble code {
  background-color: #f3f4f6;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.bubble pre {
  background-color: #f3f4f6;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 12px 0;
}

.bubble pre code {
  background-color: transparent;
  padding: 0;
}
