/* inbox.css — Conversations component
   Tokens consumed (both portals define all of these):
   --bg, --surface, --surface-2, --text, --text-2, --muted, --faint
   --gold, --gold-lt, --gold-dk, --border, --border-2, --green
   --sans, --serif, --shadow-sm, --shadow-md, --shadow-lg
   --radius-sm, --radius-md, --radius-pill, --pad               */


/* ═══════════════════════════════════════════════════════════════════════════
   VIEWPORT TAKEOVER
   When the messages view is active, strip .content padding and fill height.
   ═══════════════════════════════════════════════════════════════════════════ */
.content:has(#view-messages.active) {
  flex: none;
  padding: 0;
  overflow: hidden;
  height: calc(100dvh - 48px); /* topbar is 48px in both portals */
}
div#view-messages.view {
  height: 100%;
  overflow: hidden;
}

/* Root — fills the content area, flex row */
.inbox {
  height: 100%;
  display: flex;
  overflow: hidden;
  font-family: var(--sans);
  font-size: 0.8125rem;
}

/* Scoped focus ring */
.inbox :focus-visible,
.inbox-modal :focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════════ */
.inbox__sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

/* ── Sidebar header ─────────────────────────────────────────────────────── */
.inbox__sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.inbox__title {
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}
.inbox__new-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 12px;
  height: 30px;
  background: var(--gold);
  border: none;
  color: var(--surface);        /* white in light (4.8:1) / dark in dark (8.1:1) ✓ */
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s;
  white-space: nowrap;
}
.inbox__new-btn:hover { opacity: 0.85; }
.inbox__new-btn .material-symbols-outlined {
  font-size: 0.9rem;
  font-variation-settings: 'wght' 400, 'opsz' 20;
}

/* ── Search ─────────────────────────────────────────────────────────────── */
.inbox__search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
}
.inbox__search-wrap .material-symbols-outlined {
  font-size: 1rem;
  color: var(--faint);
  flex-shrink: 0;
  font-variation-settings: 'wght' 300, 'opsz' 20;
}
.inbox__search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text);
  min-width: 0;
}
.inbox__search::placeholder { color: var(--faint); }

/* ── Filter tabs (management only) ─────────────────────────────────────── */
.inbox__filters {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.inbox__filter-tab {
  flex: 1;
  height: 36px;
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.inbox__filter-tab:hover { color: var(--text-2); }
.inbox__filter-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ── Conversation list ──────────────────────────────────────────────────── */
.inbox__list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.inbox__item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
  position: relative;
}
.inbox__item:hover { background: var(--surface-2); }
.inbox__item.active {
  background: var(--gold-lt);
  border-left: 3px solid var(--gold);
  padding-left: 13px;
}
.inbox__item--unread .inbox__item-name { font-weight: 700; color: var(--text); }

.inbox__item-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--gold-lt);
  border: 1.5px solid var(--border-2);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.inbox__item-body { flex: 1; min-width: 0; }
.inbox__item-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}
.inbox__item-row:last-child { margin-bottom: 0; }
.inbox__item-name {
  font-size: 0.8125rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.inbox__item-time {
  font-size: 0.5625rem;
  color: var(--faint);
  white-space: nowrap;
  flex-shrink: 0;
}
.inbox__item-preview {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}
.inbox__item-badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: var(--gold);
  color: var(--surface);
  border-radius: var(--radius-pill);
  font-size: 0.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inbox__item-status {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}
.inbox__item-status.open {
  background: var(--gold-lt);
  color: var(--gold);
  border: 1px solid var(--border-2);
}
.inbox__item-status.resolved {
  color: var(--faint);
  border: 1px solid var(--border);
}

/* Sidebar empty state */
.inbox__list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  padding: 40px 24px;
  text-align: center;
}
.inbox__list-empty .material-symbols-outlined {
  font-size: 2.25rem;
  color: var(--faint);
  font-variation-settings: 'FILL' 0, 'wght' 200, 'GRAD' 0, 'opsz' 40;
  opacity: 0.5;
}
.inbox__list-empty p { font-size: 0.75rem; color: var(--muted); line-height: 1.6; }
.inbox__list-empty-cta {
  padding: 8px 16px;
  background: var(--gold-lt);
  border: 1px solid var(--border-2);
  color: var(--gold);
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s;
}
.inbox__list-empty-cta:hover { opacity: 0.75; }


/* ═══════════════════════════════════════════════════════════════════════════
   THREAD PANEL
   ═══════════════════════════════════════════════════════════════════════════ */
.inbox__thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* ── Thread header ──────────────────────────────────────────────────────── */
.inbox__thread-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 52px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.inbox__back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: color 0.15s, border-color 0.15s;
}
.inbox__back-btn:hover { color: var(--text); border-color: var(--muted); }
.inbox__back-btn .material-symbols-outlined {
  font-size: 1rem;
  font-variation-settings: 'wght' 300, 'opsz' 20;
}

/* Avatar in header */
.inbox__thread-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  background: var(--gold-lt);
  border: 1.5px solid var(--border-2);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.inbox__thread-meta { flex: 1; min-width: 0; }
.inbox__thread-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}
.inbox__unit-tag {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--gold-lt);
  border: 1px solid var(--border-2);
  color: var(--gold);
  line-height: 1.8;
  text-transform: uppercase;
}
.inbox__thread-sub {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 1px;
}
.inbox__resolve-btn {
  flex-shrink: 0;
  padding: 0 12px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s, border-color 0.15s;
}
.inbox__resolve-btn:hover:not(.resolved) { border-color: var(--green); color: var(--green); }
.inbox__resolve-btn.resolved { opacity: 0.4; cursor: default; }
.inbox__resolve-btn .material-symbols-outlined {
  font-size: 0.875rem;
  font-variation-settings: 'wght' 300, 'opsz' 20;
}

/* ── Messages area ──────────────────────────────────────────────────────── */
.inbox__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inbox__date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 8px;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}
.inbox__date-sep::before,
.inbox__date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Message rows */
.inbox__msg { display: flex; flex-direction: column; max-width: 66%; }
.inbox__msg--in  { align-self: flex-start; align-items: flex-start; }
.inbox__msg--out { align-self: flex-end;   align-items: flex-end;   }
.inbox__msg--out + .inbox__msg--in,
.inbox__msg--in  + .inbox__msg--out { margin-top: 12px; }

/* ── Bubbles ────────────────────────────────────────────────────────────── */
.inbox__msg-bubble {
  padding: 10px 15px;
  font-size: 0.8125rem;
  line-height: 1.65;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
  transition: box-shadow 0.15s;
}

/* Incoming — white card on warm bg; shadow creates lift so it's visible in light mode */
.inbox__msg--in .inbox__msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08), 0 3px 10px rgba(0,0,0,0.05);
}

/* Outgoing — gold tint */
.inbox__msg--out .inbox__msg-bubble {
  background: var(--gold-lt);
  border: 1px solid var(--border-2);
  border-radius: 18px 4px 18px 18px;
}

/* Light-mode: outgoing needs a richer gold tint so it reads differently from
   the warm cream bg (#f4f0eb). --gold-lt in light = #f0e3c6 which is too close.
   Apply to :root (portal default) and [data-theme="light"] (management switched). */
:root .inbox__msg--out .inbox__msg-bubble,
[data-theme="light"] .inbox__msg--out .inbox__msg-bubble {
  background: rgba(133, 103, 40, 0.14); /* #856728 at 14% over cream → warm tan */
  border-color: rgba(133, 103, 40, 0.28);
}

/* Timestamp */
.inbox__msg-time {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.5625rem;
  color: var(--faint);
  margin-top: 4px;
  padding: 0 3px;
}
.inbox__msg-time .material-symbols-outlined {
  font-size: 0.8rem;
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
}
.msg-status {
  display: inline-flex;
  align-items: center;
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
}
.msg-status--sent { color: var(--muted); font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20; }
.msg-status--read { color: var(--gold);  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20; }

/* Empty thread state */
.inbox__no-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  text-align: center;
}
.inbox__no-thread .material-symbols-outlined {
  font-size: 3rem;
  color: var(--faint);
  opacity: 0.35;
  font-variation-settings: 'FILL' 0, 'wght' 200, 'GRAD' 0, 'opsz' 40;
}
.inbox__no-thread p { font-size: 0.75rem; color: var(--muted); line-height: 1.6; }

/* ── Compose bar ────────────────────────────────────────────────────────── */
.inbox__compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  flex-shrink: 0;
  min-height: 56px;
}
.inbox__compose-inner {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s;
}
.inbox__compose-inner:focus-within { border-color: var(--gold); }
.inbox__compose-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--text);
  line-height: 1.55;
  max-height: 110px;
  overflow-y: auto;
  padding: 4px 0;
  align-self: center;
}
.inbox__compose-input::placeholder { color: var(--faint); }
.inbox__send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: none;
  color: var(--faint);
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
.inbox__compose-input:not(:placeholder-shown) ~ .inbox__send-btn,
.inbox__send-btn:hover {
  background: var(--gold);
  color: var(--surface);
}
.inbox__send-btn .material-symbols-outlined {
  font-size: 1rem;
  font-variation-settings: 'wght' 400, 'opsz' 20;
}


/* ═══════════════════════════════════════════════════════════════════════════
   NEW CONVERSATION MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.inbox-modal {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.inbox-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.52);
  backdrop-filter: blur(2px);
}
.inbox-modal__box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-top: 2px solid var(--gold);
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-md);
  overflow: clip;
}
.inbox-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.inbox-modal__head h3 {
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}
.inbox-modal__close {
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.inbox-modal__close:hover { color: var(--text); }
.inbox-modal__close .material-symbols-outlined {
  font-size: 1.05rem;
  font-variation-settings: 'wght' 300, 'opsz' 20;
}
.inbox-modal__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.inbox-modal__field { display: flex; flex-direction: column; gap: 5px; }
.inbox-modal__field label {
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.inbox-modal__field input,
.inbox-modal__field textarea,
.inbox-modal__field select {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.8125rem;
  padding: 9px 12px;
  min-height: 40px;
  outline: none;
  resize: vertical;
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}
.inbox-modal__field input:focus,
.inbox-modal__field textarea:focus,
.inbox-modal__field select:focus { border-color: var(--gold); }
.inbox-modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.inbox-modal__cancel {
  padding: 0 14px;
  height: 34px;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s, border-color 0.15s;
}
.inbox-modal__cancel:hover { color: var(--text); border-color: var(--muted); }
.inbox-modal__send {
  padding: 0 16px;
  height: 34px;
  background: var(--gold);
  border: none;
  color: var(--surface);
  font-family: var(--sans);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s;
}
.inbox-modal__send:hover { opacity: 0.88; }


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1000px) { .inbox__sidebar { width: 280px; } }
@media (max-width: 800px)  { .inbox__sidebar { width: 240px; } }

@media (max-width: 640px) {
  .inbox { position: relative; }
  .inbox__sidebar,
  .inbox__thread {
    position: absolute;
    inset: 0;
    width: 100%;
    transition: transform 0.24s ease;
  }
  .inbox__sidebar { transform: translateX(0); z-index: 2; }
  .inbox__thread  { transform: translateX(100%); z-index: 1; }
  .inbox--thread-open .inbox__sidebar { transform: translateX(-100%); }
  .inbox--thread-open .inbox__thread  { transform: translateX(0); }
  .inbox__back-btn { display: flex; }
  .inbox__msg { max-width: 82%; }
  .inbox__messages { padding: 16px; }
  .inbox__compose { padding: 10px 12px; }
}
