/* =========================================================================
   Chat — room list + the shared conversation view (also used by Messages).
   Tokens come from css/app.css. Mobile-first; the conversation gets a real
   height from JS so the log scrolls internally and the composer stays put.
   ========================================================================= */

/* ------------------------------------------------------------- room list */

.chat-intro {
  color: var(--muted);
  font-size: .9rem;
  margin: calc(var(--s-2) * -1) 0 var(--s-4);
}

.chat-rooms {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
  overflow: hidden;
}

.chat-room {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 68px;
  padding: var(--s-3) var(--s-4);
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  text-align: left;
  color: inherit;
}
.chat-room:first-child { border-top: 0; }
.chat-room:hover { background: var(--surface-2); }
.chat-room:active { background: var(--surface-3); }

.chat-room-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  line-height: 1;
  border-radius: var(--r-sm);
  background: var(--blue-soft);
  color: #16a34a;
}
.chat-room-icon svg { width: 22px; height: 22px; stroke-width: 2; }
.chat-room-icon svg path, .chat-room-icon svg rect, .chat-room-icon svg circle { fill: color-mix(in srgb, currentColor 18%, transparent); }

.chat-room-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-room-name { font-weight: 600; font-size: .97rem; }
.chat-room-last {
  color: var(--muted);
  font-size: .84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-room-meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.chat-room-time { color: var(--muted); font-size: .74rem; white-space: nowrap; }
.chat-room-count {
  font-size: .68rem;
  font-weight: 700;
  color: var(--slate);
  background: var(--surface-2);
  border-radius: var(--r-pill);
  padding: 1px 7px;
}

/* ---------------------------------------------------------- room header */

.chat-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.chat-back {
  flex: 0 0 auto;
  margin-left: -8px;
  font-size: 20px;
  line-height: 1;
}
.chat-head-main { flex: 1 1 auto; min-width: 0; }
.chat-head-name {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  font-size: 1.1rem;
}
.chat-head-icon { display: inline-flex; vertical-align: -3px; margin-right: 6px; color: #16a34a; }
.chat-head-icon svg { width: 20px; height: 20px; stroke-width: 2; }
.chat-head-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .82rem;
}

/* ------------------------------------------------------- conversation */

.chat-conv {
  display: flex;
  flex-direction: column;
  min-height: 300px;
  gap: var(--s-2);
}

/* The conversation is sized to the viewport in JS (it scrolls internally), so
   the shell's tab-bar padding underneath it would only add a stray page
   scroll. Rooms lists and every other route keep the default padding. */
#view:has(.chat-conv) {
  padding-bottom: calc(var(--s-2) + var(--sa-bottom));
}

.chat-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.chat-log {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-2) 2px var(--s-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
}
.chat-log:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 30%, transparent); }
.chat-log .empty { margin: auto; }
.chat-log .skeleton-wrap { padding: var(--s-3); }

.chat-jump {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 2;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--navy);
  font-size: .78rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  box-shadow: var(--sh-2);
}
.chat-jump[hidden] { display: none; }

/* --------------------------------------------------------- day divider */

.chat-day {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--s-3) 0 var(--s-2);
}
.chat-day-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--r-pill);
  padding: 3px 12px;
}

/* -------------------------------------------------------------- bubbles */

.msg {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: 1px var(--s-3);
}
.msg.grouped { margin-top: -1px; }
.msg + .msg:not(.grouped) { margin-top: var(--s-2); }

.msg-gutter { flex: 0 0 auto; width: 34px; }

.msg-avatar {
  flex: 0 0 auto;
  border: 0;
  background: none;
  padding: 0;
  line-height: 0;
  border-radius: var(--r-pill);
}

.msg-bubble {
  max-width: min(78%, 520px);
  padding: 8px 12px 6px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
}

.msg.theirs .msg-bubble { border-bottom-left-radius: 5px; }
.msg.theirs.grouped .msg-bubble { border-bottom-left-radius: 16px; border-top-left-radius: 5px; }

.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-bubble {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg.mine.grouped .msg-bubble { border-bottom-right-radius: 16px; border-top-right-radius: 5px; }

.msg-name {
  display: block;
  border: 0;
  background: none;
  padding: 0;
  margin: 0 0 2px;
  font-size: .78rem;
  font-weight: 700;
  color: var(--slate);
  text-align: left;
}
.msg-name:hover { text-decoration: underline; }

.msg-text {
  margin: 0;
  font-size: .94rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-link { color: var(--blue); text-decoration: underline; }
.msg.mine .msg-link { color: #cfe0ff; }

.msg-time {
  display: block;
  margin-top: 2px;
  font-size: .68rem;
  color: var(--muted);
  text-align: right;
}
.msg.mine .msg-time { color: rgba(255, 255, 255, .72); }
.msg.pending { opacity: .72; }

/* ------------------------------------------------------------ composer */

.chat-notice-slot:empty { display: none; }
.chat-seed-note {
  margin: 0;
  padding: 6px var(--s-3);
  font-size: .76rem;
  color: var(--muted);
  text-align: center;
}

.chat-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
}

.chat-input {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 150px;
  padding: 11px var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
}
.chat-input:disabled { opacity: .6; }

.chat-count {
  flex: 0 0 auto;
  align-self: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
}
.chat-count[hidden] { display: none; }

.chat-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--navy);
  color: #fff;
  line-height: 1;
  display: grid;
  place-items: center;
}
.chat-send svg { width: 20px; height: 20px; stroke-width: 2; }
.chat-send:hover { background: var(--navy-500); }
.chat-send:disabled { opacity: .5; }

.chat-locked {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-3);
  background: var(--blue-soft);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--navy);
  font-size: .87rem;
  font-weight: 600;
}
.chat-locked-text { flex: 1 1 180px; }

/* ----------------------------------------------------------- dark mode */

@media (prefers-color-scheme: dark) {
  .msg.mine .msg-bubble { background: var(--navy-500); border-color: var(--navy-500); }
  .chat-room-icon { background: var(--surface-3); }
  .chat-locked { background: var(--surface-2); color: var(--ink); }
  .chat-jump { color: var(--ink); }
}

/* ------------------------------------------------------------- desktop */

@media (min-width: 900px) {
  .msg-bubble { max-width: min(68%, 560px); }
  .chat-conv { gap: var(--s-3); }
}
