/* Chat page of tessairact|code. Tokens mirror web/styles.css; the chat page loads only its own files. */

:root {
  color-scheme: light;
  --bg: #eef3ef;
  --panel-solid: #ffffff;
  --panel-raised: #f4f7f4;
  --line: rgba(31, 47, 52, 0.18);
  --line-strong: rgba(31, 47, 52, 0.34);
  --text: #142126;
  --muted: #53666d;
  --muted-bright: #34474d;
  --cyan: #006f78;
  --cyan-soft: rgba(0, 111, 120, 0.11);
  --lime: #356f1d;
  --amber: #8c5700;
  --red: #b42318;
  --blue: #245fbe;
  --purple: #6f42a5;
  --radius: 10px;
  --sidebar: 248px;
  --thread: 380px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.chat-root {
  height: 100%;
}

.chat-loading {
  margin: 0;
  padding: 48px 24px;
  color: var(--muted);
  text-align: center;
}

/* Shared controls */

.chat-button {
  display: inline-flex;
  text-decoration: none;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-solid);
  font-weight: 600;
  cursor: pointer;
}

.chat-button:hover:not(:disabled) {
  border-color: var(--cyan);
  color: var(--cyan);
}

.chat-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.chat-button-primary {
  border-color: var(--cyan);
  background: var(--cyan);
  color: #fff;
}

.chat-button-primary:hover:not(:disabled) {
  background: #005a62;
  color: #fff;
}

.chat-button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted-bright);
}

.chat-button-quiet:hover:not(:disabled) {
  border-color: transparent;
  background: var(--cyan-soft);
}

.chat-button-danger {
  border-color: var(--red);
  color: var(--red);
}

.chat-button-danger:hover:not(:disabled) {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.chat-field {
  display: grid;
  gap: 4px;
}

.chat-field-label {
  color: var(--muted-bright);
  font-size: 12px;
  font-weight: 700;
}

.chat-field-hint {
  color: var(--muted);
  font-size: 12px;
}

.chat-field input,
.chat-field select,
.chat-input {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-solid);
}

.chat-error {
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.chat-badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--cyan-soft);
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.chat-badge-mention {
  background: var(--red);
  color: #fff;
}

.chat-avatar {
  display: inline-grid;
  flex: none;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 9px;
  background: var(--chat-person-color, var(--cyan));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chat-avatar[data-tone="1"] { background: var(--lime); }
.chat-avatar[data-tone="2"] { background: var(--amber); }
.chat-avatar[data-tone="3"] { background: var(--red); }
.chat-avatar[data-tone="4"] { background: var(--blue); }
.chat-avatar[data-tone="5"] { background: var(--purple); }
.chat-avatar[data-tone="6"] { background: #31545b; }
.chat-avatar[data-tone="7"] { background: #9b3d6e; }
.chat-avatar[data-kind="agent"] { border-radius: 50%; background: #1f2f34; }

/* Sign-in and join */

.chat-auth {
  display: grid;
  min-height: 100%;
  padding: 24px 16px;
  place-items: center;
  background:
    radial-gradient(circle at 12% 4%, rgba(0, 111, 120, 0.09), transparent 32%),
    linear-gradient(180deg, rgba(248, 251, 247, 0.98), rgba(232, 239, 234, 0.98));
}

.chat-auth-card {
  display: grid;
  gap: 14px;
  width: min(100%, 380px);
  padding: 26px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-solid);
  box-shadow: 0 12px 40px rgba(20, 33, 38, 0.08);
}

.chat-auth-card h1 {
  margin: 0;
  font-size: 20px;
}

.chat-auth-card p {
  margin: 0;
  color: var(--muted);
}

/* An alert in a card stays red: the card's own paragraph colour must not mute it. */
.chat-auth-card .chat-error {
  color: var(--red);
}

.chat-auth-form {
  display: grid;
  gap: 12px;
}

.chat-code-input {
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Shell */

.chat-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  height: 100%;
}

.chat-shell[data-thread="open"] {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--thread);
}

.chat-sidebar {
  display: grid;
  /* Two children: the scrolling channel list and the foot (call bar, profile, account). */
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel-raised);
}

.chat-sidebar-scroll {
  /* Containing block for the visually hidden (absolute) labels in the list, so the scroller clips
     them; otherwise the rows below the fold make the whole page taller than the window. */
  position: relative;
  min-height: 0;
  padding: 4px 8px 12px;
  overflow-y: auto;
}

.chat-sidebar-title {
  margin: 12px 6px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chat-channel {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.chat-channel:hover {
  background: var(--cyan-soft);
}

.chat-channel[data-archived="true"] {
  color: var(--muted);
}

.chat-channel[aria-current="true"] {
  background: var(--cyan);
  color: #fff;
}

.chat-channel[data-unread="true"] .chat-channel-name {
  font-weight: 700;
}

.chat-channel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-agent-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  color: var(--muted-bright);
  font-size: 13px;
}

.chat-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}

.chat-dot[data-on="true"] {
  background: var(--lime);
}

.chat-agent-state {
  color: var(--muted);
  font-size: 12px;
}

.chat-sidebar-foot {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
}

.chat-me {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.chat-me-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-me-handle {
  color: var(--muted);
  font-size: 12px;
}

.chat-foot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Main column */

/* One column that never grows past the pane: a long line inside (a channel topic) ellipsizes
   instead of widening the page. */
.chat-main,
.chat-thread {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: var(--panel-solid);
}

.chat-thread {
  border-left: 1px solid var(--line);
}

.chat-main[data-drop="true"]::after {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--cyan);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--cyan);
  font-weight: 700;
  content: "Drop files to attach them";
  pointer-events: none;
}

.chat-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  margin: 0;
  font-size: 15px;
}

/* A block, so the one line ends in an ellipsis at every width (an inline span cannot clip). */
.chat-header-topic {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The thread's title block; its channel line shows on phones only. */
.chat-thread-titles {
  min-width: 0;
}

/* Parts of the phone shell (mobile_shell.js / mobile_shell.css); hidden at every other layout. */
.chat-phone-only,
.chat-phone-screen,
.chat-tabbar {
  display: none;
}

.chat-banner {
  margin: 0;
  padding: 6px 18px;
  background: rgba(140, 87, 0, 0.12);
  color: var(--amber);
  font-size: 13px;
}

.chat-list {
  min-height: 0;
  padding: 8px 0 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-list-empty {
  margin: 0;
  padding: 40px 24px;
  color: var(--muted);
  text-align: center;
}

.chat-older {
  display: flex;
  justify-content: center;
  padding: 6px 0 10px;
}

.chat-day {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 12px 18px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-day::before,
.chat-day::after {
  flex: 1;
  height: 1px;
  background: var(--line);
  content: "";
}

.chat-new-pill {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 6px 18px rgba(20, 33, 38, 0.18);
}

/* Messages */

.chat-message {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 6px 18px;
}

.chat-message:hover,
.chat-message:focus-within {
  background: var(--panel-raised);
}

.chat-message[data-mentions-me="true"] {
  box-shadow: inset 3px 0 0 var(--amber);
  background: rgba(140, 87, 0, 0.06);
}

.chat-message-head {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
}

.chat-author {
  font-weight: 700;
}

.chat-time,
.chat-edited {
  color: var(--muted);
  font-size: 12px;
}

.chat-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-text a {
  color: var(--blue);
}

.chat-text code,
.chat-codeblock {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-raised);
  font-family: var(--mono);
  font-size: 12.5px;
}

.chat-text code {
  padding: 1px 4px;
}

.chat-codeblock {
  display: block;
  margin: 4px 0;
  padding: 8px 10px;
  overflow-x: auto;
  white-space: pre;
}

.chat-deleted {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

.chat-mention {
  padding: 0 3px;
  border-radius: 4px;
  background: var(--cyan-soft);
  color: var(--cyan);
  font-weight: 600;
}

.chat-mention[data-me="true"] {
  background: rgba(140, 87, 0, 0.18);
  color: var(--amber);
}

.chat-chip {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  max-width: 100%;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-solid);
  color: inherit;
  font-size: 13px;
  text-decoration: none;
  vertical-align: baseline;
  white-space: nowrap;
}

a.chat-chip:hover {
  border-color: var(--cyan);
}

/* In a narrow message the title gives way first; kind and status keep their words. */
.chat-chip-kind,
.chat-chip-status {
  flex: none;
}

.chat-chip-kind {
  color: var(--purple);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chat-chip-title {
  overflow: hidden;
  min-width: 0;
  max-width: 320px;
  text-overflow: ellipsis;
}

.chat-chip-status {
  color: var(--muted);
  font-size: 12px;
}

.chat-chip[data-found="false"] .chat-chip-title {
  color: var(--muted);
  font-style: italic;
}

.chat-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.chat-media a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  line-height: 0;
}

.chat-media img {
  width: auto;
  max-width: min(360px, 100%);
  height: auto;
  max-height: 280px;
}

.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.chat-reaction {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-solid);
  font-size: 13px;
  cursor: pointer;
}

.chat-reaction[aria-pressed="true"] {
  border-color: var(--cyan);
  background: var(--cyan-soft);
}

.chat-reaction-count {
  color: var(--muted-bright);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chat-thread-link {
  margin-top: 5px;
  padding: 2px 8px;
  min-height: 26px;
  color: var(--blue);
  font-size: 13px;
}

.chat-request {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0 0;
  color: var(--muted-bright);
  font-size: 13px;
}

.chat-request[data-tone="failed"] {
  color: var(--red);
}

.chat-request[data-tone="pending"]::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  content: "";
  animation: chat-pulse 1.4s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%,
  100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-request[data-tone="pending"]::before {
    animation: none;
  }
}

.chat-actions {
  position: absolute;
  top: -12px;
  right: 16px;
  display: none;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: 0 4px 14px rgba(20, 33, 38, 0.1);
}

.chat-message:hover .chat-actions,
.chat-message:focus-within .chat-actions {
  display: flex;
}

.chat-actions .chat-button {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 12px;
}

.chat-palette {
  position: absolute;
  top: 18px;
  right: 16px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 34px);
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-solid);
  box-shadow: 0 10px 28px rgba(20, 33, 38, 0.16);
}

.chat-palette button {
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 17px;
  cursor: pointer;
}

.chat-palette button:hover {
  background: var(--cyan-soft);
}

.chat-confirm {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  font-size: 13px;
}

/* Narrow screens (moved here from composer.css). Phones and tablets have their own layouts
   (<html data-chat-layout>, mobile_shell.css); the chat panel of the map pages, which has no such
   mark, keeps the one-column-at-a-time layout up to 900 px. */

.chat-back {
  display: none;
}

@media (max-width: 900px) {
  html:not([data-chat-layout]) .chat-shell,
  html:not([data-chat-layout]) .chat-shell[data-thread="open"] {
    grid-template-columns: minmax(0, 1fr);
  }

  html:not([data-chat-layout]) .chat-shell[data-pane="channels"] .chat-main,
  html:not([data-chat-layout]) .chat-shell[data-pane="channels"] .chat-thread,
  html:not([data-chat-layout]) .chat-shell[data-pane="chat"] .chat-sidebar,
  html:not([data-chat-layout]) .chat-shell[data-pane="chat"] .chat-thread,
  html:not([data-chat-layout]) .chat-shell[data-pane="thread"] .chat-sidebar,
  html:not([data-chat-layout]) .chat-shell[data-pane="thread"] .chat-main {
    display: none;
  }

  html:not([data-chat-layout]) .chat-back {
    display: inline-flex;
  }

  /* The message actions stay visible in the chat panel (and a 900 px desktop). Phones open an
     action sheet on a long press instead; tablets keep the hover bar of desktop (message_extras.css). */
  html:not([data-chat-layout="phone"], [data-chat-layout="tablet"]) .chat-actions {
    position: static;
    display: flex;
    grid-column: 2;
    width: max-content;
    margin-top: 4px;
    box-shadow: none;
  }
}

