/* ---------- Chat layout: header + sidebar + conversation ---------- */
.chat-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.chat-layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  display: flex;
  flex-direction: column;
  width: 260px;
  flex-shrink: 0;
  padding: 0.75rem;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}
.sidebar__new { margin-bottom: 0.75rem; }
.sidebar__lists { flex: 1; min-height: 0; overflow-y: auto; }
.sidebar__heading { margin: 0.5rem 0.6rem 0.25rem; font-size: 0.75rem; font-weight: bold; color: var(--color-muted); }
.sidebar__list { margin: 0 0 0.5rem; padding: 0; list-style: none; }
/* Divider between the pinned conversations and the recent ones below. */
.sidebar__list--pinned { margin-bottom: 0.75rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--color-border); }
.sidebar__item { display: flex; align-items: center; border-radius: 6px; }
.sidebar__item:hover, .sidebar__item.is-active, .sidebar__item.is-menu-open { background: var(--color-bg); }
.sidebar__link {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  color: var(--color-text);
  text-decoration: none;
}
.sidebar__meta { font-size: 0.78rem; font-weight: bold; white-space: nowrap; }
.sidebar__title { overflow: hidden; font-size: 0.85rem; color: var(--color-muted); white-space: nowrap; text-overflow: ellipsis; }
.sidebar__item.is-active .sidebar__link { font-weight: bold; }

/* "…" button: shown on hover, for the open conversation and while its menu is open. */
.sidebar__more {
  flex-shrink: 0;
  width: 1.8rem;
  height: 1.8rem;
  margin-right: 0.2rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-muted);
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 6px;
  opacity: 0;
}
.sidebar__item:hover .sidebar__more,
.sidebar__item:focus-within .sidebar__more,
.sidebar__item.is-active .sidebar__more,
.sidebar__item.is-menu-open .sidebar__more { opacity: 1; }
.sidebar__more:hover, .sidebar__item.is-menu-open .sidebar__more { color: var(--color-text); background: var(--color-border); }
@media (hover: none) { .sidebar__more { opacity: 1; } }

.sidebar__menu {
  position: fixed;
  inset: auto;
  min-width: 170px;
  margin: 0;
  padding: 0.3rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.sidebar__menu form { margin: 0; }
.sidebar__menu-item {
  display: block;
  width: 100%;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 6px;
}
.sidebar__menu-item:hover, .sidebar__menu-item:focus-visible { background: var(--color-bg); }
.sidebar__menu-item--danger { color: #cf222e; }

.chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-flash > .flash { margin: 0.75rem 1.25rem 0; }

.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.chat__heading { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.chat__title { margin: 0; overflow: hidden; font-size: 1.05rem; white-space: nowrap; text-overflow: ellipsis; }
.category-badge {
  flex-shrink: 0;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: bold;
  color: #fff;
  white-space: nowrap;
  background: var(--color-primary);
  border-radius: 999px;
}

/* ---------- Category picker (new conversation) ---------- */
.category-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 0.6rem 1.25rem;
  border: 0;
  border-bottom: 1px solid var(--color-border);
}
.category-picker__label { float: left; padding: 0; font-size: 0.9rem; font-weight: bold; white-space: nowrap; }
.category-picker__options { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.category-picker__option input { position: absolute; opacity: 0; pointer-events: none; }
.category-picker__option span {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--color-text);
  white-space: nowrap;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
}
.category-picker__option span:hover { border-color: var(--color-primary); }
.category-picker__option input:checked + span { color: #fff; background: var(--color-primary); border-color: var(--color-primary); }
.category-picker__option input:focus-visible + span { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.chat__menu { position: relative; }
.chat__menu summary { list-style: none; }
.chat__menu summary::-webkit-details-marker { display: none; }
.chat__menu-panel {
  position: absolute;
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 300px;
  margin-top: 0.4rem;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.08);
}
.chat__menu-panel form { margin: 0; }
.chat__rename { gap: 0.4rem; }

.chat__summary {
  padding: 0.4rem 1.25rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.chat__summary summary { cursor: pointer; }
.chat__summary-body { max-width: 860px; max-height: 40vh; margin: 0.5rem auto 0.25rem; overflow-y: auto; }
.chat__summary-note { margin: 0 0 0.4rem; }
.chat__summary-text {
  padding: 0.6rem 0.9rem;
  color: var(--color-text);
  white-space: pre-wrap;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.chat__messages { flex: 1; overflow-y: auto; padding: 1.25rem; }
.chat__messages--empty { display: flex; align-items: center; justify-content: center; }
.chat__welcome { text-align: center; }

/* ---------- Messages ---------- */
.message { max-width: 860px; margin: 0 auto 1.25rem; }
.message--user { display: flex; justify-content: flex-end; }
.message__question { display: flex; flex-direction: column; align-items: flex-end; gap: 0.4rem; max-width: 85%; }
.message__bubble {
  max-width: 100%;
  padding: 0.6rem 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fbe9e2;
  border-radius: 12px 12px 2px 12px;
}
.message--assistant { padding: 0.25rem 0; }

/* Files attached to a question */
.attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.attachment__link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 280px;
  padding: 0.35rem 0.6rem 0.35rem 0.35rem;
  color: var(--color-text);
  text-decoration: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.attachment__link:hover { border-color: var(--color-primary); }
.attachment__thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  object-fit: cover;
  background: var(--color-bg);
  border: 1px solid var(--color-border); /* keeps white PDF pages visible */
  border-radius: 4px;
}
.attachment__icon, .composer__file-icon {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--color-primary);
  background: #fbe9e2;
  border-radius: 4px;
}
.attachment__text { display: flex; flex-direction: column; min-width: 0; }
.attachment__name { overflow: hidden; font-size: 0.85rem; white-space: nowrap; text-overflow: ellipsis; }
.attachment__details { font-size: 0.75rem; color: var(--color-muted); }
.message__activity { display: flex; align-items: center; gap: 0.5rem; color: var(--color-muted); font-size: 0.9rem; }
.message__spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.message__controls { margin-top: 0.5rem; }
.message__controls form { margin: 0; }
.message__notice { margin-top: 0.6rem; padding: 0.45rem 0.75rem; font-size: 0.9rem; background: var(--color-bg); border-radius: 6px; }
.message__notice--warning { background: #fff8e5; color: #7a5200; }
.message__notice--error { background: var(--color-alert-bg); color: var(--color-alert-text); }
.message__sources { margin-top: 0.6rem; font-size: 0.85rem; }
.message__sources-label { font-weight: bold; color: var(--color-muted); }
.message__sources ol { margin: 0.2rem 0 0; padding-left: 1.4rem; }
.message__manual-sources { margin: 0.2rem 0 0; padding-left: 1.2rem; }
.chat__manual-notice {
  margin: 0;
  padding: 0.35rem 1.25rem;
  font-size: 0.82rem;
  color: #1f4e79;
  background: #eef5fc;
  border-bottom: 1px solid var(--color-border);
}
.chat__manual-notice[hidden] { display: none; }
.message__usage { margin-top: 0.5rem; font-size: 0.8rem; }

/* ---------- Markdown answers ---------- */
.markdown { overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown blockquote, .markdown table { margin: 0 0 0.8em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 1.2em 0 0.5em; font-size: 1.05rem; }
.markdown h1 { font-size: 1.25rem; }
.markdown h2 { font-size: 1.15rem; }
.markdown blockquote { padding-left: 0.9rem; color: var(--color-muted); border-left: 3px solid var(--color-border); }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { padding: 0.35rem 0.6rem; border: 1px solid var(--color-border); }
.markdown th { background: var(--color-bg); }
.markdown td[align="right"], .markdown th[align="right"] { text-align: right; }
.markdown td[align="center"], .markdown th[align="center"] { text-align: center; }
.markdown :not(pre) > code {
  padding: 0.1em 0.35em;
  font-size: 0.9em;
  background: #f0f1f3;
  border-radius: 4px;
}
.markdown pre { margin: 0; padding: 0.8rem 1rem; overflow-x: auto; font-size: 0.85rem; line-height: 1.55; }
.markdown pre, .markdown code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.code-block { margin: 0 0 0.9em; overflow: hidden; border: 1px solid var(--color-border); border-radius: var(--radius); }
.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  color: var(--color-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.code-block__copy {
  padding: 0.1rem 0.5rem;
  font: inherit;
  color: inherit;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
}
.code-block__copy:hover { background: var(--color-surface); }

/* ---------- Composer ---------- */
.composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 1rem;
}
.composer__input { min-height: 4.5rem; resize: none; }
.composer__actions { display: flex; align-items: center; gap: 0.75rem; }
.composer__attach { flex-shrink: 0; }

/* Files waiting to be sent with the next question */
.composer__files { display: flex; flex-direction: column; gap: 0.3rem; }
.composer__file-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.composer__file {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 260px;
  padding: 0.25rem 0.3rem 0.25rem 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.composer__file-thumb { flex-shrink: 0; width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }
.composer__file .composer__file-icon { width: 40px; height: 40px; font-size: 0.7rem; }
.composer__file-name { overflow: hidden; font-size: 0.82rem; white-space: nowrap; text-overflow: ellipsis; }
.composer__file-size { flex-shrink: 0; font-size: 0.75rem; color: var(--color-muted); }
.composer__file-remove {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-muted);
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 50%;
}
.composer__file-remove:hover { color: var(--color-text); background: var(--color-bg); }
.composer__file-note { margin: 0; font-size: 0.78rem; }
.composer__file-error {
  margin: 0;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  white-space: pre-line;
  color: var(--color-alert-text);
  background: var(--color-alert-bg);
  border-radius: 6px;
}
/* Shown over the whole window while files are dragged; drops are handled on the window. */
.composer__dropzone {
  position: fixed;
  inset: 0.75rem;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--color-primary);
  text-align: center;
  pointer-events: none;
  background: rgb(255 255 255 / 0.85);
  border: 3px dashed var(--color-primary);
  border-radius: 16px;
}
.composer__dropzone[hidden] { display: none; }
.composer__model { width: auto; }
.composer__hint { flex: 1; font-size: 0.8rem; text-align: right; }

/* ---------- Misc ---------- */
.visually-hidden { position: fixed; top: 0; left: -9999px; opacity: 0; }
.button--small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.button--danger { color: #fff; background: #cf222e; }
.button--danger:hover { background: #a40e26; }
.form__field--inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.form__field--inline input[type="checkbox"] { width: auto; }
textarea { line-height: 1.6; }

.admin-nav { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border); }
.admin-nav a {
  padding: 0.4rem 0.9rem;
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.admin-nav a.is-active { color: var(--color-text); border-bottom-color: var(--color-primary); }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .composer__hint { display: none; }
}
