/* ============================================================
   Design tokens — light (default)
   ============================================================ */
:root {
  --color-bg:          #ffffff;
  --color-bg-subtle:   #f6f7f8;
  --color-bg-sidebar:  #f0f1f3;
  --color-border:      #e2e4e8;
  --color-text:        #1a1d23;
  --color-text-muted:  #6b7280;
  --color-primary:     #5865f2;
  --color-primary-fg:  #ffffff;
  --color-primary-hover: #4752d9;
  --color-danger:      #ef4444;
  --color-github:      #24292e;
  --color-google:      #ffffff;
  --color-google-border: #dadce0;
  --color-discord:     #5865f2;
  --color-surface:     #ffffff;

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .12);

  --header-h: calc(56px + env(safe-area-inset-top, 0px));
  --room-header-h: 55px;
  --sidebar-w: 220px;
}

/* ============================================================
   Dark theme overrides
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --color-bg:          #1a1d23;
    --color-bg-subtle:   #22262e;
    --color-bg-sidebar:  #1e2128;
    --color-border:      #2e3340;
    --color-text:        #e8eaed;
    --color-text-muted:  #8b95a3;
    --color-primary:     #7c87f5;
    --color-primary-fg:  #ffffff;
    --color-primary-hover: #6c77e8;
    --color-github:      #e8eaed;
    --color-google:      #2d3038;
    --color-surface:     #2a2e37;
    --color-google-border: #3c4150;
  }
}

:root[data-theme="dark"] {
  --color-bg:          #1a1d23;
  --color-bg-subtle:   #22262e;
  --color-bg-sidebar:  #1e2128;
  --color-border:      #2e3340;
  --color-text:        #e8eaed;
  --color-text-muted:  #8b95a3;
  --color-primary:     #7c87f5;
  --color-primary-fg:  #ffffff;
  --color-primary-hover: #6c77e8;
  --color-github:      #e8eaed;
  --color-google:      #2d3038;
  --color-surface:     #2a2e37;
  --color-google-border: #3c4150;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-size: 16px;
}

body {
  height: 100%;
  height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-primary);
  color: var(--color-primary-fg);
  border-color: var(--color-primary);
}
.btn--primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}
.btn--ghost:hover { background: var(--color-bg-subtle); color: var(--color-text); }

.btn--icon {
  background: transparent;
  border: none;
  padding: .375rem;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}
.btn--icon:hover { background: var(--color-bg-subtle); color: var(--color-text); }
.btn--icon svg { width: 18px; height: 18px; }

.btn--sm { padding: .25rem .625rem; font-size: .8125rem; }

.btn--provider {
  width: 100%;
  justify-content: flex-start;
  gap: .75rem;
  padding: .75rem 1.25rem;
  font-size: .9375rem;
  border-radius: var(--radius-md);
}
.btn__icon { width: 20px; height: 20px; flex-shrink: 0; }

.btn--github {
  background: var(--color-github);
  color: var(--color-bg);
  border-color: var(--color-github);
}
.btn--github:hover { opacity: .88; }

.btn--google {
  background: var(--color-google);
  color: var(--color-text);
  border: 1px solid var(--color-google-border);
}
.btn--google:hover { background: var(--color-bg-subtle); }

.btn--discord {
  background: var(--color-discord);
  color: #fff;
  border-color: var(--color-discord);
}
.btn--discord:hover { opacity: .88; }

/* ============================================================
   Site header
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top, 0px);
  height: var(--header-h);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 calc(1.25rem + env(safe-area-inset-right, 0px)) 0 calc(1.25rem + env(safe-area-inset-left, 0px));
}

.site-header__logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

/* ---- Logo SVG ---- */
.logo {
  height: 24px;
  width: auto;
  display: block;
}

.logo__bubble { fill: var(--color-primary); }
.logo__dot    { fill: #ffffff; }
.logo__tail   { fill: var(--color-primary); stroke: var(--color-primary); stroke-width: 1.5; }
.logo__wordmark {
  fill: var(--color-text);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
}

/* Wordmark fill follows --color-text (already correct in both themes via the token) */

.site-header__actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* Update-available hint — shown right of the logo when a deploy is detected */
.update-hint {
  display: inline-flex;
  align-items: center;
  gap: .35em;
  padding: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: .8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color .15s;
}
.update-hint:hover { color: var(--color-text); }
.update-hint svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.update-hint[hidden] { display: none; }

.profile-wrap {
  position: relative;
}

.profile-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  min-width: 160px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: .375rem 0;
}
.profile-popover[hidden] { display: none; }

.profile-popover__name {
  font-size: .875rem;
  color: var(--color-text-muted);
  padding: .375rem .875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Main layout
   ============================================================ */
.site-main {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* ============================================================
   Login page
   ============================================================ */
.login-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-md);
}

.login-card__title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.025em;
  margin-bottom: .25rem;
}

.login-card__subtitle {
  color: var(--color-text-muted);
  font-size: .9375rem;
  margin-bottom: 2rem;
}

.login-card__providers {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.login-card__error {
  font-size: .875rem;
  color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-danger) 30%, transparent);
  border-radius: var(--radius-md);
  padding: .625rem .875rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.login-card__note {
  font-size: .8125rem;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.5;
}

.login-card__divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1.25rem 0;
  color: var(--color-text-muted);
  font-size: .8125rem;
}
.login-card__divider::before,
.login-card__divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.login-card__password-form {
  display: flex;
  flex-direction: column;
  gap: .875rem;
}

/* ============================================================
   Form fields (login page)
   ============================================================ */
.form-field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.form-field__label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.form-field__input {
  width: 100%;
  padding: .625rem .75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: .9375rem;
  color: var(--color-text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-field__input::placeholder { color: var(--color-text-muted); opacity: .6; }
.form-field__input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);
}

.login-card__password-form .btn {
  width: 100%;
  padding: .75rem 1.25rem;
  font-size: .9375rem;
  margin-top: .125rem;
}

/* ============================================================
   Error page
   ============================================================ */
.error-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.error-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 2.5rem 2rem;
}

.error-card__code {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -.04em;
  color: var(--color-border);
  line-height: 1;
  margin-bottom: .5rem;
}

.error-card__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.025em;
  margin-bottom: .625rem;
}

.error-card__message {
  color: var(--color-text-muted);
  font-size: .9375rem;
  line-height: 1.55;
  margin-bottom: 1.75rem;
}

/* ============================================================
   Room layout
   ============================================================ */
.room-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.room-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  padding: 1rem .75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.room-sidebar nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.room-sidebar__heading {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
  margin-bottom: .5rem;
  padding: 0 .5rem;
}

.room-sidebar__link {
  display: flex;
  align-items: center;
  padding: .375rem .5rem;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: .9375rem;
  text-decoration: none;
  transition: background .1s, color .1s;
}
.room-sidebar__link:hover { background: var(--color-border); color: var(--color-text); }
.room-sidebar__link--active { background: var(--color-border); color: var(--color-text); font-weight: 500; }
.room-sidebar__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-sidebar__badge {
  flex-shrink: 0;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  border-radius: .625rem;
  background: var(--color-primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.25rem;
  text-align: center;
}

.room-sidebar__footer {
  margin-top: auto;
  padding-top: .75rem;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.room-sidebar__new-btn {
  display: flex;
  align-items: center;
  gap: .375rem;
  width: 100%;
  padding: .375rem .5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: background .1s, color .1s;
}
.room-sidebar__new-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.room-sidebar__new-btn:hover { background: var(--color-border); color: var(--color-text); }

/* ============================================================
   New room dialog
   ============================================================ */
.new-room-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(380px, calc(100vw - 2rem));
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  background: var(--color-bg);
  color: var(--color-text);
  position: fixed;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  animation: new-room-in 180ms ease both;
}

.new-room-dialog.is-closing {
  animation: new-room-out 140ms ease both;
}

@keyframes new-room-in {
  from { opacity: 0; translate: 0 -8px; }
}

@keyframes new-room-out {
  to { opacity: 0; translate: 0 -8px; }
}

.new-room-dialog::backdrop {
  background: rgba(0,0,0,.45);
}

.new-room-dialog__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.new-room-dialog__input {
  width: 100%;
  padding: .5rem .625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: .9375rem;
  box-sizing: border-box;
}
.new-room-dialog__input:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }

.new-room-dialog__actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}

/* ---- Leave-room dialog ---- */
.leave-room-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(360px, calc(100vw - 2rem));
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  background: var(--color-bg);
  color: var(--color-text);
  position: fixed;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  animation: new-room-in 180ms ease both;
}
.leave-room-dialog::backdrop { background: rgba(0,0,0,.45); }
.leave-room-dialog__title { font-size: 1rem; font-weight: 600; margin: 0 0 .5rem; }
.leave-room-dialog__body { font-size: .9375rem; margin: 0 0 1.25rem; color: var(--color-text-muted); }
.leave-room-dialog__actions { display: flex; gap: .5rem; justify-content: flex-end; }
.leave-room-dialog__confirm { color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 35%, transparent); }
.leave-room-dialog__confirm:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: var(--color-danger); }

/* Leave-room panel button */
.room-panel__section--leave { border-top: 1px solid var(--color-border); padding-top: .75rem; margin-top: .25rem; }
.leave-room-btn { color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 30%, transparent); }
.leave-room-btn:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: var(--color-danger); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .leave-room-btn { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: var(--color-danger); }
  :root[data-theme="auto"] .leave-room-btn:hover { background: transparent; border-color: color-mix(in srgb, var(--color-danger) 30%, transparent); }
}
:root[data-theme="dark"] .leave-room-btn { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: var(--color-danger); }
:root[data-theme="dark"] .leave-room-btn:hover { background: transparent; border-color: color-mix(in srgb, var(--color-danger) 30%, transparent); }

/* ---- Settings dialog ---- */
.settings-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(400px, calc(100vw - 2rem));
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  background: var(--color-bg);
  color: var(--color-text);
  position: fixed;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  animation: new-room-in 180ms ease both;
}
.settings-dialog.is-closing { animation: new-room-out 140ms ease both; }
.settings-dialog::backdrop { background: rgba(0,0,0,.45); }

.settings-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.settings-dialog__title { font-size: 1rem; font-weight: 600; margin: 0; }

.settings-dialog__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.settings-dialog__close:hover { background: var(--color-bg-subtle); color: var(--color-text); }
.settings-dialog__close svg { width: 1rem; height: 1rem; }

.settings-dialog__body { padding: 1.25rem; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.settings-row__label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9375rem;
  font-weight: 500;
}
.settings-row__icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }

/* Theme segmented control */
.theme-switcher {
  display: flex;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.theme-switcher__option {
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 500;
  padding: .3rem .75rem;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.theme-switcher__option:hover { color: var(--color-text); }
.theme-switcher__option[aria-checked="true"] {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.settings-dialog__body { max-height: calc(80vh - 3.5rem); overflow-y: auto; }
.settings-divider { border: none; border-top: 1px solid var(--color-border); margin: 1rem 0; }
.settings-loading { font-size: .875rem; color: var(--color-text-muted); padding: .5rem 0; }

/* Settings sections */
.settings-section { margin-bottom: 1.25rem; }
.settings-section__header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .75rem;
}
.settings-section__icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.settings-section__title { font-size: .9375rem; font-weight: 600; margin: 0; }

/* Settings form fields */
.settings-field { margin-bottom: .75rem; }
.settings-field__label {
  display: block;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: .375rem;
}
.settings-field__row { display: flex; gap: .5rem; align-items: center; }
.settings-field__input {
  flex: 1;
  padding: .4rem .625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-family: inherit;
  font-size: .875rem;
  box-sizing: border-box;
}
.settings-field__input:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }
.settings-field__error { margin: .375rem 0 0; font-size: .8125rem; color: var(--color-danger); }
.settings-field__success { margin: .375rem 0 0; font-size: .8125rem; color: #16a34a; }

/* Avatar picker */
.settings-avatar-picker { display: flex; gap: .75rem; flex-wrap: wrap; }
.settings-avatar-option { display: flex; flex-direction: column; align-items: center; gap: .25rem; }
.settings-avatar-btn {
  width: 56px; height: 56px; border-radius: 50%; padding: 2px; cursor: pointer;
  border: 2px solid var(--color-border); background: none; transition: border-color .15s;
}
.settings-avatar-btn:hover { border-color: var(--color-text-secondary); }
.settings-avatar-btn--active { border-color: var(--color-primary); border-width: 3px; padding: 1px; }
.settings-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.settings-avatar-label { font-size: .6875rem; color: var(--color-text-muted); }

/* Name suggestion chips */
.settings-name-suggestion {
  display: inline-flex; align-items: center; gap: .25rem; margin-top: .375rem;
  padding: .25rem .625rem; border-radius: 999px; font-size: .75rem; cursor: pointer;
  border: 1px solid var(--color-border); background: var(--color-bg-subtle);
  color: var(--color-text-secondary); transition: background .15s, border-color .15s;
}
.settings-name-suggestion:hover { background: var(--color-border); border-color: var(--color-text-muted); }
.settings-name-suggestion__from { color: var(--color-text-muted); }

/* Identity list */
.settings-identity-list { display: flex; flex-direction: column; gap: .5rem; }
.settings-identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .375rem .625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.settings-identity__provider {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .875rem;
  font-weight: 500;
}
.settings-identity__icon { width: 1rem; height: 1rem; flex-shrink: 0; }
.settings-identity__only { font-size: .75rem; color: var(--color-text-muted); font-style: italic; }

/* Ghost button for disconnect */
.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}
.btn--ghost:hover { background: var(--color-bg-subtle); color: var(--color-text); }

/* Danger button */
.btn--danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}
.btn--danger:hover { background: #dc2626; border-color: #dc2626; }
.btn--danger:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Danger zone */
.settings-section--danger {
  border: 1px solid color-mix(in srgb, var(--color-danger) 30%, transparent);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 1rem;
}
.settings-section--danger .settings-section__title { color: var(--color-danger); }
.settings-danger__desc { font-size: .8125rem; color: var(--color-text-muted); margin: 0 0 .75rem; }
.settings-danger__guard { display: flex; flex-direction: column; gap: .625rem; margin-bottom: .75rem; }
.settings-danger__check {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8125rem;
  cursor: pointer;
}
.settings-danger__check input[type="checkbox"] { accent-color: var(--color-danger); }
.settings-danger__type { display: flex; flex-direction: column; gap: .25rem; font-size: .8125rem; }

/* Command autocomplete description text */
.command-autocomplete__desc { margin-left: auto; color: var(--color-text-muted); font-size: .8125rem; }

/* ---- Main area ---- */
.room-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.room-main__header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  min-height: var(--room-header-h);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.room-panel-toggle {
  margin-left: auto;
  color: var(--color-text-muted);
}
.room-panel-toggle:hover { color: var(--color-text); }
[aria-expanded="true"].room-panel-toggle { color: var(--color-primary); }

/* ---- Right panel (now inside .room-main, absolute below header) ---- */
.room-panel {
  position: absolute;
  top: var(--room-header-h, 55px);
  right: 0;
  z-index: 40;
  width: 260px;
  background: var(--color-bg-sidebar);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow-y: auto;
  max-height: calc(100% - var(--room-header-h, 55px));
  display: none;
}
.room-layout--panel-open .room-panel {
  display: flex;
  flex-direction: column;
}

.room-panel__inner {
  padding: 1rem .875rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.room-panel__section { display: flex; flex-direction: column; gap: .5rem; }

.room-panel__heading {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
}

.room-panel__member {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem 0;
}

.room-panel__avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.room-panel__avatar {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-border);
}

.room-panel__active-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  border: 1.5px solid var(--color-bg-sidebar);
}

.room-panel__member-name {
  flex: 1;
  font-size: .875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-panel__notif-off-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-sidebar);
  border-radius: 50%;
}
.room-panel__notif-off-badge svg {
  width: 10px;
  height: 10px;
  color: var(--color-text-muted);
}

.room-panel__empty,
.room-panel__hint {
  font-size: .8125rem;
  color: var(--color-text-muted);
}

.room-panel__add-form {
  display: flex;
  gap: .375rem;
  align-items: center;
}

.room-panel__invite-input {
  flex: 1;
  min-width: 0;
  padding: .3125rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: .875rem;
}
.room-panel__invite-input:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }

.room-panel__invite-link {
  display: flex;
  align-items: center;
  gap: .375rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .375rem .5rem;
}

.room-panel__invite-code {
  flex: 1;
  font-family: var(--font-mono);
  font-size: .75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Small button variant */
.btn--sm {
  padding: .25rem .625rem;
  font-size: .8125rem;
}

/* No-rooms page */
.no-rooms-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
}
.no-rooms-page__title { font-size: 1.25rem; font-weight: 600; }
.no-rooms-page__text { color: var(--color-text-muted); }
.no-rooms-page__form {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-top: .5rem;
}
.no-rooms-page__input {
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  width: 220px;
}
.no-rooms-page__input:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }

.room-main__title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
}

.history-spinner {
  display: none;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border: 1.5px solid var(--color-border);
  border-top-color: var(--color-text-secondary);
  border-radius: 50%;
  animation: chip-spin .7s linear infinite;
}

.history-spinner.is-loading {
  display: block;
}

/* ---- Message list ---- */
.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 0;
}

/* Invisible sentinel for infinite scroll */
.scroll-sentinel {
  height: 1px;
  visibility: hidden;
}

/* ============================================================
   Message
   ============================================================ */
.message {
  display: flex;
  gap: .75rem;
  padding: .5rem 1.25rem;
  transition: background .1s;
}
.message:hover { background: var(--color-bg-subtle); }

.message__avatar {
  flex-shrink: 0;
  margin-top: .125rem;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  object-fit: cover;
}

.avatar--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-weight: 600;
  font-size: .875rem;
  user-select: none;
}

.message__body { flex: 1; min-width: 0; }

.message__meta {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .125rem;
}

.message__author {
  font-weight: 600;
  font-size: .9375rem;
}

.message__time {
  font-size: .75rem;
  color: var(--color-text-muted);
}

.message__edited {
  font-size: .7rem;
  color: var(--color-text-muted);
  font-style: italic;
  opacity: .75;
}

/* ---- Floating message toolbar (Slack-style hover actions) ---- */
.message__toolbar {
  position: absolute;
  top: -.75rem;
  right: .75rem;
  display: flex;
  gap: 1px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  z-index: 1;
}

.message {
  position: relative;
}

.message:hover .message__toolbar,
.message__toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.message__toolbar-btn {
  color: var(--color-text-muted);
  padding: .25rem .375rem;
  border-radius: 0;
  transition: background .1s, color .1s;
}
.message__toolbar-btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.message__toolbar-btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.message__toolbar-btn:only-child { border-radius: var(--radius-sm); }

.message__toolbar-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}
.message__toolbar-btn[hidden] { display: none; }

.message__delete:hover { color: var(--color-danger); }
.message__edit:hover { color: var(--color-primary); }

.message__toolbar-btn svg {
  width: 16px;
  height: 16px;
}

.message--deleting {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity .15s;
}

.message--deleting .message__toolbar {
  opacity: 1;
  pointer-events: none;
}

/* Keyboard-navigation: active message highlighted by arrow keys */
.message--active {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.message--active .message__toolbar {
  opacity: 1;
  pointer-events: auto;
}

/* No-JS touch fallback: show toolbar when action sheet JS hasn't loaded */
@media (hover: none) {
  body:not([data-action-sheet]) .message__toolbar {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Action sheet active: hide the toolbar — actions live in the sheet */
body[data-action-sheet] .message__toolbar {
  display: none;
}

/* System messages (join / leave) */
.message--system {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: .375rem 1.25rem;
  color: var(--color-text-muted);
  font-size: .8125rem;
}
.message--system:hover { background: transparent; }
.message--system::before,
.message--system::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--color-border);
}
.message--system__text {
  white-space: nowrap;
}
.message--system__time {
  font-size: .75rem;
  white-space: nowrap;
}

/* -- Continuation grouping (consecutive same-author messages) -- */
.message--continuation {
  padding-top: .125rem;
}
.message--continuation .message__avatar {
  visibility: hidden;
  height: 0;
}
.message--continuation .message__author,
.message--continuation .message__time,
.message--continuation .message__edited {
  display: none;
}

.message__text {
  font-size: .9375rem;
  line-height: 1.55;
  user-select: text;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Blockquote */
.message__blockquote {
  margin: .25rem 0;
  padding: .375rem .75rem;
  border-left: 3px solid var(--color-primary);
  background: var(--color-bg-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  white-space: pre-wrap;
}

.message__blockquote:first-child { margin-top: 0; }
.message__blockquote:last-child  { margin-bottom: 0; }

/* ============================================================
   Inline message edit form
   ============================================================ */
.message-edit-form {
  margin-top: .25rem;
}

.message-edit-form__textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  font-family: inherit;
  font-size: .9375rem;
  line-height: 1.55;
  color: var(--color-text);
  padding: .375rem .625rem;
  outline: none;
  overflow-y: auto;
  transition: border-color .15s;
}

.message-edit-form__textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

.message-edit-form__actions {
  display: flex;
  gap: .375rem;
  margin-top: .375rem;
}

/* ============================================================
   Unfurl / link preview
   ============================================================ */
.unfurl {
  display: flex;
  gap: .75rem;
  margin-top: .5rem;
  padding: .75rem;
  border-left: 3px solid var(--color-primary);
  background: var(--color-bg-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  max-width: 480px;
}

.unfurl__image {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.unfurl__body { flex: 1; min-width: 0; }

.unfurl__title {
  display: block;
  font-weight: 600;
  font-size: .875rem;
  color: var(--color-text);
  margin-bottom: .25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unfurl__title:hover { color: var(--color-primary); }

.unfurl__desc {
  font-size: .8125rem;
  color: var(--color-text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.unfurl__domain {
  display: block;
  margin-top: .25rem;
  font-size: .75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Video unfurl (e.g. YouTube) */
.unfurl--video {
  flex-direction: column;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.unfurl__player {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}

.unfurl__thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .15s;
}
.unfurl__player:hover .unfurl__thumb { opacity: .85; }

.unfurl__play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.unfurl__play-icon svg {
  width: 64px;
  height: auto;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.4));
  transition: transform .15s;
}
.unfurl__player:hover .unfurl__play-icon svg { transform: scale(1.08); }

.unfurl--video .unfurl__body {
  padding: .625rem .75rem .75rem;
}

/* YouTube Shorts — narrow 9:16 card */
.unfurl--shorts {
  max-width: 240px;
}
.unfurl--shorts .unfurl__player {
  aspect-ratio: 9 / 16;
}

/* ============================================================
   Reactions
   ============================================================ */
.reactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem;
  margin-top: .375rem;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-bg-subtle);
  font-size: .8125rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  color: var(--color-text);
  position: relative;
}
.reaction-pill:hover {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}
.reaction-pill--active {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 14%, transparent);
  color: var(--color-primary);
}
.reaction-pill--active:hover {
  background: color-mix(in srgb, var(--color-primary) 22%, transparent);
}

.reaction-pill__emoji { font-size: 1em; line-height: 1; }
.reaction-pill__count { font-size: .75rem; color: inherit; font-weight: 500; }

.reaction-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .375rem .5rem;
  width: max-content;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .12s, visibility .12s;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
@media (hover: hover) {
  .reaction-pill:hover .reaction-tooltip {
    opacity: 1;
    visibility: visible;
  }
}
.reaction-tooltip--visible {
  opacity: 1;
  visibility: visible;
}
.reaction-tooltip__user {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-size: .75rem;
  color: var(--color-text);
}
.reaction-tooltip__avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* Add-reaction button + popover */
.reaction-add-wrap {
  position: relative;
  display: inline-flex;
}

.reaction-add {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: transparent;
  transition: border-color .12s, color .12s;
}
.reaction-add:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* Hide the entire reactions bar when there are no pills (the add button lives in the toolbar) */
.reactions:not(:has(.reaction-pill)) {
  display: none;
}


/* Compact reaction picker — approximately four visible emoji rows */
#emoji-picker-container[data-mode="reaction"] emoji-picker {
  height: 280px;
}

/* ============================================================
   Message compose form
   ============================================================ */
.message-form {
  padding: .75rem calc(1.25rem + env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) calc(1.25rem + env(safe-area-inset-left, 0px));
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
}

.message-form__bar {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: .5rem .5rem .5rem .75rem;
  transition: border-color .15s;
}
.message-form__bar:focus-within { border-color: var(--color-primary); }

.message-form__textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: .9375rem;
  line-height: 1.5;
  color: var(--color-text);
  outline: none;
  min-height: 1.5rem;
  max-height: 140px;
  overflow-y: auto;
}
.message-form__textarea::placeholder { color: var(--color-text-muted); }

.message-form__send {
  flex-shrink: 0;
  padding: .375rem .5rem;
  border-radius: var(--radius-md);
}
.message-form__send svg { width: 18px; height: 18px; }

/* ============================================================
   Emoji picker container (vendor element)
   ============================================================ */
#emoji-picker-container {
  position: fixed;
  z-index: 999;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-lg);
}

emoji-picker {
  --background:                var(--color-bg);
  --border-color:              var(--color-border);
  --border-radius:             var(--radius-lg);
  --button-hover-background:   var(--color-bg-subtle);
  --button-active-background:  var(--color-bg-sidebar);
  --indicator-color:           var(--color-primary);
  --input-border-color:        var(--color-border);
  --input-font-color:          var(--color-text);
  --input-placeholder-color:   var(--color-text-muted);
  --outline-color:             var(--color-primary);
  --category-font-color:       var(--color-text-muted);
}

/* ============================================================
   Emoji shortcode autocomplete dropdown
   ============================================================ */
.emoji-autocomplete {
  position: fixed;
  z-index: 1000;
  list-style: none;
  margin: 0;
  padding: .25rem 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
}

.emoji-autocomplete__item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .375rem .75rem;
  cursor: pointer;
  font-size: .9375rem;
  line-height: 1.4;
  color: var(--color-text);
  transition: background .08s;
}

.emoji-autocomplete__item[aria-selected="true"] {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
}

.emoji-autocomplete__glyph {
  font-size: 1.2em;
  line-height: 1;
  flex-shrink: 0;
  width: 1.4em;
  text-align: center;
}

.emoji-autocomplete__name {
  color: var(--color-text-muted);
  font-size: .875rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.emoji-autocomplete__item[aria-selected="true"] .emoji-autocomplete__name {
  color: var(--color-text);
}

/* ============================================================
   Code blocks
   ============================================================ */
.code-block {
  margin: .5rem 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: .8125rem;
  max-width: 100%;
}

.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .25rem .5rem .25rem .75rem;
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
}

.code-block__lang {
  font-size: .75rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  text-transform: lowercase;
}

.code-block__copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.code-block__copy svg { width: 14px; height: 14px; }
.code-block__copy:hover { background: var(--color-border); color: var(--color-text); }
.code-block__copy--copied { color: #16a34a; }

.code-block__pre {
  margin: 0;
  padding: .75rem 1rem;
  overflow-x: auto;
  background: var(--color-bg-subtle);
  line-height: 1.6;
  tab-size: 2;
}

/* Chroma injects <code> inside <pre>; reset its inline display */
.code-block__pre code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  padding: 0;
  border: none;
  white-space: pre;
}

/* Inline code */
.message__text code {
  font-family: var(--font-mono, ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace);
  font-size: 0.85em;
  padding: 0.125em 0.35em;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-sm);
}

/* Reset pre-wrap from .message__text inside code blocks and lists */
.message__text .code-block,
.message__text ul,
.message__text ol {
  white-space: normal;
}

.message__text ul,
.message__text ol {
  padding-left: 1.5rem;
  margin: 0.125rem 0;
}

.message__text li {
  margin: 0.125rem 0;
}

/* Dark-mode chroma overrides — fix contrast for tokens the github-dark style
   does not explicitly colour (they fall through to near-black light values). */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .code-block__pre,
  :root[data-theme="auto"] .chroma {
    background-color: #1b1f27;
    color: #e6edf3;
  }
  /* Plain identifiers, punctuation, generic output — near-black in light style */
  :root[data-theme="auto"] .chroma .na,
  :root[data-theme="auto"] .chroma .nc,
  :root[data-theme="auto"] .chroma .nx,
  :root[data-theme="auto"] .chroma .nn,
  :root[data-theme="auto"] .chroma .p,
  :root[data-theme="auto"] .chroma .ge,
  :root[data-theme="auto"] .chroma .go { color: #e6edf3; }
}

:root[data-theme="dark"] .code-block__pre,
:root[data-theme="dark"] .chroma {
  background-color: #1b1f27;
  color: #e6edf3;
}
:root[data-theme="dark"] .chroma .na,
:root[data-theme="dark"] .chroma .nc,
:root[data-theme="dark"] .chroma .nx,
:root[data-theme="dark"] .chroma .nn,
:root[data-theme="dark"] .chroma .p,
:root[data-theme="dark"] .chroma .ge,
:root[data-theme="dark"] .chroma .go { color: #e6edf3; }

/* Header bar — slightly lighter than the pre block so the border reads clearly */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .code-block__header { background-color: #22262e; }
}
:root[data-theme="dark"] .code-block__header { background-color: #22262e; }

/* The hidden textarea used by the copy button */
.code-block__raw {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   Scrollbars (subtle)
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ============================================================
   Media attachments — rendered inside messages
   ============================================================ */
.message__attachments {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin-top: .375rem;
  max-width: min(480px, 100%);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* 2 attachments: side by side */
.message__attachments:has(> :nth-child(2):last-child) {
  grid-template-columns: 1fr 1fr;
}

/* Exactly 3: large item on left spanning both rows, two stacked on right */
.message__attachments:has(> :nth-child(3):last-child) {
  grid-template-columns: 2fr 1fr;
}
.message__attachments:has(> :nth-child(3):last-child) > :first-child {
  grid-row: span 2;
}

/* 4+ attachments: 2-column grid */
.message__attachments:has(> :nth-child(4)) {
  grid-template-columns: 1fr 1fr;
}

.message__media-img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--color-bg-subtle);
  cursor: zoom-in;
}

/* Single image: natural aspect ratio, not forced square */
.message__attachments:has(> :only-child) .message__media-img {
  aspect-ratio: unset;
  height: auto;
  max-height: 320px;
  object-fit: contain;
}

.message__media-video {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
}

/* Single video: natural 16:9 ratio */
.message__attachments:has(> :only-child) .message__media-video {
  aspect-ratio: 16 / 9;
}

/* ============================================================
   Lightbox
   ============================================================ */
.lightbox {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 100dvw;
  max-height: 100dvh;
  width: 100dvw;
  height: 100dvh;
}

.lightbox[open] {
  display: grid;
  place-items: center;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}

.lightbox__img {
  max-width: min(90dvw, 1200px);
  max-height: 90dvh;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  object-fit: contain;
  touch-action: none;
  cursor: zoom-in;
}

.lightbox__img--zoomed {
  cursor: grab;
}

.lightbox__img--zoomed:active {
  cursor: move;
}

.lightbox__close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.lightbox__nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, opacity .15s;
}

.lightbox__nav svg {
  width: 1.25rem;
  height: 1.25rem;
}

.lightbox__nav--prev { left: 1rem; }
.lightbox__nav--next { right: 1rem; }

.lightbox__nav:hover { background: rgba(255, 255, 255, 0.25); }
.lightbox__nav:disabled { opacity: .25; cursor: default; }
.lightbox__nav[hidden] { display: none; }

/* ============================================================
   Attachment upload chips (shown while uploading)
   ============================================================ */
.attachment-previews {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
  padding: .375rem .75rem;
}

.attachment-previews[hidden] { display: none; }

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .25rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: .8125rem;
  color: var(--color-text);
  position: relative;
}

.attachment-chip img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.attachment-chip__icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}

/* Spinning ring shown while the upload is in progress */
.attachment-chip__spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: chip-spin .7s linear infinite;
}

@keyframes chip-spin {
  to { transform: rotate(360deg); }
}

.attachment-chip--done {
  border-color: color-mix(in srgb, var(--color-primary) 40%, transparent);
}

.attachment-chip--error {
  border-color: color-mix(in srgb, var(--color-danger) 50%, transparent);
  background: color-mix(in srgb, var(--color-danger) 8%, transparent);
}

.attachment-chip__remove {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  font-size: .875rem;
  line-height: 1;
  cursor: pointer;
  transition: background .1s, color .1s;
}

.attachment-chip__remove:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* ============================================================
   Drag-and-drop overlay
   ============================================================ */

/* The room-main column must be the positioning parent */
.room-main { position: relative; }

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg) 80%);
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius-md);
  pointer-events: none;   /* let drag events pass through to the real target */
  opacity: 0;
  transition: opacity .15s;
}

.drop-overlay[hidden] { display: none; }

.drop-overlay--active {
  opacity: 1;
  background: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg) 80%);
}

.drop-overlay__label {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-primary);
  pointer-events: none;
  user-select: none;
}

/* ============================================================
   Notification bell
   ============================================================ */
.notif-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* Bell icons: show only the relevant icon per state */
.notif-bell__icon { display: none; }

[data-state="off"]   .notif-bell__icon--off    { display: block; }
[data-state="on"]    .notif-bell__icon--filled  { display: block; }
[data-state="muted"] .notif-bell__icon--filled  { display: block; }

/* Button needs relative positioning for the badge dot.
   When a pill is visible the button gets a little extra right padding so
   the dashed border wraps tightly around icon + text. */
.notif-bell {
  position: relative;
  gap: 0;
  transition: padding-right 200ms ease;
}
[data-state="off"].notif-bell,
[data-state="muted"].notif-bell {
  padding-right: .6rem;
}

/* Off state — dashed outline to signal "available but inactive" */
[data-state="off"].notif-bell {
  border: 1px dashed var(--color-border);
  color: var(--color-text-muted);
}
[data-state="off"].notif-bell:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

/* On state — filled bell in primary colour; hold colour on hover */
[data-state="on"].notif-bell {
  color: var(--color-primary);
}
[data-state="on"].notif-bell:hover {
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

/* Muted state — filled bell greyed out */
[data-state="muted"].notif-bell {
  color: var(--color-text-muted);
}
[data-state="muted"].notif-bell:hover {
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
}

/* Spinner — shown while activating push subscription */
.notif-spinner {
  display: none;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: chip-spin .7s linear infinite;
}
[data-state="loading"] .notif-spinner,
[data-state="pending"] .notif-spinner    { display: inline-block; }
[data-state="loading"] .notif-bell__icon,
[data-state="pending"] .notif-bell__icon { display: none; }
[data-state="loading"].notif-bell,
[data-state="pending"].notif-bell        { cursor: default; }

/* Badge dot — amber, shown only when muted */
.notif-badge {
  display: none;
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  border: 1.5px solid var(--color-bg);
  pointer-events: none;
}
[data-state="muted"] .notif-badge { display: block; }

/* Pill labels — live inside the button */
.notif-pill {
  display: inline-block;
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  margin-left: 0;
  transition: max-width 200ms ease, opacity 150ms ease, margin-left 200ms ease;
  font-size: .75rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}
.notif-pill--off   { color: var(--color-text-muted); }
.notif-pill--muted { color: #f59e0b; }

/* Selectors work because the pills are children of the button that carries data-state */
[data-state="off"]   .notif-pill--off,
[data-state="muted"] .notif-pill--muted {
  max-width: 6rem;
  opacity: 1;
  margin-left: .3rem;
}

.notif-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  min-width: 180px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: .375rem 0;
}
.notif-popover[hidden] { display: none; }

.notif-popover__label {
  font-size: .75rem;
  color: var(--color-text-muted);
  padding: .25rem .875rem .125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.notif-popover__item {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .4rem .875rem;
  text-align: left;
  font-family: inherit;
  font-size: .875rem;
  color: var(--color-text);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background .1s;
}
.notif-popover__item svg {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
}
.notif-popover__item:hover { background: var(--color-bg-subtle); }
.notif-popover__item[hidden] { display: none; }

.notif-popover__item--danger { color: var(--color-danger); }
.notif-popover__item--unmute { color: var(--color-primary); }

.notif-popover__sep {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: .25rem 0;
}

/* ============================================================
   Mention autocomplete (extends .emoji-autocomplete)
   ============================================================ */
.mention-autocomplete .emoji-autocomplete__glyph {
  width: auto;
  flex-shrink: 0;
}

/* ============================================================
   Sidebar toggle button (mobile only)
   ============================================================ */
.room-sidebar-toggle {
  display: none;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

/* Backdrop: tapping outside closes sidebar on mobile */
.room-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, .4);
}

/* ============================================================
   Top-bar unread indicator (mobile only)
   ============================================================ */
.topbar-unread {
  display: none;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--color-text);
  font-size: .8125rem;
  font-weight: 600;
  animation: topbar-unread-in .25s ease both;
}

.topbar-unread__room {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-unread__count {
  background: var(--color-primary);
  color: #fff;
  font-size: .75rem;
  padding: 0 .35rem;
  border-radius: .625rem;
  min-width: 1.25rem;
  height: 1.25rem;
  line-height: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.topbar-unread__more {
  color: var(--color-text-muted);
  font-weight: 500;
  flex-shrink: 0;
  font-size: .75rem;
}

@keyframes topbar-unread-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }
  .message { padding: .4rem .875rem; }
  .message--continuation { padding-top: .0625rem; }
  .message-form { padding: .5rem calc(.875rem + env(safe-area-inset-right, 0px)) calc(.75rem + env(safe-area-inset-bottom, 0px)) calc(.875rem + env(safe-area-inset-left, 0px)); }

  /* Show sidebar toggle button */
  .room-sidebar-toggle { display: inline-flex; }

  /* Show top-bar unread indicator */
  .topbar-unread:not([hidden]) { display: flex; }

  /* Sidebar: hidden off-screen by default, slides in as full-screen overlay */
  .room-sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: 100%;
    z-index: 100;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
  }

  /* Sidebar open */
  .room-layout--sidebar-open .room-sidebar {
    transform: translateX(0);
  }
  .room-layout--sidebar-open .room-sidebar-backdrop {
    display: block;
  }

  /* Right panel: full-width fixed overlay below both headers */
  .room-panel {
    position: fixed;
    top: calc(var(--header-h) + var(--room-header-h));
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
    overflow-y: auto;
    z-index: 50;
  }
}

/* ============================================================
   iOS PWA install guide modal
   ============================================================ */
.pwa-guide {
  border: 1px solid var(--color-border);
  border-radius: .75rem;
  padding: 1.5rem;
  max-width: 380px;
  width: calc(100vw - 2rem);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  background: var(--color-bg);
  color: var(--color-text);
  position: fixed;
  top: calc(var(--header-h) + .5rem);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  animation: pwa-guide-in 200ms ease both;
}

.pwa-guide.is-closing {
  animation: pwa-guide-out 150ms ease both;
}

@keyframes pwa-guide-in {
  from { opacity: 0; translate: 0 -8px; }
}

@keyframes pwa-guide-out {
  to { opacity: 0; translate: 0 -8px; }
}

.pwa-guide::backdrop {
  background: rgba(0,0,0,.45);
}

.pwa-guide__close {
  position: absolute;
  top: .75rem;
  right: .875rem;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: .25rem .375rem;
  border-radius: .375rem;
}
.pwa-guide__close:hover { background: var(--color-bg-subtle); }

.pwa-guide__title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 .625rem;
}

.pwa-guide__intro {
  font-size: .9rem;
  color: var(--color-text-muted);
  margin: 0 0 1rem;
  line-height: 1.5;
}

.pwa-guide__steps {
  margin: 0;
  padding-left: 1.375rem;
  font-size: .9rem;
  line-height: 1.7;
}

.pwa-guide__share-icon {
  width: 1em;
  height: 1em;
  vertical-align: -.125em;
  display: inline-block;
}

/* ============================================================
   Action Sheet (mobile message actions)
   ============================================================ */
.action-sheet:not([open]) {
  display: none;
}

.action-sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text);
  overflow: hidden;
}

.action-sheet::backdrop {
  background: rgba(0, 0, 0, .15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: action-sheet-fade-in 250ms ease;
}

.message--sheet-target {
  background: var(--color-bg-subtle);
}

.action-sheet.is-closing::backdrop {
  animation: action-sheet-fade-out 200ms ease forwards;
}

.action-sheet[open] > .action-sheet__content {
  animation: action-sheet-slide-up 250ms ease;
}

.action-sheet.is-closing > .action-sheet__content {
  animation: action-sheet-slide-down 200ms ease forwards;
}

@keyframes action-sheet-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes action-sheet-slide-down {
  from { transform: translateY(0); }
  to   { transform: translateY(100%); }
}

@keyframes action-sheet-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes action-sheet-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.action-sheet__content {
  position: absolute;
  bottom: max(.5rem, env(safe-area-inset-bottom, 0px));
  left: max(.5rem, env(safe-area-inset-left, 0px));
  right: max(.5rem, env(safe-area-inset-right, 0px));
  width: auto;
  max-height: calc(100% - max(.5rem, env(safe-area-inset-bottom, 0px)) - .5rem);
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg, 16px);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, .15);
  padding: 0 0 .5rem;
  transition: transform .15s ease;
}

.action-sheet__handle {
  display: flex;
  justify-content: center;
  padding: .75rem 0 .5rem;
  cursor: grab;
  touch-action: none;
}

.action-sheet__pill {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
}

.action-sheet__preview {
  max-height: 5.5rem;
  overflow: hidden;
  pointer-events: none;
}

.action-sheet__preview:empty {
  display: none;
}

.action-sheet__preview:empty + .action-sheet__preview-sep {
  display: none;
}

/* Override message styles inside the preview clone */
.action-sheet__preview .message {
  padding: .375rem 1.25rem;
  background: transparent;
}

.action-sheet__preview .message__text {
  white-space: normal;
}

.action-sheet__item {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .875rem 1.25rem;
  border: none;
  background: none;
  color: var(--color-text);
  font: inherit;
  font-size: .9375rem;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.action-sheet__item:active {
  background: var(--color-bg-hover, rgba(128, 128, 128, .1));
}

.action-sheet__item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.action-sheet__item--danger {
  color: var(--color-danger);
}

.action-sheet__item[hidden],
.action-sheet__separator[hidden],
.action-sheet__picker[hidden] {
  display: none;
}

.action-sheet__picker {
  overflow: hidden;
}

/* When the picker is inside the sheet, override its fixed positioning */
.action-sheet__picker #emoji-picker-container {
  position: static;
  box-shadow: none;
  border-radius: 0;
  width: 100%;
}

.action-sheet__picker emoji-picker {
  width: 100%;
  height: 300px;
}

.action-sheet__separator {
  margin: 0;
  border: none;
  border-top: 1px solid var(--color-border);
}
