/* Staff chat (public/js/chat.js): list | thread on wide screens, one pane on phones. */
.chat {
  display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 0;
  height: calc(100vh - 170px); min-height: 460px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; position: relative;
}
.chat button { font: inherit; }
.chat .danger { color: var(--danger); }
.chat-sub { color: var(--text-muted); font-size: 0.85em; }
.chat-link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 4px 6px; min-height: 0; }
.chat-tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--primary-light); color: var(--primary); font-size: 0.75em; }
.chat-tag.danger { background: var(--danger-bg); color: var(--danger); margin: 0 0 4px; }

/* List pane */
.chat-list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.chat-list-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.chat-title-row { display: flex; align-items: center; justify-content: space-between; }
.chat-title-row h2 { margin: 0; font-size: 1.2rem; }
.chat-tabs { display: flex; gap: 4px; }
.chat-tabs button { flex: 1; border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: var(--radius-md); padding: 6px; cursor: pointer; }
.chat-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chat-actions { display: flex; gap: 6px; }
.chat-actions button { flex: 1; }
.chat-search { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); color: var(--text); }
.chat-notice { margin: 0; font-size: 0.78rem; color: var(--text-muted); }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list-note { padding: 14px; color: var(--text-muted); }
.chat-item {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name time" "preview unread";
  gap: 2px 8px; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border-light);
  background: none; color: var(--text); cursor: pointer;
}
.chat-item:hover { background: var(--card-hover); }
.chat-item.active { background: var(--primary-light); }
.chat-item-name { grid-area: name; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-preview { grid-area: preview; color: var(--text-muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.unread .chat-item-preview { color: var(--text); font-weight: 600; }
.chat-item-time { grid-area: time; color: var(--text-faint); font-size: 0.75rem; }
.chat-unread, .chat-badge {
  grid-area: unread; justify-self: end; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 20px;
}
.chat-badge { display: inline-block; margin-left: 6px; }
.chat-badge[hidden] { display: none; }

/* Thread */
.chat-thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-empty { margin: auto; color: var(--text-muted); padding: 24px; text-align: center; }
.chat-thread-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-head-text { flex: 1; display: grid; min-width: 0; }
.chat-head-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-back { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--text); min-height: 0; }
.chat-offline { background: var(--warning-bg); color: var(--warning); padding: 4px 12px; font-size: 0.8rem; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.chat-banner { margin: 0 0 6px; padding: 8px 10px; border-radius: var(--radius-md); background: var(--warning-bg); color: var(--warning); font-size: 0.85rem; }
.chat-older { align-self: center; }
.chat-day { align-self: center; font-size: 0.75rem; color: var(--text-muted); background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 1px 10px; margin: 6px 0; }
.chat-msg {
  max-width: min(78%, 560px); align-self: flex-start; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 10px; position: relative; overflow-wrap: anywhere;
}
.chat-msg.own { align-self: flex-end; background: var(--primary-light); border-color: transparent; }
.chat-msg.deleted .chat-msg-text { color: var(--text-muted); }
.chat-msg-sender { font-size: 0.78rem; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.chat-msg-text { white-space: pre-wrap; }
.chat-msg-meta { font-size: 0.7rem; color: var(--text-muted); text-align: right; margin-top: 2px; }
.chat-seen { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; font-size: inherit; min-height: 0; }
.chat-quote { border-left: 3px solid var(--primary); padding: 2px 8px; margin-bottom: 4px; font-size: 0.82rem; display: grid; color: var(--text-secondary); background: rgba(0,0,0,0.03); border-radius: 4px; }
.chat-msg-actions { display: none; gap: 2px; margin-top: 2px; }
.chat-msg:hover .chat-msg-actions, .chat-msg:focus-within .chat-msg-actions { display: flex; }
.chat-msg-actions button { background: none; border: 0; color: var(--primary); cursor: pointer; font-size: 0.75rem; padding: 2px 4px; min-height: 0; }
.chat-image { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; cursor: zoom-in; margin-bottom: 2px; }
.chat-voice { display: grid; gap: 4px; }
.chat-voice audio { max-width: 260px; height: 36px; }
.chat-file { background: none; border: 1px dashed var(--border); border-radius: 8px; padding: 6px 8px; cursor: pointer; color: var(--text); text-align: left; }

/* Composer */
.chat-composer { border-top: 1px solid var(--border); padding: 8px 10px; }
.chat-context { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--text-muted); padding-bottom: 4px; }
.chat-compose-row { display: flex; gap: 6px; align-items: flex-end; }
.chat-input { flex: 1; resize: none; min-height: 40px; max-height: 160px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 18px; background: var(--card); color: var(--text); font: inherit; }
.chat-icon { background: none; border: 0; font-size: 1.25rem; cursor: pointer; padding: 6px; min-height: 40px; }
.chat-send { border-radius: 18px; padding: 0 16px; min-height: 40px; }
.chat-recording { align-items: center; }
.chat-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: chat-pulse 1s infinite; }
.chat-rec-clock { font-variant-numeric: tabular-nums; flex: 1; }
@keyframes chat-pulse { 50% { opacity: 0.3; } }

/* Dialogs and toast */
.chat-modal-overlay { position: absolute; inset: 0; background: rgba(15,23,42,0.45); display: grid; place-items: center; z-index: 5; padding: 12px; }
.chat-modal { background: var(--card); color: var(--text); border-radius: var(--radius-lg); width: min(440px, 100%); max-height: 90%; display: flex; flex-direction: column; padding: 14px; gap: 8px; box-shadow: var(--shadow-lg); }
.chat-modal h3 { margin: 0; }
.chat-modal-body { overflow-y: auto; display: grid; gap: 8px; }
.chat-modal-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.chat-people { list-style: none; margin: 0; padding: 0; }
.chat-person { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; width: 100%; padding: 8px 4px; border: 0; border-bottom: 1px solid var(--border-light); background: none; color: var(--text); text-align: left; cursor: pointer; }
.chat-person-actions { margin-left: auto; display: flex; }
.chat-toast { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--text); color: var(--card); padding: 8px 14px; border-radius: 18px; font-size: 0.85rem; z-index: 6; max-width: 90%; }

@media (max-width: 760px) {
  .chat { grid-template-columns: 1fr; height: calc(100vh - 130px); }
  .chat.has-active .chat-list-pane { display: none; }
  .chat:not(.has-active) .chat-thread { display: none; }
  .chat-back { display: block; }
  .chat-msg { max-width: 88%; }
  .chat-msg-actions { display: flex; }
}

/* Notifications dialog (push on this device, quiet hours) */
.chat-push-status { margin: 0 0 10px; }
.chat-push-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-push-heading { margin: 16px 0 6px; font-size: 0.95rem; }
.chat-quiet { display: flex; flex-wrap: wrap; gap: 10px; }
.chat-quiet label { display: grid; gap: 4px; flex: 1 1 120px; font-size: 0.85rem; color: var(--text-muted); }
