@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Saira+Condensed:ital,wght@1,700&display=swap');

:root {
  /* Surfaces - soft, warm */
  --bg: #ffffff;
  --sidebar: #f5f5f7;
  --hover: #ececef;
  --soft: #fafafa;
  --card: #ffffff;

  color-scheme: light;

  /* Borders */
  --border: #e5e5e7;
  --border-2: #d1d1d6;

  /* Text - softer than pure black */
  --text: #1c1c1e;
  --text-2: #3c3c43;
  --muted: #8e8e93;
  --muted-2: #c7c7cc;

  /* Brand accent - RSDLive racing red, matches SpeedGFX family */
  --accent: #0045FD;
  --accent-deep: #0036ca;
  --accent-soft: rgba(0, 69, 253, 0.10);
  --accent-soft-2: rgba(0, 69, 253, 0.18);

  /* Bubble colors */
  --bubble-mine: #0045FD;
  --bubble-mine-text: #ffffff;
  --bubble-other: #e9e9eb;
  --bubble-other-text: #1c1c1e;

  /* Status (no red — use system tones) */
  --success: #34c759;
  --warn: #ff9500;
  --neutral-dark: #3c3c43;

  /* Type */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-bubble: 18px;
}

/* Dark theme - applied via .dark on <html> (set by FOUC-prevention script in <head>) */
.dark {
  color-scheme: dark;

  /* Surfaces (inverted hierarchy: bg darkest, card most elevated) */
  --bg: #0e0f11;
  --soft: #14151a;
  --sidebar: #16171a;
  --hover: #25272d;
  --card: #1c1d22;

  /* Borders */
  --border: #2a2c33;
  --border-2: #3a3d44;

  /* Text */
  --text: #f0f0f3;
  --text-2: #d0d1d5;
  --muted: #8b8c91;
  --muted-2: #5e5f64;

  /* Bubble colors - own stays brand red, others use elevated dark surface */
  --bubble-mine: #0045FD;
  --bubble-mine-text: #ffffff;
  --bubble-other: #25272c;
  --bubble-other-text: #f0f0f3;
}

/* Dark-specific tweaks where simple var swap isn't enough */
.dark .toast { background: #2a2c33; color: var(--text); }
.dark .toast.error { background: #dc2626; }

/* Theme toggle button: show moon in light, sun in dark */
#themeBtn .theme-sun { display: none; }
#themeBtn .theme-moon { display: inline-block; }
.dark #themeBtn .theme-moon { display: none; }
.dark #themeBtn .theme-sun { display: inline-block; }

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-feature-settings: 'cv11';
  height: 100%;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; font-size: inherit; }
input, textarea { font-family: inherit; color: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon {
  width: 16px; height: 16px;
  display: inline-block;
  vertical-align: middle;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 20px; height: 20px; }

/* ─────────────────────────────────────────────────────────
   AUTH SCREEN
   ───────────────────────────────────────────────────────── */

.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--sidebar);
  z-index: 90;
  padding: 20px;
}

.auth-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 16px 40px rgba(0,0,0,0.06);
}

.auth-logo {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 4138 / 1744;
  margin: 4px auto 26px;
  background-image: url('/logo.svg');
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  user-select: none;
}
.dark .auth-logo { background-image: url('/logo-dark.svg'); }

.auth-tabs { display: flex; margin-bottom: 22px; background: var(--sidebar); padding: 3px; border-radius: var(--r-md); }
.auth-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: 7px;
  transition: background 0.12s, color 0.12s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  background: var(--sidebar);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 11px 14px;
  font-size: 15px;
  outline: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  color: var(--text);
}
.field input::placeholder { color: var(--muted); }
.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.4;
}
.field input:focus { background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.auth-actions { margin-top: 22px; }
.auth-actions button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--r-md);
  transition: background 0.12s, transform 0.04s;
}
.auth-actions button:hover { background: var(--accent-deep); }
.auth-actions button:active { transform: scale(0.99); }
.auth-actions button:disabled { opacity: 0.5; cursor: not-allowed; background: var(--muted-2); }

.auth-error { color: var(--warn); font-size: 13px; margin-top: 12px; min-height: 16px; text-align: center; font-weight: 500; }
.auth-foot { text-align: center; margin-top: 22px; color: var(--muted); font-size: 12.5px; }

/* ─────────────────────────────────────────────────────────
   APP SHELL
   ───────────────────────────────────────────────────────── */

.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; position: relative; }
.app.hidden { display: none; }

/* ─────────────────────────────────────────────────────────
   SIDEBAR
   ───────────────────────────────────────────────────────── */

.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  padding: 16px 18px 14px;
  display: flex;
  align-items: center;
}
.brand-logo {
  width: 100%;
  max-width: 150px;
  aspect-ratio: 4138 / 1744;
  background-image: url('/logo.svg');
  background-repeat: no-repeat;
  background-size: contain;
  background-position: left center;
  user-select: none;
}
.dark .brand-logo { background-image: url('/logo-dark.svg'); }

.user-card {
  padding: 8px 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px; height: 32px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  text-transform: uppercase;
  border-radius: 50%;
}
.user-card .user-name {
  flex: 1; font-weight: 500; font-size: 14px;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  border-radius: 50%;
  transition: color 0.12s, background 0.12s;
}
.icon-btn:hover { color: var(--text); background: rgba(0,0,0,0.06); }

.section { padding: 4px 0; flex: 1; overflow-y: auto; min-height: 0; }
.section::-webkit-scrollbar { width: 6px; }
.section::-webkit-scrollbar-track { background: transparent; }
.section::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 3px; }

.section-header {
  padding: 12px 18px 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: -0.005em;
}
.section-header .icon-btn { width: 22px; height: 22px; }
.section-header .icon-btn .icon { width: 12px; height: 12px; }

.channel-item {
  padding: 8px 12px;
  margin: 1px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  color: var(--text-2);
  border-radius: var(--r-md);
  transition: background 0.1s, color 0.1s;
}
.channel-item:hover { background: rgba(0,0,0,0.04); color: var(--text); }
.channel-item.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
.channel-item .hash { color: var(--muted-2); font-weight: 400; }
.channel-item.active .hash { color: rgba(255,255,255,0.8); }
.channel-item .lock { color: var(--muted); margin-left: auto; width: 13px; height: 13px; }
.channel-item.active .lock { color: rgba(255,255,255,0.8); }
.channel-item .join-pill {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--muted);
  border-radius: 10px;
  font-weight: 500;
  background: rgba(0,0,0,0.06);
}
.channel-item:hover .join-pill { color: var(--text); }

.sidebar-footer { padding: 10px; }
.sidebar-footer button {
  width: 100%;
  padding: 10px;
  background: rgba(0,0,0,0.04);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  transition: background 0.12s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.sidebar-footer button:hover { background: rgba(0,0,0,0.08); }
.sidebar-footer button .icon { width: 14px; height: 14px; color: var(--muted); }

.connection-status {
  padding: 8px 16px 12px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex; align-items: center; gap: 7px;
}
.connection-status .conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
}
.connection-status.connected .conn-dot { background: var(--success); }
.connection-status.connecting .conn-dot { background: var(--warn); }

/* ─────────────────────────────────────────────────────────
   MAIN
   ───────────────────────────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
  border-left: 1px solid var(--border);
}

.channel-header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.channel-title { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.channel-title .hash { color: var(--muted-2); font-weight: 500; font-size: 18px; }
.channel-title .name {
  font-size: 17px; font-weight: 600;
  color: var(--text);
  letter-spacing: -0.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.channel-title .desc {
  color: var(--muted); font-size: 13.5px;
  padding-left: 12px; margin-left: 6px;
  border-left: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 400;
}

.channel-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}
.presence-pill::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success);
}

.channel-action-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  color: var(--muted);
  border-radius: 50%;
  transition: background 0.12s, color 0.12s;
}
.channel-action-btn:hover { background: var(--hover); color: var(--text); }
.channel-action-btn .icon { width: 18px; height: 18px; }
.channel-action-btn .lbl { display: none; }

/* ─────────────────────────────────────────────────────────
   MESSAGES (bubbles)
   ───────────────────────────────────────────────────────── */

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 10px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 5px; }
.messages-area::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.16); }

.load-older {
  margin: 4px auto 12px;
  padding: 7px 16px;
  background: var(--sidebar);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  border-radius: 20px;
  transition: background 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.load-older:hover { background: var(--hover); }
.load-older.hidden { display: none; }
.load-older .icon { width: 13px; height: 13px; color: var(--muted); }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 60px 20px;
}

/* Message wrapper */
.message {
  position: relative;
  padding: 0;
  margin: 8px 0 0;
}
.message.grouped { margin-top: 2px; }

.msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
}
.message.mine .msg-row { flex-direction: row-reverse; }

/* Avatar - round, only on first of group for others, never for mine */
.msg-avatar {
  width: 28px; height: 28px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  flex-shrink: 0;
  text-transform: uppercase;
  border-radius: 50%;
  align-self: flex-end;
  margin-bottom: 2px;
}
.message.mine .msg-avatar { display: none; }
.message.grouped .msg-avatar { visibility: hidden; }

.msg-body {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  min-width: 0;
}
.message.mine .msg-body { align-items: flex-end; }

/* Meta above bubble (others only — own messages don't show name) */
.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 0 12px;
  margin-bottom: 3px;
  font-size: 12px;
}
.message.mine .msg-meta { display: none; }
.message.grouped .msg-meta { display: none; }

.msg-user {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
  letter-spacing: -0.005em;
}
.msg-time {
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.msg-badge {
  background: var(--hover);
  color: var(--muted);
  padding: 0 6px;
  font-size: 10px;
  border-radius: var(--r-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.msg-edited { color: var(--muted-2); font-size: 11px; }

/* Bubble */
.msg-bubble {
  background: var(--bubble-other);
  color: var(--bubble-other-text);
  padding: 8px 13px;
  border-radius: var(--r-bubble);
  display: inline-block;
  max-width: 100%;
  box-sizing: border-box;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.message.mine .msg-bubble {
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
}

.msg-text {
  line-height: 1.4;
  font-size: 15px;
  white-space: pre-wrap;
  color: inherit;
}
.msg-text a { color: inherit; text-decoration: underline; opacity: 0.95; }
.message:not(.mine) .msg-text a { color: var(--accent); text-decoration: none; }
.message:not(.mine) .msg-text a:hover { text-decoration: underline; }

/* Hover-revealed inline time for grouped */
.message.grouped .msg-time-inline {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: -2px;
  font-size: 10.5px;
  color: var(--muted-2);
  opacity: 0;
  transition: opacity 0.12s;
  width: 46px;
  text-align: right;
  pointer-events: none;
}
.message.mine.grouped .msg-time-inline { left: auto; right: -2px; text-align: left; }
.message.grouped:hover .msg-time-inline { opacity: 1; }

/* Attachments inside bubble */
.msg-attachment {
  margin-top: 6px;
  max-width: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
}
.msg-bubble > .msg-attachment:first-child,
.msg-bubble > .msg-attachment:only-child {
  margin-top: 0;
  margin-left: -7px;
  margin-right: -7px;
  margin-bottom: -2px;
  border-radius: calc(var(--r-bubble) - 6px);
}
.msg-bubble:has(> .msg-attachment:only-child) {
  padding: 6px;
  background: transparent;
}
.message.mine .msg-bubble:has(> .msg-attachment:only-child) { background: transparent; }

.msg-attachment img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  cursor: zoom-in;
}
.msg-attachment .file {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.04);
}
.message.mine .msg-bubble .msg-attachment .file { background: rgba(255,255,255,0.15); }
.msg-attachment .file-icon {
  width: 32px; height: 32px;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.message.mine .msg-bubble .msg-attachment .file-icon { background: rgba(255,255,255,0.2); color: #fff; }
.msg-attachment .file-icon .icon { width: 16px; height: 16px; }
.msg-attachment .file-info { flex: 1; min-width: 0; }
.msg-attachment .file-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.message.mine .msg-bubble .file-name { color: #fff; }
.msg-attachment .file-size { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.message.mine .msg-bubble .file-size { color: rgba(255,255,255,0.7); }
.msg-attachment .file-dl {
  padding: 5px 11px;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 12px;
  background: rgba(0,0,0,0.05);
  transition: background 0.12s;
}
.message.mine .msg-bubble .file-dl { color: #fff; background: rgba(255,255,255,0.2); }
.msg-attachment .file-dl:hover { background: rgba(0,0,0,0.10); }
.message.mine .msg-bubble .file-dl:hover { background: rgba(255,255,255,0.3); }

/* Reactions below bubble */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}
.message.mine .msg-reactions { justify-content: flex-end; }

.reaction-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.4;
}
.reaction-chip:hover { background: var(--sidebar); }
.reaction-chip.mine {
  background: var(--accent-soft);
  border-color: var(--accent-soft-2);
}
.reaction-chip .count {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.reaction-chip.mine .count { color: var(--accent); }

/* Message actions popover */
.msg-actions {
  position: absolute;
  top: -14px;
  display: none;
  gap: 1px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  z-index: 5;
}
.message:not(.mine) .msg-actions { left: 44px; }
.message.mine .msg-actions { right: 8px; }
.message:hover .msg-actions { display: flex; }

.msg-action-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  border-radius: 50%;
  transition: color 0.12s, background 0.12s;
}
.msg-action-btn:hover { color: var(--text); background: var(--hover); }
.msg-action-btn.danger:hover { color: var(--text); background: var(--hover); }
.msg-action-btn .icon { width: 15px; height: 15px; }

.reaction-picker {
  position: absolute;
  top: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 5px;
  display: flex;
  gap: 1px;
  z-index: 20;
  border-radius: 22px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.10);
}
.message:not(.mine) .reaction-picker { left: 0; }
.message.mine .reaction-picker { right: 0; }
.reaction-picker button {
  padding: 4px 7px;
  font-size: 19px;
  border-radius: 50%;
  transition: background 0.1s, transform 0.1s;
  line-height: 1;
}
.reaction-picker button:hover { background: var(--hover); transform: scale(1.18); }

/* ─────────────────────────────────────────────────────────
   COMPOSER
   ───────────────────────────────────────────────────────── */

.composer {
  padding: 8px 14px 14px;
  background: var(--bg);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}
.composer.disabled { opacity: 0.5; pointer-events: none; }

.attachment-staged {
  display: none;
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: var(--r-md);
  align-items: center;
  gap: 11px;
  background: var(--sidebar);
}
.attachment-staged.show { display: flex; }
.attachment-staged img { max-height: 56px; max-width: 96px; border-radius: var(--r-sm); }
.attachment-staged .file-icon-staged {
  width: 40px; height: 40px;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  border-radius: var(--r-md);
}
.attachment-staged .info { flex: 1; min-width: 0; }
.attachment-staged .info .name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-staged .info .size { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.attachment-staged .cancel {
  padding: 6px 12px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  transition: background 0.12s;
}
.attachment-staged .cancel:hover { background: var(--hover); }

.composer-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.composer-row .input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--sidebar);
  border-radius: 22px;
  padding-left: 4px;
}
.composer-row input[type=text] {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 16px 10px 14px;
  font-size: 15px;
  outline: none;
}
.composer-row input[type=text]::placeholder { color: var(--muted); }

.attach-btn {
  width: 36px; height: 36px;
  background: transparent;
  color: var(--muted);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}
.attach-btn:hover { color: var(--accent); background: rgba(0,0,0,0.04); }
.attach-btn .icon { width: 18px; height: 18px; }

.send-btn {
  width: 36px; height: 36px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  transition: background 0.12s, transform 0.04s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn span { display: none; } /* hide "Send" text — icon only */
.send-btn:hover { background: var(--accent-deep); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; background: var(--muted-2); }
.send-btn .icon { width: 16px; height: 16px; transform: translateX(-1px); }

/* ─────────────────────────────────────────────────────────
   MODAL
   ───────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.12s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.show { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 26px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 24px 56px rgba(0,0,0,0.12);
  animation: modalIn 0.16s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal h2 {
  font-weight: 600;
  font-size: 19px;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.015em;
}
.modal-subtitle { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

.modal label {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 6px;
  margin-top: 14px;
}

.modal input[type=text], .modal textarea, .modal select {
  width: 100%;
  background: var(--sidebar);
  border: 1px solid transparent;
  padding: 10px 13px;
  font-size: 14.5px;
  outline: none;
  border-radius: var(--r-md);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  color: var(--text);
}
.modal input[type=text]::placeholder, .modal textarea::placeholder { color: var(--muted); }
.modal input[type=text]:focus, .modal textarea:focus, .modal select:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modal textarea { resize: vertical; min-height: 60px; }

.modal-radio-group { display: flex; gap: 6px; }
.modal-radio {
  flex: 1;
  padding: 11px;
  background: var(--sidebar);
  border-radius: var(--r-md);
  text-align: center;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.12s;
}
.modal-radio:hover { background: var(--hover); }
.modal-radio.active { background: var(--accent); color: #fff; }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
}
.btn-primary, .btn-secondary, .btn-danger {
  flex: 1;
  padding: 11px;
  font-size: 14.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  transition: background 0.12s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-deep); }
.btn-secondary { background: var(--sidebar); color: var(--text); }
.btn-secondary:hover { background: var(--hover); }
.btn-danger { background: var(--neutral-dark); color: #fff; }
.btn-danger:hover { background: #000; }
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

/* members */
.member-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; margin-top: 10px; }
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--r-md);
  transition: background 0.1s;
}
.member-row:hover { background: var(--sidebar); }
.member-row .name { flex: 1; font-size: 14px; font-weight: 500; }
.member-row .role {
  font-size: 10.5px;
  padding: 1px 7px;
  font-weight: 600;
  border-radius: var(--r-sm);
  background: var(--hover);
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.member-row .role.owner, .member-row .role.admin {
  background: var(--accent-soft);
  color: var(--accent);
}
.member-row .online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.member-row .online-dot.online { background: var(--success); }
.member-row .mgr-btn {
  padding: 5px 11px;
  background: var(--sidebar);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  border-radius: 12px;
  transition: background 0.12s;
}
.member-row .mgr-btn:hover { background: var(--hover); }
.member-row .mgr-btn.danger:hover { background: var(--hover); color: var(--text); }

/* invites */
.invite-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.invite-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px;
  background: var(--sidebar);
  border-radius: var(--r-md);
}
.invite-code {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.1em;
  font-size: 15px;
  color: var(--text);
}
.invite-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.invite-actions { display: flex; gap: 4px; margin-left: auto; }

.invite-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  background: var(--sidebar);
  border-radius: var(--r-md);
  margin-top: 8px;
}

/* profile color grid */
.color-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 4px; }
.color-swatch {
  aspect-ratio: 1;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: 50%;
  transition: transform 0.1s, border-color 0.12s;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected { border-color: var(--bg); box-shadow: 0 0 0 2px var(--accent); }

.modal-readonly {
  font-size: 14px;
  padding: 10px 13px;
  background: var(--sidebar);
  color: var(--muted);
  border-radius: var(--r-md);
}
.modal-info {
  font-size: 14px;
  padding: 12px 14px;
  background: var(--sidebar);
  color: var(--text);
  line-height: 1.5;
  border-radius: var(--r-md);
}
.modal-section-header {
  margin-top: 22px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ─────────────────────────────────────────────────────────
   TOAST + LIGHTBOX
   ───────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  z-index: 300;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 22px;
  animation: slideUp 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.toast.error { background: var(--text); }
.toast.success { background: var(--success); }
@keyframes slideUp { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 40px;
  cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--r-md); }

/* ─────────────────────────────────────────────────────────
   MOBILE
   ───────────────────────────────────────────────────────── */

.mobile-toggle {
  display: none;
  width: 34px; height: 34px;
  background: var(--sidebar);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
}
.mobile-toggle:hover { background: var(--hover); }

.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 70;
  display: none;
}
.scrim.show { display: block; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 8px 0 30px rgba(0,0,0,0.18);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-toggle { display: flex; }
  .channel-title .desc { display: none; }
  .messages-area { padding: 12px 14px; }
  .msg-body { max-width: 80%; }
}
