/* Site message threads. The same sheet in the owner app and the staff screen. */

/*
 * A closed <dialog> is display:none in the UA stylesheet, and any `display` we
 * set here beats that, which silently renders the whole sheet inline in the
 * page. Scope the flex to [open] so the closed state stays hidden.
 */
.msg-sheet { display: none; }
.msg-sheet[open] {
  display: flex; flex-direction: column;
  width: min(520px, 100%); height: min(86dvh, 720px);
  margin: auto auto 0; padding: 0;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  overflow: hidden;
}
.msg-sheet::backdrop { background: rgba(0, 0, 0, .5); }
@media (min-width: 640px) {
  .msg-sheet[open] { margin: auto; border-radius: var(--r-lg); }
}

/* ── head ───────────────────────────────────────────────────────────────── */

.msg-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.msg-head-main { min-width: 0; flex: 1; display: grid; gap: 1px; }
.msg-head h2 {
  margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-head small { font-size: 12.5px; color: var(--muted); }
.msg-site {
  width: calc(100% - 32px); margin: 12px 16px 0;
  padding: 8px 12px; font-size: 14px;
}

/* ── the thread ─────────────────────────────────────────────────────────── */

.msg-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px;
}

.msg-day {
  display: flex; align-items: center; gap: 12px;
  margin: 6px 0;
  font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.msg-day::before, .msg-day::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Square-cornered, left-edged, like a note pinned to the wall. The chat bubble
   with a tail is the other thing this product does not do. */
.msg {
  align-self: flex-start; max-width: 86%;
  display: grid; gap: 3px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.msg.is-mine {
  align-self: flex-end;
  color: var(--accent-text); background: var(--accent);
  border-color: var(--accent);
}
.msg-who { display: flex; align-items: center; gap: 7px; }
.msg-who b { font-size: 12.5px; font-weight: 700; }
.msg-role {
  padding: 0 6px;
  font-size: 10px; font-weight: 700; font-style: normal;
  letter-spacing: .06em; text-transform: uppercase;
  border-radius: var(--r-sm);
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line);
}
.msg-role.is-owner { color: var(--brand-warm-ink); background: var(--brand-warm-soft); border-color: var(--brand-warm-line); }

.msg-body { margin: 0; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: 11px; color: var(--muted); }
.msg.is-mine .msg-time { color: var(--accent-text); opacity: .75; }

.msg-empty { padding: 32px; text-align: center; color: var(--muted); font-size: 14px; }
.msg-blank {
  display: grid; place-items: center; gap: 6px;
  margin: auto; padding: 32px 24px; text-align: center;
}
.msg-blank svg { width: 34px; height: 34px; color: var(--faint); margin-bottom: 6px; }
.msg-blank p { margin: 0; font-size: 14px; color: var(--muted); max-width: 34ch; }
.msg-blank b { color: var(--text); }

/* ── composer ───────────────────────────────────────────────────────────── */

.msg-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.msg-input {
  flex: 1; min-height: 42px; max-height: 140px;
  padding: 10px 12px;
  font: 14.5px/1.45 var(--font);
  color: var(--text); background: var(--surface-2);
  border: 1px solid transparent; border-radius: var(--r-md);
  resize: none;
}
.msg-input::placeholder { color: var(--muted); opacity: .8; }
.msg-input:focus { outline: none; background: var(--bg); border-color: var(--accent); }
.msg-send {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  color: var(--accent-text); background: var(--accent);
  border: 0; border-radius: var(--r-md); cursor: pointer;
}
.msg-send:hover { background: var(--accent-hover); }
.msg-send svg { width: 19px; height: 19px; }

/* ── the top-bar button ─────────────────────────────────────────────────── */

.msg-open { position: relative; }
.msg-open .msg-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 17px; padding: 0 4px;
  font: 700 10px/17px var(--font); font-style: normal; text-align: center;
  color: #fff; background: var(--danger);
  border-radius: var(--r-sm);
}
