/* Light, clean ChatGPT-like layout */

:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #e5e5e5;
  --text: #222;
  --muted: #6b7280;
  --brand: #0d3a68;
  --brand-hover: #0b3158;
}

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* prevent page-level scrollbars; inner panes manage scrolling */
}

/* Top bar */
.app-header {
  width: 100%;
  background: var(--brand);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.app-header img { height: 48px; width: auto; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2)); }

/* Main layout: sidebar + chat */
.app-main {
  width: 100%;
  flex: 1;              /* fill remaining height below header */
  min-height: 0;        /* allow children to shrink and scroll internally */
  display: flex;
  flex-direction: row;
  background: transparent;
  overflow: hidden;     /* hide extra scrollbars; delegate to children */
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;      /* fixed width; don't shrink */
  max-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;        /* allow thread list to scroll without growing parent */
  overflow: hidden;     /* hide any horizontal bleed */
}
.sidebar-header { padding: 12px; border-bottom: 1px solid var(--border); }
.new-chat-btn {
  width: 100%;
  background: #eef3fb;
  color: var(--brand);
  border: 1px solid #d5e3f5;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s ease;
}
.new-chat-btn:hover { background: #e2ecf8; }

.thread-list { padding: 6px 0; flex: 1; overflow-y: auto; overflow-x: hidden; }
.thread-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden; /* ensure inner ellipsis works */
}
.thread-row:hover { background: #f7f9fb; }
.thread-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn { background: transparent; border: 0; color: #61758a; cursor: pointer; font-size: 14px; padding: 2px 4px; }
.icon-btn:hover { color: var(--brand); }
.empty { padding: 12px; font-size: 13px; color: #8c97a1; }
.thread-title-input {
  flex: 1 1 auto;
  width: 100%;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  background: #fff;
  box-sizing: border-box;
}
.thread-title-input:focus { border-color: var(--brand); }
.thread-actions .confirm { color: #0d7a2b; }
.thread-actions .confirm:hover { color: #0b5e21; }
.thread-actions .cancel { color: #b30000; }
.thread-actions .cancel:hover { color: #860000; }
.confirm-text { font-weight: 600; color: #b30000; }

/* Chat area */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden; /* contain inner scroll */
  min-width: 0;
  min-height: 0;
}

.chat-container.empty .chat-messages { display: none; }
.chat-container.empty .chat-input {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.chat-container.empty .chat-input-row {
  width: 100%;
  max-width: 720px;
  justify-content: center;
  gap: 12px;
}
.chat-container.empty .chat-input-row input {
  max-width: 620px;
  padding: 18px 26px;
  font-size: 16px;
  border-radius: 34px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.chat-container.empty .chat-input-row button.icon-send {
  width: 60px;
  height: 54px;
  margin-left: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.chat-container.empty .progress-indicator { display: none; }

.chat-messages {
  flex: 1;
  width: 100%;
  padding: 32px 0 24px;
  overflow-y: auto;  /* the only vertical scroller for chat */
  overflow-x: hidden; /* avoid horizontal scrollbar */
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Center content column without extra boxes */
.message-block {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message-block-user,
.message-block-bot {
  align-items: flex-start;
}
.message {
  width: 100%;
  margin: 0;
  padding: 0;
  line-height: 1.6;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere; /* robust line breaking for long URLs/strings */
}
.user-message {
  background: #e9eef3;
  padding: 10px 14px;
  border-radius: 14px;
}
.bot-message { background: transparent; }


/* PDB data block styling */
.pdb-block {
  position: relative;
  width: 100%;
  max-width: 820px;
  margin: 6px auto 14px;
  background: #f5f7fa; /* light gray fill */
  color: var(--text);
  border: 1px solid var(--brand); /* blue border to match header */
  border-radius: 10px;
  padding: 14px 16px 20px;
  box-sizing: border-box;
  overflow-x: auto;
}
.pdb-block::-webkit-scrollbar { height: 8px; }
.pdb-block::-webkit-scrollbar-track { background: #edf2f7; }
.pdb-block::-webkit-scrollbar-thumb { background: #c9d6e5; border-radius: 4px; }
.pdb-content {
  margin: 0; /* remove default p margin */
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; /* not monospace */
}
.pdb-toolbar {
  position: absolute;
  top: 6px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.pdb-badge {
  background: transparent; /* label-like, no fill */
  color: var(--brand);     /* dark blue text */
  padding: 0;
  border: 0;
  font-weight: 700;
  letter-spacing: .3px;
}
.pdb-copy {
  background: transparent;
  color: #4a5568;
  border: 0;
  padding: 0;                 /* icon fills button */
  width: 28px;                /* square hit area */
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;       /* center icon */
  align-items: center;
  justify-content: center;
}
.pdb-copy:hover { color: var(--brand); background: rgba(13,58,104,0.06); }
.pdb-copy:active { transform: scale(0.96); }
.pdb-copy svg { width: 18px; height: 18px; display: block; pointer-events: none; }
.pdb-copied {
  position: absolute;
  right: 10px;
  bottom: 6px;
  background: #10b981;
  color: #fff;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  animation: fadeOut 1.4s forwards;
}
@keyframes fadeOut {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Markdown within bot messages */
.bot-message strong { font-weight: 600; color: #111; }
.bot-message em { font-style: italic; }
.bot-message ol, .bot-message ul { padding-left: 24px; margin: 10px 0; }
.bot-message li { margin: 4px 0; }
.bot-message p { margin: 10px 0; line-height: 1.6; }

/* Input area centered and wide */
.chat-input {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 0 28px;
  gap: 6px;
  box-sizing: border-box;
}
.chat-input-row {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 10px;
  box-sizing: border-box;
}
.chat-input-row .icon-attach {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid #d0d7df;
  background: #fff;
  color: #4b5563;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
  transition: border-color .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.chat-input-row .icon-attach:hover {
  color: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.12);
}
.chat-input-row .icon-attach:active { transform: scale(.94); }
.chat-input-row .icon-attach:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-input-row .icon-attach svg { width: 20px; height: 20px; }
.chat-input-row input {
  flex: 1 1 720px;
  max-width: 820px;
  padding: 14px 20px;
  border: 1px solid #d0d7df;
  background: #fff;
  border-radius: 28px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.chat-input-row input:focus { border-color: var(--brand); }
.chat-input-row button.icon-send {
  width: 48px;
  height: 48px;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .15s ease;
}
.chat-input-row button.icon-send:hover { background: var(--brand-hover); }
.chat-input-row button.icon-send:active { transform: scale(.94); }
.chat-input-row button.icon-send:disabled { background: #b7c2cc; cursor: not-allowed; }

.progress-indicator {
  width: 100%;
  max-width: 820px;
  align-self: center;
  font-size: 12px;
  letter-spacing: 0.3px;
  color: rgba(55, 65, 81, 0.8);
  pointer-events: none;
  text-align: left;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.progress-indicator.active {
  opacity: 1;
  animation: progressPulse 1.4s ease-in-out infinite;
}

.attachment-status {
  width: 100%;
  max-width: 820px;
  font-size: 12px;
  color: #4b5563;
  min-height: 20px;
  align-self: center;
  transition: color .15s ease;
}
.attachment-status.active { margin-top: 6px; }
.attachment-status.error { color: #b91c1c; }
.attachment-pill {
  width: auto;
  max-width: min(420px, 100%);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid #d0d7df;
  background: #f1f5f9;
  box-sizing: border-box;
}
.attachment-pill.attachment-upload-row { justify-content: flex-start; }
.attachment-upload-text { font-weight: 500; }
.attachment-details { display: flex; flex-direction: column; min-width: 0; }
.attachment-name {
  font-weight: 600;
  font-size: 13px;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-meta {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-remove {
  border: 0;
  background: transparent;
  color: #6b7280;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.attachment-remove:hover { color: #b91c1c; }
.message-file-pill {
  margin-top: 8px;
  padding-right: 16px;
}
.message-attachment-row {
  display: flex;
  width: 100%;
}
.attachment-name-link {
  color: var(--brand);
  text-decoration: none;
}
.attachment-name-link:hover {
  text-decoration: underline;
}
.attachment-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(13,58,104,0.2);
  border-top-color: var(--brand);
  display: inline-block;
  margin-right: 8px;
  animation: attachmentSpin .9s linear infinite;
}

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

@keyframes progressPulse {
  0% { opacity: 0.85; }
  50% { opacity: 0.2; }
  100% { opacity: 0.85; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background-color: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--panel);
  border-radius: 10px;
  width: 90%;
  max-width: 420px;
  padding: 20px;
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
  text-align: center;
}
.modal-content h2 { margin-top: 0; color: var(--brand); font-size: 18px; }
.modal-content input[type="password"] {
  width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; margin-top: 10px;
}
.modal-actions { margin-top: 15px; display: flex; justify-content: center; }
.modal-actions button {
  padding: 10px 20px; background: var(--brand); color: #fff; border: 0; border-radius: 6px; cursor: pointer;
}
.modal-actions button:hover { background: var(--brand-hover); }
.error { color: #b00020; margin-top: 10px; font-size: 14px; }
/* Cleaned legacy duplicates removed */