/* Osmosis Chat app — mobile-first layout on the Organic design system.
   Every color / radius / spacing comes from ds.css tokens. */

html, body { height: 100%; }
body { overscroll-behavior-y: none; }

#app { height: 100%; }

/* ── boot splash ─────────────────────────────────────────────── */
.boot-splash {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-3);
  padding: var(--space-6);
}
.boot-blob {
  width: 74px; height: 74px; border-radius: 50%;
  background: var(--color-accent-300);
  animation: pulse-soft 1.6s ease-in-out infinite;
}
.boot-title { font-size: 28px; margin: 0; }
.boot-hint { font-size: 13px; }
@keyframes pulse-soft { 0%,100% { opacity: .45; transform: scale(.96); } 50% { opacity: 1; transform: scale(1); } }

/* ── shell: single column on mobile, two panes on desktop ────── */
.shell {
  height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pane-list, .pane-detail {
  height: 100%; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* mobile: list ↔ detail navigation */
.shell .pane-detail { display: none; }
.shell.in-room .pane-list { display: none; }
.shell.in-room .pane-detail { display: flex; }

@media (min-width: 900px) {
  .shell {
    flex-direction: row;
    gap: var(--space-3);
    padding: var(--space-3);
  }
  .shell .pane-list,
  .shell.in-room .pane-list { display: flex; flex: 0 0 320px; }
  .shell .pane-detail,
  .shell.in-room .pane-detail { display: flex; flex: 1; }
  .pane-list {
    background: var(--color-surface);
    border-radius: calc(var(--radius-lg) * 1.15);
  }
  .pane-detail {
    border: 1px solid var(--color-divider);
    border-radius: calc(var(--radius-lg) * 1.15);
  }
  .btn-back { display: none !important; }
}

/* ── headers ─────────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  flex: none;
}
.app-header h1, .app-header h2 { margin: 0; font-size: 21px; }
.app-header .spacer { margin-left: auto; }

.convo-head {
  display: flex; align-items: center; gap: var(--space-2);
  min-width: 0;
}
.convo-head .titles { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.convo-head .titles .t {
  font-family: var(--font-heading); font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo-head .titles .s {
  font-size: 11px; color: var(--color-neutral-700);
  display: flex; align-items: center; gap: 5px;
}

/* buttons need 44px targets on touch */
.btn-tap { min-width: 44px; min-height: 44px; }
.btn-icon.btn-tap { width: 44px; height: 44px; }

/* ── avatars & dots ──────────────────────────────────────────── */
.avatar {
  flex: none; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  width: 40px; height: 40px; font-size: 15px;
  background: var(--color-accent-2-200); color: var(--color-accent-2-900);
}
.avatar.rafa { background: var(--color-accent-300); color: var(--color-accent-900); }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; }
.dot.online { background: var(--color-accent-2-600); }
.dot.away { background: var(--color-accent-500); }
.dot.offline { background: var(--color-neutral-400); }

/* ── chats list ──────────────────────────────────────────────── */
.chat-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 0 var(--space-2) calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: var(--space-1);
  -webkit-overflow-scrolling: touch;
}
.list-label {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--color-neutral-600);
  padding: var(--space-3) var(--space-2) var(--space-1);
}
.chat-item {
  border: 0; cursor: pointer; font: inherit; text-align: left;
  color: var(--color-text); background: transparent;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  min-height: 60px;
  border-radius: var(--radius-md);
}
.chat-item:hover { background: color-mix(in srgb, var(--color-text) 6%, transparent); }
.chat-item:active { background: color-mix(in srgb, var(--color-text) 12%, transparent); }
.chat-item.active { background: var(--color-neutral-100); }
@media (min-width: 900px) { .chat-item.active { background: var(--color-bg); } }
.chat-item .col { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; flex: 1; }
.chat-item .name { font-family: var(--font-heading); font-size: 15px; }
.chat-item .sub {
  font-size: 12px; color: var(--color-neutral-700);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; flex: none;
  border-radius: 999px; background: var(--color-accent); color: var(--color-bg);
  font-size: 11px; display: grid; place-items: center;
}

/* hero card for the anonymous first visit */
.hero-wrap {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: var(--space-4);
}
.hero-card { gap: var(--space-3); padding: var(--space-6); }
.hero-card .avatar { width: 58px; height: 58px; font-size: 22px; }

.identity-row {
  display: flex; flex-direction: column; gap: var(--space-2);
}
.identity-row .btns { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ── conversation ────────────────────────────────────────────── */
.banner {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 9px var(--space-4); font-size: 12px;
  background: var(--color-accent-100); color: var(--color-accent-800);
}
.banner .pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-accent-600);
  animation: pulse-soft 1.4s infinite;
}

.msg-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.msg-list {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-3);
}
.msg { display: flex; flex-direction: column; gap: 3px; max-width: 84%; }
.msg .bubble {
  padding: 10px 14px; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.msg.theirs { align-items: flex-start; align-self: flex-start; }
.msg.theirs .bubble {
  background: var(--color-surface);
  border-radius: 20px 20px 20px 6px;
}
.msg.mine { align-items: flex-end; align-self: flex-end; }
.msg.mine .bubble {
  background: var(--color-accent); color: var(--color-bg);
  border-radius: 20px 20px 6px 20px;
}
.msg .meta {
  font-size: 10px; color: var(--color-neutral-600); padding: 0 6px;
  display: flex; align-items: baseline; gap: 6px;
}
.msg .meta .author { font-family: var(--font-heading); font-size: 11px; color: var(--color-neutral-800); }
.msg.pending .bubble { opacity: .65; }
.msg.failed .meta { color: var(--color-accent-700); }
.sys-pill {
  align-self: center; text-align: center;
  font-size: 11px; color: var(--color-neutral-700);
  background: var(--color-neutral-200);
  padding: 4px 14px; border-radius: 999px;
  max-width: 90%;
}
.day-pill { align-self: center; font-size: 11px; color: var(--color-neutral-600); padding: 4px 0; }

/* poke prompt — accent-2 tinted, inline */
.poke-card {
  background: var(--color-accent-2-100); border-radius: 20px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
  align-self: flex-start; max-width: 84%;
  color: var(--color-accent-2-900); font-size: 14px; line-height: 1.45;
}
.poke-card .row { display: flex; gap: var(--space-2); }

/* gentle notification nudge */
.nudge-card {
  background: var(--color-neutral-100); border-radius: 20px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
  align-self: stretch; font-size: 13px; color: var(--color-neutral-800);
}
.nudge-card .row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.typing-bubble {
  background: var(--color-surface); padding: 12px 16px;
  border-radius: 20px 20px 20px 6px; align-self: flex-start;
  display: flex; gap: 4px;
}
.typing-bubble i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-neutral-600); animation: pulse-soft 1.2s infinite;
}
.typing-bubble i:nth-child(2) { animation-delay: .2s; }
.typing-bubble i:nth-child(3) { animation-delay: .4s; }

/* sign-in strip above the composer for anonymous users */
.signin-strip {
  flex: none; display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap; padding: 10px var(--space-4);
  background: var(--color-neutral-100); font-size: 12px;
}
.signin-strip .hint { color: var(--color-neutral-700); font-size: 11px; margin-right: auto; }

/* ── composer ────────────────────────────────────────────────── */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  background: var(--color-bg);
  border-top: 1px solid color-mix(in srgb, var(--color-text) 8%, transparent);
}
.composer textarea.input {
  flex: 1; min-height: 44px; max-height: 132px; resize: none;
  border-radius: 22px; padding: 11px 16px; line-height: 1.45;
}
.composer-foot {
  flex: none; text-align: center; font-size: 10px;
  color: var(--color-neutral-600);
  padding: 0 var(--space-4) 6px;
}
.composer-foot.near { color: var(--color-accent-700); }
@media (max-width: 899px) { .composer-foot.hint-desktop { display: none; } }

/* older-messages loader */
.load-older { align-self: center; font-size: 12px; }

/* ── bottom sheet / drawer ───────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--color-neutral-900) 45%, transparent);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 86dvh;
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--color-bg);
  border-radius: calc(var(--radius-lg) * 1.15) calc(var(--radius-lg) * 1.15) 0 0;
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 900px) {
  .sheet-backdrop { align-items: center; padding: var(--space-4); }
  .sheet { border-radius: calc(var(--radius-lg) * 1.15); max-height: 80vh; }
}
.sheet-grip {
  width: 42px; height: 5px; border-radius: 999px;
  background: var(--color-neutral-300); margin: 0 auto; flex: none;
}
@media (min-width: 900px) { .sheet-grip { display: none; } }
.sheet h3 { font-size: 21px; margin: 0; }
.sheet .sheet-head { display: flex; align-items: center; gap: var(--space-2); }
.sheet .sheet-head .spacer { margin-left: auto; }

.member-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-2);
  min-height: 52px;
  border-radius: var(--radius-md); background: var(--color-surface);
}
.member-row .col { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.member-row .n { font-size: 14px; }
.member-row .r { font-size: 11px; color: var(--color-neutral-700); }

.invite-url {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 12px 14px; background: var(--color-surface);
  border-radius: var(--radius-md);
}
.invite-url .u {
  font-size: 12px; word-break: break-all; color: var(--color-neutral-800); flex: 1;
}

/* settings sheet bits */
.setting-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) 0; min-height: 48px;
}
.setting-row .col { display: flex; flex-direction: column; line-height: 1.35; flex: 1; min-width: 0; }
.setting-row .l { font-size: 14px; }
.setting-row .d { font-size: 12px; color: var(--color-neutral-700); }

/* pill toggle */
.toggle {
  position: relative; flex: none; width: 52px; height: 32px;
  border-radius: 999px; border: 0; cursor: pointer;
  background: var(--color-neutral-300); transition: background .15s ease;
  padding: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 4px; left: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--color-bg); box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}
.toggle[aria-checked="true"] { background: var(--color-accent); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }
.toggle:disabled { opacity: .45; cursor: not-allowed; }

/* ── join screen ─────────────────────────────────────────────── */
.join-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-4);
  padding: var(--space-4);
  padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
}
.join-card { width: min(520px, 100%); padding: var(--space-6); gap: var(--space-3); align-items: flex-start; }
.join-card h2 { margin: 0; }
.inviter-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 12px 14px; background: var(--color-bg);
  border-radius: var(--radius-md); width: 100%;
}

/* full-screen friendly error */
.error-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-3);
  padding: var(--space-6); text-align: center;
}

/* utility */
.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.grow { flex: 1; min-width: 0; }
svg.lucide { flex: none; }
