/* ============================================================
   THREADLINE — design system
   Signature motif: the "stitch" — three shortening threads (in the
   mark) and dashed stitch-rules used as dividers/skeletons. Palette
   is a deep teal-black paired with a single warm amber accent kept
   rare (owner badges, unread knots) so it reads as a spark, not a
   scheme.
   ============================================================ */

@media (prefers-reduced-motion: no-preference) {
  :root { --motion-ok: 1; }
}

/* ---------- Design tokens ---------- */
:root,
body[data-theme="dark"] {
  --bg: #0A1210;
  --bg-elevated: #0E1815;
  --surface: #121D1A;
  --surface-raised: #172420;
  --surface-hover: #1C2B26;
  --border: rgba(237, 243, 241, 0.09);
  --border-strong: rgba(237, 243, 241, 0.16);
  --text: #EAF2EF;
  --text-secondary: #93A9A3;
  --text-tertiary: #5E736D;
  --accent: #4FD8C4;
  --accent-strong: #35C2AD;
  --accent-contrast: #04211C;
  --accent-soft: rgba(79, 216, 196, 0.14);
  --spark: #E3A548;
  --spark-soft: rgba(227, 165, 72, 0.16);
  --danger: #E2685A;
  --danger-soft: rgba(226, 104, 90, 0.14);
  --outgoing-bubble: #1B4741;
  --outgoing-bubble-text: #EAF2EF;
  --incoming-bubble: #172420;
  --shadow-color: 0deg 0% 0%;
  --shadow-md: 0 8px 24px hsl(var(--shadow-color) / 0.35);
  --shadow-lg: 0 20px 60px hsl(var(--shadow-color) / 0.5);
  --focus-ring: 0 0 0 3px rgba(79, 216, 196, 0.45);
  --overlay-scrim: rgba(4, 8, 7, 0.6);
}

body[data-theme="light"] {
  --bg: #F2F5F3;
  --bg-elevated: #FFFFFF;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --surface-hover: #E8EEEB;
  --border: rgba(14, 26, 22, 0.10);
  --border-strong: rgba(14, 26, 22, 0.18);
  --text: #101B18;
  --text-secondary: #52685F;
  --text-tertiary: #7C948B;
  --accent: #0E8F7C;
  --accent-strong: #0B7566;
  --accent-contrast: #F2FFFB;
  --accent-soft: rgba(14, 143, 124, 0.10);
  --spark: #B8721D;
  --spark-soft: rgba(184, 114, 29, 0.12);
  --danger: #C6483B;
  --danger-soft: rgba(198, 72, 59, 0.10);
  --outgoing-bubble: #DBEFE9;
  --outgoing-bubble-text: #0E2622;
  --incoming-bubble: #F4F6F5;
  --shadow-color: 160deg 20% 30%;
  --shadow-md: 0 8px 24px hsl(var(--shadow-color) / 0.12);
  --shadow-lg: 0 20px 60px hsl(var(--shadow-color) / 0.18);
  --focus-ring: 0 0 0 3px rgba(14, 143, 124, 0.35);
  --overlay-scrim: rgba(16, 27, 24, 0.4);
}

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100dvh;
  transition: background-color 0.25s ease, color 0.25s ease;
}
h1, h2, h3 { font-family: 'Fraunces', serif; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
input, textarea, select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
}
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
::selection { background: var(--accent-soft); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 6px;
}

.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* stitch-rule: the recurring dashed divider motif */
.divider {
  border: none;
  border-top: 1.5px dashed var(--border-strong);
  margin: 20px 0;
}

/* ============================================================
   LOADING SCREEN
   ============================================================ */
.app-loading {
  position: fixed; inset: 0; z-index: 300;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: var(--bg);
}
.app-loading__ring { fill: none; stroke: var(--border-strong); stroke-width: 3; }
.app-loading__thread { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 120; stroke-dashoffset: 120;
  animation: stitch-draw 1.6s ease-in-out infinite;
}
@keyframes stitch-draw {
  0% { stroke-dashoffset: 120; }
  50% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -120; }
}
.app-loading__label { color: var(--text-secondary); font-size: 13px; letter-spacing: 0.02em; }
.app-loading__bar { width: 160px; height: 3px; border-radius: 3px; background: var(--border); overflow: hidden; }
.app-loading__bar-fill { height: 100%; width: 30%; background: var(--accent); border-radius: 3px; animation: bar-sweep 1.2s ease-in-out infinite; }
@keyframes bar-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(340%); }
}
@media (prefers-reduced-motion: reduce) {
  .app-loading__thread, .app-loading__bar-fill { animation: none; }
}

/* ============================================================
   ACCESS GATE
   ============================================================ */
.access-gate {
  position: fixed; inset: 0; z-index: 250;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
  overflow-y: auto;
}
.access-gate__panel {
  width: 100%; max-width: 400px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.access-gate__brand {
  display: flex; align-items: center; gap: 10px;
  font-family: 'Fraunces', serif; font-size: 20px; font-weight: 600;
  color: var(--accent); margin-bottom: 28px;
}
.access-gate__brand svg .app-loading__ring { stroke: var(--border-strong); }
.access-gate__brand svg .app-loading__thread { stroke: var(--accent); stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
.access-gate__title { font-size: 24px; font-weight: 600; margin-bottom: 6px; }
.access-gate__sub { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 22px; }
.access-gate__tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.access-gate__tab {
  flex: 1; padding: 9px 0; border-radius: 9px; border: none; background: transparent;
  color: var(--text-secondary); font-weight: 600; font-size: 13.5px; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.access-gate__tab.is-active { background: var(--accent); color: var(--accent-contrast); }
.access-gate__form { display: flex; flex-direction: column; gap: 16px; }
.access-gate__footer { margin-top: 20px; font-size: 12px; color: var(--text-tertiary); text-align: center; line-height: 1.6; }
.link-inline { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field--row { flex-direction: row; align-items: center; justify-content: space-between; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.field input, .field textarea, .field select {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14.5px;
  color: var(--text);
  transition: border-color 0.15s ease;
}
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2393A9A3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 34px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); outline: none; box-shadow: var(--focus-ring); }
.field__with-action { position: relative; display: flex; align-items: center; }
.field__with-action input { flex: 1; padding-right: 42px; }
.field__with-action .btn { margin-left: 8px; }
.field__reveal {
  position: absolute; right: 10px; background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); font-size: 14px; padding: 4px;
}
.field__error { color: var(--danger); font-size: 12.5px; }
.field__hint { color: var(--text-tertiary); font-size: 12px; line-height: 1.55; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 11px; border: 1.5px solid transparent;
  padding: 11px 18px; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn--ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); }
.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
.btn--sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.btn__spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Passcode digits ---------- */
.passcode-input { display: flex; gap: 10px; justify-content: center; margin: 4px 0; }
.passcode-digit {
  width: 44px; height: 52px; text-align: center; font-size: 20px; font-weight: 700;
  border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface);
  font-family: 'JetBrains Mono', monospace;
}
.passcode-digit:focus { border-color: var(--accent); box-shadow: var(--focus-ring); outline: none; }

/* ---------- Avatars ---------- */
.avatar { border-radius: 50%; object-fit: cover; background: var(--surface-hover); flex-shrink: 0; }
.avatar--sm { width: 30px; height: 30px; }
.avatar--md { width: 40px; height: 40px; }
.avatar--lg { width: 84px; height: 84px; margin: 0 auto 12px; }

/* ============================================================
   TOP NAVIGATION
   ============================================================ */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topnav__cluster { display: flex; align-items: center; gap: 6px; }
.topnav__btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px; border-radius: 10px; border: none;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.topnav__btn:hover { background: var(--surface-hover); color: var(--text); }
.icon--moon { display: none; }
body[data-theme="dark"] .icon--sun { display: none; }
body[data-theme="dark"] .icon--moon { display: block; }
.topnav__btn--ai { color: var(--accent); font-weight: 700; }
.topnav__ai-label { font-size: 12.5px; letter-spacing: 0.02em; }
.presence-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
}
.presence-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-tertiary); }
.presence-dot--online { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.topnav__avatar-btn { background: none; border: none; padding: 0; cursor: pointer; border-radius: 50%; margin-left: 4px; }

/* ============================================================
   APP SHELL / SIDEBAR / CONVERSATION PANEL
   ============================================================ */
.app-shell {
  position: fixed; inset: 0; top: 56px;
  display: flex;
}

.sidebar {
  width: 100%;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.sidebar__header { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.sidebar__title { font-size: 21px; font-weight: 600; }
.sidebar__actions { display: flex; gap: 4px; }
.sidebar__search { padding: 0 16px 12px; }
.sidebar__search input {
  width: 100%; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 9px 12px; font-size: 13.5px;
}
.sidebar__search input:focus { border-color: var(--accent); outline: none; }
.sidebar__tabs { display: flex; gap: 6px; padding: 0 16px 12px; overflow-x: auto; }
.sidebar__tab {
  flex-shrink: 0; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.sidebar__tab.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.conversation-item {
  display: flex; gap: 12px; align-items: center; padding: 10px 8px; border-radius: 12px;
  cursor: pointer; transition: background-color 0.12s ease;
}
.conversation-item:hover { background: var(--surface-hover); }
.conversation-item.is-active { background: var(--accent-soft); }
.conversation-item__avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--surface-hover); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px; overflow: hidden;
}
.conversation-item__avatar--global { background: var(--accent-soft); }
.conversation-item__body { flex: 1; min-width: 0; }
.conversation-item__top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-item__name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item__time { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; }
.conversation-item__bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.conversation-item__preview { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.badge--unread { background: var(--spark); color: #1B1103; }

.empty-state { padding: 28px 20px; text-align: center; color: var(--text-tertiary); font-size: 13px; line-height: 1.6; }
.empty-state--inline { padding: 16px 4px; }

.sidebar__footer { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.sidebar__footer-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 0; border-radius: 10px; border: none; background: transparent;
  color: var(--text-secondary); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.sidebar__footer-btn:hover { background: var(--surface-hover); color: var(--text); }
.sidebar__footer-btn--danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Conversation panel ---------- */
.conv-panel {
  flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative;
  background: var(--bg);
}
.conv-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--text-tertiary); text-align: center; padding: 24px;
}
.conv-empty__mark .app-loading__thread { animation: none; stroke-dashoffset: 0; }
.conv-empty h2 { color: var(--text-secondary); font-size: 20px; }
.conv-empty p { font-size: 13.5px; max-width: 260px; }

.conv-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.conv-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg-elevated); flex-shrink: 0;
}
.conv-header__back { display: none; }
.conv-header__identity {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0;
  background: none; border: none; cursor: pointer; text-align: left; padding: 4px;
  border-radius: 10px;
}
.conv-header__identity:hover { background: var(--surface-hover); }
.conv-header__text { display: flex; flex-direction: column; min-width: 0; }
.conv-header__name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-header__sub { font-size: 12px; color: var(--text-tertiary); }
.conv-header__actions { display: flex; align-items: center; gap: 6px; }
.typing-indicator { font-size: 12px; color: var(--accent); font-style: italic; }
.ai-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}

.disappearing-banner {
  display: flex; align-items: center; gap: 6px; padding: 7px 16px;
  background: var(--spark-soft); color: var(--spark); font-size: 12px; flex-shrink: 0;
}

/* ---------- Message list & bubbles ---------- */
.message-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; }
.message-list__load-more { text-align: center; margin-bottom: 12px; }
.message-list__items { display: flex; flex-direction: column; gap: 3px; }
.empty-state--messages { margin: auto; }

.message-item { display: flex; margin-top: 10px; }
.message-item[data-grouped="true"] { margin-top: 2px; }
.message-item--outgoing { justify-content: flex-end; }
.message-item--incoming { justify-content: flex-start; }
.message-item__group { display: flex; flex-direction: column; max-width: 72%; gap: 3px; }
.message-item--outgoing .message-item__group { align-items: flex-end; }
.message-item__sender { font-size: 11.5px; font-weight: 700; color: var(--accent); margin: 0 4px; }
.message-bubble {
  position: relative; padding: 9px 13px; border-radius: 16px; font-size: 14.5px; line-height: 1.4;
  word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.message-item--incoming .message-bubble { background: var(--incoming-bubble); border-bottom-left-radius: 5px; color: var(--text); }
.message-item--outgoing .message-bubble { background: var(--outgoing-bubble); color: var(--outgoing-bubble-text); border-bottom-right-radius: 5px; }
.message-bubble__forwarded { font-size: 11px; color: var(--text-tertiary); font-style: italic; margin-bottom: 3px; }
.message-bubble__meta { display: flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 10.5px; opacity: 0.6; justify-content: flex-end; }
.message-bubble img.message-media, .message-bubble video.message-media {
  max-width: 260px; border-radius: 12px; margin-bottom: 4px; cursor: pointer;
}
.voice-message { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.voice-message__play { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); border: none; flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.voice-message__wave { flex: 1; height: 22px; background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); opacity: 0.4; border-radius: 4px; }
.voice-message__speed { font-size: 10.5px; font-weight: 700; background: var(--surface-hover); border: none; border-radius: 6px; padding: 3px 7px; cursor: pointer; color: inherit; }

.message-reactions { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.message-reactions__pill {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 7px;
  cursor: pointer;
}
.message-reactions__pill.is-mine { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Reaction picker / action menu (floating) ---------- */
.reaction-picker, .msg-action-menu {
  position: absolute; z-index: 60; background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-md); padding: 6px;
}
.reaction-picker { display: flex; gap: 2px; }
.reaction-picker__emoji, .reaction-picker__more {
  width: 34px; height: 34px; border-radius: 8px; border: none; background: none; font-size: 18px; cursor: pointer;
}
.reaction-picker__emoji:hover, .reaction-picker__more:hover { background: var(--surface-hover); }
.msg-action-menu { display: flex; flex-direction: column; min-width: 160px; }
.msg-action-menu__item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  border: none; background: none; color: var(--text); font-size: 13.5px; cursor: pointer; text-align: left;
}
.msg-action-menu__item:hover { background: var(--surface-hover); }

/* ---------- Attachment preview / voice recorder ---------- */
.attachment-preview {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-top: 1px solid var(--border); background: var(--bg-elevated); flex-shrink: 0;
}
.attachment-preview__media { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--surface-hover); flex-shrink: 0; }
.attachment-preview__media img, .attachment-preview__media video { width: 100%; height: 100%; object-fit: cover; }
.attachment-preview__meta { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-secondary); }
.attachment-preview__progress { height: 4px; border-radius: 4px; background: var(--border); margin-top: 5px; overflow: hidden; }
.attachment-preview__progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.2s ease; }

.voice-recorder {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-top: 1px solid var(--border); background: var(--bg-elevated); flex-shrink: 0;
}
.voice-recorder__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.voice-recorder__timer { font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.voice-recorder__hint { color: var(--text-tertiary); font-size: 12.5px; flex: 1; }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 10px 12px;
  border-top: 1px solid var(--border); background: var(--bg-elevated); flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  position: relative;
}
.composer__input {
  flex: 1; resize: none; max-height: 120px; padding: 10px 12px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 16px;
  font-size: 14.5px; line-height: 1.4;
}
.composer__input:focus { border-color: var(--accent); outline: none; }
.composer__count { font-size: 10.5px; color: var(--text-tertiary); align-self: center; padding: 0 4px; display: none; }
.composer__btn--send { background: var(--accent); color: var(--accent-contrast); }
.composer__btn--send:disabled { background: var(--surface-hover); color: var(--text-tertiary); }
.composer__btn--send:hover:not(:disabled) { background: var(--accent-strong); }

.emoji-popover {
  position: absolute; bottom: 62px; left: 12px; z-index: 60;
  width: 260px; max-height: 220px; overflow-y: auto;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 8px;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px;
}
.emoji-popover button { font-size: 19px; padding: 6px 0; border-radius: 8px; border: none; background: none; cursor: pointer; }
.emoji-popover button:hover { background: var(--surface-hover); }

/* ---------- AI panel ---------- */
.conv-active--ai .message-list { background: linear-gradient(180deg, var(--accent-soft), transparent 140px); }
.ai-typing { display: flex; gap: 4px; padding: 8px 4px; }
.ai-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-tertiary); animation: ai-bounce 1.2s infinite ease-in-out; }
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--overlay-scrim); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 440px; max-height: 88vh;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal--wide { max-width: 600px; }
.modal--narrow { max-width: 360px; }
.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal__header h2 { font-size: 17px; }
.modal__body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal__footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }

.modal__steps { display: flex; gap: 4px; padding: 0 20px; margin-top: 12px; }
.modal__step {
  flex: 1; text-align: center; font-size: 11.5px; font-weight: 600; color: var(--text-tertiary);
  padding-bottom: 10px; border-bottom: 2px solid var(--border);
}
.modal__step.is-active { color: var(--accent); border-color: var(--accent); }

.modal__tabs { display: flex; gap: 4px; padding: 12px 20px 0; border-bottom: 1px solid var(--border); }
.modal__tab {
  padding: 9px 4px; margin-right: 16px; border: none; background: none; cursor: pointer;
  color: var(--text-tertiary); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent;
}
.modal__tab.is-active { color: var(--accent); border-color: var(--accent); }
.gs-panel { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }

.wizard-step { display: flex; flex-direction: column; gap: 14px; }
.group-photo-picker { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.group-photo-picker__placeholder {
  width: 84px; height: 84px; border-radius: 50%; border: 1.5px dashed var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--text-tertiary);
}

.search-results { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.search-result-item {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer;
}
.search-result-item:hover { background: var(--surface-hover); }
.search-result-item__name { font-weight: 600; font-size: 13.5px; }
.search-result-item__code { font-size: 11.5px; color: var(--text-tertiary); font-family: 'JetBrains Mono', monospace; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 5px;
  background: var(--accent-soft); border-radius: 999px; font-size: 12.5px; color: var(--accent);
}
.chip img { width: 20px; height: 20px; border-radius: 50%; }
.chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; padding: 2px; }

.group-review { display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: var(--text-secondary); }

.member-list { display: flex; flex-direction: column; gap: 2px; }
.member-list__item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.member-list__name { font-weight: 600; font-size: 13.5px; flex: 1; }
.member-list__role-badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.member-list__role-badge--owner { background: var(--spark-soft); color: var(--spark); }
.member-list__role-badge--admin { background: var(--accent-soft); color: var(--accent); }
.member-list__actions { display: flex; gap: 4px; }

.destination-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.destination-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-radius: 10px; cursor: pointer;
}
.destination-item:hover { background: var(--surface-hover); }
.destination-item.is-selected { background: var(--accent-soft); }
.forward-preview {
  background: var(--surface); border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; color: var(--text-secondary);
}

.user-card { text-align: center; }
.user-card__code { font-family: 'JetBrains Mono', monospace; color: var(--text-tertiary); font-size: 13px; margin-bottom: 4px; }
.user-card__presence { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 18px; }

.switch {
  width: 42px; height: 24px; border-radius: 999px; background: var(--border-strong); border: none;
  position: relative; cursor: pointer; padding: 3px; flex-shrink: 0;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch__thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #fff; display: block;
  transition: transform 0.18s ease; transform: translateX(0);
}
.switch[aria-checked="true"] .switch__thumb { transform: translateX(18px); }

.lightbox { max-width: 92vw; max-height: 92vh; position: relative; display: flex; }
.lightbox__content img, .lightbox__content video { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
.lightbox__close { position: absolute; top: -44px; right: 0; color: #fff; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast-stack {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 400;
  display: flex; flex-direction: column-reverse; gap: 8px; width: 100%; max-width: 360px; padding: 0 16px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow-md); font-size: 13.5px;
  animation: toast-in 0.2s ease;
}
.toast--success { border-left: 3px solid var(--accent); }
.toast--error { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   RESPONSIVE — mobile-first: single pane, swap views
   ============================================================ */
@media (max-width: 767px) {
  .app-shell[data-mobile-view] .sidebar,
  .sidebar[data-mobile-view="list"] { display: flex; }
  .app-shell .sidebar { width: 100%; border-right: none; }
  .conv-panel { display: none; position: fixed; inset: 56px 0 0 0; }
  .conv-panel.is-mobile-active { display: flex; }
  .sidebar.is-mobile-hidden { display: none; }
  .conv-header__back { display: inline-flex; }
  .message-item__group { max-width: 84%; }
  .composer__count { display: none; }
}

@media (min-width: 768px) {
  .sidebar { width: 340px; flex-shrink: 0; }
  .conv-panel { display: flex !important; }
  .conv-header__back { display: none !important; }
  .composer__count { display: inline-block; }
}

@media (min-width: 1100px) {
  .sidebar { width: 380px; }
}

/* Prevent any horizontal overflow on small screens */
html, body { max-width: 100%; overflow-x: hidden; }