/* allchat — a conversa é um link */

:root {
  --bg: #ECEEEA;
  --surface: #FFFFFF;
  --ink: #000000;
  --muted: #6B6F69;
  --line: #D6D9D2;
  --hover: rgba(0,0,0,.05);
  --bubble-in: #FFFFFF;
  --bubble-out: #000000;
  --bubble-out-ink: #FFFFFF;
  --field: #FFFFFF;
  --scrim: rgba(20,21,19,.45);
  --shadow: 0 18px 48px rgba(20,21,19,.18);
  --radius: 14px;
  --sans: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Fragment Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --list-w: 360px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513;
    --surface: #1E201D;
    --ink: #F3F4F0;
    --muted: #9A9E96;
    --line: #2C2F2B;
    --hover: rgba(255,255,255,.06);
    --bubble-in: #262925;
    --bubble-out: #F3F4F0;
    --bubble-out-ink: #000000;
    --field: #262925;
    --scrim: rgba(0,0,0,.6);
    --shadow: 0 18px 48px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  touch-action: manipulation;
  position: fixed; inset: 0; width: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
code { font-family: var(--mono); font-size: .92em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }

/* ---------- esqueleto ---------- */
.app {
  height: var(--vvh, 100dvh);
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.pane-list { background: var(--bg); }
.pane-chat { background: var(--bg); }

/* mobile: uma coluna por vez */
.app[data-view="loading"] .pane,
.app[data-view="list"] .pane-chat,
.app[data-view="chat"] .pane-list { display: none; }

@media (min-width: 840px) {
  .app { grid-template-columns: var(--list-w) 1fr; }
  .app[data-view="list"] .pane-chat,
  .app[data-view="chat"] .pane-list,
  .app[data-view="loading"] .pane { display: flex; }
  .pane-list { border-right: 1px solid var(--line); }
  .icon-btn.back { display: none; }
}

/* ---------- barras ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px 16px;
  min-height: 56px;
}
.wordmark { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.wordmark a { text-decoration: none; }
.bar-actions { margin-left: auto; display: flex; gap: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: var(--ink);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.close { font-size: 28px; font-weight: 400; line-height: 1; }

/* ---------- lista de conversas ---------- */
.list-wrap { flex: 1; overflow-y: auto; padding-bottom: 96px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.rooms { list-style: none; margin: 0; padding: 0 8px; }
.room {
  width: 100%; text-align: left;
  display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 10px; border-radius: 12px;
}
.room:hover { background: var(--hover); }
.room[aria-current="true"] { background: var(--surface); }
.room-text { min-width: 0; display: flex; flex-direction: column; }
.room-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.room-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); }
.unread {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 600;
  display: inline-grid; place-items: center;
}

.stripe {
  display: inline-block; flex: none;
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(90deg, var(--line) 0 100%);
}
.stripe.sm { width: 34px; height: 34px; border-radius: 9px; }
.stripe.lg { width: 76px; height: 76px; border-radius: 18px; }

.fab {
  position: absolute; left: 16px; right: 16px; bottom: calc(16px + var(--safe-b));
  height: 52px; border-radius: 26px;
  background: var(--ink); color: var(--bg);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 600; font-size: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.fab:active { transform: translateY(1px); }
@media (min-width: 840px) {
  .fab { left: 16px; right: 16px; }
}

.empty { padding: 56px 28px 0; text-align: center; }
.empty-stripe {
  width: 76px; height: 76px; border-radius: 18px; margin: 0 auto 20px;
  background: linear-gradient(90deg, var(--line) 0 20%, var(--muted) 20% 40%, var(--line) 40% 60%, var(--muted) 60% 80%, var(--line) 80%);
  opacity: .5;
}
.empty-title { font-weight: 600; margin: 0 0 6px; font-size: 17px; }
.empty-sub { color: var(--muted); margin: 0; font-size: 15px; max-width: 30ch; margin-inline: auto; }

/* ---------- conversa ---------- */
.chat-placeholder {
  flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px;
}
.placeholder-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--line); margin-bottom: 14px; opacity: .6; }
.chat-placeholder p { margin: 0; }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-bar { padding-left: 8px; background: var(--bg); border-bottom: 1px solid var(--line); gap: 6px; }
@media (min-width: 840px) { .chat-bar { padding-left: 16px; } }
.chat-id {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 4px 8px 4px 4px; border-radius: 10px;
}
.chat-id:hover { background: var(--hover); }
.chat-id-text { min-width: 0; display: flex; flex-direction: column; }
.chat-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.chat-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 4px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.messages > :first-child { margin-top: auto; }
.messages {
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { .messages { scroll-behavior: auto; } }
@media (min-width: 840px) { .messages { padding: 24px 32px 12px; } }

.msg { display: flex; flex-direction: column; max-width: min(84%, 560px); align-self: flex-start; }
@media (min-width: 840px) { .msg { max-width: min(72%, 560px); } }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg + .msg.gap { margin-top: 8px; }
.msg-name { font-size: 12px; color: var(--muted); margin: 0 0 2px 12px; }
.bubble {
  padding: 9px 13px; border-radius: 18px;
  background: var(--bubble-in); color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 16px; line-height: 1.38;
  border-bottom-left-radius: 6px;
}
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-ink); border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.msg-time { font-size: 11px; color: var(--muted); margin: 3px 12px 0; }
.msg.out .msg-time { text-align: right; }
.msg-time .warn { color: #C0392B; }
.sys { align-self: center; text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0 6px; max-width: 70%; }
.sys .stamp { display: block; font-size: 12px; opacity: .8; }

.jump {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b));
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; box-shadow: var(--shadow); z-index: 5;
}
.chat { position: relative; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(10px + var(--safe-b)) 12px;
  border-top: 1px solid var(--line); background: var(--bg);
}
@media (min-width: 840px) { .composer { padding: 10px 24px 14px; } }
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  padding: 11px 16px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--field); line-height: 1.35; font-size: 16px;
}
.composer textarea:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: transparent; }
.send {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--ink); color: var(--bg); display: grid; place-items: center;
}
.send:disabled { opacity: .35; cursor: default; }

/* ---------- folhas ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; }
.sheet {
  position: fixed; z-index: 30; background: var(--surface); color: var(--ink);
  left: 0; right: 0; bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(24px + var(--safe-b));
  max-height: 92dvh; overflow-y: auto;
  box-shadow: var(--shadow);
  animation: rise .28s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 840px) {
  .sheet {
    left: 50%; top: 50%; bottom: auto; right: auto;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 40px)); border-radius: 20px;
    padding: 14px 28px 28px; max-height: 88vh;
    animation: pop .22s cubic-bezier(.2,.8,.2,1);
  }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes pop { from { transform: translate(-50%, -48%); opacity: 0 } to { transform: translate(-50%, -50%); opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-bar { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px; }
.sheet-bar h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; flex: 1; }
.sheet h2 { font-size: 22px; letter-spacing: -.015em; font-weight: 700; line-height: 1.2; margin: 0 0 8px; }
.sheet p { margin: 0 0 14px; color: var(--muted); font-size: 15px; line-height: 1.45; }
.fine { font-size: 13px !important; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; position: relative; }
.form input, .form textarea {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--field);
  font-size: 16px; font-weight: 400; width: 100%;
}
.form input:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: transparent; }
.form small { font-weight: 400; color: var(--muted); font-size: 13px; line-height: 1.35; }
.form.inline { flex-direction: row; flex-wrap: wrap; gap: 8px; }
.form.inline input { flex: 1 1 120px; padding: 10px 12px; }
.form.inline .btn { flex: 0 0 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: transparent; }
.btn.primary:hover { opacity: .92; }
.btn:disabled { opacity: .5; cursor: default; }

/* boas-vindas */
.sheet-welcome { padding-top: 0; }
@media (max-width: 839px) {
  .sheet-welcome { top: 0; border-radius: 0; max-height: none; padding-top: calc(16px + var(--safe-t)); display: flex; flex-direction: column; justify-content: flex-end; }
}
@media (min-width: 840px) { .sheet-welcome { width: min(560px, calc(100vw - 40px)); padding-top: 24px; } }
.welcome-hero { padding: 18px 0 10px; }
.welcome-stripes { display: flex; gap: 8px; margin-bottom: 26px; }
.welcome-stripes i { display: block; width: 44px; height: 44px; border-radius: 11px; background: var(--line); transition: background .9s ease; }
.welcome-hero h2 { font-size: 30px; letter-spacing: -.025em; line-height: 1.1; margin-bottom: 12px; max-width: 14ch; }
.welcome-hero p { color: var(--muted); font-size: 16px; max-width: 46ch; }
.welcome-hero .welcome-quiet { color: var(--ink); }

/* entrar */
.join-head { padding: 16px 0 8px; }
.join-head .stripe { margin-bottom: 18px; }

/* nova conversa */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 8px 6px 12px; border-radius: 999px; background: var(--bg); font-weight: 500; font-size: 14px;
}
.chip button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; line-height: 1; color: var(--muted); }
.chip button:hover { background: var(--hover); color: var(--ink); }
.suggest { display: flex; flex-direction: column; gap: 2px; }
.suggest:empty { display: none; }
.suggest button { text-align: left; padding: 8px 10px; border-radius: 8px; font-weight: 400; display: flex; gap: 8px; align-items: baseline; }
.suggest button:hover { background: var(--hover); }
.suggest button span { color: var(--muted); font-size: 13px; }

/* link */
.link-card { display: flex; gap: 16px; align-items: center; padding: 6px 0 16px; }
.link-meta { min-width: 0; }
.link-name { font-weight: 600; font-size: 17px; margin-bottom: 6px; }
.link-url { display: block; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; line-height: 1.45; }
.link-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.link-actions .btn { flex: 1 1 140px; }
.members { margin-top: 6px; }
.members h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 14px 0 8px; }
.members ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.members li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.members li .who { flex: 1; min-width: 0; }
.members li .who b { display: block; font-weight: 600; }
.members li .who span { color: var(--muted); font-size: 13px; }
.members li .add { font-size: 14px; font-weight: 600; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); }
.members li .add:hover { background: var(--hover); }

/* contatos */
.contacts { list-style: none; margin: 10px 0 0; padding: 0; }
.contacts li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.contacts li:first-child { border-top: 0; }
.contacts .who { flex: 1; min-width: 0; }
.contacts .who b { display: block; font-weight: 600; }
.contacts .who span { color: var(--muted); font-size: 13px; }
.contacts .talk { font-size: 14px; font-weight: 600; padding: 7px 12px; border-radius: 8px; background: var(--ink); color: var(--bg); }
.contacts .rm { color: var(--muted); font-size: 20px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; }
.contacts .rm:hover { background: var(--hover); color: var(--ink); }
.me { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.me b { color: var(--ink); }
.me button { margin-left: 8px; text-decoration: underline; color: var(--muted); }
.move-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.move-row .btn { flex: 1 1 160px; font-size: 15px; padding: 11px 14px; }
#moveCode { font-family: var(--mono); font-size: 12.5px; line-height: 1.45; resize: vertical; min-height: 96px; overflow-wrap: anywhere; }
.install { margin: 4px 0 12px; display: flex; flex-direction: column; gap: 10px; }
.install .fine { margin: 0; }

/* sobre */
.prose p { color: var(--ink); font-size: 16px; line-height: 1.5; margin-bottom: 14px; }
.prose p.fine { color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 500; z-index: 40; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
