/* The match chat in the match panel, and the admins' Match chats list.
 * Paired with js/tournaments/match-chat.js and the cup page's admin list.
 */

/* A panel that holds a chat is wider on a desktop, so a line reads. */
@media (min-width: 768px) {
  .slide-over--chat .slide-over__panel {
    width: min(560px, 100vw);
  }
}

/* The chat is one window under the match: a plate a step darker than the
 * panel, at the dialogs' 14px radius under a Strong Rule (DESIGN.md, the
 * trading card and the dialogs). Inside it, from the top: the title and Call
 * an admin, the two sides' managers and game IDs, the messages, and the
 * writing at the foot, each part parted by a Hairline. */
.match-chat {
  --chat-pad: var(--space-4);
  /* The two rules that frame the messages, brighter than a Hairline so the
   * conversation reads as its own part of the card (Sergio, 7 October
   * 2026), Polished Silver at 40%. */
  --chat-frame: color-mix(in srgb, var(--accent) 40%, transparent);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-deep);
  overflow: hidden;
}

.match-chat > * {
  padding-inline: var(--chat-pad);
}

/* The title over who can read it, and Call an admin at the right. */
/* Call an admin drops under the title when large text leaves no room
 * beside it, so the window never cuts it off. */
.match-chat__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.match-chat__head > div {
  flex: 1 1 0;
  min-width: min(9rem, 100%);
}

.match-chat__title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
}

.match-chat__who {
  margin: var(--space-1) 0 0;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  line-height: 1.4;
}

.match-chat__icon {
  display: inline-flex;
  flex-shrink: 0;
}

.match-chat__icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* A small outlined button: the one escalation in the window. */
.match-chat__call-btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  max-width: 100%;
  text-align: start;
  cursor: pointer;
  transition: border-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

.match-chat__call-btn[hidden] {
  display: none;
}

.match-chat__call-btn .match-chat__icon svg {
  width: 15px;
  height: 15px;
}

.match-chat__call-btn:hover,
.match-chat__call-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent-hover);
}

@media (pointer: coarse) {
  .match-chat__call-btn {
    min-height: 44px;
  }
}

.match-chat__hint,
.match-chat__closed {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* The two sides' managers and game IDs, side by side, one under the other
 * where the window is narrow. */
.match-chat__people {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr));
  gap: var(--space-3) var(--space-10);
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--chat-frame);
}

.match-chat__people:empty {
  display: none;
}

.match-chat__side {
  min-width: 0;
}

.match-chat__team {
  display: flex;
  align-items: center;
  min-height: 32px;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  font-family: var(--font-display);
  font-size: var(--text-base);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.match-chat__team::-webkit-details-marker {
  display: none;
}

.match-chat__side[open] > .match-chat__team {
  margin-bottom: var(--space-2);
}

/* "Manager" and a chevron on a folded side; open, only the chevron. */
.match-chat__ids-hint {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-xs);
}

.match-chat__ids-hint::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--duration) var(--ease-out);
}

.match-chat__side[open] .match-chat__ids-hint {
  font-size: 0;
}

.match-chat__side[open] .match-chat__ids-hint::after {
  transform: translateY(2px) rotate(-135deg);
}

@media (pointer: coarse) {
  .match-chat__team {
    min-height: 44px;
  }
}

.match-chat__team:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.match-chat__staff {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.match-chat__person {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-2);
  margin: 0;
}

.match-chat__name {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.match-chat__role {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* Platform in a narrow column, the ID beside it, so IDs line up. */
.match-chat__ids {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  gap: 2px var(--space-2);
  margin: var(--space-1) 0 0;
}

.match-chat__ids dt {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  line-height: 1.5rem;
}

.match-chat__ids dd {
  margin: 0;
  color: var(--led-pale);
  line-height: 1.5rem;
  overflow-wrap: anywhere;
  user-select: all;
}

/* The messages: the newest at the foot, scrolled on their own. */
.match-chat__list {
  display: flex;
  flex-direction: column;
  /* Never taller than about six messages, so the box and the lineups
   * stay near; older messages scroll inside. */
  max-height: min(36vh, 18rem);
  min-height: 7rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* An empty chat is one short line, not a reserved block. */
.match-chat__list:has(> .match-chat__quiet:only-child) {
  min-height: 0;
}

.match-chat__quiet {
  padding: var(--space-3) var(--chat-pad);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.match-chat .match-chat__list {
  padding-inline: 0;
}

/* No rules between messages: one open space, each message parted from the
 * next by room alone (Sergio, 7 October 2026). */
.match-chat__msg {
  padding: var(--space-2) var(--chat-pad);
}

.match-chat__msg:first-child {
  padding-top: var(--space-3);
}

.match-chat__msg:last-child {
  padding-bottom: var(--space-3);
}

/* The site's own lines (a rule, heights, Done) on a step of floodlight
 * blue, a call on a step of silver. */
.match-chat__msg--site {
  background: var(--led-10);
}

.match-chat__msg--site .match-chat__author {
  color: var(--led-bright);
}

.match-chat__msg--call {
  background: var(--accent-10);
}

.match-chat__msg--call .match-chat__author,
.match-chat__msg--admin .match-chat__author {
  color: var(--accent-hover);
}

.match-chat__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 2px;
  font-size: var(--text-xs);
}

.match-chat__author {
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.match-chat__meta time {
  flex-shrink: 0;
  color: var(--text-muted);
  font-family: var(--font-figures);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.match-chat__body {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.match-chat__msg--quick .match-chat__body {
  font-weight: var(--weight-semibold);
}

.match-chat__image {
  display: block;
  margin-top: var(--space-2);
  max-width: 18rem;
}

/* An image keeps its box before it loads, so the list does not jump. */
.match-chat__image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

/* Open calls, between the messages and the writing. */
.match-chat__calls:empty {
  display: none;
}

.match-chat__calls {
  border-top: 1px solid var(--chat-frame);
}

.match-chat .match-chat__calls {
  padding-inline: 0;
}

.match-chat__open-call {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--chat-pad);
  background: var(--accent-10);
  font-size: var(--text-sm);
}

.match-chat__open-call p {
  margin: 0;
}

/* Writing, at the foot of the window. */
.match-chat__foot {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-block: var(--space-3);
  border-top: 1px solid var(--chat-frame);
}

.match-chat__error:not([hidden]) {
  padding-bottom: var(--space-3);
}

/* Quick messages above the field, wrapping to a second line where the
 * window is narrow, so every one shows. */
.match-chat__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.match-chat__chip {
  flex-shrink: 0;
  min-height: 32px;
  padding: 0 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

.match-chat__chip:hover,
.match-chat__chip:focus-visible {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Heights is a request to the other side, not a status, so it reads blue. */
.match-chat__chip--ask {
  border-color: var(--led-20);
  color: var(--led-pale);
}

@media (pointer: coarse) {
  .match-chat__chip {
    min-height: 44px;
  }
}

/* The field: image at the left, the growing box, Send at the right. */
.match-chat__compose {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  transition: border-color var(--duration) var(--ease-out);
}

.match-chat__compose:hover {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.match-chat__compose:focus-within {
  border-color: var(--accent);
}

.match-chat__input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 9rem;
  padding: 0.55rem var(--space-1);
  border: 0;
  background: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}

@media (pointer: coarse) {
  .match-chat__input {
    min-height: 44px;
  }

}

.match-chat__input:focus {
  outline: none;
}

.match-chat__input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.match-chat__attach,
.match-chat__send {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

@media (pointer: coarse) {
  .match-chat__attach,
  .match-chat__send {
    width: 44px;
    height: 44px;
  }
}

.match-chat__attach {
  background: none;
  color: var(--text-secondary);
}

.match-chat__attach:hover,
.match-chat__attach:focus-visible {
  color: var(--text-primary);
}

.match-chat__send {
  background: var(--accent);
  color: var(--bg-deep);
}

.match-chat__send:hover:not(:disabled),
.match-chat__send:focus-visible {
  background: var(--accent-hover);
}

.match-chat__send:disabled {
  background: var(--accent-10);
  color: var(--text-muted);
  cursor: default;
}

.match-chat__attach:focus-visible,
.match-chat__send:focus-visible,
.match-chat__chip:focus-visible,
.match-chat__call-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.match-chat__call-actions .btn-sm {
  min-height: 44px;
}

.match-chat__chosen {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.match-chat__error {
  margin: 0;
  color: var(--danger-text);
  font-size: var(--text-sm);
}

.match-chat .link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

/* Call an admin, in place of the writing box. */
.match-chat__call {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.match-chat__call-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.match-chat__call-title {
  margin: 0;
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

/* The reasons under the four kinds they come in. */
.match-chat__reason-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.match-chat__reason-kind {
  margin: 0;
  color: var(--led-pale);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.match-chat__reasons {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border-strong);
}

.match-chat__reasons li {
  border-bottom: 1px solid var(--border);
}

.match-chat__reason {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) 0;
  border: 0;
  background: none;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: color var(--duration) var(--ease-out);
}

.match-chat__reason:hover,
.match-chat__reason:focus-visible {
  color: var(--accent-hover);
}

.match-chat__answer {
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--led-10);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.match-chat__answer--quiet {
  color: var(--text-secondary);
}

.match-chat__call-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.match-chat__call-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.match-chat__kinds {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.match-chat__kinds legend {
  width: 100%;
  margin-bottom: var(--space-2);
}

.match-chat__kind {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}

.match-chat__kind:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-10);
}

.match-chat__proof {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.match-chat__proof .form-label {
  margin: 0;
}

.match-chat__proof-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.match-chat__proof-row .form-control {
  flex: 1;
  min-width: 12rem;
}

/* Match chat on a manager's Your match panel: the chat's own door, an
 * outlined button with the chat icon and the unread count. */
.entry-card__chat {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  margin-block: var(--space-1);
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease-out);
}

.entry-card__chat svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.entry-card__chat:hover,
.entry-card__chat:focus-visible {
  border-color: var(--accent);
}

.entry-card__chat:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.entry-card__chat .chat-unread {
  margin-left: 0;
}

@media (pointer: coarse) {
  .entry-card__chat {
    min-height: 44px;
  }
}

/* The match panel's head: its state on the left, its buttons (Send the
 * score, Dispute result, Set the result, Overturn) on the right. */
.tdv2-match__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.tdv2-match__head .tdv2-match__actions {
  margin: 0;
}

/* The unread count beside "Match chat" on a manager's match. */
.chat-unread {
  display: inline-block;
  min-width: 1.25rem;
  margin-left: var(--space-2);
  padding: 0 0.3rem;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--bg-deep);
  font-family: var(--font-figures);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 1.25rem;
  text-align: center;
}

/* ── The admins' Match chats list ─────────────────────────────────────── */
.chat-rooms {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.chat-rooms__section h4 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.chat-rooms__rows {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border-strong);
}

.chat-rooms__rows li {
  border-bottom: 1px solid var(--border);
}

.chat-rooms__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) 0;
  border: 0;
  background: none;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}

.chat-rooms__row:hover .chat-rooms__fixture,
.chat-rooms__row:focus-visible .chat-rooms__fixture {
  color: var(--accent-hover);
}

.chat-rooms__fixture {
  font-family: var(--font-display);
  font-size: var(--text-base);
  line-height: 1.25;
  overflow-wrap: anywhere;
  transition: color var(--duration) var(--ease-out);
}

.chat-rooms__meta {
  grid-column: 1 / -1;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.chat-rooms__count {
  align-self: center;
}

.chat-rooms__empty {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.chat-rooms__changed {
  margin: 0;
  padding: var(--space-3);
  border-left: 2px solid var(--warning);
  background: var(--warning-10);
  font-size: var(--text-sm);
  line-height: 1.55;
}

/* The header button's count of open calls. */
.cup-chats__btn {
  position: relative;
}

.cup-chats__count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 1.1rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--bg-deep);
  font-family: var(--font-figures);
  font-size: 0.75rem;
  font-weight: var(--weight-semibold);
  line-height: 1.1rem;
  text-align: center;
}

.cup-chats__count:empty {
  display: none;
}
