/* PER-PARK CHAT - all of the chat feature's styling, in its own file.
 *
 * WHY A SEPARATE FILE AT ALL. web/style.css is edited by several parallel
 * streams and it is 95 KB of the map's own vocabulary; a chat panel is a
 * self-contained surface that needs none of it. Everything here is
 * namespaced under #chatpanel / #chattab / #chattoasts / .chat*, so the
 * only selectors that reach outside the feature are the four documented
 * body-class rules in the STACKED block below - and each of those exists
 * because the operator's rule is about the LAYOUT, not about chat.
 *
 * IT DELIBERATELY REUSES style.css's TOKENS (--bg2/--line/--accent/...)
 * rather than inventing a palette. A second panel that does not look like
 * the first one is a second panel; the operator asked to "just duplicate
 * the side panel we already have but on the left side", so the numbers
 * here (380px basis, 45vw cap, 0.25s flex-basis transition, the 20px tab)
 * are the shipped #panel / #paneltab numbers MIRRORED, not re-chosen.
 *
 * THE MAP IS NEVER COVERED. #chatpanel is a FLEX ITEM of <main>, exactly
 * as #panel is, so opening it takes layout space and shrinks #mapwrap
 * (chat.js calls the host's map.invalidateSize() after the transition).
 * There is no position:fixed anywhere in the desktop panel - a floating
 * overlay was the one thing the operator ruled out ("Not over top of the
 * map").
 */

/* ================================================================== *
 * THE LEFT PANEL (desktop: a mirror of #panel)
 * ================================================================== */
#chatpanel {
  flex: 0 0 340px;
  max-width: 45vw;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  /* the panel body scrolls per-section (#chatlog), not as a whole: the
   * composer must stay reachable while the log scrolls, which is the one
   * way this panel is NOT #panel */
  overflow: hidden;
  transition: flex-basis 0.25s ease;
}
#chatpanel.collapsed {
  flex-basis: 0;
  max-width: 0;
  border-right: none;
  overflow: hidden;
}
/* nothing inside a collapsed panel may be focusable or measurable: a
 * zero-width flex item still lays its children out, and this project has
 * fixed horizontal-overflow bugs three times that came from exactly that
 * (a laid-out-but-invisible element counting in scrollWidth) */
#chatpanel.collapsed > * { display: none; }

/* the slim always-visible tab, mirroring #paneltab (which sits on the
 * other side of the map with border-LEFT) */
#chattab {
  flex: 0 0 20px;
  padding: 0;
  background: var(--bg2);
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--line);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  position: relative;
}
#chattab:hover { color: var(--accent); }
/* UNREAD ON THE TAB ITSELF. The tab is the only part of chat that is
 * visible while the panel is collapsed, so it carries the count - a
 * notification you can only see by opening the thing it is about is not a
 * notification. */
#chattab .chattabdot {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 15px;
  padding: 0 2px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1016;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}
#chatpanel.hidden, #chattab.hidden { display: none !important; }

/* ---------- header ---------- */
#chathead {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px 8px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
#chathead .chattitle {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}
#chathead .chattitle .chatsub {
  display: block;
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  text-transform: none;
}
/* ------------------------------------------------------------------ *
 * THE SURFACE TABS: community | global | feed.
 * A strip, not a dropdown - three destinations that must all be one tap
 * away, because the whole point of the change that added them is that
 * chat is always reachable.
 * ------------------------------------------------------------------ */
#chatviews {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
#chatviews.hidden { display: none; }
.chatview {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap, 28px);
  padding: 4px 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}
.chatview:hover { color: var(--fg); border-color: var(--line); }
.chatview.chatviewon {
  background: var(--bg3);
  color: var(--fg);
  border-color: var(--accent);
  font-weight: 700;
}
.chatview.hidden { display: none; }
/* the feed's unread count. A DOT WITH A NUMBER, not a badge that steals
 * the tab's width - the tab still has to read as its own label. */
.chatviewdot {
  display: inline-block;
  margin-left: 5px;
  min-width: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-size: 9.5px;
  font-weight: 700;
  line-height: 15px;
  vertical-align: middle;
}
.chatviewdot.hidden { display: none; }

/* A FEED ROW is a message plus the room it came from, and it is
 * clickable - it opens that room (see onLogClick). */
.chatfeedrow {
  padding: 5px 8px;
  border-left: 2px solid var(--line);
  margin-bottom: 6px;
  cursor: pointer;
  border-radius: 0 6px 6px 0;
}
.chatfeedrow:hover { border-left-color: var(--accent); background: var(--bg3); }
.chatfeedrow .chatfeedpark {
  font-weight: 700;
  color: var(--accent);
  margin-right: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

/* THE ROOMS-PAGE SEARCH. Sticky, so it stays reachable while a long list
 * scrolls under it - the point of a filter is to reach a room you cannot
 * currently see. */
.chatsearch {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 0 6px;
  background: var(--bg2, var(--bg));
}
#chatroomq {
  width: 100%;
  min-height: var(--tap, 28px);
  padding: 5px 8px;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
}
#chatroomq:focus { border-color: var(--accent); outline: none; }

/* PER-MESSAGE CONTROLS. Quiet until the message is hovered or something
 * inside it has keyboard focus - a row of buttons on every message turns a
 * conversation into a control panel. `:focus-within` is what keeps them
 * reachable without a mouse. */
.chatact {
  background: none;
  border: 0;
  padding: 0 3px;
  margin-left: 4px;
  color: var(--muted);
  font: inherit;
  font-size: 10.5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.chatmsg:hover .chatact,
.chatmsg:focus-within .chatact { opacity: 1; }
.chatact:hover { color: var(--accent); text-decoration: underline; }

/* THE EDITED MARKER. Always visible (unlike the action buttons) - it is a
 * statement about the text, not a control - and its `title` carries the
 * ORIGINAL message, which is the whole point of it. */
.chatedited {
  margin-left: 4px;
  color: var(--muted);
  font-size: 10.5px;
  cursor: help;
}
.chatedited:hover, .chatedited:focus { color: var(--accent); outline: none; }

/* A TOMBSTONE keeps the author and the time and loses everything else. */
.chatdeleted { color: var(--muted); font-style: italic; font-size: 12px; }
.chatmsg.chatgone { opacity: 0.72; }

.chatbtn {
  flex: 0 0 auto;
  min-height: var(--tap, 28px);
  min-width: var(--tap, 28px);
  padding: 3px 7px;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.chatbtn:hover { border-color: var(--accent); color: var(--accent); }
.chatbtn[disabled] { opacity: 0.5; cursor: default; }
.chatbtn[disabled]:hover { border-color: var(--line); color: var(--fg); }
.chatbtn.chatprimary { border-color: var(--accent); color: var(--accent); }

/* ---------- the log ---------- */
#chatlog {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* the panel's own horizontal containment: a pasted log line is the one
   * thing in here that can be arbitrarily wide, and #chatlog absorbing it
   * keeps <main> from scrolling sideways */
  overflow-x: hidden;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.chatmsg { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chatmeta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 10.5px;
  color: var(--muted);
}
.chatwho { color: var(--fg); font-weight: 600; font-size: 11.5px; }
.chatmsg.chatmine .chatwho { color: var(--accent); }
.chatbody {
  font-size: 12.5px;
  line-height: 1.42;
  /* people paste log lines: keep the newlines, wrap the long tokens, and
   * never let one widen the panel */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chatnew {
  /* THE UNREAD LINE. A count on a tab says how many; this says WHICH. */
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
}
.chatnew::before, .chatnew::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--accent);
  opacity: 0.45;
}

/* ---------- photos ---------- */
.chatphotos {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 3px;
}
.chatphotos a {
  display: block;
  line-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.chatphotos a:hover { border-color: var(--accent); }
.chatphotos img {
  display: block;
  max-width: 132px;
  max-height: 132px;
  width: auto;
  height: auto;
  background: var(--bg3);
}
.chatflat {
  font-size: 9.5px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 5px;
}

/* ---------- composer ---------- */
#chatcompose {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chatrow { display: flex; align-items: flex-end; gap: 6px; }
#chatinput {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  min-height: 34px;
  max-height: 120px;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.35;
}
#chatinput:focus { border-color: var(--accent); outline: none; }
#chatpending { display: flex; flex-wrap: wrap; gap: 5px; }
#chatpending:empty { display: none; }
.chatpend {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
}
.chatpend img { display: block; width: 54px; height: 54px;
                object-fit: cover; background: var(--bg3); }
.chatpend.chatpendbusy { border-style: dashed; }
.chatpend .chatpendx {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  border: none;
  border-radius: 999px;
  background: rgba(9, 12, 16, 0.82);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.chatpend .chatpendspin {
  display: block;
  width: 54px;
  height: 54px;
  line-height: 54px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

/* ---------- notes / errors ---------- */
.chatnote {
  flex: 0 0 auto;
  margin: 0;
  padding: 7px 12px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.chatnote.chatbad { color: var(--bad); }
.chatnote.hidden { display: none; }
.chatempty { color: var(--muted); font-size: 12px; font-style: italic; }

/* ================================================================== *
 * THE ROOMS HOME PAGE (pop-out window with no #park=)
 * ================================================================== */
.chatrooms { display: flex; flex-direction: column; gap: 6px; }
.chatroomrow {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  font: inherit;
  cursor: pointer;
  min-width: 0;
}
.chatroomrow:hover { border-color: var(--accent); }
.chatroomrow .chatroomtop {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.chatroomrow .chatroomname {
  font-size: 12.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
}
.chatroomrow .chatroomprev {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chatpill {
  flex: 0 0 auto;
  font-size: 9.5px;
  border-radius: 999px;
  padding: 0 6px;
  border: 1px solid var(--muted);
  color: var(--muted);
  white-space: nowrap;
}
.chatpill.chatrecent { border-color: var(--good); color: var(--good); }
.chatpill.chatunreadpill { border-color: var(--accent); color: var(--accent); }

/* ================================================================== *
 * TOASTS - "float it over the whole UI for a few seconds at the bottom
 * right" (operator). This is the ONE fixed-position surface in the
 * feature; it is transient by definition and it is what the panel
 * exists NOT to be.
 * ================================================================== */
#chattoasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 2200;          /* over #maploading (1400) and the banners */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  /* the container must never eat map clicks - only the toasts do */
  pointer-events: none;
  max-width: min(340px, calc(100vw - 28px));
}
.chattoast {
  pointer-events: auto;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-left-width: 3px;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  padding: 8px 10px;
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
  animation: chat-toast-in 0.18s ease-out;
}
.chattoast .chattoastwho {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.chattoast .chattoastwho .chattoastpark {
  font-weight: 400;
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chattoast .chattoastbody {
  font-size: 12px;
  line-height: 1.35;
  margin-top: 2px;
  /* a toast is a PREVIEW: three lines, then it stops. An unbounded body
   * would let one pasted log line cover the map the panel refuses to. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
@keyframes chat-toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .chattoast { animation: none; }
}

/* ================================================================== *
 * THE UNREAD PULSE on the presence control (operator: "once every 30
 * seconds make the presence view pulse with the color for who sent it").
 *
 * THE COLOUR IS INJECTED, NOT CHOSEN HERE: chat.js sets --chatpulse from
 * the SHIPPED disjoint presence classifier (classifyPresence), so the
 * pulse hue is the same token the pill's dot and the map pin already use
 * for that person. A second grouping in CSS would be the double-listing
 * bug this app has already fixed once.
 * ================================================================== */
.chatpulse {
  animation: chat-presence-pulse 1.25s ease-in-out 1;
  border-color: var(--chatpulse, var(--accent)) !important;
}
@keyframes chat-presence-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
  45% { box-shadow: 0 0 0 4px var(--chatpulse, var(--accent)); }
}
/* .flpulse's rule, followed exactly: no motion, but the SIGNAL SURVIVES -
 * a steady ring rather than a breathing one. A reduced-motion user must
 * not simply lose the notification. */
@media (prefers-reduced-motion: reduce) {
  .chatpulse {
    animation: none;
    box-shadow: 0 0 0 3px var(--chatpulse, var(--accent));
  }
}

/* ================================================================== *
 * STANDALONE POP-OUT WINDOW (web/chat.html)
 * ================================================================== */
/* chat.html loads style.css TOO - the tokens above (--bg2/--line/...) and
 * the global `.hidden` live there, and a pop-out that invented its own
 * palette would be a second look for the same feature. So this block only
 * has to undo the SPA body (a flex COLUMN sized to the viewport) enough
 * for one panel to fill the window. */
body.chatstandalone {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.chatstandalone #chatpanel {
  flex: 1 1 auto;
  max-width: none;
  border-right: none;
  transition: none;
}
/* a window whose whole reason to exist is the panel cannot collapse it */
body.chatstandalone #chattab { display: none !important; }

/* ================================================================== *
 * STACKED / MOBILE (<=860px - the width at which style.css turns <main>
 * into a COLUMN and hides #paneltab; mirrored, not re-chosen, and
 * chat.js's MQ_STACK matches this literal).
 *
 * THE OPERATOR'S RULE: "On mobile users should be able to see the
 * communities accordion, or the chat. not both", and "the half screen
 * panel can be expanded or hidden and toggled easily". So:
 *   chat CLOSED -> #panel (the accordion) is the bottom half, as shipped
 *   chat HALF   -> #chatpanel is the bottom half and #panel is GONE
 *   chat BIG    -> #chatpanel takes the viewport and the map is GONE
 *                  (body.kbd-search's shipped precedent for "give this
 *                  panel the whole phone screen")
 * #chattab becomes a full-width bar between the map and the panel: on a
 * phone a 20px vertical strip at the screen edge is not a tap target.
 * ================================================================== */
@media (max-width: 860px) {
  #chatpanel, #chatpanel.collapsed {
    /* ORDER, not DOM position: #chatpanel is the first child of <main> so
     * that the desktop row puts it left of the map, and in the column it
     * has to come back down to where #panel is. */
    order: 3;
    flex: 0 0 45%;
    max-width: none;
    border-right: none;
    border-top: 1px solid var(--line);
    transition: none;
  }
  /* collapsed on a phone means GONE, not zero-height: the tab bar below
   * is the affordance that brings it back */
  #chatpanel.collapsed { display: none; }
  #chatpanel.collapsed > * { display: none; }

  #chattab {
    order: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
    min-height: 34px;
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--line);
    font-size: 12px;
    letter-spacing: 0.3px;
  }
  #chattab .chattabdot {
    position: static;
    transform: none;
    left: auto;
    top: auto;
  }
  /* ONE OR THE OTHER. This is the only rule in this file that styles an
   * element the map owns, and it is the operator's requirement stated
   * directly: with chat open on a phone the communities accordion is not
   * also on screen. */
  body.chatopen #panel, body.chatopen #panel.collapsed { display: none; }
  body.chatopen #paneltab { display: none; }
  /* EXPANDED: the map yields, exactly as it does for keyboard search */
  body.chatbig #mapwrap { display: none; }
  body.chatbig #chatpanel, body.chatbig #chatpanel.collapsed {
    flex: 1 1 auto;
    min-height: 0;
  }
  /* a phone's toast sits above the tab bar rather than on top of it */
  #chattoasts { right: 8px; bottom: 46px; left: 8px; max-width: none; }
  .chattoast { width: 100%; }
}
