/* Chat layout: servers | channels | messages, filling the window (or the central site's frame).
   Colours, fonts and buttons come from the central site's theme. */
html, body { height: 100%; }
body { padding: 0; overflow: hidden; }
.chat { display: grid; grid-template-columns: 64px minmax(160px, 240px) minmax(0, 1fr); height: 100vh; }
.chat.is-members { grid-template-columns: 64px minmax(160px, 240px) minmax(0, 1fr) minmax(170px, 230px); }
.chat:not(.is-members) .chat-members { display: none; }

.chat-rail { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; background: var(--bg); border-right: 1px solid var(--line); overflow-y: auto; }
.chat-server { position: relative; width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--fg); font-family: var(--font-display), monospace; font-size: 1.2rem; cursor: pointer; }
.chat-server img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.chat-server:hover, .chat-server.is-on { border-color: var(--accent); color: var(--accent); box-shadow: var(--glow); }
.chat-server.is-unread::after { content: ""; position: absolute; left: -9px; width: 4px; height: 16px; background: var(--fg); border-radius: 2px; }
.chat-add { color: var(--muted); border-style: dashed; }

.chat-side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.chat-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.chat-channels { flex: 1; overflow-y: auto; padding: 8px 6px; }
.chat-category + .chat-category { margin-top: 10px; }
.chat-category-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.chat-channel-row { display: flex; align-items: center; }
.chat-channel { flex: 1; min-width: 0; text-align: left; padding: 5px 8px; border: 0; border-radius: var(--radius); background: none; color: var(--muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font: inherit; }
.chat-channel:hover { background: var(--surface2); color: var(--fg); }
.chat-channel.is-on { background: var(--surface2); color: var(--fg); }
.chat-channel.is-unread { color: var(--fg); font-weight: 700; }
.chat-icon { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; font: inherit; }
.chat-icon:hover { color: var(--accent); }
.chat-side-admin { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }

.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; align-items: baseline; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-topic { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px 16px; }
.chat-older { display: block; margin: 0 auto 12px; }
.chat-empty { color: var(--muted); font-size: .85rem; padding: 12px; }

.chat-message { position: relative; padding: 2px 6px; border-radius: var(--radius); }
.chat-message:not(.is-joined) { margin-top: 12px; }
.chat-message:hover { background: var(--surface); }
.chat-message.is-mention { box-shadow: inset 3px 0 0 var(--warn); background: color-mix(in srgb, var(--warn) 6%, transparent); }
.chat-message-row { display: flex; gap: 12px; align-items: flex-start; }
.chat-avatar { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface2); color: var(--accent); object-fit: cover; font-family: var(--font-display), monospace; font-size: 1.2rem; }
.chat-avatar-space { visibility: hidden; height: 0; }
.chat-message-main { min-width: 0; flex: 1; }
.chat-meta { display: flex; gap: 8px; align-items: baseline; }
.chat-meta small, .chat-edited { color: var(--muted); font-size: .72rem; }
.chat-body { overflow-wrap: anywhere; }
.chat-body pre { margin: 4px 0; padding: 8px; background: var(--bg); border: 1px solid var(--line); overflow-x: auto; font-size: .82rem; }
.chat-body code { background: var(--bg); padding: 0 4px; font-size: .9em; }
.chat-body .quote { display: inline-block; border-left: 3px solid var(--muted); padding-left: 8px; color: var(--muted); }
.chat-body .mention { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); padding: 0 2px; }
.chat-body .mention-me { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.chat-deleted { color: var(--muted); font-style: italic; }
.chat-reply-to { margin-left: 48px; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-files { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin-top: 6px; }
.chat-files img { max-width: min(360px, 100%); max-height: 280px; border: 1px solid var(--line); border-radius: var(--radius); }
.chat-file { padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-size: .85rem; }
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-reaction { padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--fg); cursor: pointer; font: inherit; font-size: .8rem; }
.chat-reaction.is-mine { border-color: var(--accent); }
.chat-tools { position: absolute; right: 8px; top: -12px; display: none; gap: 2px; padding: 2px; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius); }
.chat-message:hover .chat-tools, .chat-message:focus-within .chat-tools { display: flex; }
.chat-tools button { border: 0; background: none; color: var(--fg); cursor: pointer; padding: 2px 6px; font: inherit; }
.chat-tools button:hover { background: var(--surface); }

.chat-composer { padding: 10px 16px 16px; border-top: 1px solid var(--line); }
.chat-replying { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .8rem; padding-bottom: 6px; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-chips:not(:empty) { padding-bottom: 6px; }
.chat-chip { display: inline-flex; gap: 6px; align-items: center; padding: 2px 8px; border: 1px solid var(--line); border-radius: var(--radius); font-size: .8rem; }
.chat-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; }
.chat-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-compose-row textarea { flex: 1; resize: none; min-height: 40px; max-height: 200px; }
.chat-attach { font-size: 1.1rem; padding: 6px 12px; }

.chat-dialog { width: min(440px, calc(100vw - 32px)); padding: 0; background: var(--surface); color: var(--fg); border: 1px solid var(--accent); border-radius: var(--radius); }
.chat-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.chat-dialog form { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.chat-dialog h2 { font-size: 1.5rem; }
.chat-dialog label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .85rem; }
.chat-dialog small { font-size: .75rem; }
.chat-dialog-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.chat-dialog-buttons .btn + .btn { margin-left: 0; }
.chat-toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; padding: 8px 14px; background: var(--fg); color: var(--bg); border-radius: var(--radius); }

.chat-note-page { padding: 32px; overflow: auto; height: 100%; }
.chat-note { border-left: 2px solid var(--warn); padding: 8px 12px; margin-top: 16px; }

@media (max-width: 700px) {
  .chat { grid-template-columns: 56px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .chat-rail { grid-row: 1 / span 2; }
  .chat-side { max-height: 30vh; }
}

/* Head tools, user list */
.chat-head { position: relative; }
.chat-head-tools { margin-left: auto; display: flex; gap: 2px; }
.chat-icon.is-on { color: var(--accent); }
.chat-members { overflow-y: auto; padding: 10px 8px; background: var(--surface); border-left: 1px solid var(--line); }
.chat-members h3 { margin: 10px 6px 4px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.chat-member { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 6px; border: 0; border-radius: var(--radius); background: none; color: var(--muted);
  cursor: pointer; font: inherit; text-align: left; }
.chat-member:hover { background: var(--surface2); color: var(--fg); }
.chat-member.is-online { color: var(--fg); }
.chat-member-face { position: relative; width: 32px; height: 32px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface2); color: var(--accent); font-size: .9rem; }
.chat-member-face img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.chat-member:not(.is-online) .chat-member-face img { opacity: .55; }
.chat-dot { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--surface); background: var(--muted); }
.is-online > .chat-dot, .is-online .chat-dot { background: var(--ok, var(--accent)); }
.chat-member-text { display: flex; flex-direction: column; min-width: 0; }
.chat-member-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-member-text small { font-size: .7rem; color: var(--muted); }

/* Clickable people in messages */
.chat-person { padding: 0; border: 0; background: none; cursor: pointer; border-radius: var(--radius); }
.chat-name { padding: 0; border: 0; background: none; color: var(--fg); font: inherit; font-weight: 700; cursor: pointer; }
.chat-name:hover { text-decoration: underline; color: var(--accent); }

/* Typing, dropping files */
.chat-typing { min-height: 1.2em; padding: 0 16px; color: var(--muted); font-size: .75rem; font-style: italic; }
.chat-main { position: relative; }
.chat-drop { position: absolute; inset: 8px; z-index: 30; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--accent); font-size: 1.2rem; pointer-events: none; }
.chat-drop[hidden] { display: none; }

/* Images and videos in messages */
.chat-image { padding: 0; border: 0; background: none; cursor: zoom-in; }
.chat-video { max-width: min(480px, 100%); max-height: 360px; border: 1px solid var(--line); border-radius: var(--radius); background: #000; }

/* Image viewer */
.chat-viewer { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(0, 0, 0, .9); color: #fff; }
.chat-viewer::backdrop { background: rgba(0, 0, 0, .6); }
.chat-viewer[open] { display: flex; flex-direction: column; }
.chat-viewer-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; }
.chat-viewer-caption { font-size: .85rem; overflow-wrap: anywhere; }
.chat-viewer-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-viewer-tools .btn + .btn { margin-left: 0; }
.chat-viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 8px 12px; }
.chat-viewer-stage img { max-width: calc(100% - 100px); max-height: 100%; object-fit: contain; }
.chat-viewer-step { width: 40px; height: 64px; border: 0; border-radius: var(--radius); background: rgba(255, 255, 255, .12); color: #fff; font-size: 2rem; cursor: pointer; }
.chat-viewer-step:hover { background: rgba(255, 255, 255, .25); }

/* Who reacted */
.chat-popover { position: fixed; z-index: 60; max-width: 260px; padding: 8px 10px; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius); font-size: .8rem; }
.chat-popover ul { margin: 4px 0 0; padding-left: 16px; }

/* Profile card, settings */
.chat-card-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px; text-align: center; }
.chat-card-picture { width: 96px; height: 96px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface2);
  color: var(--accent); font-size: 2.2rem; object-fit: cover; }
.chat-card-handle { color: var(--muted); font-size: .85rem; }
.chat-card-status { position: relative; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.chat-card-status .chat-dot { position: static; border: 0; }
.chat-card-bio { white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; align-self: stretch; padding: 8px; background: var(--bg); border-radius: var(--radius); }
.chat-card .chat-dialog-buttons { align-self: stretch; }
.chat-check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--fg) !important; }

@media (max-width: 1000px) {
  .chat.is-members { grid-template-columns: 64px minmax(160px, 240px) minmax(0, 1fr); }
  .chat.is-members .chat-members { position: fixed; right: 0; top: 0; bottom: 0; width: 240px; z-index: 40; box-shadow: -8px 0 24px rgba(0, 0, 0, .4); }
}
