/* The conversation is a workspace: compact chrome, one shared reading measure. */
.chat-menu-toggle { display: none; }
.chat-drawer { width: min(360px, calc(100% - 24px)); height: 100dvh; max-height: 100dvh; max-width: none; margin: 0; padding: 0; border: 0; border-right: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.chat-drawer::backdrop { background: #20383c66; }
.chat-menu-close { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 1; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--ink); }
.chat-drawer .chat-sidebar { display: flex; flex-direction: column; height: 100%; width: 100%; min-height: 0; padding: max(24px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); border: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-drawer .chat-sidebar-heading { display: block; flex: none; }
.chat-drawer .chat-sidebar-heading h2 { display: block; font-size: 24px; padding-right: 44px; margin: 0 0 24px; }
.chat-drawer .chat-new { width: 100%; min-height: 44px; }
.chat-drawer .chat-sidebar-note { display: block; flex: none; font-size: 13px; }
.chat-drawer #conversation-list { flex: 1 0 120px; min-height: 120px; max-height: none; min-width: 0; flex-direction: column; overflow: auto; overscroll-behavior: contain; margin: 8px 0 0; gap: 8px; }
.chat-drawer .conversation-link { width: 100%; max-width: none; min-height: 44px; font-size: 14px; white-space: normal; overflow-wrap: anywhere; text-overflow: clip; padding: 12px; }
.chat-drawer nav[aria-label="Основная навигация"] { display: grid; grid-template-columns: minmax(0, 1fr); flex: none; gap: 0; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.chat-drawer nav[aria-label="Основная навигация"] a { display: flex; align-items: center; min-height: 44px; color: var(--ink); font-size: 13px; text-decoration: none; }
.chat-drawer nav[aria-label="Основная навигация"] a[aria-current=page] { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.chat-drawer .chat-profile { display: none; }
.conversation-item { flex: none; min-width: 0; border: 1px solid transparent; }
.conversation-row { display: flex; align-items: center; min-width: 0; }
.conversation-row .conversation-link { flex: 1; width: 0; min-width: 0; border: 0; }
.conversation-item:has(.conversation-link[aria-current=page]) { border-color: var(--line); background: var(--paper); }
.conversation-more { display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border: 0; color: var(--muted); background: transparent; }
.conversation-more svg { width: 20px; height: 20px; fill: currentColor; }
.conversation-more:hover, .conversation-more[aria-expanded=true] { color: var(--ink); background: var(--sheet); }
.conversation-actions { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0 8px 8px; padding-top: 4px; border-top: 1px solid var(--line); }
.conversation-actions button { min-height: 44px; padding: 8px 12px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; text-align: left; }
.conversation-actions button:hover { background: var(--sheet); }
.conversation-actions .conversation-delete { color: #963d2e; }
.chat-drawer .conversation-row .conversation-link { width: 0; }
.chat-page {
  height: 100dvh;
  min-height: 0;
}
.chat-page .site-header {
  min-height: 56px;
  padding: 0 24px;
  gap: 24px;
}
.chat-page .brand { width: auto; font-size: 15px; gap: 10px; }
.chat-page .brand svg { width: 28px; height: 28px; }
.chat-page .site-header nav { gap: 24px; }
.chat-page .site-header nav a { display: flex; align-items: center; min-height: 44px; font-size: 12px; }
.chat-page .header-note { font-size: 11px; }
.chat-layout { --chat-sidebar-width: 232px; grid-template-columns: var(--chat-sidebar-width) minmax(0, 1fr); }
.chat-sidebar { padding: 24px 20px 20px; }
.chat-sidebar-heading h2 { font-size: 22px; margin-bottom: 16px; }
.chat-new { min-height: 44px; padding: 8px 12px; }
.chat-sidebar-note { margin: 12px 0 16px; }
.conversation-link { min-height: 44px; padding: 10px 12px; }
.chat-profile { font-size: 12px; padding-top: 16px; margin-top: 16px; }
.chat-panel { --chat-inset: clamp(20px, 3vw, 40px); }
.chat-panel-heading { min-height: 64px; padding: 8px var(--chat-inset); gap: 16px; }
.chat-panel-heading h1 { font-size: 20px; margin: 0; min-width: 0; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-tools { flex-direction: row; gap: 12px; }
.chat-tools button { font-size: 12px; min-height: 44px; padding: 8px 0; border-bottom: 0; }
.chat-tools button:hover:not(:disabled) { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.chat-messages { padding: 24px var(--chat-inset); scrollbar-gutter: stable both-edges; }
.chat-exchange { max-width: 760px; margin-bottom: 32px; }
.chat-user-message { width: fit-content; max-width: 90%; padding: 12px 16px; margin-bottom: 24px; }
.chat-user-message p { margin-top: 4px; line-height: 1.7; }
.chat-assistant-message > p { font-size: 14px; line-height: 1.8; margin: 12px 0; }
.chat-assistant-message h3 { margin: 24px 0 8px; }
.chat-welcome { max-width: 760px; margin: clamp(24px, 6vh, 56px) auto; }
.chat-welcome h2 { font-size: clamp(28px, 3vw, 36px); letter-spacing: -.025em; }
.chat-welcome > p { font-size: 14px; line-height: 1.75; }
.chat-suggestions { margin-top: 24px; }
.chat-suggestions button { min-height: 44px; padding: 12px 0; font-size: 13px; }
.chat-composer {
  position: relative;
  padding: 12px max(var(--chat-inset), calc((100% - 760px) / 2)) max(12px, env(safe-area-inset-bottom));
  box-shadow: none;
  z-index: 3;
}
.chat-composer textarea {
  min-height: 72px;
  max-height: min(160px, 24dvh);
  padding: 10px 12px;
  font-size: 16px;
  line-height: 1.5;
  caret-color: var(--accent);
}
.chat-composer textarea::placeholder { color: var(--muted); opacity: 1; }
.chat-composer-controls { align-items: center; gap: 16px; margin-top: 8px; }
.chat-composer-controls > .save-button { min-height: 44px; padding: 8px 16px; font-size: 13px; }
.chat-methods { position: relative; flex: 0 1 auto; min-width: 0; font-size: 12px; }
.chat-methods > summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 0; list-style: none; }
.chat-methods > summary::-webkit-details-marker { display: none; }
.chat-methods > summary::before { content: ''; width: 6px; height: 6px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: rotate(45deg); margin: 0 2px 4px; }
.chat-methods[open] > summary::before { transform: rotate(225deg); margin-bottom: -2px; }
.chat-methods > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.chat-methods .method-choices {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(500px, calc(100vw - var(--chat-sidebar-width) - 2 * var(--chat-inset)));
  max-height: min(340px, 48dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  gap: 4px 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: var(--sheet);
  box-shadow: 0 8px 24px #20383c18;
}
.chat-methods .method-choice { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 0; font-size: 13px; line-height: 1.5; color: var(--ink); cursor: pointer; }
.chat-methods .method-choice span { min-width: 0; overflow-wrap: anywhere; }
.chat-methods .method-choice input { width: 18px; height: 18px; flex: 0 0 18px; }
.chat-methods .method-choice:hover { color: var(--accent); }
.chat-methods .method-choice:focus-within { outline-offset: 0; }
@media (max-width: 1000px) {
  .chat-page .header-note { display: none; }
  .chat-page .site-header nav { margin-left: auto; margin-right: 0; }
  .chat-layout { --chat-sidebar-width: 208px; }
  .chat-sidebar { padding-inline: 16px; }
}
@media (max-width: 720px) {
  .chat-page .site-header { display: none; }
  .chat-layout { display: flex; flex-direction: column; --chat-sidebar-width: 0px; }
  .chat-panel { min-height: 0; flex: 1; }
  .chat-menu-toggle { display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; background: transparent; color: var(--ink); border: 1px solid var(--line); }
  .chat-panel-heading { min-height: 52px; padding: 4px 16px; gap: 12px; align-items: center; }
  .chat-page .site-header { padding: 8px 20px 0; gap: 0; }
  .chat-page .brand { width: 100%; min-height: 32px; }
  .chat-page .site-header nav { width: 100%; margin: 0; gap: 8px; justify-content: space-between; }
  .chat-page .site-header nav a { min-height: 44px; }
  .chat-panel-heading h1 { flex: 1; display: block; font-family: var(--font-body); font-size: 16px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
  .chat-tools { gap: 12px; }
  .chat-tools button { font-size: 11px; }
}
@media (max-width: 600px) {
  .chat-layout { --chat-sidebar-width: 0px; }
  .chat-sidebar { padding: 12px 20px; }
  .chat-sidebar-heading { gap: 12px; }
  .chat-sidebar-heading h2 { margin: 0; font-size: 18px; }
  .chat-new { min-height: 44px; padding: 8px 12px; font-size: 12px; }
  #conversation-list { margin-top: 8px; max-height: 44px; gap: 8px; }
  .conversation-link { width: auto; max-width: 200px; min-height: 44px; padding: 8px 12px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .chat-panel { min-height: 0; flex: 1; --chat-inset: 20px; }
  .chat-panel-heading { min-height: 52px; padding-block: 4px; gap: 12px; }
  .chat-tools { gap: 12px; }
  .chat-messages { overflow-y: auto; min-height: 0; padding-block: 20px; scrollbar-gutter: auto; }
  .chat-welcome { margin: 16px 0 24px; }
  .chat-welcome h2 { font-size: 28px; }
  .chat-user-message { max-width: 95%; }
  .chat-composer { position: relative; padding-top: 10px; }
  .chat-methods .method-choices { grid-template-columns: 1fr; }
}
/* Keep typing usable when the visible viewport is shortened by a keyboard. */
@media (max-width: 720px) and (max-height: 600px) {
  .chat-page .site-header { min-height: 44px; flex-wrap: nowrap; padding: 0 12px; gap: 12px; }
  .chat-page .brand { flex: 0 0 28px; width: 28px; }
  .chat-page .brand span { display: none; }
  .chat-page .site-header nav { width: auto; flex: 1; min-width: 0; }
  .chat-sidebar { flex-direction: row; align-items: center; gap: 12px; padding-block: 8px; }
  .chat-sidebar-heading { flex: none; }
  .chat-sidebar-heading h2 { display: none; }
  #conversation-list { margin: 0; min-width: 0; flex: 1; }
  .chat-panel-heading { min-height: 44px; padding-block: 0; }
  .chat-composer textarea { height: 48px; min-height: 48px; max-height: 72px; }
}
