/*
  chat.css (Unified)
  Single rule:
  - ANY styling that targets the chat module lives here.
  - index.php and dj/index.php should not style .chat* classes directly.

  Includes:
  - Full-width chat band
  - Log + rows
  - System message styling
  - Form + inputs
  - Mobile sticky composer behavior
*/

/* =========================
   Chat (shared)
   ========================= */

:root {
  --chat-max: 720px;
  --chat-font-size: 15px;
  --chat-line-height: 1.5;

  --chat-grey: #c2c2c2;     /* timestamps + system */
  --chat-border-idle: #b3b3b3;
  --chat-border-focus: #000000;
}

/* Status line (if used by the page near the chat module) */
.status-line {
  display: block;
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: 2px 10px 0 10px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: #ffffff;
  color: #000000;
  font-size: 12px;
}

/* Full-width (full-bleed) background band behind chat */
.chat-band {
  background: #ffffff;
  margin-left: -40px;
  margin-right: -40px;
  padding: 20px 40px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));

  flex: 1 1 auto;
  display: flex;
  box-sizing: border-box;
  min-height: 0;
}

.chat {
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  text-align: left;
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: 0;

  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;

  background: #ffffff;
  color: #000000;
}

/* Message list */
.chat-log {
  flex: 1 1 auto;
  min-height: calc(5 * var(--chat-line-height));
  overflow-y: auto;
  padding: 0;
  background: #ffffff;

  font-size: var(--chat-font-size);
  line-height: var(--chat-line-height);
}

/* Rows */
.chat-row {
  display: block;
  padding: 0;
  border: none;
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
}

/* DJ name only: solid color tag with white text */
.chat-name.dj-name {
  display: inline-block;
  max-width: 100%;
  padding: 1px 6px;
  margin: 1px 0;
  border-radius: 0;
}

/* All timestamps (system + user) */
.chat-time {
  font-size: inherit;
  line-height: inherit;
  color: var(--chat-grey);
  opacity: 1;
}

.chat-name {
  font-weight: normal;
  color: inherit; /* per-user colour is applied to the row */
  word-break: break-word;
}

/* System messages */
.chat-row.system {
  padding: 0;
  font-weight: normal;
  background: transparent;
}

.chat-row.system,
.chat-row.system .system-text {
  font-size: inherit;
  line-height: inherit;
  color: var(--chat-grey);
}

.chat-msg a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.chat-msg {
  display: inline;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Composer */
.chat-form {
  margin-top: 10px;
  display: block;
  flex: 0 0 auto;
  padding-bottom: 6px;
  background: #ffffff;
}

.chat-fields {
  display: grid;
  grid-template-columns: 120px 1fr 96px; /* fixed Send column prevents overlap */
  gap: 8px;
  align-items: stretch;
  background: #ffffff;
}

/* Grid children must be allowed to shrink (prevents overlap/overflow) */
.chat-fields > * { min-width: 0; }

.chat-input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  height: 28px;
  padding: 4px 6px;
  border: 1px solid var(--chat-border-idle); /* grey when unfocused */
  border-radius: 0;
  font-family: inherit;
  font-size: var(--chat-font-size);
  line-height: var(--chat-line-height);
  -webkit-appearance: none;
  appearance: none;

  background: #ffffff;
  color: #000000;

  outline: none;     /* remove macOS blue glow */
  box-shadow: none; /* remove UA glow */
}

.chat-send {
  box-sizing: border-box;
  display: flex;                 /* allow vertical centering */
  align-items: center;           /* vertical centre */
  justify-content: flex-start;   /* left-align text */
  width: 96px;
  height: 28px;
  padding: 4px 10px;

  border: none;                  /* no edge */
  border-radius: 0;

  background-color: #e6e6e6 !important; /* force solid grey */
  background-image: none !important;   /* kill UA gradients */

  color: #000000;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--chat-font-size);
  line-height: var(--chat-line-height);

  -webkit-appearance: none;
  appearance: none;
  outline: none;
  box-shadow: none;
}

/* Focus: no outline/glow for Send; inputs keep border focus */
.chat-input:focus,
.chat-input:focus-visible {
  border-color: var(--chat-border-focus);
  outline: none;
}

.chat-send:focus,
.chat-send:focus-visible {
  outline: none;
  box-shadow: none;
}

.chat-send:hover {
  background: #e0e0e0; /* subtle hover, stays grey */
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 600px) {
  :root {
    --chat-font-size: 14px;
    --chat-line-height: 1.4;
  }

  .chat-log {
    min-height: calc(6 * var(--chat-line-height));
    max-height: 58vh;
    overflow-y: auto;
    padding: 0;
    padding-bottom: 0;
    scroll-padding-bottom: 56px;
    background: #ffffff;

    font-size: var(--chat-font-size);
    line-height: var(--chat-line-height);
  }

  /* Sticky composer so last message stays visible */
  .chat-form {
    position: sticky;
    bottom: 0;
    margin-top: 12px;
    padding-top: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: #ffffff;
    border-top: 1px solid #000000;
  }

  .chat-fields {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "message message"
      "name send";
    gap: 10px;
    align-items: end;
    background: #ffffff;
  }

  .field-message { grid-area: message; }
  .field-name    { grid-area: name; }
  .chat-send     { grid-area: send; width: 96px; }

  .chat-input,
  .chat-send {
    height: 36px;
    font-size: 15px;
    line-height: 22px;
  }
}
