/* Community chat room (/chat/) — loaded only on that route.
   Uses the theme tokens (--fg / --bg / --panel / --hairline / --accent) so it
   inherits every skin and both colour schemes for free. */

/* The room renders inside .main (header.php owns it) — only the inner
   wrapper is ours. Height accounts for the topbar + the admin bar when the
   viewer is logged in, so the composer always sits on screen. */
.chat-off { padding: 60px 28px; }
.chat-off h1 { margin: 0 0 8px; }

.chat-wrap {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  padding: 12px 28px 24px;
  align-items: stretch;
  min-height: 0;
}

/* ---------- room ---------- */
.chat-room {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Fill the viewport under the topbar: the composer must stay put while only
     the message list scrolls — the whole point of a chat layout. */
  height: calc(100vh - 132px);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius, 14px);
  overflow: hidden;
  position: relative;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
  background: var(--panel-solid, var(--panel));
}
.chat-head-t { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-head h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.chat-online {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.chat-online i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 0 3px color-mix(in oklab, #22c55e 25%, transparent);
}
.chat-online b { color: var(--fg); font-weight: 600; }
.chat-note { font-size: 12px; color: var(--muted); }

.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 8px; scrollbar-width: thin; }
.chat-list { display: flex; flex-direction: column; gap: 2px; }

.chat-day { display: flex; align-items: center; gap: 12px; margin: 16px 0 10px; }
.chat-day::before, .chat-day::after { content: ''; flex: 1; height: 1px; background: var(--hairline); }
.chat-day span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.chat-msg {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 3px 6px;
  border-radius: 10px;
  position: relative;
  transition: background 0.15s, opacity 0.2s;
}
.chat-msg:hover { background: color-mix(in oklab, var(--fg) 4%, transparent); }
.chat-msg.is-grouped { margin-top: -2px; }
.chat-msg.is-gone { opacity: 0; }

.chat-av, .chat-av-sp { width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto; }
.chat-av {
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, oklch(0.65 0.15 var(--h, 280)), oklch(0.42 0.13 var(--h, 280)));
}
.chat-msg-c { min-width: 0; padding-top: 1px; }
.chat-msg-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.chat-msg-h b { font-size: 13px; font-weight: 600; }
.chat-msg-h time { font-size: 11px; color: var(--muted); }
.chat-body { font-size: 14px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; }
.chat-body a { color: var(--accent, #6aa6ff); text-decoration: underline; text-underline-offset: 2px; }

.chat-img { display: block; margin-top: 6px; max-width: 320px; }
.chat-img img {
  max-width: 100%; height: auto; border-radius: 10px;
  border: 1px solid var(--hairline); display: block;
}

/* Own messages get a tinted bubble — enough to scan the room, without the
   left/right split that wastes width on a desktop feed. */
.chat-msg.is-mine .chat-msg-c {
  background: color-mix(in oklab, var(--accent, #6aa6ff) 12%, transparent);
  border-radius: 10px; padding: 6px 10px; margin-left: -4px;
}

.chat-tools { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; align-self: start; }
.chat-msg:hover .chat-tools { opacity: 1; }
.chat-tools button {
  background: none; border: 0; cursor: pointer; font-size: 13px; line-height: 1;
  padding: 4px 5px; border-radius: 6px; color: var(--muted);
}
.chat-tools button:hover { background: color-mix(in oklab, var(--fg) 10%, transparent); color: var(--fg); }

.chat-loading { display: flex; gap: 5px; justify-content: center; padding: 20px; }
.chat-loading span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: chatdot 1s infinite ease-in-out;
}
.chat-loading span:nth-child(2) { animation-delay: 0.15s; }
.chat-loading span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatdot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.chat-jump {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 84px; z-index: 3;
  background: var(--fg); color: var(--bg);
  border: 0; border-radius: 999px; padding: 7px 14px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-pop, 0 6px 20px rgba(0,0,0,.3));
}

/* ---------- composer ---------- */
.chat-composer { border-top: 1px solid var(--hairline); padding: 10px 14px 12px; background: var(--panel-solid, var(--panel)); position: relative; }
.chat-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-ico {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: none; border: 0; cursor: pointer; border-radius: 10px;
  color: var(--muted);
}
.chat-ico svg { width: 20px; height: 20px; }
.chat-ico:hover { background: color-mix(in oklab, var(--fg) 8%, transparent); color: var(--fg); }
.chat-composer textarea {
  flex: 1; min-height: 36px; max-height: 140px; resize: none;
  padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--bg); color: var(--fg);
  font: inherit; font-size: 14px; line-height: 1.4;
}
.chat-composer textarea:focus { outline: none; border-color: color-mix(in oklab, var(--accent, #6aa6ff) 60%, var(--hairline)); }
.chat-send {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--accent, #6aa6ff); color: #fff;
}
.chat-send svg { width: 18px; height: 18px; }
.chat-send:hover { filter: brightness(1.08); }

.chat-attach { position: relative; display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.chat-attach img { max-height: 80px; border-radius: 8px; border: 1px solid var(--hairline); display: block; }
.chat-attach-x {
  position: absolute; top: -6px; left: 62px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 0; cursor: pointer; background: var(--fg); color: var(--bg);
  font-size: 14px; line-height: 1;
}
.chat-attach-state { font-size: 12px; color: var(--muted); }

.chat-err {
  margin-top: 8px; font-size: 12px;
  color: #f87171;
}
.chat-locked { border-top: 1px solid var(--hairline); padding: 18px; text-align: center; color: var(--muted); }

/* ---------- emoji ---------- */
.chat-emoji {
  position: absolute; bottom: 60px; left: 14px; z-index: 5;
  width: 300px; max-width: calc(100% - 28px);
  background: var(--panel-solid, var(--panel));
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow-pop, 0 10px 30px rgba(0,0,0,.35));
  display: none;
  overflow: hidden;
}
.chat-emoji.is-open { display: block; }
.chat-emoji-tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--hairline); }
.chat-emoji-tabs button {
  flex: 1; background: none; border: 0; cursor: pointer;
  font-size: 18px; padding: 4px; border-radius: 8px; opacity: 0.55;
}
.chat-emoji-tabs button.is-on { background: color-mix(in oklab, var(--fg) 8%, transparent); opacity: 1; }
.chat-emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 2px; padding: 8px; max-height: 210px; overflow-y: auto;
}
.chat-emoji-grid button {
  background: none; border: 0; cursor: pointer;
  font-size: 20px; line-height: 1; padding: 5px; border-radius: 7px;
}
.chat-emoji-grid button:hover { background: color-mix(in oklab, var(--fg) 10%, transparent); }

/* ---------- side ---------- */
.chat-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.chat-card {
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: var(--radius, 14px); padding: 14px 16px;
}
.chat-card-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.chat-links { display: flex; flex-direction: column; gap: 8px; }
.chat-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--hairline);
  color: var(--fg); text-decoration: none; font-size: 13px; font-weight: 500;
  transition: border-color 0.15s, transform 0.15s;
}
.chat-link .ico { width: 18px; height: 18px; flex: 0 0 auto; }
.chat-link span { flex: 1; }
.chat-link em { font-style: normal; color: var(--muted); font-size: 12px; }
.chat-link:hover { transform: translateX(2px); }
.chat-link.tg:hover { border-color: #2aabee; }
.chat-link.dc:hover { border-color: #5865f2; }
.chat-link.xx:hover { border-color: var(--fg); }
.chat-rules { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.chat-rules li + li { margin-top: 6px; }
.chat-rules p { margin: 0 0 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .chat-wrap { grid-template-columns: 1fr; padding: 10px 16px 20px; }
  .chat-side { flex-direction: row; flex-wrap: wrap; }
  .chat-card { flex: 1 1 260px; }
  .chat-room { height: calc(100vh - 210px); min-height: 420px; }
}
@media (max-width: 640px) {
  .chat-wrap { padding: 8px 10px 16px; }
  .chat-room { height: calc(100vh - 172px); border-radius: 12px; }
  .chat-head { padding: 10px 12px; }
  .chat-note { display: none; }
  .chat-scroll { padding: 12px 10px 6px; }
  .chat-img { max-width: 220px; }
  .chat-side { flex-direction: column; }
}

/* Guest strip above the composer — the daily quota + a register nudge. */
.chat-guestbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-top: 1px solid var(--hairline);
  background: color-mix(in oklab, var(--accent, #6aa6ff) 8%, transparent);
  font-size: 12.5px; color: var(--muted);
}
.chat-guest-join {
  background: none; border: 0; cursor: pointer; padding: 0;
  font: inherit; font-weight: 600; color: var(--accent, #6aa6ff);
}
.chat-guest-join:hover { text-decoration: underline; }
.chat-msg .chat-av.is-guest { background: linear-gradient(135deg, #8b8b8b, #4a4a4a); }
