/* ============================================================
   Relay — dark chat theme
   ============================================================ */

:root {
  --bg-deepest: #101216;
  --bg-deep: #16181d;
  --bg-base: #1c1f26;
  --bg-raised: #232733;
  --bg-hover: #2a2f3d;
  --bg-active: #323848;

  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);

  --text: #e6e8ee;
  --text-dim: #9aa0ae;
  --text-faint: #6b7180;

  --accent: #5865f2;
  --accent-hover: #6a76ff;
  --accent-soft: rgba(88, 101, 242, 0.16);
  --accent-glow: rgba(88, 101, 242, 0.45);

  --danger: #ed4245;
  --danger-soft: rgba(237, 66, 69, 0.14);
  --success: #3ba55d;

  --radius: 10px;
  --radius-lg: 14px;

  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-deepest);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img { max-width: 100%; }

.hidden { display: none !important; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.09);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

/* ============ Shared bits ============ */

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px; color: #fff;
  flex-shrink: 0;
  user-select: none;
  text-transform: uppercase;
  box-shadow: inset 0 -2px 6px rgba(0,0,0,0.25);
}
.avatar.small { width: 32px; height: 32px; font-size: 14px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.small { width: 24px; height: 24px; }
.icon-btn.small svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 11px 20px;
  border-radius: var(--radius);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 10px rgba(88, 101, 242, 0.25);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 18px var(--accent-glow); }
.btn-primary:active { transform: translateY(1px) scale(0.99); }
.btn-primary:disabled { opacity: 0.55; cursor: default; box-shadow: none; }

.btn-ghost {
  color: var(--text-dim);
  font-weight: 600;
  padding: 11px 16px;
  border-radius: var(--radius);
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.field .optional { text-transform: none; font-weight: 500; color: var(--text-faint); }
.field input {
  width: 100%;
  background: var(--bg-deepest);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============ Auth screen ============ */

.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(88, 101, 242, 0.16), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(88, 101, 242, 0.10), transparent 55%),
    var(--bg-deepest);
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 34px 30px;
  box-shadow: var(--shadow-pop);
  animation: card-in 0.4s cubic-bezier(0.21, 1.02, 0.55, 1);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-logo-mark {
  width: 58px; height: 58px;
  margin: 0 auto 14px;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 8px 26px var(--accent-glow);
}
.auth-logo-mark svg { width: 30px; height: 30px; }
.auth-logo h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.auth-tagline { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

.auth-tabs {
  display: flex;
  background: var(--bg-deepest);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  padding: 9px 0;
  border-radius: 7px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-dim);
  transition: background 0.18s ease, color 0.18s ease;
}
.auth-tab.active { background: var(--bg-raised); color: var(--text); box-shadow: var(--shadow-soft); }

.auth-error {
  background: var(--danger-soft);
  border: 1px solid rgba(237, 66, 69, 0.35);
  color: #ff8a8c;
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 13.5px;
  margin-bottom: 16px;
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

#auth-form .btn-primary { width: 100%; margin-top: 4px; }

/* ============ App layout ============ */

.app {
  display: grid;
  grid-template-columns: 248px 1fr auto;
  height: 100vh;
  height: 100dvh;
}

/* ---- Sidebar ---- */

.sidebar {
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 18px; letter-spacing: -0.01em;
}
.brand svg {
  width: 26px; height: 26px;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.channels-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 6px 16px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 10px;
}

.channel-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 1px;
  text-align: left;
  transition: background 0.13s ease, color 0.13s ease;
  position: relative;
}
.channel-item .hash { color: var(--text-faint); font-weight: 600; flex-shrink: 0; }
.channel-item .ch-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.channel-item:hover { background: var(--bg-hover); color: var(--text); }
.channel-item.active {
  background: var(--accent-soft);
  color: var(--text);
}
.channel-item.active .hash { color: var(--accent-hover); }
.channel-item.active::before {
  content: "";
  position: absolute;
  left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 65%;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}
.channel-item.unread { color: var(--text); font-weight: 600; }

.unread-badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  animation: pop-in 0.25s cubic-bezier(0.3, 1.4, 0.6, 1);
}
@keyframes pop-in {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.user-panel {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg-deepest);
  border-top: 1px solid var(--border);
}
.user-panel-info { flex: 1; min-width: 0; }
.user-panel-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-panel-status {
  font-size: 11.5px; color: var(--text-faint);
  display: flex; align-items: center; gap: 5px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px rgba(59, 165, 93, 0.7);
}

/* ---- Main pane ---- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
}

.channel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  height: 54px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  position: relative;
  z-index: 5;
  background: var(--bg-base);
}
.channel-hash { color: var(--text-faint); font-size: 22px; font-weight: 600; }
.channel-title { font-size: 16.5px; font-weight: 700; white-space: nowrap; }
.channel-topic {
  color: var(--text-dim);
  font-size: 13.5px;
  border-left: 1px solid var(--border-strong);
  padding-left: 12px;
  margin-left: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.channel-topic:empty { display: none; }
.header-spacer { flex: 1; }
.mobile-only { display: none; }

/* ---- Messages ---- */

.messages-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

.messages {
  position: absolute; inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 0 10px;
  outline: none;
}

.load-older {
  text-align: center;
  padding: 8px;
  color: var(--text-faint);
  font-size: 13px;
}

.day-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 16px 6px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 700;
}
.day-divider::before, .day-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-strong);
}

.msg {
  position: relative;
  padding: 2px 48px 2px 72px;
  animation: msg-in 0.22s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg:hover { background: rgba(255, 255, 255, 0.025); }

.msg.group-start { margin-top: 14px; padding-top: 4px; }

.msg .msg-avatar {
  position: absolute;
  left: 16px; top: 5px;
}

.msg-header {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 1px;
}
.msg-author { font-weight: 700; font-size: 15px; }
.msg-time { font-size: 11.5px; color: var(--text-faint); }

.msg .hover-time {
  position: absolute;
  left: 8px; top: 4px;
  width: 58px;
  text-align: right;
  font-size: 10.5px;
  color: var(--text-faint);
  opacity: 0;
  user-select: none;
}
.msg:hover .hover-time { opacity: 1; }

.msg-content {
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg-content a { color: #6a9df8; text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.edited-tag { font-size: 10.5px; color: var(--text-faint); margin-left: 5px; user-select: none; }

/* editing state */
.msg-edit-box { margin: 4px 0; }
.msg-edit-box textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  resize: none;
  outline: none;
  line-height: 1.4;
}
.msg-edit-box textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.msg-edit-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.msg-edit-hint button { color: #6a9df8; font-size: 11.5px; }
.msg-edit-hint button:hover { text-decoration: underline; }

/* attachments */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.att-image {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 400px;
  max-height: 300px;
  cursor: zoom-in;
  background: var(--bg-deepest);
  border: 1px solid var(--border);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.att-image img { display: block; max-width: 100%; max-height: 300px; object-fit: contain; }
.att-image:hover { filter: brightness(1.08); }

.att-gif { max-width: 320px; }
.att-gif img { border-radius: var(--radius); display: block; max-width: 100%; }

.att-file {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  max-width: 400px;
  min-width: 240px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.att-file:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.att-file-icon {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.att-file-icon svg { width: 20px; height: 20px; }
.att-file-meta { min-width: 0; }
.att-file-name {
  font-weight: 600; font-size: 14px; color: #8bb0f9;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-file-size { font-size: 12px; color: var(--text-faint); }

/* reactions */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; align-items: center; }
.reaction-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 13.5px;
  transition: background 0.13s ease, border-color 0.13s ease, transform 0.1s ease;
}
.reaction-pill .count { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.reaction-pill:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.reaction-pill:active { transform: scale(0.92); }
.reaction-pill.mine {
  background: var(--accent-soft);
  border-color: rgba(88, 101, 242, 0.55);
}
.reaction-pill.mine .count { color: var(--accent-hover); }

.reaction-add {
  width: 26px; height: 24px;
  border-radius: 999px;
  border: 1px dashed var(--border-strong);
  color: var(--text-faint);
  font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.13s ease, background 0.13s ease, color 0.13s ease;
}
.msg:hover .reaction-add, .msg-reactions:hover .reaction-add { opacity: 1; }
.reaction-add:hover { background: var(--bg-hover); color: var(--text); }

/* hover action bar */
.msg-actions {
  position: absolute;
  top: -14px; right: 16px;
  display: none;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  z-index: 3;
}
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
  width: 34px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  transition: background 0.12s ease, color 0.12s ease;
}
.msg-actions button svg { width: 16px; height: 16px; }
.msg-actions button:hover { background: var(--bg-hover); color: var(--text); }
.msg-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* reaction picker popup */
.reaction-picker {
  position: fixed;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  display: flex;
  gap: 2px;
  z-index: 300;
  animation: pop-in 0.15s cubic-bezier(0.3, 1.4, 0.6, 1);
}
.reaction-picker button {
  width: 36px; height: 36px;
  font-size: 20px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s ease, transform 0.12s ease;
}
.reaction-picker button:hover { background: var(--bg-hover); transform: scale(1.18); }

/* jump to latest */
.jump-latest {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 6px 20px var(--accent-glow);
  transition: background 0.15s ease, transform 0.15s ease;
  animation: pop-in 0.2s cubic-bezier(0.3, 1.4, 0.6, 1);
  z-index: 10;
}
.jump-latest svg { width: 14px; height: 14px; }
.jump-latest:hover { background: var(--accent-hover); transform: translateX(-50%) translateY(-2px); }

/* empty channel state */
.channel-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-faint);
}
.channel-empty .big-hash {
  width: 66px; height: 66px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--bg-raised);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 700; color: var(--text-dim);
}
.channel-empty h3 { color: var(--text); font-size: 20px; margin-bottom: 4px; }

/* ---- Composer ---- */

.composer-area {
  padding: 0 16px 18px;
  position: relative;
  flex-shrink: 0;
}

.typing-indicator {
  height: 22px;
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 0 6px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.typing-indicator.visible { opacity: 1; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.pending-attachments {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.pending-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  max-width: 230px;
  animation: pop-in 0.2s cubic-bezier(0.3, 1.4, 0.6, 1);
}
.pending-chip img.thumb {
  width: 34px; height: 34px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.pending-chip .file-glyph {
  width: 34px; height: 34px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pending-chip .file-glyph svg { width: 17px; height: 17px; }
.pending-chip .chip-meta { min-width: 0; }
.pending-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pending-chip .chip-size { font-size: 11px; color: var(--text-faint); }
.pending-chip .chip-remove {
  color: var(--text-faint);
  width: 20px; height: 20px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  transition: background 0.12s ease, color 0.12s ease;
}
.pending-chip .chip-remove:hover { background: var(--danger-soft); color: var(--danger); }
.pending-chip.uploading { opacity: 0.6; }

.composer {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 7px 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within { border-color: rgba(88, 101, 242, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }
.pending-attachments:not(.hidden) + .popover + .popover + .composer,
.pending-attachments:not(.hidden) ~ .composer { border-top-left-radius: 0; border-top-right-radius: 0; }

.composer textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  padding: 8px 6px;
  max-height: 200px;
  line-height: 1.4;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-faint); }

.composer-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.13s ease, color 0.13s ease, transform 0.1s ease;
}
.composer-btn svg { width: 20px; height: 20px; }
.composer-btn:hover { background: var(--bg-hover); color: var(--text); }
.composer-btn:active { transform: scale(0.9); }
.composer-btn.text { font-size: 12px; font-weight: 800; letter-spacing: 0.02em; width: auto; padding: 0 9px; }
.composer-btn.send { color: var(--accent-hover); }
.composer-btn.send:hover { background: var(--accent-soft); }
.composer-btn.send:disabled { color: var(--text-faint); background: none; cursor: default; }

/* ---- Popovers (gif / emoji) ---- */

.popover {
  position: absolute;
  bottom: calc(100% - 16px);
  right: 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  z-index: 50;
  animation: popover-in 0.18s cubic-bezier(0.2, 1.1, 0.5, 1);
  overflow: hidden;
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.gif-panel { width: 420px; max-width: calc(100vw - 32px); }
.popover-header { padding: 12px; border-bottom: 1px solid var(--border); }
.popover-header input {
  width: 100%;
  background: var(--bg-deepest);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s ease;
}
.popover-header input:focus { border-color: var(--accent); }

.gif-grid {
  height: 320px;
  overflow-y: auto;
  padding: 10px;
  column-count: 2;
  column-gap: 8px;
}
.gif-cell {
  width: 100%;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  break-inside: avoid;
  background: var(--bg-deepest);
  border: 2px solid transparent;
  padding: 0;
  display: block;
  transition: border-color 0.13s ease, transform 0.13s ease;
}
.gif-cell img { display: block; width: 100%; }
.gif-cell:hover { border-color: var(--accent); transform: scale(1.015); }
.gif-hint {
  column-span: all;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 36px 20px;
  line-height: 1.6;
}

.emoji-panel {
  width: 316px;
  max-width: calc(100vw - 32px);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
}
.emoji-panel button {
  font-size: 21px;
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s ease, transform 0.1s ease;
}
.emoji-panel button:hover { background: var(--bg-hover); transform: scale(1.2); }

/* ---- Members pane ---- */

.members-pane {
  width: 224px;
  background: var(--bg-deep);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 10px;
  transition: width 0.2s ease, padding 0.2s ease;
}
.members-pane.collapsed { width: 0; padding: 16px 0; overflow: hidden; border-left: none; }

.members-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 8px 10px;
  white-space: nowrap;
}

.member-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.13s ease;
  animation: msg-in 0.2s ease;
}
.member-item:hover { background: var(--bg-hover); }
.member-item .avatar { position: relative; }
.member-item .avatar::after {
  content: "";
  position: absolute;
  right: -1px; bottom: -1px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--success);
  border: 2.5px solid var(--bg-deep);
}
.member-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.member-item .you-tag {
  font-size: 10px; font-weight: 700;
  color: var(--accent-hover);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ---- Modal ---- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow-pop);
  animation: card-in 0.25s cubic-bezier(0.21, 1.02, 0.55, 1);
}
.modal h3 { font-size: 20px; font-weight: 800; }
.modal-sub { color: var(--text-dim); font-size: 13.5px; margin: 4px 0 20px; }

.input-hash-wrap {
  display: flex; align-items: center;
  background: var(--bg-deepest);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-hash-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-hash-wrap span { padding: 0 4px 0 13px; color: var(--text-faint); font-weight: 700; font-size: 16px; }
.input-hash-wrap input { flex: 1; background: none; border: none; outline: none; padding: 11px 13px 11px 4px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---- Lightbox ---- */

.lightbox {
  position: fixed; inset: 0;
  background: rgba(4, 5, 8, 0.88);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: zoom-out;
  animation: fade-in 0.15s ease;
  padding: 30px;
}
.lightbox img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  cursor: default;
}
.lightbox a {
  color: var(--text-dim);
  font-size: 13.5px;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  transition: color 0.15s ease, background 0.15s ease;
}
.lightbox a:hover { color: var(--text); background: var(--bg-hover); }

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  z-index: 500;
  animation: toast-in 0.25s cubic-bezier(0.2, 1.2, 0.5, 1);
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.error { border-color: rgba(237, 66, 69, 0.5); color: #ff9a9c; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* connection banner */
.conn-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: linear-gradient(90deg, #b7791f, #d69e2e);
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  padding: 6px;
  z-index: 600;
  animation: fade-in 0.2s ease;
}

/* ============ Responsive ============ */

@media (max-width: 1000px) {
  .members-pane {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    z-index: 120;
    box-shadow: var(--shadow-pop);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    width: 240px;
  }
  .members-pane.open { transform: translateX(0); }
  .members-pane.collapsed { width: 240px; padding: 16px 10px; border-left: 1px solid var(--border); }
  .app { grid-template-columns: 248px 1fr; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 270px;
    z-index: 130;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .channel-topic { display: none; }
  .msg { padding-right: 14px; }
  .att-image, .att-file { max-width: 100%; }
  .gif-panel { right: 8px; left: 8px; width: auto; }
  .composer-area { padding: 0 10px 12px; }
  .messages { padding-top: 10px; }
}

.mobile-overlay {
  position: fixed; inset: 0;
  background: rgba(4, 5, 8, 0.55);
  z-index: 110;
  animation: fade-in 0.2s ease;
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
