.message {
  flex: 0 0 auto;
  min-width: 0;
  transform: translateX(-16px);
}

#chat {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#chat[hidden] {
  display: none !important;
}

#user-meta {
  color: #a8b5cb;
  font-size: .88rem;
}

#messages {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-header,
.composer {
  flex: 0 0 auto;
}

.message-body pre {
  max-height: min(55dvh, 520px);
  overflow: auto;
}

.message.mine {
  background: #192b49;
  border-color: #30496c;
  transform: translateX(16px);
}

.message.mine header { border-color: #30496c; }

fieldset label {
  display: flex;
  align-items: center;
  gap: 10px;
}

fieldset input[type="radio"] {
  width: auto;
  flex: 0 0 auto;
}

.shared-image {
  display: block;
  width: 100%;
  height: min(55dvh, 520px);
  border-radius: 6px;
  object-fit: contain;
  background: #0a0f1b;
  cursor: zoom-in;
}

.message.has-image .message-body {
  min-height: min(55dvh, 520px);
}

.composer.drop-target {
  background: #183253;
  outline: 2px dashed #67e8c6;
  outline-offset: -6px;
}

.composer textarea {
  min-height: 96px;
}

.pending-attachment { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #101929; color: var(--muted); font-size: .85rem; }
.pending-attachment span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#mode-controls, #master-controls { display: flex; gap: 6px; align-items: center; }
#readonly-toggle:disabled { opacity: .85; cursor: default; }
#readonly-toggle.chat-mode { background: #29466f; border-color: #3a5c89; color: #dbeafe; }
#readonly-toggle.read-only-mode { background: #4a2933; border-color: #70404b; color: #fecdd3; }
#active-users { display: grid; gap: 8px; min-width: min(440px, 80vw); }
.active-user { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.active-user span { flex: 1; font-size: .9rem; }
.danger { color: #fda4af; }

#file-preview { width: min(1100px, calc(100vw - 32px)); max-width: none; }
.preview-dialog { gap: 12px; }
.preview-dialog header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#preview-content { display: grid; place-items: center; min-height: 120px; }
.file-preview-image { display: block; max-width: min(100%, 1000px); max-height: calc(100dvh - 180px); object-fit: contain; }
.file-preview-pdf { width: min(100%, 1000px); height: calc(100dvh - 210px); min-height: 500px; border: 0; background: #fff; }
.file-preview-text { width: 100%; max-height: calc(100dvh - 220px); overflow: auto; margin: 0; padding: 14px; border-radius: 7px; background: var(--code); white-space: pre-wrap; overflow-wrap: anywhere; }
.file-preview-button { margin-left: 10px; }

@media (max-width: 600px) {
  .message { transform: translateX(-8px); }
  .message.mine { transform: translateX(8px); }
}

@media (max-width: 1000px) {
  .chat-header {
    min-height: 50px;
    gap: 7px;
    padding: 7px 12px;
  }

  .chat-header .brand {
    flex: 0 0 auto;
    font-size: 1rem;
    white-space: nowrap;
  }

  .chat-header #room-meta { display: none; }

  #user-meta {
    margin-left: auto;
    font-size: .8rem;
    white-space: nowrap;
  }

  #mode-controls, #master-controls { gap: 4px; }

  #mode-controls button,
  #copy-link {
    padding: 6px 8px;
    font-size: .75rem;
    white-space: nowrap;
  }

  #messages {
    gap: 10px;
    padding: 12px max(12px, calc((100vw - 920px) / 2));
  }

  .message header { padding: 6px 9px; }
  .message-body { padding: 9px; }

  .composer {
    gap: 10px;
    padding: 10px 12px max(5px, env(safe-area-inset-bottom));
  }

  .composer textarea { min-height: 86px; }

  .composer div {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
  }

  #char-count { white-space: nowrap; }
  .composer div label { min-width: 0; font-size: .78rem; }
  #file-input { min-width: 0; max-width: 100%; font-size: .78rem; }
  .composer .pending-attachment { display: flex; grid-template-columns: none; }
}

@media (max-width: 600px) {
  .chat-header .brand { font-size: 0; }
  .chat-header .brand .mark { font-size: 1.15rem; }
  #user-meta { font-size: .75rem; }
  #messages { padding-inline: 10px; }
  .message { transform: translateX(-4px); }
  .message.mine { transform: translateX(4px); }
}

html { min-height: 100%; background: var(--bg); }
body { min-height: 100dvh; background-repeat: no-repeat; background-attachment: fixed; }
#app { min-height: 100dvh; display: flow-root; }
.brand-logo { display: block !important; width: 30px !important; height: 28px !important; min-width: 30px; max-width: 30px !important; min-height: 28px; max-height: 28px !important; object-fit: contain; transform: rotate(-90deg); flex: 0 0 30px !important; }
#chat, .chat-header, .composer { min-width: 0; max-width: 100%; }
.chat-header { position: relative; }
#user-meta { min-width: 0; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; background: #1a2940; }
#chat-actions { display: flex; align-items: center; gap: 8px; }
#master-controls[hidden] { display: none !important; }
#chat-menu-toggle { display: none; }
.message .author { min-width: 0; overflow-wrap: anywhere; }
.message header { flex-wrap: wrap; }

#copy-link { display: inline-grid; place-items: center; min-width: 38px; min-height: 34px; padding: 5px 8px; }
.share-boomerang { display: block; width: 22px; height: 20px; object-fit: contain; transform: rotate(-90deg); transform-origin: center; }
#copy-link:hover .share-boomerang, #copy-link:focus-visible .share-boomerang { animation: boomerang-throw .72s cubic-bezier(.36,.07,.19,.97) infinite; }
@keyframes boomerang-throw { from { transform: rotate(-90deg); } to { transform: rotate(-810deg); } }

#share-dialog { width: min(560px, calc(100vw - 32px)); }
.share-dialog { display: grid; gap: 14px; }
.share-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.share-dialog p { margin: 0; }
#share-url { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }

@media (max-width: 1000px) {
  #chat-menu-toggle { display: block; flex: 0 0 auto; width: 44px; height: 44px; padding: 4px; font-size: 24px; background: transparent; }
  #user-meta { margin-left: auto; }
  #chat-actions { display: none; position: absolute; z-index: 10; right: 12px; top: calc(100% + 4px); width: min(260px, calc(100vw - 24px)); padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 8px 24px #0006; }
  #chat-actions.is-open { display: grid; gap: 8px; }
  #copy-link .share-boomerang { animation: boomerang-throw .72s cubic-bezier(.36,.07,.19,.97) infinite; }
  #mode-controls, #master-controls { display: grid; width: 100%; gap: 8px; }
  #chat-actions button { width: 100%; min-height: 44px; font-size: .9rem; white-space: normal; }
  .composer textarea { font-size: 16px; }
}
