/* ============================================================
   Theme tokens (light default; dark via [data-theme="dark"] set
   by common.js before first paint)
   ============================================================ */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --surface-hover: #e9eaf0;
  --border: #e3e5ec;
  --text: #14161c;
  --text-muted: #6b7080;
  --text-faint: #9498a8;
  --accent: #6366f1;
  --accent-hover: #5457e5;
  --accent-contrast: #ffffff;
  --danger: #ef4444;
  --success: #22c55e;
  --overlay: rgba(15, 16, 22, 0.55);
  --shadow-sm: 0 1px 2px rgba(20, 22, 28, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 22, 28, 0.12);

  --xl-grid: #c7ccd1;
  --xl-header-bg: #f3f2f1;
  --xl-header-text: #21252b;
  --xl-green: #217346;
  --xl-green-dark: #0f5c30;
  --xl-cell-bg: #ffffff;
  --xl-row-sender: #ddebf7;
  --xl-row-receiver: #e2efda;
  --xl-selection: #107c41;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1d2129;
  --surface-hover: #262b35;
  --border: #2a2f3a;
  --text: #eef0f5;
  --text-muted: #9498a8;
  --text-faint: #6b7080;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-contrast: #0f1115;
  --danger: #f87171;
  --success: #4ade80;
  --overlay: rgba(0, 0, 0, 0.65);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);

  --xl-grid: #3a3f44;
  --xl-header-bg: #23272b;
  --xl-header-text: #d7dadd;
  --xl-green: #2e8b57;
  --xl-green-dark: #14532d;
  --xl-cell-bg: var(--surface);
  --xl-row-sender: rgba(56, 132, 197, 0.22);
  --xl-row-receiver: rgba(46, 139, 87, 0.2);
  --xl-selection: #4ade80;
}

/* ============================================================
   Reset & base
   ============================================================ */
* {
  box-sizing: border-box;
  min-width: 0;
}
/* Several components below set `display: flex` at the same specificity as
   the browser's built-in `[hidden] { display: none }` rule, which lets the
   author rule win and silently defeats `hidden` (e.g. the lightbox was
   rendering as a full-viewport opaque layer on every page load). This
   always wins regardless of what any individual component declares. */
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button,
input,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: none;
  border: none;
}
a {
  color: inherit;
  text-decoration: none;
}
img,
video {
  max-width: 100%;
  display: block;
}
::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.scrollbar-thin::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.fade-in-up {
  animation: fade-in-up 0.18s ease-out;
}

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

@keyframes typing-dot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.spinner-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================================
   Utilities
   ============================================================ */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.min-w-0 {
  min-width: 0;
}
.muted {
  color: var(--text-muted);
}
.small {
  font-size: 0.75rem;
}

/* ============================================================
   App shell layout
   ============================================================ */
.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

.shell-sidebar {
  display: none;
  width: 16rem;
  flex-shrink: 0;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.shell-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1.25rem;
}
.shell-brand span {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-other {
  margin: 0 0.75rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border-radius: 0.75rem;
  background: var(--surface-2);
  padding: 0.625rem 0.75rem;
}
.shell-avatar {
  position: relative;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  font-size: 1rem;
}
.shell-other .shell-name {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0 0.75rem;
}
.shell-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.75rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.shell-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.shell-nav-item.active {
  background: var(--accent);
  color: var(--accent-contrast);
}
.nav-badge {
  margin-left: auto;
  display: flex;
  height: 1.25rem;
  min-width: 1.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--danger);
  padding: 0 0.25rem;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.shell-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
}
.shell-me {
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 0.5rem;
}
.shell-logout {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.shell-logout:hover {
  background: var(--surface-hover);
  color: var(--danger);
}

.shell-main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}
.page-content {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.bottom-nav {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.375rem 0;
  padding-bottom: max(0.375rem, env(safe-area-inset-bottom));
}
.bottom-nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}
.bottom-nav-item.active {
  color: var(--accent);
}
.bottom-nav-item .nav-icon {
  font-size: 20px;
  line-height: 1;
}
.bottom-nav-item .nav-badge {
  position: absolute;
  right: 0.25rem;
  top: 0.125rem;
  height: 1rem;
  min-width: 1rem;
  font-size: 10px;
}

@media (min-width: 768px) {
  .app-shell.nav-open .shell-sidebar {
    display: flex;
  }
}
@media (max-width: 767px) {
  .app-shell.nav-open .bottom-nav {
    display: flex;
  }
}

.shell-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.3125rem 0.5rem;
}
.nav-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  color: var(--text-muted);
  font-size: 1.0625rem;
}
.nav-toggle-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ============================================================
   Lock gate (heavy full-page blur) + reveal toggle (lighter blur)
   ============================================================ */
.shell-body-inner {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.app-shell.locked .shell-body-inner {
  pointer-events: none;
  user-select: none;
  filter: blur(100px);
  transform: scale(1.1);
}
.lock-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 16, 22, 0.55);
}
.app-shell.locked .lock-overlay {
  display: flex;
}

.reveal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 16, 22, 0.4);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

/* ============================================================
   Excel password prompt card (shared: lock gate, reveal toggle, login)
   ============================================================ */
.excel-password-card {
  display: flex;
  width: 100%;
  max-width: 360px;
  flex-direction: column;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid #8a8a8a;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  font-family: Calibri, "Segoe UI", Aptos, Arial, sans-serif;
}
.excel-password-titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #f0f0f0;
  border-bottom: 1px solid #d4d4d4;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 600;
}
.excel-password-titlebar .titlebar-icon {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}
.excel-password-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: #ffffff;
}
.excel-password-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.lock-badge {
  margin-top: 2px;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: #fdecea;
  font-size: 16px;
}
.protected-line {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: #1a1a1a;
}
.protected-sub {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.35;
  color: #444444;
}
.excel-password-body input[type="password"] {
  width: 100%;
  border: 1px solid #767676;
  color: #1a1a1a;
  background: #fff;
  padding: 0.375rem 0.625rem;
  font-size: 14px;
  outline: none;
}
.excel-password-body input[type="password"]:focus {
  border-color: var(--xl-green, #217346);
}
.excel-password-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.25rem;
}
.btn-ok {
  display: flex;
  min-width: 76px;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 1px solid #185c37;
  background: #217346;
  color: #fff;
  padding: 0.375rem 1rem;
  font-size: 13px;
  font-weight: 500;
}
.btn-ok:hover {
  background: #185c37;
}
.btn-ok:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.field-error {
  margin: 0;
  font-size: 12px;
  color: #c00000;
}

/* ============================================================
   Login page (identity picker)
   ============================================================ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 1rem;
  background: var(--bg);
}
.login-main {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.identity-card {
  display: flex;
  width: 100%;
  max-width: 360px;
  flex-direction: column;
  gap: 0.625rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}
.identity-title {
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.identity-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.identity-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}
.identity-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.identity-btn .avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  font-size: 1.125rem;
}
.link-btn {
  align-self: center;
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.link-btn:hover {
  color: var(--accent);
}

/* ============================================================
   Toasts
   ============================================================ */
.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  left: 1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  max-width: 320px;
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 0.75rem;
  animation: toast-in 0.2s ease-out;
}
.toast-icon {
  font-size: 1.125rem;
}
.toast-title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}
.toast-body {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Excel worksheet chat theme
   ============================================================ */
.xl-sheet {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  background: var(--xl-cell-bg);
  font-family: Calibri, "Segoe UI", Aptos, Arial, sans-serif;
}
.xl-cell {
  border-right: 1px solid var(--xl-grid);
  border-bottom: 1px solid var(--xl-grid);
}
.xl-active-cell {
  outline: 2px solid var(--xl-selection);
  outline-offset: -2px;
  position: relative;
}
.xl-active-cell::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 6px;
  height: 6px;
  background: var(--xl-selection);
}

.xl-titlebar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: #fff;
  background: var(--xl-green-dark);
}
.xl-titlebar .xl-title {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.xl-titlebar .xl-saved {
  display: none;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}
.xl-titlebar-right {
  margin-left: auto;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
}
.xl-reconnecting {
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.125rem 0.5rem;
  font-size: 11px;
  font-weight: 500;
}
.xl-titlebar-avatar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 0.875rem;
}
.xl-titlebar-who {
  display: none;
  text-align: right;
}
.xl-titlebar-who .name {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.xl-titlebar-who .status {
  margin: 0;
  font-size: 10px;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 640px) {
  .xl-titlebar .xl-saved,
  .xl-titlebar-who {
    display: block;
  }
}

.xl-toolbar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid var(--xl-grid);
  background: var(--xl-header-bg);
  padding: 0.25rem 0.75rem;
}
.xl-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.xl-toolbar-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--xl-header-text);
}
.xl-spinner {
  display: flex;
  align-items: center;
  border: 1px solid var(--xl-grid);
  background: var(--surface);
}
.xl-spinner-value {
  width: 1.5rem;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--xl-header-text);
}
.xl-spinner-btns {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--xl-grid);
}
.xl-spinner-btns button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 0.875rem;
  line-height: 1;
  color: var(--xl-header-text);
  font-size: 9px;
}
.xl-spinner-btns button:first-child {
  border-bottom: 1px solid var(--xl-grid);
}
.xl-spinner-btns button:hover:not(:disabled) {
  background: var(--surface-hover);
}
.xl-spinner-btns button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.xl-toggle-btn {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.375rem;
  border: 1px solid var(--xl-grid);
  background: var(--surface);
  color: var(--xl-header-text);
  padding: 0.25rem 0.625rem;
  font-size: 11px;
  font-weight: 500;
  transition: background 0.15s;
}
.xl-toggle-btn:hover {
  background: var(--surface-hover);
}

.xl-scroll {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
}
.xl-scroll-inner {
  min-width: 420px;
  font-size: var(--xl-msg-font-size, 13px);
}
.xl-grid-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 2.75rem 1fr 4.5rem;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--xl-header-text);
}
.xl-grid-header .xl-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0;
  background: var(--xl-header-bg);
}

/* Blank-sheet look for the hidden state: real column letters + gridded
   empty cells, so a glance shows an ordinary empty spreadsheet rather than
   an obvious "content hidden" placeholder. */
.blank-grid-header,
.blank-grid-row {
  display: grid;
  grid-template-columns: 2.75rem repeat(6, minmax(4rem, 1fr));
}
.blank-grid-header .xl-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0;
  background: var(--xl-header-bg);
}
.blank-grid-cell {
  min-height: 1.75rem;
  border-right: 1px solid var(--xl-grid);
  border-bottom: 1px solid var(--xl-grid);
}
.blank-grid-cell.blank-row-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85em;
  font-weight: 600;
  background: var(--xl-header-bg);
  color: var(--xl-header-text);
}

.xl-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 4rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}
.xl-empty .emoji {
  font-size: 1.875rem;
}
.xl-hidden-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 6rem 1.5rem;
  text-align: center;
  color: var(--xl-header-text);
  opacity: 0.35;
}
.xl-hidden-state .emoji {
  font-size: 1.375rem;
}
.xl-hidden-state p {
  margin: 0;
  font-size: 0.85em;
}

.xl-date-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0;
  background: var(--xl-header-bg);
  color: var(--xl-header-text);
}
.xl-date-sep span {
  font-size: 0.85em;
  font-weight: 600;
}
.xl-unread-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--danger);
  background: var(--xl-header-bg);
}

/* ---- message row (grid: row-number | message | tick) ---- */
.msg-row {
  position: relative;
  display: grid;
  grid-template-columns: 2.75rem 1fr 4.5rem;
  font-size: var(--xl-msg-font-size, 13px);
}
.msg-row-num {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.375rem;
  font-size: 0.85em;
  font-weight: 600;
  background: var(--xl-header-bg);
  color: var(--xl-header-text);
}
.msg-row-body {
  position: relative;
  padding: 0.375rem 0.5rem;
}
.msg-row-tick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.375rem 0.25rem 0;
}
.msg-time {
  white-space: nowrap;
  font-size: 0.8em;
  line-height: 1;
  color: var(--text-muted);
}
.msg-edited {
  font-size: 0.7em;
  font-style: italic;
  line-height: 1;
  color: var(--text-faint);
}
.msg-deleted {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
  font-style: italic;
  color: var(--text-faint);
}

.msg-actions {
  position: absolute;
  right: 0.25rem;
  top: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-row:hover .msg-actions,
.msg-actions.open {
  opacity: 1;
}
.msg-actions-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  color: var(--text-muted);
}
.msg-actions-btn:hover {
  background: var(--surface-hover);
}
.msg-actions-menu {
  position: absolute;
  right: 0;
  top: 1.75rem;
  z-index: 20;
  min-width: 140px;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 0.25rem;
  display: none;
}
.msg-actions-menu.open {
  display: block;
}
.msg-actions-menu button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.375rem;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--text);
  text-align: left;
}
.msg-actions-menu button:hover {
  background: var(--surface-hover);
}
.msg-actions-menu .danger {
  color: var(--danger);
}
.msg-actions-emojis {
  display: flex;
  gap: 0.125rem;
  padding: 0.25rem;
}
.msg-actions-emojis button {
  width: 1.75rem;
  padding: 0.125rem;
  text-align: center;
  font-size: 1rem;
  border-radius: 0.375rem;
}

.msg-reply {
  margin-bottom: 0.375rem;
  max-width: 28rem;
  border-radius: 0.25rem;
  border-left: 2px solid var(--xl-green);
  background: var(--xl-header-bg);
  padding: 0.25rem 0.5rem;
  font-size: 0.85em;
  opacity: 0.8;
}
.msg-reply p {
  margin: 0;
}
.msg-reply .who {
  font-weight: 500;
}
.msg-reply .snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-media-note {
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding-right: 1.5rem;
  font-size: 0.85em;
  font-style: italic;
  color: var(--text-faint);
}
.msg-media-note .icon {
  color: var(--xl-green);
}

.msg-text {
  margin: 0;
  padding-right: 1.5rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  line-height: 1.5;
  color: var(--text);
}

.msg-edit-box {
  display: flex;
  max-width: 28rem;
  flex-direction: column;
  gap: 0.375rem;
}
.msg-edit-box textarea {
  resize: none;
  border: 1px solid var(--xl-green);
  background: var(--surface);
  padding: 0.25rem 0.5rem;
  outline: none;
}
.msg-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
}
.msg-edit-actions button {
  border-radius: 0.375rem;
  padding: 0.25rem;
}
.msg-edit-actions button:hover {
  background: var(--surface-hover);
}

.msg-tags {
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.msg-tag {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.375rem;
  padding: 0.125rem 0.375rem;
  font-size: 0.75em;
  font-weight: 500;
}
.msg-tag button {
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-tag:hover button {
  opacity: 1;
}

.msg-tagging {
  margin-top: 0.375rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}
.msg-tagging button {
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 0.125rem 0.375rem;
  font-size: 10px;
}
.msg-tagging button:hover {
  background: var(--surface-hover);
}
.msg-tagging input {
  width: 6rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.125rem 0.375rem;
  font-size: 10px;
  outline: none;
}
.msg-tagging input:focus {
  border-color: var(--accent);
}

.msg-reactions {
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.msg-reaction-pill {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.0625rem 0.4375rem;
  font-size: 0.75em;
}
.msg-reaction-pill.mine {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.msg-ticks {
  display: inline-flex;
  align-items: center;
}
.msg-ticks svg {
  display: block;
}
.msg-ticks.read {
  color: var(--tick-read, #4fc3f7);
}
.msg-ticks:not(.read) {
  color: var(--text-muted);
}

.typing-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8em;
  color: var(--text-muted);
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--text-muted);
  animation: typing-dot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.jump-wrap {
  pointer-events: none;
  display: flex;
  justify-content: center;
}
.jump-btn {
  pointer-events: auto;
  margin-top: -3.5rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-md);
}

/* ---- composer ---- */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--xl-grid);
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}
.composer-reply {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
  border-radius: 0.5rem;
  background: var(--surface-2);
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}
.composer-reply .info {
  min-width: 0;
  flex: 1;
}
.composer-reply .who {
  margin: 0;
  font-weight: 600;
  color: var(--accent);
}
.composer-reply .snippet {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}
.composer-icon-btn {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  color: var(--text-muted);
}
.composer-icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 8rem;
  border-radius: 1.125rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.5rem 0.875rem;
  font-size: 0.9375rem;
  line-height: 1.4;
  outline: none;
}
.composer textarea:focus {
  border-color: var(--accent);
}
.composer-send {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
}
.composer-send:hover {
  background: var(--accent-hover);
}
.composer-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.composer-upload-progress {
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   Gallery
   ============================================================ */
.gallery-page {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}
.gallery-header {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1rem;
}
.gallery-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.gallery-tabs {
  display: flex;
  gap: 0.25rem;
  border-radius: 0.5rem;
  background: var(--surface-2);
  padding: 0.1875rem;
}
.gallery-tab {
  border-radius: 0.375rem;
  padding: 0.3125rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}
.gallery-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.gallery-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.gallery-scroll {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0.75rem;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-size, 150px), 1fr));
  gap: 0.5rem;
}
.gallery-tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 0.5rem;
  background: var(--surface-2);
}
.gallery-tile img,
.gallery-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-tile-caption {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  padding: 1rem 0.5rem 0.375rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  opacity: 0;
  transition: opacity 0.15s;
}
.gallery-tile:hover .gallery-tile-caption {
  opacity: 1;
}
.gallery-tile-caption p {
  margin: 0;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-tile-caption .who {
  font-size: 11px;
  font-weight: 500;
}
.gallery-tile-caption .when {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
}
.gallery-tile .video-badge {
  position: absolute;
  right: 0.25rem;
  bottom: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.75rem;
}
.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 4rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.92);
}
.lightbox-top {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
}
.lightbox-top button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.lightbox-top button:hover {
  background: rgba(255, 255, 255, 0.2);
}
.lightbox-body {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
}
.lightbox-body img,
.lightbox-body video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
}
.lightbox-nav.prev {
  left: 0.75rem;
}
.lightbox-nav.next {
  right: 0.75rem;
}

/* ============================================================
   Search
   ============================================================ */
.search-page {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}
.search-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.search-input-wrap {
  position: relative;
}
.search-input-wrap input {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.875rem;
  outline: none;
}
.search-input-wrap input:focus {
  border-color: var(--accent);
}
.search-input-wrap .icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.search-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}
.search-tag-chip {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}
.search-tag-chip.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}
.search-results {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0.5rem 0.75rem;
}
.search-result {
  border-radius: 0.75rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.375rem;
}
.search-result:hover {
  background: var(--surface-hover);
}
.search-result .meta {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.125rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.search-result .snippet {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text);
}
.search-result mark {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: inherit;
  border-radius: 2px;
}

/* ============================================================
   Settings / Profile
   ============================================================ */
.settings-page,
.profile-page {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 1rem;
}
.settings-section,
.profile-card {
  max-width: 32rem;
  margin: 0 auto 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem 1.25rem;
}
.settings-section h2,
.profile-card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child {
  border-bottom: none;
}
.settings-row .label {
  font-size: 0.875rem;
  font-weight: 500;
}
.settings-row .desc {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 2.75rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}
.toggle.on {
  background: var(--accent);
}
.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}
.toggle.on .knob {
  transform: translateX(1.25rem);
}

.theme-options {
  display: flex;
  gap: 0.5rem;
}
.theme-option {
  flex: 1;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  padding: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);
}
.theme-option.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.profile-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 999px;
  font-size: 1.75rem;
}
.profile-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.profile-role {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ============================================================
   Presence dot
   ============================================================ */
.presence-dot {
  position: absolute;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 999px;
  border: 2px solid var(--surface);
  background: var(--text-faint);
}
.presence-dot.online {
  background: var(--success);
}

/* ============================================================
   Generic loading state
   ============================================================ */
.page-loading {
  display: flex;
  flex: 1;
  min-height: 100%;
  align-items: center;
  justify-content: center;
}
.page-loading .spin {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.6s linear infinite;
}
