.chat-page { padding-top: 40px; }
.chat-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.chat-heading h1 { margin: 4px 0; font-size: clamp(2rem, 5vw, 3rem); }
.chat-heading p, .chat-channel-header p { color: var(--text-secondary); margin: 0; }
.chat-eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-weight: 800; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; }
.chat-eyebrow::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 12px var(--primary); }
.chat-notice { padding: 14px 18px; border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 12px; background: var(--surface); color: var(--text-secondary); font-size: .88rem; }
.chat-layout { display: grid; grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); align-items: start; gap: 18px; }
.chat-sidebar, .chat-conversation { border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-md); }
.chat-sidebar { padding: 20px; }
.chat-sidebar h2 { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 12px; }
.chat-channels { display: grid; gap: 6px; }
.chat-channels button, .chat-sidebar summary, .chat-message-actions button, .chat-emoji, #chat-reply-cancel, .chat-item-button {
  border: 0; background: transparent; color: var(--text-secondary); font: inherit; cursor: pointer;
}
.chat-channels button { text-align: left; padding: 10px 12px; border-radius: 10px; transition: background .2s, color .2s, transform .2s; }
.chat-channels button:hover { background: var(--surface-hover); color: var(--text); transform: translateX(3px); }
.chat-channels button[aria-pressed="true"] { background: var(--surface-hover); color: var(--primary); box-shadow: inset 3px 0 var(--primary); font-weight: 700; }
.chat-sidebar details { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; overflow-wrap: anywhere; }
.chat-sidebar summary { color: var(--text); font-weight: 700; padding: 5px 0; }
.chat-sidebar summary:hover { color: var(--primary); }
.chat-sidebar details p { color: var(--text-secondary); font-size: .85rem; line-height: 1.5; }
.chat-sidebar details a { color: var(--primary); text-decoration: underline; }
#chat-profile-settings summary { display: flex; align-items: center; gap: 9px; list-style: none; }
#chat-profile-settings summary::-webkit-details-marker { display: none; }
#chat-profile-settings summary::before { content: "+"; display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 9px; background: var(--surface-hover); color: var(--primary); font-size: 1.2rem; }
#chat-profile-settings[open] summary::before { content: "−"; }
.chat-summary-hint { margin-left: auto; color: var(--text-muted); font-size: .75rem; font-weight: 500; }
#chat-profile-settings form { margin-top: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-secondary); }
.chat-settings-intro { margin-top: 0; }
#chat-profile-form > label:not(.chat-profile-choice) { display: block; font-size: .85rem; font-weight: 700; }
#chat-profile-bio { width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; resize: vertical; }
.chat-profile-choice { display: flex; align-items: flex-start; gap: 9px; margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: .85rem; cursor: pointer; }
.chat-profile-choice input { flex: none; margin-top: .35em; accent-color: var(--primary); }
#chat-profile-form .btn { padding: 9px 12px; }
#chat-banner-form label { display: block; font-size: .85rem; font-weight: 700; }
#chat-banner-file { display: block; width: 100%; margin: 10px 0; color: var(--text-secondary); font-size: .8rem; }
#chat-banner-file::file-selector-button { max-width: 100%; margin: 0 8px 6px 0; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
#chat-banner-form .btn { padding: 9px 12px; }
#chat-banner-preview { display: block; width: 100%; aspect-ratio: 3 / 1; object-fit: cover; border: 1px solid var(--border); border-radius: 10px; }
#chat-profile-status:empty, #chat-banner-status:empty { display: none; }
#chat-profile-status:not(:empty), #chat-banner-status:not(:empty) { margin-bottom: 0; color: var(--primary); }
.chat-item-button { color: var(--primary); padding: 4px; text-decoration: underline; }
.chat-conversation { min-width: 0; padding: 24px; }
.chat-channel-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 18px; }
.chat-channel-header h2 { margin: 0; font-size: 1.2rem; }
.chat-channel-header span { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-secondary); color: var(--primary); font-size: .8rem; }
.chat-channel-header span::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
#chat-status { min-height: 1.5em; color: var(--primary); font-size: .9rem; }
#chat-messages { display: grid; gap: 12px; max-height: 540px; overflow-y: auto; overscroll-behavior: contain; }
.chat-message { min-width: 0; padding: 16px; border: 1px solid transparent; border-radius: 14px; background: var(--bg-secondary); overflow-wrap: anywhere; transition: border-color .2s, background .2s; }
.chat-message:hover, .chat-message:focus-within { border-color: var(--border); }
.chat-message header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.chat-avatar { display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; overflow: hidden; border: 2px solid var(--border); border-radius: 50%; background: var(--surface-hover); color: var(--primary); vertical-align: middle; }
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-author { border: 0; padding: 0; background: transparent; color: var(--text); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.chat-author:hover { color: var(--primary); }
.chat-message time { margin-left: auto; color: var(--text-muted); font-size: .75rem; }
.chat-rank { padding: 2px 7px; border-radius: 999px; background: var(--surface-hover); color: var(--primary); font-size: .72rem; font-weight: 700; }
.chat-message p { margin: 6px 0; white-space: pre-wrap; }
.chat-reference { border-left: 2px solid var(--primary); padding-left: 10px; color: var(--text-secondary); font-size: .85rem; }
.chat-message-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.chat-message-actions button { padding: 4px 0; font-size: .8rem; }
.chat-message-actions button:hover { color: var(--primary); }
#chat-form, #chat-guest { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
#chat-form label { display: block; font-weight: 700; }
#chat-form textarea { width: 100%; margin-top: 8px; padding: 12px; resize: vertical; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-secondary); color: var(--text); font: inherit; }
#chat-guest a { color: var(--primary); text-decoration: underline; }
.chat-compose { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }
.chat-emoji { font-size: 1.1rem; padding: 6px; border-radius: 8px; transition: background .2s, transform .2s; }
.chat-emoji:hover { background: var(--surface-hover); transform: translateY(-2px); }
#chat-reply { color: var(--text-secondary); font-size: .85rem; }
#chat-reply-cancel { color: var(--primary); text-decoration: underline; }
.chat-page :focus-visible, #chat-profile-dialog :focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
#chat-profile-dialog { width: min(420px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow-wrap: anywhere; }
#chat-profile-dialog::backdrop { background: rgba(0, 0, 0, .7); }
.chat-profile-cover { height: 140px; background: linear-gradient(120deg, var(--accent), var(--bg-secondary)); overflow: hidden; }
.chat-profile-cover img { width: 100%; height: 100%; object-fit: cover; }
.chat-profile-content { padding: 0 24px 24px; }
#chat-profile-picture { margin-top: -36px; position: relative; }
#chat-profile-dialog h2 { margin: 12px 0 0; }
#chat-profile-dialog p { white-space: pre-wrap; }
#chat-profile-dialog .chat-avatar { width: 72px; height: 72px; border: 4px solid var(--surface); font-size: 1.5rem; }
#chat-profile-close { position: absolute; z-index: 1; top: 8px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 1.5rem; cursor: pointer; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: no-preference) {
  .chat-heading, .chat-notice, .chat-layout { animation: chat-enter .4s ease both; }
  .chat-layout { animation-delay: .08s; }
  #chat-profile-settings[open] form, #chat-profile-dialog[open] { animation: chat-enter .25s ease both; }
  @keyframes chat-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
}
@media (prefers-reduced-motion: reduce) {
  .chat-channels button, .chat-message, .chat-emoji { transition: none; }
  .chat-channels button:hover, .chat-emoji:hover { transform: none; }
}
@media (max-width: 700px) {
  .chat-heading { align-items: start; flex-direction: column; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-channels { display: flex; flex-wrap: wrap; }
  .chat-conversation { padding: 16px; }
}
