/* Blat-Chat — modern dark theme, no build step, ~9KB. */

:root {
  /* Surface tones */
  --bg-0: #07080d;          /* page */
  --bg-1: #0d1018;          /* app shell */
  --bg-2: #141823;          /* panel */
  --bg-3: #1c2230;          /* input/hover */
  --bg-4: #252b3a;          /* elevated */
  /* Borders / glass */
  --border: rgba(255, 255, 255, 0.07);
  --border-2: rgba(255, 255, 255, 0.12);
  /* Text */
  --text: #eef0f5;
  --text-dim: #a4abbb;
  --text-faint: #6b7385;
  /* Accent (gradient) */
  --accent-1: #6c8cff;
  --accent-2: #8a6cff;
  --accent-3: #4dc3ff;
  --accent-grad: linear-gradient(135deg, #6c8cff 0%, #8a6cff 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(108,140,255,0.18), rgba(138,108,255,0.18));
  /* States */
  --success: #2dd4a3;
  --danger: #ff5470;
  --warn: #f7b955;
  /* Bubbles — both near-bg subtle; alignment is the "this is me" cue. */
  --bubble-other: rgba(255, 255, 255, 0.04);
  --bubble-other-border: rgba(255, 255, 255, 0.07);
  --bubble-other-text: var(--text);
  --bubble-me-bg: rgba(255, 255, 255, 0.06);   /* one notch brighter than other */
  --bubble-me-border: rgba(255, 255, 255, 0.10);
  --bubble-me-text: var(--text);
  /* Geometry */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 22px;
  --shadow-1: 0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 8px 32px rgba(0,0,0,0.45);
  --shadow-pop: 0 16px 48px rgba(0,0,0,0.55);
  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 120ms;
  --t-med: 200ms;
  --t-slow: 360ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(138, 108, 255, 0.10), transparent 60%),
    var(--bg-0);
  background-attachment: fixed;
}

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

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

input, textarea, select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 14px;
  outline: none;
  width: 100%;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
input:hover, textarea:hover, select:hover { border-color: var(--border-2); }
input:focus, textarea:focus, select:focus {
  border-color: rgba(108, 140, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.18);
  background: var(--bg-3);
}
/* Composer textarea: don't let the global focus ring dominate — the composer
   is a 24/7 input surface, ANY ring looks like a 4-5x thicker border.
   Just nudge the border colour a hair and skip the box-shadow ring entirely. */
.composer textarea:focus {
  box-shadow: none;
  border-color: rgba(108, 140, 255, 0.40);
  background: var(--bg-3);
}

button {
  background: var(--accent-grad);
  color: #fff;
  border: 0;
  border-radius: var(--r-md);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
  min-height: 42px;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), filter var(--t-fast) var(--ease);
  box-shadow: 0 6px 20px rgba(108, 140, 255, 0.35);
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; filter: none; box-shadow: none; }
button.secondary {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  box-shadow: none;
  color: var(--text);
}
button.secondary:hover { background: var(--bg-4); }
button.danger { background: linear-gradient(135deg, #ff5470, #e63a5a); box-shadow: 0 6px 20px rgba(255, 84, 112, 0.3); }
button.ghost {
  background: transparent;
  border: 1px solid var(--border-2);
  box-shadow: none;
  color: var(--text-dim);
}
button.ghost:hover { color: var(--text); background: var(--bg-3); }

/* ----- Password input with eye toggle ----- */
.password-wrap {
  position: relative;
  display: block;
}
.password-wrap input {
  padding-right: 44px; /* room for the eye button */
}
.password-wrap .eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
  display: grid;
  place-items: center;
  padding: 0;
  margin: 0;
  min-height: 0;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.password-wrap .eye:hover { color: var(--text); background: var(--bg-3); }
.password-wrap .eye:focus-visible { outline: 2px solid var(--accent-1); outline-offset: 2px; }
.password-wrap .eye.showing { color: var(--accent-1); }
.password-wrap .eye svg { display: block; }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01)), var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 36px 28px;
  box-shadow: var(--shadow-pop);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  background: var(--accent-grad);
  opacity: 0.18;
  filter: blur(40px);
  z-index: -1;
}
.login-card .brand {
  display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px;
}
.login-card .brand .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 0 16px rgba(108,140,255,0.7);
}
.login-card h1 {
  margin: 8px 0 4px;
  font-size: 22px;
  text-align: center;
  letter-spacing: -0.01em;
}
.login-card .sub {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 13px;
}
.login-card label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 14px 0 6px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.login-card button { width: 100%; margin-top: 22px; }
.login-card .error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
  text-align: center;
}

/* ---- App shell ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent 30%), var(--bg-1);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

@media (min-width: 920px) {
  .app {
    margin-top: 24px;
    margin-bottom: 24px;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-2);
    overflow: hidden;
    border: 1px solid var(--border-2);
  }
}

header.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(13, 16, 24, 0.7);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 5;
}
header.bar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
header.bar h1 .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 0 10px rgba(108,140,255,0.6);
}
header.bar .spacer { flex: 1; }
header.bar .me {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
header.bar .me .me-greeting { color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
header.bar .me .me-name { color: var(--text); font-size: 13px; font-weight: 500; }
@media (max-width: 600px) {
  header.bar .me { display: none; } /* mobile: save space, name visible in menu */
}
header.bar a.btn, header.bar button.link {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  min-height: 0;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  text-decoration: none;
}
header.bar a.btn:hover, header.bar button.link:hover { color: var(--text); background: var(--bg-3); text-decoration: none; }

/* ----- Hamburger menu button + dropdown ----- */
.menu-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background var(--t-fast) var(--ease);
}
.menu-btn:hover { background: var(--bg-4); }
.menu-btn .bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
  transform-origin: center;
}
.menu-btn.open .bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-btn.open .bar:nth-child(2) { opacity: 0; transform: scaleX(0); }
.menu-btn.open .bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 12px;
  min-width: 220px;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 6px;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: dropfade 0.14s var(--ease);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
@keyframes dropfade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dropdown button, .dropdown a {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease);
}
.dropdown button:hover, .dropdown a:hover { background: var(--bg-3); text-decoration: none; }
.dropdown .ico {
  display: inline-grid;
  place-items: center;
  width: 20px;
  font-size: 14px;
  color: var(--text-dim);
  flex: 0 0 auto;
}
.dropdown button:hover .ico, .dropdown a:hover .ico { color: var(--text); }
.dropdown .divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}
.dropdown .danger { color: var(--danger); }
.dropdown .danger .ico { color: var(--danger); }

/* ----- Avatar cropper modal ----- */
.avatar-modal { width: min(420px, 96vw); }
.crop-help {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 12px;
  text-align: center;
}
.crop-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 12px;
}
.crop-frame {
  position: relative;
  width: 300px;
  height: 300px;
  background:
    repeating-conic-gradient(rgba(255,255,255,0.04) 0% 25%, transparent 0% 50%) 50% / 16px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: grab;
}
.crop-frame.dragging { cursor: grabbing; }
.crop-stage {
  position: relative;
  overflow: hidden;
}
.crop-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  font-size: 13px;
  pointer-events: none;
}
.crop-image {
  position: absolute;
  left: 0;
  top: 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  image-rendering: -webkit-optimize-contrast;
}
/* A circular guide showing what will be saved. */
.crop-circle-mask {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 220px;
  height: 220px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  outline: 2px dashed rgba(255, 255, 255, 0.55);
  pointer-events: none;
}
.crop-zoom {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.crop-zoom label { font-size: 12px; color: var(--text-dim); min-width: 36px; }
.crop-zoom input[type=range] { flex: 1 1 auto; padding: 0; background: transparent; border: 0; }
.crop-err, .crop-status {
  font-size: 12px;
  min-height: 16px;
  margin-bottom: 6px;
}
.crop-err { color: var(--danger); }
.crop-status { color: var(--text-dim); }

/* ----- Avatar <img> replacement ----- */
.avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-3);
}
.msg .avatar-img,
.avatar.avatar-img-wrap {
  width: 100%;
  height: 100%;
}
.avatar.avatar-img-wrap {
  display: block;
  position: relative;
  overflow: hidden;
}

/* ----- Lightbox (image preview overlay) ----- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadein 0.14s var(--ease);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--r-sm);
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.6);
  cursor: default;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.05); }
.lightbox-close:focus-visible { outline: 2px solid var(--accent-1); outline-offset: 2px; }

/* ---- Chat area ---- */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  /* Clip the messages list to the chat column on small viewports so
     overflow can't push the composer off-screen. */
  overflow: hidden;
  position: relative;
}
.messages {
  flex: 1 1 auto;
  /* Always keep at least 120px of message space, even on very small
     phones. Prevents the messages area from collapsing to 0 height
     when the parent flex container can't determine a baseline size. */
  min-height: 120px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
.messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* Drag-over state for the messages pane. */
.messages.drag-over {
  outline: 2px dashed var(--accent-1);
  outline-offset: -8px;
  background: rgba(108, 140, 255, 0.04);
}
.messages.drag-over::after {
  content: attr(data-drag-text);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--accent-1);
  pointer-events: none;
}

/* Load older button — sits at the top of the messages list, centered. */
.load-older {
  display: block;
  margin: 8px auto 0;
  padding: 6px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--text-dim);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: none;
  min-height: 0;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.load-older:hover { color: var(--text); background: var(--bg-4); }
.load-older:disabled { opacity: 0.5; cursor: default; }

/* Typing indicator — sits between messages and composer, slides in. */
.typing {
  padding: 6px 20px 4px;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  min-height: 22px;
  animation: msgIn var(--t-fast) var(--ease);
}
.typing::before {
  content: "\2026";
  display: inline-block;
  margin-right: 6px;
  letter-spacing: 2px;
  color: var(--accent-1);
  font-style: normal;
  animation: typingPulse 1.2s ease-in-out infinite;
}
@keyframes typingPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Online dot in avatar — small green pip in the bottom-right. */
.avatar { position: relative; }
.avatar .online-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2dd4a3;
  border: 2px solid var(--bg-2);
  display: none;
}
.avatar.online .online-dot { display: block; }

/* ---- Message rows & bubbles ----
   Each message is a single .msg-row containing one .bubble. Own
   messages (.me) sit on the right; others sit on the left. The
   bubble's header carries a small avatar, nickname, and time. No
   action buttons, no hover chips, no white X — chat is just chat. */
.msg-row {
  display: flex;
  margin-top: 6px;
  animation: msgIn var(--t-med) var(--ease) both;
}
.msg-row.grouped { margin-top: 3px; }
.msg-row.me { justify-content: flex-end; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble {
  /* Subtle near-bg colour, one notch brighter than the page so the
     bubble reads as a card without shouting. Avatar + name + time
     sit inside the header so each message is self-contained. */
  background: var(--bubble-other);
  color: var(--bubble-other-text);
  border: 1px solid var(--bubble-other-border);
  border-radius: var(--r-lg);
  padding: 8px 12px 9px;
  max-width: min(560px, 80%);
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bubble.me {
  background: var(--bubble-me-bg);
  border-color: var(--bubble-me-border);
}

.bubble-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  line-height: 1;
  /* Subtle baseline separation between the sender line and the body. */
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 2px;
}
.bubble-header .bubble-name {
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}
.bubble-header .bubble-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
}
/* Slightly brighter header text for own messages so it reads against
   the brighter own-bubble background. */
.bubble.me .bubble-header .bubble-name { color: rgba(255, 255, 255, 0.85); }
.bubble.me .bubble-header .bubble-time { color: rgba(255, 255, 255, 0.65); }

/* Shrink the shared avatar element (default 32px) to 20px so it sits
   neatly inline with the nickname. */
.bubble-header .avatar,
.bubble-header .avatar-wrap {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  box-shadow: none;
  font-size: 10px;
}
.bubble-header .avatar-img,
.bubble-header .avatar > img.avatar-img {
  width: 20px;
  height: 20px;
}
.bubble-header .online-dot { display: none; }

.bubble .body { white-space: pre-wrap; }
.bubble .body img.attachment {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--r-md);
  margin-top: 6px;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease);
}
.bubble .body img.attachment:hover { transform: scale(1.01); }
.bubble .body a.attach-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--accent-3);
}
.bubble.me .body a.attach-link { color: rgba(255, 255, 255, 0.92); }

/* "Message deleted" tombstone. */
.msg-deleted {
  font-style: italic;
  color: var(--text-faint);
  font-size: 13px;
  padding: 6px 14px;
}

.day-sep {
  align-self: center;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 12px;
  margin: 6px 0 2px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 280px;
  justify-content: center;
}
.day-sep::before, .day-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex: 0 0 auto;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 4px 12px rgba(0,0,0,0.35);
  overflow: hidden;
  background: var(--bg-3);
}

/* ---- Composer ---- */
/* .composer-stack wraps the attach-preview (absolutely positioned
   above the form) and the <form.composer> itself. Without this wrapper
   the absolute preview's `bottom:100%` resolves against the form, and
   the form's overflow:hidden (needed to keep flex children from
   pushing it wider than the chat column on narrow phones) silently
   clips the preview off-screen. The stack provides a containing block
   whose height equals the form's, so bottom:100% lands cleanly above. */
.composer-stack {
  flex: 0 0 auto;
  position: relative;
  min-width: 0;
  max-width: 100%;
}
.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 14px;
  background: rgba(13, 16, 24, 0.7);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border);
  position: relative;
  /* Keep the composer inside the chat panel even when flex children would
     push it wider than the viewport. Without min-width:0 + overflow:hidden
     the row overflows horizontally and the leftmost child (the emoji button)
     gets pushed off-screen on narrow phones. */
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.composer textarea {
  resize: none;
  min-height: 42px;
  max-height: 140px;
  flex: 1 1 auto;
  /* Default flex item min-width is auto (= min-content) which keeps a
     textarea from shrinking below one word's width. Set it to 0 so the
     flex shorthand can actually compress it. */
  min-width: 0;
  font-size: 15px;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: var(--r-md);
}
.composer .icon-btn {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
  color: var(--text-dim);
  box-shadow: none;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.composer .icon-btn:hover { color: var(--text); background: var(--bg-4); }
.composer .send-btn {
  padding: 0 18px;
  min-width: 56px;
  display: grid;
  place-items: center;
  font-size: 16px;
}
.composer-stack .attach-preview {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  padding: 10px 14px;
  background: rgba(13, 16, 24, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  animation: msgIn var(--t-fast) var(--ease);
}
.composer-stack .attach-preview img {
  height: 72px;
  width: 72px;
  border-radius: var(--r-sm);
  object-fit: cover;
  flex: 0 0 auto;
}
.composer-stack .attach-preview .name {
  color: var(--text-dim);
  font-size: 12px;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none; /* filename hidden — the thumbnail speaks for itself */
}
.composer-stack .attach-preview button {
  background: transparent;
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  min-height: 0;
  box-shadow: none;
}
.composer-stack .attach-preview button:hover { color: var(--text); }
.composer input[type=file] { display: none; }

/* ---- Voice message recording ----
   The mic button sits inline with the other composer icon buttons.
   When recording, a small indicator (red dot + timer + cancel) slides
   in just above the composer — same pattern as the photo attach
   preview so the UI feels consistent. The textarea/icon-buttons
   become visually dimmed to make the recording state obvious. */
.composer .voice-btn.recording {
  color: #fff;
  background: #d9384a;
  border-color: #d9384a;
  animation: recPulse 1.2s var(--ease) infinite;
}
@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 56, 74, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(217, 56, 74, 0); }
}
.composer-stack .recording {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  padding: 10px 14px;
  background: rgba(13, 16, 24, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  animation: msgIn var(--t-fast) var(--ease);
}
.recording .rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #d9384a;
  box-shadow: 0 0 0 0 rgba(217, 56, 74, 0.6);
  animation: recPulse 1.2s var(--ease) infinite;
  flex: 0 0 auto;
}
.recording .rec-time {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--text);
  flex: 1 1 auto;
  font-size: 14px;
}
.recording button {
  background: transparent;
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  min-height: 0;
  box-shadow: none;
}
.recording button:hover { color: var(--text); background: var(--bg-4); }
.composer-stack.recording .send-btn {
  background: #2a7a4d;
  border-color: #2a7a4d;
  color: #fff;
}
.composer-stack.recording .send-btn:hover { background: #23814f; border-color: #23814f; }
/* While recording, disable the other composer buttons to keep the
   state machine obvious — there's exactly one thing to do (hit send
   or cancel). */
.composer-stack.recording .emoji-btn,
.composer-stack.recording .voice-btn,
.composer-stack.recording textarea,
.composer-stack.recording [for=photoInput] {
  opacity: 0.5;
  pointer-events: none;
}

/* ---- Inline audio player in chat bubbles ----
   A custom, low-chrome player: circular play/pause button on the left,
   duration / progress / status text on the right, hidden <audio>
   element actually does the playback. The bar is clickable to seek. */
.voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  min-width: 220px;
  max-width: 280px;
  user-select: none;
}
.voice-player .vp-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(108, 140, 255, 0.18);
  border: 1px solid rgba(108, 140, 255, 0.35);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex: 0 0 auto;
  box-shadow: none;
  min-height: 0;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.voice-player .vp-btn:hover { background: rgba(108, 140, 255, 0.3); }
.voice-player .vp-btn:active { transform: scale(0.95); }
.voice-player .vp-btn[data-state=playing] {
  background: rgba(108, 140, 255, 0.32);
}
.bubble.me .voice-player .vp-btn {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.32);
  color: #fff;
}
.bubble.me .voice-player .vp-btn:hover { background: rgba(255, 255, 255, 0.28); }
.voice-player .vp-track {
  flex: 1 1 auto;
  height: 22px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
}
.voice-player .vp-bar {
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  transform: translateY(-50%);
  overflow: hidden;
}
.voice-player .vp-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent-1, #6ea8ff);
  border-radius: 2px;
  transition: width 0.1s linear;
}
.bubble.me .voice-player .vp-bar { background: rgba(255, 255, 255, 0.24); }
.bubble.me .voice-player .vp-bar-fill { background: #fff; }
.voice-player .vp-time {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  flex: 0 0 auto;
  text-align: right;
  min-width: 36px;
}
.bubble.me .voice-player .vp-time { color: rgba(255, 255, 255, 0.7); }

/* Audio bubbles: keep the header (avatar/name/time) so the sender is
   always visible, but compact the rest. The body uses white-space:
   pre-wrap to preserve newlines in text messages — for audio messages
   the body's template-literal whitespace would otherwise inflate into
   empty lines (~21.75px each), blowing the bubble up to ~140px tall. */
.bubble:has(.voice-player) {
  padding: 4px 10px 5px;
  gap: 2px;
}
.bubble:has(.voice-player) .body {
  white-space: normal;
}

/* Subtle disabled state on the composer while a photo is uploading, so
   the user knows the round-trip is in progress and the preview isn't
   "stuck". */
.composer-stack.uploading .send-btn,
.composer-stack.uploading .icon-btn,
.composer-stack.uploading textarea { opacity: 0.55; pointer-events: none; }
.composer-stack.uploading .attach-preview {
  outline: 2px solid var(--accent, #6ea8ff);
  outline-offset: -2px;
}
.composer-stack.uploading .attach-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  animation: uploadShimmer 1.2s linear infinite;
  pointer-events: none;
}
@keyframes uploadShimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---- Admin ---- */
.admin {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 22px 16px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}
.admin h2 { margin: 0 0 14px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.admin .card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-1);
}
.admin .card-header {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px;
}
.admin .card-header .count {
  font-size: 12px; color: var(--text-faint);
}
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.admin tr:last-child td { border-bottom: 0; }
.admin tr:hover td { background: rgba(255,255,255,0.02); }

.admin .pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.admin .pill.admin { background: rgba(138, 108, 255, 0.15); color: #c4a5ff; border: 1px solid rgba(138, 108, 255, 0.3); }
.admin .pill.user  { background: rgba(108, 140, 255, 0.12); color: #93b4ff; border: 1px solid rgba(108, 140, 255, 0.25); }
.admin .pill.off   { background: rgba(255, 84, 112, 0.10); color: #ff8aa0; border: 1px solid rgba(255, 84, 112, 0.25); }
.admin .pill.on    { background: rgba(45, 212, 163, 0.10); color: #5ee6bb; border: 1px solid rgba(45, 212, 163, 0.25); }

.admin .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin .row-actions button { padding: 5px 10px; font-size: 12px; min-height: 30px; }

.admin .form-grid { display: grid; gap: 12px; }
.admin .form-grid .row { display: flex; gap: 10px; align-items: center; }
.admin .form-grid .row > * { flex: 1 1 auto; }
.admin .form-grid .row label { font-size: 12px; color: var(--text-dim); flex: 0 0 auto; width: 90px; font-weight: 500; }
.admin .form-grid .form-actions { display: flex; gap: 8px; margin-top: 4px; }
.admin .err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---- Language picker (modal) ---- */
.lang-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lang-picker .lang-option {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  min-height: 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.lang-picker .lang-option:hover { background: var(--bg-3); border-color: var(--accent-1); }
.lang-picker .lang-option.active { background: var(--accent-grad); border-color: transparent; color: #fff; }

/* ---- Emoji popover (above the emoji button) ---- */
.emoji-popover {
  position: fixed;
  z-index: 50;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 32px);
  gap: 2px;
  box-shadow: var(--shadow-2);
  animation: msgIn var(--t-fast) var(--ease);
  max-width: 90vw;
}
.emoji-popover .emoji-opt {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: transparent;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  padding: 0;
  min-height: 0;
  box-shadow: none;
  transition: background var(--t-fast) var(--ease);
}
.emoji-popover .emoji-opt:hover { background: var(--bg-3); }

/* ---- Settings (admin) ---- */
.admin .settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 4px;
}
.admin .settings-label {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}
.admin .settings-help {
  font-size: 12px;
  color: var(--text-dim);
  max-width: 540px;
  line-height: 1.4;
}
.admin .lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 3px;
  background: var(--bg-2);
  flex: 0 0 auto;
}
.admin .lang-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  min-height: 0;
  cursor: pointer;
  box-shadow: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.admin .lang-btn:hover { color: var(--text); }
.admin .lang-btn.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(108, 140, 255, 0.35);
}

/* ---- 403 ---- */
.error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
}
.error-page h1 { margin-bottom: 8px; }
.error-page p { color: var(--text-dim); margin: 4px 0; }
.error-page a { color: var(--accent-1); }

/* ---- Modal (used for admin edits + change password) ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fade var(--t-fast) var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 22px;
  box-shadow: var(--shadow-pop);
  animation: pop var(--t-med) var(--ease);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.modal .form-row { display: grid; gap: 6px; margin-bottom: 12px; }
.modal .form-row label { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.modal .form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal .err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 6px; }

/* ---- Toasts ---- */
.toast-stack {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-2);
  color: var(--text);
  animation: toastIn var(--t-med) var(--ease), toastOut 0.3s var(--ease) 2.5s forwards;
  pointer-events: auto;
  max-width: 90vw;
}
.toast.error { border-color: rgba(255,84,112,0.4); color: #ffb1c0; }
.toast.success { border-color: rgba(45,212,163,0.4); color: #a9f0d6; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(8px); } }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .msg { max-width: 82%; }
  .admin .form-grid .row { flex-direction: column; align-items: stretch; }
  .admin .form-grid .row label { width: auto; }
  .admin th, .admin td { padding: 8px 4px; }
  .admin .row-actions button { padding: 4px 8px; font-size: 11px; }
  header.bar h1 { font-size: 15px; }
  header.bar .me .me-greeting { display: none; }
}

/* ---- Utilities ---- */
.hidden { display: none !important; }
.spacer { flex: 1; }
