/* FVMessenger — design tokens & layout.
   Signature element: the violet paper-plane mark (brand + send + empty state).
   Dark theme is default; [data-theme="light"] overrides the surface tokens. */

:root {
  --accent: oklch(62% 0.19 292);
  --accent-strong: oklch(from var(--accent) calc(l - 0.1) c h);
  --accent-quiet: color-mix(in oklch, var(--accent) 20%, transparent);
  --success: oklch(70% 0.16 152);
  --danger: oklch(64% 0.22 25);

  --bg: oklch(15% 0.018 290);
  --sidebar-bg: oklch(17% 0.02 290);
  --surface: oklch(21% 0.024 290);
  --surface-2: oklch(25% 0.03 290);
  --bubble-in: oklch(24% 0.026 290);
  --bubble-out: oklch(39% 0.11 292);
  --text: oklch(93% 0.01 290);
  --text-muted: oklch(66% 0.02 290);
  --border: color-mix(in oklch, white 10%, transparent);
  --shadow: 0 12px 32px oklch(8% 0.02 290 / 0.45);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

html[data-theme="light"] {
  --bg: oklch(97% 0.006 290);
  --sidebar-bg: oklch(99% 0.004 290);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(94% 0.01 290);
  --bubble-in: oklch(96% 0.006 290);
  --bubble-out: oklch(85% 0.07 292);
  --text: oklch(22% 0.02 290);
  --text-muted: oklch(46% 0.02 290);
  --border: color-mix(in oklch, black 10%, transparent);
  --shadow: 0 12px 28px oklch(60% 0.02 290 / 0.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font-family: inherit; color: inherit; }
a { color: var(--accent); }
::selection { background: var(--accent-quiet); }

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

.hidden { display: none !important; }

/* ── Buttons / fields (shared: auth + app) ─────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 11px 18px; font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: white; }
.btn--primary:hover { background: var(--accent-strong); }
.btn--ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); justify-content: flex-start; }
.btn--ghost:hover { border-color: var(--accent); }
.btn--danger { background: color-mix(in oklch, var(--danger) 16%, transparent); color: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { padding: 7px 12px; font-size: 13px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 999px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer; font-size: 16px;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn--send { background: var(--accent); color: #fff; }
.icon-btn--send:hover { background: var(--accent-strong); color: #fff; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13.5px; color: var(--text-muted); }
.field input, .field textarea, .field select {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 15px; outline: none;
  transition: border-color .15s ease;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field--checkbox { flex-direction: row; align-items: flex-start; gap: 10px; font-size: 13px; }
.field--checkbox input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.field-error { color: var(--danger); font-size: 12.5px; margin: -2px 0 8px; }
.field-error--form { text-align: center; }

/* ── Auth / legal screens ──────────────────────────────────────── */

.auth-screen, .legal-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(circle at 15% 10%, color-mix(in oklch, var(--accent) 22%, transparent), transparent 45%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 28px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-plane {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 12px; background: var(--accent); color: #fff; font-size: 16px;
  transform: rotate(-8deg);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-sub { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }
.auth-switch { text-align: center; font-size: 13.5px; color: var(--text-muted); margin-top: 16px; }
.auth-switch a { text-decoration: none; font-weight: 600; }

.legal-card {
  max-width: 640px; width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px; line-height: 1.6; box-shadow: var(--shadow);
}
.legal-card h1 { font-size: 22px; margin-top: 8px; }
.legal-card p { color: var(--text-muted); font-size: 14.5px; }
.legal-back { display: inline-flex; gap: 8px; align-items: center; font-size: 13.5px; text-decoration: none; }
.legal-inline-link { color: var(--text-muted); font-size: 13px; text-decoration: underline; }
.legal-reference-source {
  white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 12.5px;
  color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 14px; max-height: 60vh; overflow: auto;
}

/* ── App shell ──────────────────────────────────────────────────── */

.app-shell {
  display: grid; grid-template-columns: 320px 1fr; height: 100vh; overflow: hidden;
}
.sidebar {
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}
.sidebar-header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 8px; }
.me-chip {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0;
  background: transparent; border: none; text-align: left; cursor: pointer; border-radius: var(--radius-md); padding: 6px;
}
.me-chip:hover { background: var(--surface-2); }
.me-chip-text { display: flex; flex-direction: column; min-width: 0; }
.me-chip-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-chip-text small { color: var(--text-muted); font-size: 12px; }

.avatar {
  --avatar-color: var(--accent);
  width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--avatar-color); color: #fff; font-weight: 700; font-size: 16px; flex: none; text-transform: uppercase;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar--sm { width: 32px; height: 32px; font-size: 13px; }
.avatar--lg { width: 84px; height: 84px; font-size: 30px; }
.avatar--xs { width: 18px; height: 18px; font-size: 9px; }

.sidebar-tabs { display: flex; gap: 4px; margin: 4px 14px 10px; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.sidebar-tabs button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.sidebar-tabs button.active { background: var(--accent); color: #fff; }

.sidebar-search { display: flex; align-items: center; gap: 8px; margin: 6px 14px 10px; padding: 9px 12px;
  background: var(--surface-2); border-radius: 999px; color: var(--text-muted); }
.sidebar-search input { flex: 1; border: none; background: transparent; outline: none; font-size: 14px; color: var(--text); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.chat-item {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius-md);
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-quiet); }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; gap: 6px; }
.chat-item-name { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: 11.5px; color: var(--text-muted); flex: none; }
.chat-item-preview { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.chat-item-badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px;
  min-width: 19px; height: 19px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}
.chat-type-tag { font-size: 10.5px; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; margin-right: 4px; }
.chat-empty-list { padding: 30px 18px; color: var(--text-muted); font-size: 13.5px; text-align: center; }

.chat-pane { display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 30px; text-align: center;
}
.empty-plane {
  width: 76px; height: 76px; border-radius: 50%; background: var(--accent-quiet); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 30px; transform: rotate(-10deg);
}
.chat-empty h2 { margin: 0; font-size: 19px; }
.chat-empty p { margin: 0; color: var(--text-muted); font-size: 14px; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; max-width: 460px; }
.empty-sample { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; opacity: .55; max-width: 320px; }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 4px; padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mobile-back { display: none; }
.chat-header-info { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: none; text-align: left; cursor: pointer; min-width: 0; padding: 4px; border-radius: var(--radius-md); }
.chat-header-info:hover { background: var(--surface-2); }
.chat-header-text { display: flex; flex-direction: column; min-width: 0; }
.chat-header-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header-sub { font-size: 12px; color: var(--text-muted); }

.offline-banner {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: color-mix(in oklch, var(--danger) 16%, transparent); color: var(--danger);
  font-size: 12.5px; padding: 7px; border-bottom: 1px solid var(--border);
}

.messages { flex: 1; overflow-y: auto; padding: 16px 5% 8px; display: flex; flex-direction: column; gap: 4px; }
.msg-day { align-self: center; font-size: 11.5px; color: var(--text-muted); background: var(--surface-2); padding: 3px 10px; border-radius: 999px; margin: 10px 0; }
.msg-row { display: flex; flex-direction: column; max-width: 68%; margin-bottom: 6px; position: relative; }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }
.msg-sender { font-size: 12px; font-weight: 600; color: var(--accent); margin: 0; }
.msg-sender-btn { display: flex; align-items: center; gap: 5px; border: none; background: transparent; padding: 0; margin: 0 4px 2px; cursor: pointer; }
.msg-sender-btn:hover .msg-sender { text-decoration: underline; }
.search-section-label { padding: 10px 10px 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.bubble {
  padding: 9px 12px 8px; border-radius: var(--radius-md); font-size: 15px; line-height: 1.4; position: relative;
  word-break: break-word; box-shadow: 0 1px 0 color-mix(in oklch, black 6%, transparent);
}
.bubble--in, .msg-row.theirs .bubble { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble--out, .msg-row.mine .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg-row.mine .bubble { color: var(--text); }
.bubble-time { font-size: 10.5px; color: var(--text-muted); margin-left: 8px; float: right; margin-top: 4px; display: inline-flex; align-items: center; gap: 3px; }
.bubble-status { font-size: 11px; }
.bubble img.msg-photo { max-width: 260px; border-radius: var(--radius-sm); display: block; margin-bottom: 4px; }
.bubble .msg-file { display: flex; align-items: center; gap: 8px; background: color-mix(in oklch, white 6%, transparent); padding: 8px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--text); margin-bottom: 4px; }
.bubble .msg-file i { font-size: 20px; color: var(--accent); }

.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; cursor: pointer;
}
.reaction-chip.mine { background: var(--accent-quiet); border-color: var(--accent); }
.reaction-add {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); font-size: 11px; cursor: pointer;
}
.msg-row:hover .hover-react { opacity: 1; pointer-events: auto; }
.hover-react { opacity: 0; pointer-events: none; position: absolute; top: -34px; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 5px; box-shadow: var(--shadow); transition: opacity .12s ease; z-index: 3; }
.msg-row.mine .hover-react { right: 0; }
.msg-row.theirs .hover-react { left: 0; }
.hover-react button { border: none; background: transparent; font-size: 16px; cursor: pointer; padding: 3px; border-radius: 50%; }
.hover-react button:hover { background: var(--surface-2); }

.poll-card { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; min-width: 220px; }
.poll-question { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.poll-option { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; margin-bottom: 6px; cursor: pointer; font-size: 13.5px; position: relative; overflow: hidden; }
.poll-option-fill { position: absolute; inset: 0; background: var(--accent-quiet); z-index: 0; }
.poll-option-label { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 8px; }
.poll-option.voted { border-color: var(--accent); }
.poll-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.skeleton-row { display: flex; gap: 8px; padding: 6px 0; }
.skeleton-bubble { height: 38px; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: skeleton-sheen 1.3s ease-in-out infinite; }
@keyframes skeleton-sheen { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.pending .bubble { opacity: .65; }
.msg-status-icon.sending { color: var(--text-muted); }
.msg-status-icon.sent { color: var(--text-muted); }
.msg-status-icon.failed { color: var(--danger); }

.composer-wrap { border-top: 1px solid var(--border); background: var(--surface); }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 10px; }
.composer textarea {
  flex: 1; resize: none; border: none; background: var(--surface-2); border-radius: var(--radius-md);
  padding: 10px 12px; font-size: 15px; max-height: 140px; outline: none; line-height: 1.4;
}
.emoji-panel {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 10px; max-height: 200px; overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.emoji-panel button { border: none; background: transparent; font-size: 21px; padding: 5px; border-radius: var(--radius-sm); cursor: pointer; }
.emoji-panel button:hover { background: var(--surface-2); }

.mobile-tabbar { display: none; }

/* ── Modal ──────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; background: oklch(10% 0.01 290 / 0.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 440px;
  max-height: 86vh; display: flex; flex-direction: column; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16.5px; }
.modal-body { padding: 18px; overflow-y: auto; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 3px; margin-bottom: 16px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.tabs button.active { background: var(--accent); color: #fff; }

.search-results { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; max-height: 200px; overflow-y: auto; }
.search-result-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-md); border: none; background: var(--surface-2); cursor: pointer; text-align: left; }
.search-result-item:hover { border: 1px solid var(--accent); }

.invite-box { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.invite-box input { flex: 1; }

.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.member-row .role-tag { margin-left: auto; font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.member-row--clickable { width: 100%; border: none; background: transparent; cursor: pointer; border-radius: var(--radius-sm); text-align: left; }
.member-row--clickable:hover { background: var(--surface-2); }

.profile-actions-row { display: flex; gap: 8px; margin-bottom: 6px; }
.profile-actions-row .btn { flex: 1; flex-direction: column; gap: 6px; font-size: 12px; padding: 12px 6px; font-weight: 500; }
.profile-actions-row .btn i { font-size: 17px; }

.menu-list { display: flex; flex-direction: column; }
.menu-list button {
  display: flex; align-items: center; gap: 12px; padding: 11px 4px; border: none; background: transparent;
  color: var(--text); font-size: 14.5px; text-align: left; cursor: pointer; border-radius: var(--radius-sm);
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list button i { width: 18px; text-align: center; color: var(--text-muted); }
.menu-list-danger, .menu-list-danger i { color: var(--danger) !important; }

.settings-section { margin-bottom: 20px; }
.settings-section h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 14px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: background .15s ease; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-muted); transition: transform .15s ease, background .15s ease; }
.switch input:checked + .switch-track { background: var(--accent-quiet); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: var(--accent); }

.theme-swatches { display: flex; gap: 10px; }
.theme-swatch { flex: 1; border-radius: var(--radius-md); border: 2px solid var(--border); padding: 10px; cursor: pointer; text-align: center; font-size: 12.5px; }
.theme-swatch.active { border-color: var(--accent); }
.swatch-preview { height: 40px; border-radius: var(--radius-sm); margin-bottom: 6px; }
.swatch-preview--dark { background: oklch(18% 0.02 290); }
.swatch-preview--light { background: oklch(96% 0.006 290); border: 1px solid var(--border); }

.poll-option-input-row { display: flex; gap: 6px; margin-bottom: 8px; }
.poll-option-input-row input { flex: 1; }

.toast-host { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 16px;
  border-radius: var(--radius-md); box-shadow: var(--shadow); font-size: 13.5px; display: flex; align-items: center; gap: 10px;
}
.toast--error { border-color: var(--danger); }
.toast button { border: none; background: var(--accent-quiet); color: var(--accent); border-radius: var(--radius-sm); padding: 4px 9px; font-size: 12px; cursor: pointer; font-weight: 600; }

/* ── Responsive: mobile < 768px ────────────────────────────────── */

@media (max-width: 767px) {
  .app-shell { grid-template-columns: 1fr; height: 100dvh; }
  .sidebar { display: none; padding-bottom: 58px; }
  .chat-pane { display: none; padding-bottom: 58px; }
  .app-shell[data-view="list"] .sidebar { display: flex; }
  .app-shell[data-view="chat"] .chat-pane { display: flex; }
  .mobile-back { display: inline-flex; }
  .mobile-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 58px; background: var(--surface);
    border-top: 1px solid var(--border); z-index: 20;
  }
  .app-shell[data-view="chat"] .mobile-tabbar { display: none; }
  .mobile-tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: none; color: var(--text-muted); font-size: 10.5px; cursor: pointer;
  }
  .mobile-tabbar button i { font-size: 18px; }
  .mobile-tabbar button.active { color: var(--accent); }
  .msg-row { max-width: 84%; }
  .empty-actions { flex-direction: column; width: 100%; }
  .empty-actions .btn { width: 100%; }
}

@media (min-width: 768px) {
  .modal-backdrop[data-kind="settings"] .modal { max-width: 480px; }
}
