/* Generic Room UI - skin v2: visual parity with the main agents room
   (2026-10-25). White header, off-white background, right-aligned white
   bubbles with avatar on the trailing side, green-circle send button.
   Structure/DOM unchanged; textContent-only rendering preserved. */
:root {
  --room-bg: #f5f3ee; --room-panel: #ffffff; --room-line: #e6e2da;
  --room-fg: #1b1b1b; --room-meta: #8a8a84; --room-accent: #075e54;
  --room-accent-fg: #ffffff; --room-link: #0b7a6f;
  --bg: #f5f3ee; --fg: #1b1b1b; --panel: #ffffff; --accent: #075e54;
}
[data-theme="dark"] {
  --room-bg: #111b21; --room-panel: #202c33; --room-line: #2f3b43;
  --room-fg: #e9edef; --room-meta: #8696a0; --room-accent: #00a884;
  --room-accent-fg: #111b21; --room-link: #53bdeb;
  --bg: #111b21; --fg: #e9edef; --panel: #202c33; --accent: #00a884;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--room-bg); color: var(--room-fg);
  font-family: system-ui, Arial, sans-serif;
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
}

/* Header bar: white, thin bottom border, title in accent green */
header {
  background: var(--room-panel); color: var(--room-fg);
  border-bottom: 1px solid var(--room-line);
  padding: 8px 14px; display: flex; justify-content: space-between;
  align-items: center; gap: 8px; flex: none; flex-wrap: wrap; row-gap: 4px;
}
header h1 { font-size: 17px; font-weight: 700; margin: 0; color: var(--room-accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
header .controls label { position: absolute; width: 1px; height: 1px; overflow: hidden; }
header select, header button {
  background: transparent; color: var(--room-fg); border: 1px solid var(--room-line);
  border-radius: 6px; padding: 3px 8px; font-size: 13px; cursor: pointer;
}
header select option { color: #111; }

/* Login + bootstrap views */
#login-view, #bootstrap-view {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px;
}
#login-view[hidden], #bootstrap-view[hidden] { display: none; }
#login-form, #bootstrap-view {
  background: var(--room-panel); border: 1px solid var(--room-line);
  border-radius: 10px; padding: 22px 26px;
  box-shadow: 0 2px 8px #0001; display: flex; flex-direction: column; gap: 10px;
  min-width: min(320px, 90vw); text-align: center;
}
#login-form input {
  padding: 10px; border: 1px solid var(--room-line); border-radius: 8px; font-size: 15px;
  background: var(--room-bg); color: var(--room-fg);
}
#login-form button, #bootstrap-view button {
  background: var(--room-accent); color: var(--room-accent-fg); border: 0;
  border-radius: 8px; padding: 9px; font-size: 15px; font-weight: 600; cursor: pointer;
}
#login-error { color: #c0392b; margin: 0; font-size: 13px; min-height: 1em; }

/* Layout */
main { flex: 1; display: flex; gap: 10px; padding: 10px; min-height: 0; overflow: hidden; }
#threads {
  width: 220px; flex-shrink: 0; overflow-y: auto;
  background: var(--room-panel); border: 1px solid var(--room-line);
  border-radius: 10px; padding: 8px;
}
#threads h2, #library h2 { font-size: 13px; margin: 4px 6px 8px; color: var(--room-meta); }
#thread-list, #file-list { list-style: none; margin: 0; padding: 0; }
#thread-list button, #file-list li {
  display: block; width: 100%; text-align: start; padding: 7px 9px; border: 0;
  background: transparent; border-radius: 8px; cursor: pointer; font-size: 14px;
  color: var(--room-fg);
}
#thread-list button[aria-current="true"], #thread-list button:hover,
#file-list li:hover { background: var(--room-bg); }
#file-list li { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
#file-list button { flex: none; }

/* Chat column */
#chat { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
#message-list {
  list-style: none; margin: 0 auto; padding: 6px 10px; flex: 1; overflow-y: auto;
  overflow-x: hidden; display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 860px; min-height: 0;
}
#message-list li {
  display: flex; align-items: flex-start; gap: 8px;
  flex-direction: row-reverse; /* avatar on the trailing (left in RTL) side */
  justify-content: flex-end;   /* bubble hugs the leading (right in RTL) edge */
}
#message-list li.cancelled { justify-content: center; opacity: .55; font-style: italic; font-size: 13px; }
#message-list li.is-new .b { border-color: var(--room-accent); }

/* Bubbles: white, thin border, content right-aligned, name top, time bottom-left */
.b {
  max-width: 85%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap;
  word-wrap: break-word; background: var(--room-panel);
  border: 1px solid var(--room-line); display: inline-block;
}
.b .n { font-size: 13px; font-weight: 700; margin-bottom: 2px; display: block; }

/* Per-sender identity (s0-s7 from the same hash as the avatar): a soft
   tinted background + leading accent + colored sender name, so senders
   read apart at a glance. Own bubble keeps the accent tint and wins by
   specificity. No member names appear in code. */
.b.s0 { background: rgba(13,42,76,.07); border-inline-start: 3px solid #0D2A4C; }
.b.s0 .n { color: #0D2A4C; }
.b.s1 { background: rgba(93,24,50,.07); border-inline-start: 3px solid #5D1832; }
.b.s1 .n { color: #5D1832; }
.b.s2 { background: rgba(36,71,122,.07); border-inline-start: 3px solid #24477A; }
.b.s2 .n { color: #24477A; }
.b.s3 { background: rgba(74,74,68,.07); border-inline-start: 3px solid #4A4A44; }
.b.s3 .n { color: #4A4A44; }
.b.s4 { background: rgba(138,106,31,.08); border-inline-start: 3px solid #8a6a1f; }
.b.s4 .n { color: #8a6a1f; }
.b.s5 { background: rgba(47,125,82,.08); border-inline-start: 3px solid #2F7D52; }
.b.s5 .n { color: #2F7D52; }
.b.s6 { background: rgba(88,65,142,.08); border-inline-start: 3px solid #58418e; }
.b.s6 .n { color: #58418e; }
.b.s7 { background: rgba(54,88,99,.08); border-inline-start: 3px solid #365863; }
.b.s7 .n { color: #365863; }
[data-theme="dark"] .b.s0 { background: rgba(127,168,224,.13); }
[data-theme="dark"] .b.s0 .n { color: #7FA8E0; }
[data-theme="dark"] .b.s1 { background: rgba(224,138,168,.13); }
[data-theme="dark"] .b.s1 .n { color: #E08AA8; }
[data-theme="dark"] .b.s2 { background: rgba(143,176,232,.13); }
[data-theme="dark"] .b.s2 .n { color: #8FB0E8; }
[data-theme="dark"] .b.s3 { background: rgba(201,196,184,.11); }
[data-theme="dark"] .b.s3 .n { color: #C9C4B8; }
[data-theme="dark"] .b.s4 { background: rgba(227,199,126,.13); }
[data-theme="dark"] .b.s4 .n { color: #E3C77E; }
[data-theme="dark"] .b.s5 { background: rgba(127,203,160,.13); }
[data-theme="dark"] .b.s5 .n { color: #7FCBA0; }
[data-theme="dark"] .b.s6 { background: rgba(185,163,232,.13); }
[data-theme="dark"] .b.s6 .n { color: #B9A3E8; }
[data-theme="dark"] .b.s7 { background: rgba(143,188,203,.13); }
[data-theme="dark"] .b.s7 .n { color: #8FBCCB; }
li.own .b { background: rgba(7,94,84,.10); border: 1px solid rgba(7,94,84,.35); border-inline-start: 3px solid #075e54; }
[data-theme="dark"] li.own .b { background: rgba(0,168,132,.15); border-color: rgba(0,168,132,.4); border-inline-start-color: #00a884; }
.b .n .num { font-weight: 400; color: var(--room-meta); font-size: 12px; }
.b .body { display: block; }
.b .t { font-size: 11px; color: var(--room-meta); margin-top: 3px; text-align: left; display: block; }

/* Avatars: circle with initial; palette mirrors the main room */
.av {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex: none; margin-top: 2px;
  font: 700 13px/1 system-ui, Arial;
  background: #E4DDCF; color: #4A4A44;
}
.av.c0 { background: #0D2A4C; color: #F8F5EE; }
.av.c1 { background: #5D1832; color: #F8F5EE; }
.av.c2 { background: #24477A; color: #F8F5EE; }
.av.c3 { background: #4A4A44; color: #F8F5EE; }
.av.c4 { background: #CCA667; color: #0D2A4C; }
.av.c5 { background: #2F7D52; color: #F8F5EE; }
.av.c6 { background: #F8F5EE; color: #5D1832; box-shadow: inset 0 0 0 1.5px #5D1832; }
.av.c7 { background: #E4DDCF; color: #4A4A44; }

/* Composer: input center, green-circle send on the trailing edge */
#send-form {
  flex: none; display: flex; gap: 8px; padding: 8px 10px; align-items: center;
  background: var(--room-panel); border-top: 1px solid var(--room-line); margin: 0;
  flex-direction: row-reverse;
}
#message-input {
  flex: 1; min-width: 0; border: 1px solid var(--room-line); border-radius: 22px;
  padding: 10px 16px; font-size: 15px; background: var(--room-bg); color: var(--room-fg);
}
#message-input:focus { outline: 2px solid var(--room-accent); }
#send-button {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--room-accent); color: var(--room-accent-fg);
  font-size: 0; cursor: pointer; position: relative;
}
#send-button::after {
  content: "\27A4"; font-size: 17px; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
#mention-picker {
  position: absolute; bottom: 60px; inset-inline-start: 12px;
  background: var(--room-panel); border: 1px solid var(--room-line);
  border-radius: 8px; box-shadow: 0 2px 8px #0002;
  display: none; flex-wrap: wrap; padding: 4px; z-index: 5;
}
#mention-picker { direction: rtl; }
#mention-picker:not(:empty) { display: flex; }
#mention-picker button { margin: 2px; border: 1px solid var(--room-line); border-radius: 6px; background: var(--room-panel); color: var(--room-fg); padding: 6px 10px; font-size: 14px; cursor: pointer; }
#mention-picker button.sel, #mention-picker button:focus { background: var(--room-accent); color: var(--room-accent-fg, #fff); border-color: var(--room-accent); }
#mention-toggle { border: 1px solid var(--room-line); background: transparent; color: var(--room-fg); border-radius: 6px; font-size: 15px; padding: 4px 10px; cursor: pointer; }

/* Outbox + upload */
#outbox { flex: none; padding: 0 12px; background: var(--room-panel); }
#outbox h3 { font-size: 12px; margin: 6px 0 2px; color: var(--room-meta); }
#outbox-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
#outbox-list li { padding: 3px 0; }
#upload-form {
  flex: none; display: none; gap: 6px; padding: 6px 10px; align-items: center;
  background: var(--room-panel); border-top: 1px solid var(--room-line); flex-wrap: wrap; margin: 0;
}
#upload-form.open { display: flex; }
#attach-toggle, #threads-toggle {
  flex: none; border: 0; background: transparent; font-size: 18px; padding: 6px;
  color: var(--room-fg); cursor: pointer;
}
#upload-form input[type="file"] { font-size: 12px; max-width: 46%; }
#file-visible-to { flex: 1; min-width: 0; padding: 6px 9px; border: 1px solid var(--room-line); border-radius: 14px; font-size: 12px; background: var(--room-bg); color: var(--room-fg); }
#upload-button { flex: none; border: 0; border-radius: 14px; background: var(--room-accent); color: var(--room-accent-fg); padding: 6px 12px; font-size: 13px; }
#status { flex: none; margin: 0; padding: 2px 12px; font-size: 12px; color: var(--room-meta); min-height: 1.2em; background: var(--room-panel); }

button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; }

/* Mobile (390px verified target) */
@media (max-width: 700px) {
  main { flex-direction: column; padding: 6px; gap: 6px; }
  #threads { width: 100%; max-height: 30vh; display: none; }
  #threads.open { display: block; }
  #message-list { padding: 4px 6px; }
  .b { max-width: 92%; }
  header { padding: 6px 10px; }
  header h1 { font-size: 15px; }
  #send-form { padding: 6px; gap: 6px; }
  #message-input { padding: 9px 12px; }
  #upload-form input[type="file"] { max-width: 100%; }
}

/* Reactions */
.rx { display: block; margin-top: 4px; }
.rx-chip {
  display: inline-block; background: var(--room-bg); border: 1px solid var(--room-line);
  border-radius: 12px; padding: 1px 7px; margin-inline-end: 4px; font-size: 13px;
}
.rx-pick {
  position: absolute; z-index: 6; background: var(--room-panel);
  border: 1px solid var(--room-line); border-radius: 20px; padding: 3px 6px;
  box-shadow: 0 2px 8px #0002; inset-inline-start: 40px; bottom: calc(100% + 4px);
}
.rx-pick button { border: 0; background: transparent; font-size: 17px; padding: 3px; cursor: pointer; }
#message-list li { position: relative; }

/* ---- Owner admin panel ---- */
#admin-panel {
  position: fixed; inset: 0; background: #0006; z-index: 30;
  display: flex; align-items: center; justify-content: center;
}
#admin-panel[hidden] { display: none; }
#admin-card {
  background: var(--room-panel); color: var(--room-fg);
  border: 1px solid var(--room-line); border-radius: 10px;
  width: min(560px, 92vw); max-height: 84vh; overflow: auto;
  padding: 12px 16px;
}
#admin-head { display: flex; justify-content: space-between; align-items: center; }
#admin-head h2 { font-size: 17px; margin: 4px 0; }
#admin-close { border: none; background: transparent; color: var(--room-fg); font-size: 17px; cursor: pointer; }
#admin-status { min-height: 18px; font-size: 13px; color: var(--room-meta); margin: 4px 0; }
#admin-create-form { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#admin-create-form input, #admin-create-form select {
  border: 1px solid var(--room-line); border-radius: 6px; padding: 6px 8px;
  background: var(--room-bg, #fff); color: var(--room-fg); font-size: 14px;
}
#admin-create-button, .admin-token-actions button, .admin-revoke {
  border: 1px solid var(--room-line); border-radius: 6px; padding: 6px 12px;
  background: var(--room-accent); color: var(--room-accent-fg, #fff);
  font-size: 14px; cursor: pointer;
}
.admin-revoke { background: transparent; color: var(--room-fg); }
#admin-member-list { list-style: none; margin: 8px 0 0; padding: 0; }
#admin-member-list li {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 7px 2px; border-top: 1px solid var(--room-line);
  font-size: 14px;
}
#admin-token-box {
  border: 1px solid var(--room-accent); border-radius: 8px;
  padding: 10px; margin: 8px 0; font-size: 14px;
}
#admin-token-value {
  display: block; direction: ltr; word-break: break-all;
  background: var(--room-bg, #fff); border: 1px solid var(--room-line);
  border-radius: 6px; padding: 8px; margin: 6px 0; font-size: 13px;
  user-select: all;
}
.admin-token-actions { display: flex; gap: 8px; }
