/* ==========================================================================
   Privát Chat – dark, responsive UI
   Modern CSS: dynamic viewport units, container queries, :user-invalid,
   field-sizing, native dialog + top-layer transitions, color-mix().
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: dark;

  --bg-0: #111214;
  --bg-1: #191a1e;
  --bg-2: #1e1f22;
  --bg-3: #26272b;
  --bg-4: #34363c;
  --bg-5: #3f4147;

  --text-1: #f2f3f5;
  --text-2: #c3c6cc;
  --text-3: #9aa0a8;
  --text-4: #72767e;

  --accent: #5865f2;
  --accent-bright: #7c8cff;
  --accent-soft: rgb(88 101 242 / 0.18);
  --green: #23a55a;
  --amber: #f0b232;
  --red: #ed4245;
  --red-soft: rgb(237 66 69 / 0.14);

  --border: rgb(255 255 255 / 0.07);
  --border-strong: rgb(255 255 255 / 0.13);
  --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / 0.75);
  --shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.55);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 26px;

  --sidebar-w: 264px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas,
    monospace;

  --ease-out: cubic-bezier(0.22, 0.8, 0.28, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.44, 1);
}

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

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2 {
  text-wrap: balance;
}

img {
  max-width: 100%;
  height: auto;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

::selection {
  background: var(--accent);
  color: #fff;
}

/* Custom scrollbars: the standard properties are enough in modern browsers. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-5) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--bg-5) padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: #4c4f57 padding-box;
}

/* The SVG symbol sheet must stay in the DOM but never take space. */
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.72rem 1.1rem;
  border: 0;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    filter 0.16s ease,
    transform 0.12s ease,
    box-shadow 0.16s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.65;
  cursor: progress;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6e7bff 65%, #8f9dff);
  color: #fff;
  box-shadow:
    0 1px 0 rgb(255 255 255 / 0.18) inset,
    0 8px 20px -8px rgb(88 101 242 / 0.7);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-ghost {
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-4);
  color: var(--text-1);
}

.btn-wide {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-4);
  color: var(--text-1);
}

.icon-btn:active {
  background: var(--bg-5);
}

/* ==========================================================================
   Auth screen
   ========================================================================== */
.auth-view {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: clamp(1rem, 4vw, 3rem);
  overflow: auto;
  background:
    radial-gradient(1200px 600px at 15% -10%, #2b2f70 0%, transparent 55%),
    radial-gradient(900px 700px at 110% 110%, #123a3a 0%, transparent 50%),
    linear-gradient(160deg, #131418 0%, #101114 100%);
}

.auth-aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.5;
}

.auth-aurora::before,
.auth-aurora::after {
  content: "";
  position: absolute;
  width: min(46vw, 560px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #5865f2, transparent 68%);
  animation: aurora-drift 22s var(--ease-out) infinite alternate;
}

.auth-aurora::before {
  top: 8%;
  left: 6%;
}

.auth-aurora::after {
  right: 4%;
  bottom: 2%;
  background: radial-gradient(circle at 60% 60%, #23a55a, transparent 66%);
  animation-delay: -11s;
  animation-duration: 28s;
}

@keyframes aurora-drift {
  from {
    transform: translate3d(-3%, -2%, 0) scale(1);
  }
  to {
    transform: translate3d(5%, 4%, 0) scale(1.16);
  }
}

.auth-card {
  position: relative;
  z-index: 1;
  width: min(100%, 430px);
  padding: clamp(1.4rem, 4vw, 2.1rem);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.045), transparent 30%),
    color-mix(in srgb, var(--bg-1) 88%, transparent);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  flex: none;
  border-radius: 16px;
  background: linear-gradient(140deg, var(--accent), #8f9dff);
  color: #fff;
  box-shadow: 0 10px 26px -10px rgb(88 101 242 / 0.9);
}

.brand-mark .icon {
  width: 1.6rem;
  height: 1.6rem;
}

.brand-mark.small {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 12px;
}

.brand-mark.small .icon {
  width: 1.2rem;
  height: 1.2rem;
}

.eyebrow {
  color: var(--text-3);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.auth-brand h1 {
  margin-top: 0.1rem;
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.6rem);
  font-weight: 750;
  letter-spacing: -0.02em;
}

.auth-lead {
  margin-bottom: 1.35rem;
  color: var(--text-3);
  font-size: 0.9rem;
  text-wrap: pretty;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 1.2rem;
  border-radius: 14px;
  background: var(--bg-0);
  border: 1px solid var(--border);
}

.auth-tab {
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-3);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.auth-tab:hover {
  color: var(--text-1);
}

.auth-tab[aria-selected="true"] {
  background: var(--bg-3);
  color: var(--text-1);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.06) inset, var(--shadow-md);
}

.auth-form {
  display: grid;
  gap: 0.95rem;
}

.field {
  display: grid;
  gap: 0.38rem;
}

.field label,
.color-field legend {
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.field input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  background: var(--bg-0);
  color: var(--text-1);
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background-color 0.16s ease;
}

.field input:hover {
  border-color: rgb(255 255 255 / 0.2);
}

.field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input:user-invalid {
  border-color: var(--red);
}

.field input:user-invalid:focus-visible {
  box-shadow: 0 0 0 3px var(--red-soft);
}

.field-hint {
  color: var(--text-4);
  font-size: 0.74rem;
  line-height: 1.4;
}

.color-field {
  padding: 0;
  margin: 0;
  border: 0;
}

.color-field legend {
  padding: 0;
  margin-bottom: 0.5rem;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.swatch {
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch) padding-box;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.14);
  transition:
    transform 0.15s var(--ease-spring),
    box-shadow 0.15s ease;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch[aria-pressed="true"] {
  box-shadow:
    0 0 0 2px var(--bg-1),
    0 0 0 4px var(--swatch);
}

.swatches input[type="color"] {
  width: 2.3rem;
  height: 2.3rem;
  padding: 0;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.swatches input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 3px;
}

.swatches input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.form-error {
  padding: 0.6rem 0.75rem;
  border: 1px solid rgb(237 66 69 / 0.32);
  border-radius: 10px;
  background: var(--red-soft);
  color: #ffb9ba;
  font-size: 0.82rem;
  line-height: 1.45;
}

.auth-foot {
  margin-top: 1.2rem;
  color: var(--text-4);
  font-size: 0.72rem;
  text-align: center;
}

/* ==========================================================================
   App shell
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.25);
}

.sidebar-brand strong {
  display: block;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.server-sub {
  display: block;
  color: var(--text-4);
  font-size: 0.7rem;
}

.online-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.4rem;
  color: var(--text-4);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.online-header .count {
  min-width: 1.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--bg-4);
  color: var(--text-2);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: 0;
}

.online-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  margin: 0;
  padding: 0.25rem 0.55rem 0.75rem;
  overflow-y: auto;
  list-style: none;
}

.online-user {
  display: flex;
  align-items: center;
  gap: 0.62rem;
  padding: 0.34rem 0.5rem;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 0.9rem;
  transition: background-color 0.15s ease;
}

.online-user:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.online-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.you-badge {
  margin-left: auto;
  padding: 0.05rem 0.38rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-bright);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.user-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.7rem 0.7rem calc(0.7rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-0) 55%, var(--bg-2));
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.user-chip-text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.user-chip-text strong {
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-4);
  font-size: 0.7rem;
}

.user-actions {
  display: flex;
  gap: 0.1rem;
}

/* The volume button swaps its icon based on aria-pressed. */
.icon-sound-off {
  display: none;
}

[aria-pressed="false"] .icon-sound-on {
  display: none;
}

[aria-pressed="false"] .icon-sound-off {
  display: block;
}

/* ---------- Avatars ---------- */
.avatar {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.08) inset;
}

.avatar-small {
  width: 2rem;
  height: 2rem;
  font-size: 0.82rem;
}

.avatar-tiny {
  width: 1.75rem;
  height: 1.75rem;
  font-size: 0.72rem;
}

/* ---------- Chat column ---------- */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(1000px 400px at 80% -10%, rgb(88 101 242 / 0.07), transparent 60%),
    var(--bg-1);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.6rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.2);
}

.channel-heading {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.channel-heading h1 {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.hash {
  display: grid;
  place-items: center;
  color: var(--text-4);
}

.hash .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.channel-sub {
  overflow: hidden;
  padding-left: 0.6rem;
  margin-left: 0.2rem;
  border-left: 1px solid var(--border-strong);
  color: var(--text-4);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.28rem 0.62rem;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-0);
  color: var(--text-3);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  flex: none;
  border-radius: 50%;
  background: var(--text-4);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 3px rgb(35 165 90 / 0.18);
}

.status-dot.connecting {
  background: var(--amber);
  animation: pulse-dot 1.3s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--red);
}

@keyframes pulse-dot {
  50% {
    opacity: 0.35;
    transform: scale(0.85);
  }
}

/* ---------- Message list ---------- */
.messages-wrap {
  position: relative;
  min-height: 0;
  flex: 1;
  container-type: inline-size;
  container-name: chat;
}

.messages {
  height: 100%;
  margin: 0;
  padding: 0.9rem clamp(0.6rem, 2vw, 1.25rem) 1.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none; /* older pages are restored manually below */
  scrollbar-gutter: stable;
}

/* ---------- Date separators & empty state ---------- */
.day-divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.7rem 0.35rem;
  color: var(--text-4);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.day-divider::before,
.day-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--border);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  padding: clamp(2.5rem, 12vh, 6rem) 1rem;
  color: var(--text-3);
  text-align: center;
  text-wrap: pretty;
}

.empty-state strong {
  color: var(--text-1);
  font-size: 1.05rem;
}

.empty-state span {
  font-size: 0.85rem;
}

.history-sentinel {
  display: flex;
  justify-content: center;
  padding: 0.35rem 0 1rem;
}

.history-sentinel[data-end="true"] {
  padding-bottom: 0.5rem;
  opacity: 0.6;
}

.message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.8rem;
  padding: 0.42rem 0.7rem;
  border-radius: 10px;
  content-visibility: auto;
  contain-intrinsic-size: auto 74px;
  transition: background-color 0.14s ease;
}

.message:hover {
  background: rgb(255 255 255 / 0.028);
}

.message + .message {
  margin-top: 0.1rem;
}

.message.is-new {
  animation: message-in 0.22s var(--ease-out);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.message-body {
  min-width: 0;
  padding-top: 0.05rem;
}

.message-head {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  min-width: 0;
}

.message-author {
  overflow: hidden;
  color: var(--accent-bright);
  font-size: 0.92rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-time {
  color: var(--text-4);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.message-content {
  margin-top: 0.08rem;
  color: var(--text-2);
  font-size: 0.94rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  text-wrap: pretty;
  white-space: pre-wrap;
}

.message-content:empty {
  display: none;
}

.message-content a {
  color: #8fa7ff;
  text-decoration: none;
  text-underline-offset: 2px;
}

.message-content a:hover {
  text-decoration: underline;
}

/* ---------- Attachments ---------- */
.message-attachments {
  display: grid;
  gap: 0.45rem;
  max-width: min(440px, 100%);
  margin-top: 0.45rem;
}

.message-attachments:empty,
.message-preview:empty {
  display: none;
}

.attachment-image {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-3);
  cursor: zoom-in;
  overflow: hidden;
}

.attachment-image img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 340px;
  aspect-ratio: auto;
  object-fit: contain;
}

.attachment-image:hover img {
  filter: brightness(1.04);
}

.attachment-image:focus-visible {
  outline-offset: 3px;
}

/* ---------- Link previews ---------- */
.message-preview {
  max-width: min(520px, 100%);
  margin-top: 0.5rem;
}

.preview-card {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--bg-3);
  color: inherit;
  text-decoration: none;
  transition:
    border-color 0.15s ease,
    transform 0.15s ease,
    background-color 0.15s ease;
}

.preview-card:hover {
  background: var(--bg-4);
  border-color: rgb(255 255 255 / 0.2);
  border-left-color: var(--accent-bright);
}

.preview-image {
  display: block;
  width: 100%;
  max-height: 220px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--bg-0);
}

.preview-body {
  display: grid;
  gap: 0.2rem;
  padding: 0.7rem 0.85rem;
}

.preview-site {
  color: var(--text-4);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.preview-title {
  color: var(--text-1);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.35;
}

.preview-desc {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-3);
  font-size: 0.8rem;
  line-height: 1.45;
  text-wrap: pretty;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

@container chat (min-width: 640px) {
  .preview-card:has(.preview-image) {
    grid-template-columns: 170px minmax(0, 1fr);
  }

  .preview-card:has(.preview-image) .preview-image {
    height: 100%;
    max-height: 170px;
    min-height: 100px;
    aspect-ratio: auto;
  }

  .preview-card:has(.preview-image) .preview-body {
    align-content: center;
  }
}

/* ---------- New messages pill ---------- */
.new-messages-pill {
  position: absolute;
  bottom: 0.9rem;
  left: 50%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 8px 24px -6px rgb(0 0 0 / 0.6);
  transform: translateX(-50%);
  animation: pill-in 0.2s var(--ease-spring);
}

.new-messages-pill .icon {
  width: 0.95rem;
  height: 0.95rem;
}

.new-messages-pill:hover {
  background: var(--accent-bright);
}

@keyframes pill-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ---------- Composer ---------- */
.composer {
  display: grid;
  gap: 0.5rem;
  padding: 0.65rem clamp(0.7rem, 2vw, 1.1rem) calc(0.8rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-1) 86%, var(--bg-0));
}

.attachment {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: fit-content;
  max-width: 100%;
  padding: 0.4rem 0.45rem 0.4rem 0.4rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-3);
}

.attachment img {
  width: 2.6rem;
  height: 2.6rem;
  flex: none;
  border-radius: 7px;
  object-fit: cover;
  background: var(--bg-0);
}

.attachment-meta {
  display: grid;
  min-width: 0;
  line-height: 1.3;
}

.attachment-meta strong {
  max-width: 16rem;
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta span {
  color: var(--text-4);
  font-size: 0.68rem;
}

.attachment .icon-btn {
  width: 1.9rem;
  height: 1.9rem;
}

.attachment .icon-btn .icon {
  width: 1rem;
  height: 1rem;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem 0.3rem 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--bg-4);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background-color 0.15s ease;
}

.composer-row:focus-within {
  border-color: rgb(88 101 242 / 0.55);
  background: #3a3c43;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.attach-btn {
  margin-bottom: 0.05rem;
  color: var(--text-3);
}

.attach-btn:hover {
  background: rgb(255 255 255 / 0.08);
  color: var(--text-1);
}

#message-input {
  flex: 1;
  min-width: 0;
  max-height: 13rem;
  padding: 0.48rem 0.2rem;
  border: 0;
  background: transparent;
  color: var(--text-1);
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  field-sizing: content;
  overflow-y: auto;
  outline: none;
}

#message-input::placeholder {
  color: var(--text-4);
}

.send-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7d8bff);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px -6px rgb(88 101 242 / 0.8);
  transition:
    filter 0.15s ease,
    transform 0.12s var(--ease-spring);
}

.send-button:hover {
  filter: brightness(1.1);
  transform: scale(1.04);
}

.send-button:active {
  transform: scale(0.96);
}

.send-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.send-button .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.35rem;
  color: var(--text-4);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.composer-meta .is-warning {
  color: var(--amber);
}

.composer-meta .is-error {
  color: #ff9a9c;
}

/* ==========================================================================
   Native dialogs
   ========================================================================== */
dialog {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-1);
}

dialog::backdrop {
  background: rgb(4 5 8 / 0.62);
  backdrop-filter: blur(3px);
}

/* ---------- Mobile drawer ---------- */
.drawer {
  position: fixed;
  inset: 0;
  display: none;
  width: 100%;
  max-width: none;
  height: 100dvh;
  margin: 0;
  opacity: 0;
  transition:
    opacity 0.2s ease,
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}

.drawer[open] {
  display: block;
  opacity: 1;
}

@starting-style {
  .drawer[open] {
    opacity: 0;
  }
}

.drawer-panel {
  display: flex;
  flex-direction: column;
  width: min(86vw, 330px);
  height: 100%;
  margin-left: auto;
  background: var(--bg-2);
  border-left: 1px solid var(--border-strong);
  box-shadow: -24px 0 60px -20px rgb(0 0 0 / 0.8);
  transform: translateX(100%);
  transition: transform 0.24s var(--ease-out);
}

.drawer[open] .drawer-panel {
  transform: none;
}

@starting-style {
  .drawer[open] .drawer-panel {
    transform: translateX(100%);
  }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.8rem 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
}

.drawer .online-list {
  flex: 1;
  padding: 0.5rem 0.7rem;
}

.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.8rem 0.8rem calc(0.8rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-0);
}

/* ---------- Lightbox ---------- */
.lightbox {
  display: none;
  width: fit-content;
  max-width: 94vw;
  margin: auto;
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity 0.2s ease,
    transform 0.2s var(--ease-out),
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}

.lightbox[open] {
  display: grid;
  place-items: center;
  opacity: 1;
  transform: none;
}

@starting-style {
  .lightbox[open] {
    opacity: 0;
    transform: scale(0.96);
  }
}

.lightbox::backdrop {
  background: rgb(3 4 6 / 0.85);
  backdrop-filter: blur(6px);
}

#lightbox-image {
  display: block;
  max-width: 92vw;
  max-height: 86dvh;
  border-radius: var(--radius-md);
  object-fit: contain;
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.9);
  user-select: none;
}

.lightbox-close {
  position: fixed;
  top: max(0.8rem, env(safe-area-inset-top));
  right: 0.8rem;
  z-index: 1;
  background: rgb(20 21 25 / 0.75);
  color: var(--text-1);
  box-shadow: 0 0 0 1px var(--border-strong);
  backdrop-filter: blur(8px);
}

/* ==========================================================================
   Toasts, drop overlay
   ========================================================================== */
.toast-region {
  position: fixed;
  right: max(0.9rem, env(safe-area-inset-right));
  bottom: calc(0.9rem + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(340px, calc(100vw - 1.8rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.65rem 0.65rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-3) 92%, transparent);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
  pointer-events: auto;
  animation: toast-in 0.24s var(--ease-out);
}

.toast.error {
  border-color: rgb(237 66 69 / 0.5);
  background: color-mix(in srgb, #3a1f22 88%, transparent);
}

.toast.success {
  border-color: rgb(35 165 90 / 0.45);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

.toast-text {
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.4;
}

.toast-close {
  width: 1.8rem;
  height: 1.8rem;
  flex: none;
}

.toast-close .icon {
  width: 0.9rem;
  height: 0.9rem;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(10 11 14 / 0.72);
  backdrop-filter: blur(5px);
}

.drop-card {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  width: min(420px, 92vw);
  padding: 2.4rem 1.5rem;
  border: 2px dashed rgb(124 140 255 / 0.55);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.drop-card .icon {
  width: 2.4rem;
  height: 2.4rem;
  color: var(--accent-bright);
}

.drop-card strong {
  font-size: 1.05rem;
}

.drop-card span {
  color: var(--text-3);
  font-size: 0.8rem;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
.mobile-only {
  display: none;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    display: none;
  }

  .mobile-only {
    display: inline-grid;
  }

  .chat-header {
    padding-inline: 0.55rem;
  }

  .channel-sub {
    display: none;
  }

  .chat-status #conn-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .chat-status {
    padding: 0.3rem;
  }

  .message {
    gap: 0.65rem;
    padding-inline: 0.35rem;
  }

  .avatar {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.9rem;
  }

  .attachment-image img {
    max-height: 260px;
  }

  .toast-region {
    bottom: auto;
    top: calc(0.7rem + env(safe-area-inset-top));
  }
}

@media (max-width: 420px) {
  .chat-status .status-dot {
    margin: 0;
  }

  .message-content {
    font-size: 0.92rem;
  }

  .auth-card {
    padding: 1.25rem 1.1rem;
  }
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .auth-aurora::before,
  .auth-aurora::after {
    animation: none !important;
  }
}
