/* Private conversations share the site's light and dark palettes. */
:root {
  --chat-sidebar: #fcfafe;
  --chat-canvas: #f8f6fb;
  --chat-bubble: #ffffff;
  --chat-own: #ece4fa;
  --chat-own-ink: #574176;
  --chat-selected: #eee8f8;
  --chat-online: #4c8d72;
  --chat-danger: #b6455b;
}
html[data-theme="dark"] {
  --chat-sidebar: #24202d;
  --chat-canvas: #211e29;
  --chat-bubble: #302a3a;
  --chat-own: #443256;
  --chat-own-ink: #edddff;
  --chat-selected: #382e47;
  --chat-online: #8ccbad;
  --chat-danger: #f5a3b4;
}
.chat-panel { display: grid; grid-template-columns: minmax(225px, 29%) minmax(0, 1fr); height: min(710px, calc(100dvh - 230px)); min-height: 510px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); }
.chat-panel :is(button, input, textarea) { font: inherit; }
.chat-panel button { touch-action: manipulation; }
.chat-panel button:focus-visible { outline: 3px solid var(--theme-focus); outline-offset: -3px; }
.chat-panel [hidden] { display: none !important; }
.chat-sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-sidebar); border-right: 1px solid var(--line); }
.chat-sidebar-head { padding: 21px 18px 15px; border-bottom: 1px solid var(--line); }
.chat-sidebar-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 15px; }
.chat-sidebar-title h2 { font-size: 16px; font-weight: 600; letter-spacing: .3px; }
.chat-live { display: inline-flex; align-items: center; gap: 5px; color: var(--chat-online); font-size: 10px; white-space: nowrap; }
.chat-live::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.chat-live.is-offline { color: var(--muted); }
.chat-search { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; }
.chat-search:focus-within { border-color: var(--purple); box-shadow: 0 0 0 2px color-mix(in srgb, var(--purple) 12%, transparent); }
.chat-search svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--muted); }
.chat-search input { border: 0; outline: none; min-width: 0; width: 100%; color: var(--ink); background: transparent; padding: 11px 0; font-size: 11px; }
.chat-sidebar-hint { color: var(--muted); font-size: 10px; line-height: 1.8; margin-top: 10px; }
.chat-sidebar-scroll { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; padding: 9px; }
.chat-list-heading { padding: 11px 9px 8px; color: var(--muted); font-size: 10px; font-weight: 500; letter-spacing: .8px; }
.chat-person { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 12px 10px; border-radius: 9px; min-width: 0; margin-bottom: 3px; border: 1px solid transparent; }
.chat-person:hover { background: var(--settings-soft); }
.chat-person.is-selected { background: var(--chat-selected); border-color: color-mix(in srgb, var(--purple) 17%, transparent); }
.chat-person .role-avatar { width: 35px; height: 35px; }
.chat-person-copy { min-width: 0; flex: 1; }
.chat-person-title { display: flex; align-items: baseline; justify-content: space-between; gap: 7px; }
.chat-person-title strong { color: var(--ink); font-size: 12px; font-weight: 550; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-person-title time { font-size: 9px; color: var(--muted); flex-shrink: 0; }
.chat-person-preview { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.chat-person-preview p { font-size: 10px; line-height: 1.6; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.chat-unread { border-radius: 12px; min-width: 17px; height: 17px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; background: var(--purple); color: var(--paper); font-size: 9px; line-height: 1; font-weight: 600; flex-shrink: 0; }
html[data-theme="dark"] .chat-unread { color: #241b31; }
.chat-list-empty { color: var(--muted); font-size: 11px; line-height: 1.9; padding: 17px 10px; }
.chat-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; background: var(--chat-canvas); }
.chat-header { display: flex; align-items: center; gap: 11px; padding: 17px 22px; min-height: 77px; border-bottom: 1px solid var(--line); background: var(--paper); }
.chat-header .role-avatar { width: 37px; height: 37px; }
.chat-header-copy { min-width: 0; flex: 1; }
.chat-header h3 { font-size: 14px; font-weight: 600; line-height: 1.6; overflow-wrap: anywhere; }
.chat-header p { font-size: 10px; color: var(--muted); line-height: 1.7; margin-top: 2px; overflow-wrap: anywhere; }
.chat-header .chat-clear { color: var(--chat-danger); padding: 7px 9px; font-size: 10px; white-space: nowrap; border-radius: 6px; }
.chat-header .chat-clear:hover { background: color-mix(in srgb, var(--chat-danger) 8%, transparent); }
.chat-back { display: none; flex-shrink: 0; }
.chat-welcome { display: flex; flex: 1; min-height: 0; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 35px; }
.chat-welcome-icon { width: 68px; height: 68px; display: grid; place-items: center; background: var(--chat-selected); color: var(--purple); border-radius: 22px; margin-bottom: 20px; }
.chat-welcome-icon svg { width: 29px; height: 29px; }
.chat-welcome h3 { font-size: 17px; color: var(--ink); font-weight: 550; }
.chat-welcome p { color: var(--muted); font-size: 12px; line-height: 1.95; max-width: 300px; margin-top: 11px; }
.chat-message-list { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 23px 22px 17px; scroll-behavior: auto; }
.chat-message-list > .chat-list-empty { text-align: center; margin: 25px auto; }
.chat-message { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 21px; }
.chat-message > .role-avatar { width: 29px; height: 29px; margin-top: 19px; }
.chat-message-content { max-width: min(80%, 590px); min-width: 0; }
.chat-message-meta { display: flex; gap: 9px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; line-height: 1.6; }
.chat-message-meta strong { font-size: 10px; font-weight: 500; color: var(--school-copy, var(--muted)); }
.chat-message-meta time { font-size: 9px; color: var(--muted); }
.chat-bubble { background: var(--chat-bubble); border: 1px solid var(--line); border-radius: 2px 12px 12px 12px; padding: 11px 14px; font-size: 12px; line-height: 1.9; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.chat-message.is-own { flex-direction: row-reverse; }
.chat-message.is-own .chat-message-meta { justify-content: flex-end; }
.chat-message.is-own .chat-bubble { background: var(--chat-own); border-color: color-mix(in srgb, var(--purple) 14%, transparent); color: var(--chat-own-ink); border-radius: 12px 2px 12px 12px; }
.chat-message.is-retracted .chat-bubble { font-style: italic; color: var(--muted); background: transparent; border-style: dashed; }
.chat-message-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.chat-message.is-own .chat-message-foot { justify-content: flex-end; }
.chat-message-foot span { color: var(--muted); font-size: 9px; }
.chat-message-action { color: var(--muted); font-size: 9px !important; text-decoration: underline; text-underline-offset: 3px; padding: 2px; border-radius: 3px; }
.chat-message-action:hover { color: var(--purple); }
.chat-message-action.is-danger:hover { color: var(--chat-danger); }
.chat-new-messages { position: absolute; right: 22px; bottom: 151px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow); color: var(--purple); font-size: 11px !important; padding: 8px 13px; z-index: 1; }
.chat-composer { flex-shrink: 0; padding: 15px 20px 13px; background: var(--paper); border-top: 1px solid var(--line); }
.chat-composer textarea { width: 100%; min-height: 56px; max-height: 150px; resize: vertical; padding: 0; border: 0; background: transparent; outline: none; color: var(--ink); font-size: 12px; line-height: 1.9; display: block; }
.chat-composer textarea:focus-visible { outline: none; }
.chat-composer:focus-within { box-shadow: inset 0 2px 0 color-mix(in srgb, var(--purple) 40%, transparent); }
.chat-composer textarea:disabled { cursor: not-allowed; }
.chat-composer-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; }
.chat-composer-foot > span { font-size: 9px; color: var(--muted); line-height: 1.7; }
.chat-composer .button { min-height: 33px; font-size: 11px; padding: 7px 14px; white-space: nowrap; }
.chat-composer .button svg { width: 13px; height: 13px; }
.chat-composer .button:disabled { opacity: .5; cursor: not-allowed; }
.chat-inline-error { color: var(--chat-danger); font-size: 11px; line-height: 1.7; margin: 0; padding: 10px 20px; background: var(--paper); overflow-wrap: anywhere; }
.chat-edit-banner, .chat-confirm { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 11px 20px; font-size: 11px; line-height: 1.8; border-bottom: 1px solid var(--line); background: var(--chat-selected); color: var(--ink); }
.chat-edit-banner { margin: -15px -20px 13px; }
.chat-edit-banner button { color: var(--purple); text-decoration: underline; white-space: nowrap; }
.chat-confirm { background: var(--paper); color: var(--chat-danger); flex-wrap: wrap; }
.chat-confirm > div { display: flex; gap: 9px; margin-left: auto; }
.chat-confirm .button { min-height: 30px; font-size: 10px; padding: 6px 10px; }
.chat-moderation-note { color: var(--muted); text-align: center; font-size: 10px; line-height: 1.8; padding: 11px 19px; background: var(--paper); border-top: 1px solid var(--line); }
.chat-loading { padding: 20px; color: var(--muted); font-size: 11px; }
@media (max-width: 1000px) {
  .chat-panel { grid-template-columns: 225px minmax(0, 1fr); }
  .chat-header { padding: 15px; }
  .chat-message-list { padding: 20px 15px; }
  .chat-message-content { max-width: 85%; }
  .chat-composer { padding: 14px 15px 12px; }
  .chat-edit-banner { margin: -14px -15px 12px; padding: 10px 15px; }
}
@media (max-width: 700px) {
  .chat-panel { display: block; height: min(720px, calc(100dvh - 218px)); min-height: 460px; }
  .chat-sidebar, .chat-main { height: 100%; }
  .chat-sidebar { border-right: 0; }
  .chat-main { display: none; }
  .chat-panel.has-conversation .chat-sidebar { display: none; }
  .chat-panel.has-conversation .chat-main { display: flex; }
  .chat-back { display: inline-flex; width: 26px; height: 30px; align-items: center; justify-content: center; color: var(--muted); }
  .chat-back svg { width: 19px; height: 19px; }
  .chat-header { min-height: 71px; gap: 8px; padding: 12px; }
  .chat-header .role-avatar { width: 32px; height: 32px; }
  .chat-header h3 { font-size: 12px; }
  .chat-header p { font-size: 9px; }
  .chat-header .chat-clear { font-size: 9px; padding: 5px; }
  .chat-message-list { padding: 18px 12px; }
  .chat-message { gap: 7px; }
  .chat-message-content { max-width: calc(100% - 39px); }
  .chat-bubble { font-size: 12px; padding: 10px 12px; }
  .chat-composer textarea { font-size: 16px; min-height: 52px; }
  .chat-composer-foot > span { max-width: 160px; }
  .chat-new-messages { bottom: 150px; right: 14px; }
}
@media (prefers-reduced-motion: reduce) { .chat-panel * { scroll-behavior: auto !important; transition: none !important; } }
