/* The chat component's own styling (partials/_chat_macros.html).

   One vocabulary for every surface that shows a chat, because a message
   is a message whether it's on a phone or in the org's triage split. The
   chrome around it is the caller's business: the portals wrap this in a
   plain .card, the org wraps it in a fixed-height .panel-card so it twins
   with Internal notes (_panels.css), and the two rules at the bottom are
   all it takes to make the shared thread sit correctly inside that.

   Quieter than the full-screen thread it links to (customer/chat.css):
   that page IS the conversation and paints its own tinted canvas edge to
   edge, where here the conversation is one card among the status, the
   photos and the timeline. */

/* Colours this sheet alone uses, named so none of them is a bare hex.
   Same values as before — this changed no pixel. */
:root {
  --chat-open-ink   : #147A86;
  --chat-msg-shadow : #1D2B32;
  --chat-msg-mine-bg: #E3F4F6;
  --chat-stamp-ink  : #8A9AA4;
  --panel-error-ink : #B3261E;
}

/* ── The same palette, for a system-set dark scheme ───────────────────
   "System" writes no attribute, so `prefers-color-scheme` is the only
   thing that says dark — and it is the DEFAULT: the state of every
   dark-set device whose owner never opened More → Appearance. This sheet
   had only the block below, so those readers got this family's light
   grounds under common/_tokens.css's dark ink.

   Declared twice because CSS cannot say "either condition", which is what
   common/_tokens.css does too; `dark-half` checks the two say the same
   thing. The `:not([data-appearance="light"])` guard is load-bearing —
   without it an explicit Light pick loses to this block on a dark-set OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-appearance="light"]) {
    --chat-msg-mine-bg: var(--teal-pale);
    /* The "open" chip is a status ground, so it takes the progress bucket
       the seven-colour map already carries a dark value for rather than a
       second teal of its own. */
    --chat-open-ink: var(--status-progress-ink);
  }
}

/* ── Dark half ────────────────────────────────────────────────────────
   The own-message bubble is a teal tint of the card, which is exactly
   what --teal-pale already derives in dark (18% of whatever the accent
   is, over --surface) — so a paid brand_color gets a correct bubble
   without a literal here, same reasoning as the token file's. */
:root[data-appearance="dark"] {
  --chat-msg-mine-bg: var(--teal-pale);
  /* The "open" chip is a status ground, so it takes the progress bucket
     the seven-colour map already carries a dark value for rather than a
     second teal of its own. */
  --chat-open-ink: var(--status-progress-ink);
}

.chat-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.chat-card-head .card-title { margin-bottom: 0; }
.chat-open {
  font-size: 13px;
  font-weight: 600;
  color: var(--teal-deep, var(--chat-open-ink));
  white-space: nowrap;
}
.chat-open i { font-size: 13px; vertical-align: -1px; }

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Roughly five messages, then it scrolls. The thread is read
     newest-first (panel_card.js pins it to the bottom); anyone wanting the
     whole history has "Full thread" in the header. Without a cap, one old
     conversation pushes the rest of the request off the screen. */
  max-height: 300px;
  overflow-y: auto;
  margin: 12px 0;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--teal, var(--teal)) 5%, var(--paper-linen));
}
.chat-empty { margin: auto 0; text-align: center; }

.chat-msg {
  max-width: 85%;
  padding: 7px 10px 5px;
  border-radius: 14px;
  border-end-start-radius: 4px;
  background: var(--white, var(--white));
  align-self: flex-start;
  box-shadow: 0 1px 1px color-mix(in srgb, var(--ink, var(--chat-msg-shadow)) 8%, transparent);
}
.chat-msg--mine {
  align-self: flex-end;
  background: var(--teal-pale, var(--chat-msg-mine-bg));
  border-end-start-radius: 14px;
  border-end-end-radius: 4px;
}
.chat-sender {
  margin: 0 0 1px;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-deep, var(--chat-open-ink));
}
.chat-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.chat-stamp {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--text-tertiary, var(--chat-stamp-ink));
  text-align: end;
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 6px;
}
.chat-attachments img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.chat-doc {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.chat-composer .chat-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
.chat-attach,
.chat-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  position: relative;
}
.chat-attach {
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-secondary);
}
.chat-attach:hover { background: var(--paper, var(--paper-bone)); color: var(--teal); }
.chat-send {
  border: none;
  background: var(--teal);
  color: var(--white);
}
.chat-send:hover { background: var(--teal-deep, var(--chat-open-ink)); }
/* How many files are staged, since the input itself is hidden — without
   it, picking three photos looks identical to picking none. */
.chat-attach-count {
  position: absolute;
  top: -2px;
  inset-inline-end: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--teal);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* A composer mid-send: the whole row dims and stops taking input, so a
   slow connection can't be double-submitted into two identical messages. */
.chat-composer.panel-sending { opacity: 0.55; pointer-events: none; }

.panel-error {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--danger, var(--panel-error-ink));
}

/* Inside the org's fixed-height panel (_panels.css), the thread takes
   whatever height is left over rather than its own 300px cap, so chat and
   Internal notes stay exactly the same height side by side. */
.panel-body .chat-thread {
  flex: 1;
  min-height: 0;
  max-height: none;
  margin-top: 0;
}
.panel-body .chat-composer { margin-top: 10px; }

/* The labelled variant of .chat-send, for an empty thread that has to say
   what the button will do. It was borrowing .btn-save/.btn-save--sm — an
   admin pair living in common/_shell.css and css/org/services.css, neither
   of which the customer or tenant portal loads — so on the two surfaces
   this macro was written for, "Start chat" rendered as native browser
   chrome. This file is the one every caller already has to load. */
.chat-submit {
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 20px;
  background: var(--teal);
  color: var(--white);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.chat-submit:hover { background: var(--teal-deep); }
