/* WIRE20-21: Original LexiPanel chat shell. All names scoped to chat. */
.chat-page, :root[data-chat-theme="light"] .chat-page {

  --chat-bg: #f6f8fc;
  --chat-sidebar: #edf1f8;
  --chat-surface: #ffffff;
  --chat-inset: #f3f6fa;
  --chat-text: #14243b;
  --chat-muted: #617089;
  --chat-edge: #d8e0ec;
  --chat-primary: #285bbb;
  --chat-primary-text: #ffffff;
  --chat-soft-primary: #dfeaff;
  --chat-focus: #508be7;
  --chat-error: #934132;
  --chat-shadow: 0 8px 24px rgba(15,37,70,.09);
}
@media(prefers-color-scheme:dark) {
  :root[data-chat-theme="system"] .chat-page, :root:not([data-chat-theme]) .chat-page {

    --chat-bg: #101722;
    --chat-sidebar: #161f2e;
    --chat-surface: #1c2838;
    --chat-inset: #121c2b;
    --chat-text: #edf4ff;
    --chat-muted: #b4c1d7;
    --chat-edge: #33465f;
    --chat-primary: #82b3ff;
    --chat-primary-text: #101b2f;
    --chat-soft-primary: #223b61;
    --chat-focus: #a9c9fa;
    --chat-error: #ffad94;
    --chat-shadow: 0 8px 24px rgba(0,0,0,.3);
  }
}
:root[data-chat-theme="dark"] .chat-page {

  --chat-bg: #101722;
  --chat-sidebar: #161f2e;
  --chat-surface: #1c2838;
  --chat-inset: #121c2b;
  --chat-text: #edf4ff;
  --chat-muted: #b4c1d7;
  --chat-edge: #33465f;
  --chat-primary: #82b3ff;
  --chat-primary-text: #101b2f;
  --chat-soft-primary: #223b61;
  --chat-focus: #a9c9fa;
  --chat-error: #ffad94;
  --chat-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.chat-page, .chat-page *, .chat-page *::before, .chat-page *::after { box-sizing: border-box; }
.chat-page { margin: 0; min-height: 100%; background: var(--chat-bg); color: var(--chat-text); }
.chat-page { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
.chat-page button, .chat-page input, .chat-page textarea,
.chat-page select { font: inherit; }
.chat-page button, .chat-page select, .chat-page a { cursor: pointer; }
.chat-page a { color: inherit; }
.chat-page :focus-visible { outline: 3px solid var(--chat-focus); outline-offset: 2px; }
.chat-skip { position: absolute; z-index: 100; top: -100px; background: var(--chat-surface); padding: 8px; }
.chat-skip:focus { top: 0; }
.lexi-chat { min-height: 480px; height: min(78dvh, 960px); display: grid; grid-template-columns: 274px minmax(0,1fr); }
.chat-sidebar { background: var(--chat-sidebar); border-inline-end: 1px solid var(--chat-edge);
  display: flex; flex-direction: column; min-height: 0; gap: 9px; padding: 18px 14px; overflow-y: auto; }
.chat-sidebar a.chat-new { display: block; text-decoration: none; text-align: center; font-weight: 700;
  background: var(--chat-primary); color: var(--chat-primary-text); padding: 10px 12px; border-radius: 12px; }
.chat-sidebar label { color: var(--chat-muted); font-size: 12px; font-weight: 600; }
.chat-sidebar input[type="search"], .chat-sidebar select { display: block; width: 100%; padding: 8px;
  border: 1px solid var(--chat-edge); border-radius: 9px; background: var(--chat-surface); color: var(--chat-text); }
.chat-filter-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 12px; }
.chat-filter-row label:last-child { display: grid; justify-items: center; gap: 4px; }
.chat-temp-toggle { display: flex; gap: 8px; align-items: center; padding: 5px 0; }
.chat-sidebar-head { display: flex; align-items: center; justify-content: space-between; font-weight: 650; }
.chat-sidebar button { background: transparent; border: 1px solid transparent; border-radius: 9px; color: inherit;
  padding: 5px 8px; }
.chat-sidebar button:hover, .chat-sidebar button.selected { background: var(--chat-soft-primary); }
.chat-folders { display: flex; flex-direction: column; align-items: stretch; gap: 2px; }
.chat-folders button { text-align: start; }
.chat-history { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.chat-history li { display: flex; align-items: center; border-radius: 9px; min-height: 38px; }
.chat-history li:hover { background: var(--chat-inset); }
.chat-history-item { min-width: 0; flex: 1; display: block; padding: 9px 10px; border-radius: 9px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-decoration: none; }
.chat-history-item.selected { background: var(--chat-soft-primary); font-weight: 700; }
.chat-history-pin { flex-shrink: 0; font-size: 11px !important; }
/* History operations are available to keyboard and touch users without
 * crowding the conversation titles out of the narrow sidebar. */
.chat-history li { flex-wrap: wrap; padding-bottom: 4px; }
.chat-history li > .chat-history-item { flex-basis: 100%; }
.chat-history li > .chat-action, .chat-history li > .chat-history-export {
  font-size: 10px; padding: 2px 5px; line-height: 1.4; color: var(--chat-muted);
}
.chat-history-export { text-decoration: none; border-radius: 7px; }
.chat-history-export:hover { color: var(--chat-text); background: var(--chat-inset); }
.chat-citations { margin: 8px 0; font-size: 12px; color: var(--chat-muted); }
.chat-citation-source { overflow-wrap: anywhere; }
.chat-attachment-link { display: inline-block; margin: 3px 6px 3px 0; font-size: 12px; }

.chat-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-topbar { display: flex; align-items: center; padding: 10px 18px; background: var(--chat-surface);
  min-height: 70px; gap: 12px; border-bottom: 1px solid var(--chat-edge); }
.chat-title-wrap { min-width: 0; flex: 1; }
.chat-topbar h1 { font-size: 15px; margin: 0; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.chat-back { color: var(--chat-muted) !important; font-size: 12px; }
.chat-topbar button, .chat-composer button { border: 1px solid var(--chat-edge);
  border-radius: 10px; background: var(--chat-surface); color: var(--chat-text); padding: 8px 10px; }
.chat-topbar button:hover, .chat-composer button:hover { background: var(--chat-inset); }
.chat-model-picker { display: flex; flex-direction: column; gap: 3px; min-width: 200px; max-width: min(40vw,360px); }
.chat-model-picker label { font-size: 11px; color: var(--chat-muted); }
.chat-model-picker select { border: 1px solid var(--chat-edge); background: var(--chat-surface);
  color: var(--chat-text); border-radius: 8px; max-width: 100%; padding: 5px 8px; }
.chat-model-picker button { align-self: end; font-size: 11px; padding: 2px 6px; }
.chat-messages { flex: 1; min-height: 0; width: 100%; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 18px; padding: 32px max(20px,calc((100% - 880px)/2)) 24px; }
.chat-empty { margin: auto; max-width: 42ch; text-align: center; font-size: 22px; font-weight: 570;
  color: var(--chat-muted); }
.chat-message { min-width: 0; border-radius: 14px; padding: 14px 16px; background: var(--chat-surface);
  border: 1px solid var(--chat-edge); box-shadow: 0 2px 6px rgba(0,0,0,.025); }
.chat-role-user { background: var(--chat-soft-primary); margin-inline-start: min(8%,70px); }
.chat-role-assistant { margin-inline-end: min(6%,50px); }
.chat-message-header { display: flex; gap: 10px; align-items: center; font-size: 12px; margin-bottom: 8px; }
.chat-message-header small, .chat-message-status, .chat-message-model { color: var(--chat-muted); }
.chat-message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.chat-message-text pre { max-width: 100%; overflow-x: auto; }
.chat-message-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chat-action { color: var(--chat-muted); background: transparent; border: 0;
  padding: 4px 8px; border-radius: 7px; font-size: 12px; }
.chat-action:hover { color: var(--chat-text); background: var(--chat-inset); }
.chat-sibling-count { font-size: 12px; padding: 4px 0; color: var(--chat-muted); }
.chat-composer { position: relative; background: var(--chat-surface); border: 1px solid var(--chat-edge);
  border-radius: 16px; padding: 12px 14px; margin: 8px max(20px,calc((100% - 880px)/2)) 22px; box-shadow: var(--chat-shadow); }
.chat-composer textarea { resize: none; display: block; width: 100%; min-height: 64px; max-height: 240px;
  padding: 6px 4px; background: transparent; color: var(--chat-text); border: 0; outline: 0; }
.chat-composer textarea:focus-visible { outline: 0 !important; }
.chat-composer-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#lexi-chat-composer-actions { display: flex; gap: 6px; }
#lexi-chat-composer-hint { color: var(--chat-muted); font-size: 11px; margin-inline-end: auto; }
.chat-composer .chat-send { background: var(--chat-primary); color: var(--chat-primary-text); font-weight: 700; }
.chat-composer #lexi-chat-stop { color: var(--chat-error); border-color: currentColor; }
.chat-composer button:disabled { opacity: .5; cursor: not-allowed; }
.chat-picker { position: absolute; left: 10px; right: 10px; bottom: 100%; z-index: 20;
  overflow-y: auto; max-height: 260px; padding: 10px; background: var(--chat-surface);
  box-shadow: var(--chat-shadow); border: 1px solid var(--chat-edge); border-radius: 12px; }
.chat-picker button { display: block; text-align: start; width: 100%; margin: 2px 0; }
.chat-notice { margin: 10px 20px 0; color: var(--chat-error); padding: 8px 12px;
  border: 1px solid currentColor; border-radius: 8px; font-size: 13px; }
.chat-toast { position: fixed; bottom: 15px; inset-inline-end: 18px; z-index: 40; background: var(--chat-surface);
  color: var(--chat-text); border-radius: 12px; box-shadow: var(--chat-shadow); }
.chat-toast:not(:empty) { padding: 8px 12px; border: 1px solid var(--chat-edge); }
#lexi-chat-modal { background: var(--chat-surface); color: var(--chat-text); border: 1px solid var(--chat-edge);
  border-radius: 16px; width: min(90vw,560px); max-height: 80dvh; box-shadow: var(--chat-shadow); }
#lexi-chat-modal::backdrop { background: rgba(0,0,0,.5); }
#lexi-chat-modal h2 { margin-top: 0; }
#lexi-chat-modal-content { display: flex; flex-direction: column; gap: 12px; overflow: auto; max-height: 65dvh; }
.chat-setting-label { display: grid; gap: 5px; }
#lexi-chat-modal-close { display: block; margin-top: 16px; margin-inline-start: auto;
  border: 1px solid var(--chat-edge); border-radius: 8px; padding: 6px 12px;
  background: var(--chat-inset); color: var(--chat-text); }
.chat-sidebar-collapsed { grid-template-columns: 0 minmax(0,1fr); }
.chat-sidebar-collapsed .chat-sidebar { visibility: hidden; overflow: hidden; padding: 0; }
.chat-visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.chat-page [hidden] { display: none !important; }
@media(max-width:760px) {
  .lexi-chat { grid-template-columns: minmax(0,1fr); }
  .chat-sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw,320px); z-index: 30;
    box-shadow: var(--chat-shadow); transform: translateX(-110%); transition: transform .16s ease; }
  .lexi-chat:not(.chat-sidebar-collapsed) .chat-sidebar { transform: translateX(0); }
  .chat-sidebar-collapsed { grid-template-columns: minmax(0,1fr); }
  .chat-sidebar-collapsed .chat-sidebar { visibility: visible; padding: 18px 14px; }
  .chat-topbar { padding: 8px 10px; gap: 8px; }
  .chat-topbar h1 { max-width: 150px; }
  .chat-model-picker { min-width: 110px; max-width: 45vw; }
  .chat-messages { padding: 18px 12px; }
  .chat-composer { margin: 6px 8px 10px; }
  #lexi-chat-composer-hint { display: none; }
  .chat-message { padding: 11px 12px; }
  .chat-role-user { margin-inline-start: 4%; }
  .chat-role-assistant { margin-inline-end: 3%; }
}
@media(prefers-reduced-motion:reduce) {
  .chat-sidebar { transition: none; }
}
.chat-preset-select { display: flex; flex-direction: column; align-items: start; gap: 2px;
  font-size: 11px; color: var(--chat-muted); }
.chat-preset-select select { max-width: 160px; border: 1px solid var(--chat-edge); border-radius: 7px;
  padding: 5px; background: var(--chat-surface); color: var(--chat-text); }
.chat-answer-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(250px,100%),1fr));
  gap: 10px; align-items: start; }
.chat-answer-grid .chat-message { margin: 0; height: 100%; }

/* L23-14: inert tool details, keyboard navigation, and narrow-screen code. */
.chat-message-tools, .lexi-chat-message-tools { margin-top: 10px; min-width: 0; }
.chat-tool, .lexi-chat-tool { border: 1px solid var(--chat-edge); border-radius: 8px; padding: 6px 10px; }
.chat-tool summary, .lexi-chat-tool summary { cursor: pointer; overflow-wrap: anywhere; }
.chat-tool pre, .lexi-chat-tool pre { max-width: 100%; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-messages { overscroll-behavior: contain; }
@media (max-width:760px) {
  .chat-message-text pre { -webkit-overflow-scrolling: touch; }
  .chat-answer-grid { grid-template-columns: minmax(0,1fr); }
}

/* Conversation controls live in a modal drawer; account preferences use tabs. */
.chat-settings-drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(94vw, 480px);
  height: 100dvh; max-height: 100dvh; max-width: 100vw; overflow-y: auto;
  padding: 24px; border: 0; border-inline-start: 1px solid var(--chat-edge);
  background: var(--chat-surface); color: var(--chat-text); box-shadow: var(--chat-shadow);
}
.chat-settings-drawer::backdrop { background: rgba(0,0,0,.4); }
.chat-settings-drawer section { padding-block: 16px; border-block-start: 1px solid var(--chat-edge); }
.chat-settings-drawer h2, .chat-settings-drawer h3 { margin: 0 0 8px; }
.chat-settings-help { color: var(--chat-muted); font-size: 13px; }
.chat-settings-drawer input:not([type="checkbox"]), .chat-settings-drawer select,
.chat-settings-drawer textarea, #lexi-chat-modal select {
  width: 100%; padding: 8px; border: 1px solid var(--chat-edge); border-radius: 8px;
  color: var(--chat-text); background: var(--chat-inset);
}
.chat-settings-drawer label { margin-block: 10px; }
.chat-settings-drawer button { padding: 7px 12px; border: 1px solid var(--chat-edge);
  border-radius: 8px; color: var(--chat-text); background: var(--chat-inset); }
#lexi-chat-drawer-close { float: inline-end; }
#lexi-chat-settings-status { min-height: 1.5em; overflow-wrap: anywhere; }
.chat-settings-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-settings-tabs [aria-selected="true"] { color: var(--chat-text); background: var(--chat-soft-primary); }
#lexi-chat-sidebar-toggle { position: fixed; bottom: 12px; left: 12px; z-index: 35;
  border: 1px solid var(--chat-edge); border-radius: 8px; padding: 8px;
  color: var(--chat-text); background: var(--chat-surface); }
.chat-sidebar { padding-bottom: 60px; }
@media(max-width:760px) {
  .chat-topbar { flex-wrap: wrap; }
  .chat-title-wrap { flex-basis: 100%; }
  .chat-model-picker { flex: 1; max-width: none; }
}

/* The chat surface occupies the native content area; it must not displace
 * the common Panel navigation or override form styles on other pages. */
#lexi-main-content:has(> .chat-page) { min-width: 0; max-width: none; padding: 0; }
.chat-page { width: 100%; min-width: 0; border-radius: 12px; overflow: clip; }
.chat-page .lexi-chat { min-height: min(480px, 75dvh); max-height: 960px; }
.chat-page #lexi-chat-sidebar-toggle { position: absolute; bottom: 12px; inset-inline-start: 12px; left: auto; }
@media (max-width: 760px) {
  .chat-page .lexi-chat { min-height: 520px; height: 78dvh; }
}
