/* ── Internal Dispatch Chat — full-height Slack-style 3-pane layout
 * (INTERNAL-CHAT-UI, 2026-06-17). Markup + CSS only — chat.js is the
 * single source of behaviour and is NEVER edited. Every required ID it
 * touches is preserved (chat-tab-group/-dms, chat-group-entry,
 * chat-group-preview, chat-dm-list, chat-users-list, chat-area-title/-sub,
 * chat-messages, chat-mention-list, chat-mention-preview, chat-input,
 * chat-ai-btn, dm-unread-total).
 *
 * Layout: LEFT rail (workspace header + channel list + Team/DMs tab +
 * DM-thread list + online-presence roster, stacked) | MAIN conversation
 * (header + scrolling messages + compose).  chat.js's chatSwitchTab()
 * toggles chat-users-list (roster, "Team" tab) vs chat-dm-list (threads,
 * "DMs" tab) inside the left rail's lower zone — we keep that semantics
 * exactly; this file only restyles the shell.
 *
 * ALL selectors scoped under #panel-chat so the generic class names never
 * collide with the rest of the dashboard. Tokens reuse the dashboard's
 * --bg/--bg2/--border/--text/--gold/--emr-* so it follows light + dark
 * themes automatically. chat.js writes several inline styles (tab active
 * state, row highlight, mention .focused) — those inline writes win over
 * these rules by specificity, so the dynamic states keep working. */

/* ── Panel shell: full-height 3-pane flex row ─────────────────────────── */
#panel-chat {
  flex-direction: row;
  overflow: hidden;
  min-height: 0;            /* allow children to scroll inside flex height */
  background: var(--bg);
}
#panel-chat *,
#panel-chat *::before,
#panel-chat *::after { box-sizing: border-box; }

/* ── LEFT RAIL ────────────────────────────────────────────────────────── */
#panel-chat .chat-rail {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--bg2);
}

/* Workspace header (top of the rail) */
#panel-chat .chat-rail-head {
  flex-shrink: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--emr-charcoal, #1a1a1a);
  color: #fff;
}
#panel-chat .chat-rail-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .2px;
  color: #fff;
}
#panel-chat .chat-rail-title .chat-rail-logo {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--gold);
  color: var(--emr-charcoal, #1a1a1a);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
#panel-chat .chat-rail-sub {
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: rgba(255,255,255,.55);
}

/* Section labels inside the rail */
#panel-chat .chat-rail-section-label {
  flex-shrink: 0;
  padding: 12px 16px 6px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text3);
}

/* Channel list — the Team Chat channel entry (#chat-group-entry) */
#panel-chat .chat-channel-list { flex-shrink: 0; }
#panel-chat #chat-group-entry {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 8px 4px;
  padding: 9px 11px;
  border-radius: 8px;
  border-bottom: none;            /* was a border-bottom in the old markup */
  cursor: pointer;
  background: transparent;        /* chat.js sets inline bg when active */
  transition: background .12s;
}
#panel-chat #chat-group-entry:hover { background: var(--bg3); }
#panel-chat #chat-group-entry .chat-channel-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
#panel-chat #chat-group-preview {
  font-size: 10px;
  color: var(--text3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Team / DMs tab switcher */
#panel-chat .chat-rail-tabs {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--border);
}
#panel-chat .chat-rail-tabs button {
  flex: 1;
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border2);
  border-radius: 7px;
  background: var(--bg3);
  color: var(--text3);
  cursor: pointer;
  position: relative;
  transition: background .12s, color .12s;
  font-family: var(--sans);
}
/* chat.js sets active/inactive via inline styles (background/color/
 * borderBottomColor); these are only the resting hover affordances and
 * lose to the inline writes by specificity. */
#panel-chat .chat-rail-tabs button:hover { color: var(--text); }

/* Scrollable lower zone holding the roster OR the DM thread list */
#panel-chat .chat-rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#panel-chat #chat-dm-list,
#panel-chat #chat-users-list { /* chat.js toggles their display:block/none */ }

/* Presence roster rows + DM-thread rows (chat.js emits .chat-user-row with
 * its own inline styles; we add only resting niceties that inline wins over) */
#panel-chat .chat-user-row { border-bottom: 1px solid var(--border); }

/* ── MAIN CONVERSATION COLUMN ─────────────────────────────────────────── */
#panel-chat .chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Conversation header */
#panel-chat .chat-main-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
#panel-chat .chat-main-head-left { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#panel-chat #chat-area-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
}
#panel-chat #chat-area-sub {
  font-size: 11px;
  color: var(--text3);
}
#panel-chat #chat-online-count { font-size: 10px; color: var(--text3); flex-shrink: 0; }

/* Message scroll region */
#panel-chat #chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
}
#panel-chat #chat-messages::-webkit-scrollbar { width: 8px; }
#panel-chat #chat-messages::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* Compose dock */
#panel-chat .chat-compose {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  background: var(--bg);
}
#panel-chat .chat-compose-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#panel-chat #chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg2);
  outline: none;
  line-height: 1.45;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .12s, box-shadow .12s;
}
#panel-chat #chat-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245,166,35,.14);
}
#panel-chat .chat-compose-btn {
  flex-shrink: 0;
  white-space: nowrap;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  transition: filter .12s, background .12s;
}
#panel-chat .chat-compose-btn:hover { filter: brightness(1.06); }
#panel-chat #chat-ai-btn {
  background: rgba(168,85,247,.12);
  border: 1px solid rgba(168,85,247,.32);
  color: var(--emr-status-purple, #a855f7);
}
#panel-chat .chat-send-btn {
  background: var(--emr-charcoal, #1a1a1a);
  color: #fff;
  border: none;
  padding: 10px 20px;
  font-size: 13px;
}

/* Mention preview pill */
#panel-chat #chat-mention-preview {
  font-size: 10px;
  color: var(--emr-status-purple, #a855f7);
  margin-bottom: 8px;
  padding: 4px 9px;
  background: rgba(168,85,247,.08);
  border-radius: 6px;
  border-left: 3px solid var(--emr-status-purple, #a855f7);
}

/* ── Responsive: collapse the rail on narrow viewports ────────────────── */
@media (max-width: 860px) {
  #panel-chat .chat-rail { width: 200px; }
}
@media (max-width: 680px) {
  #panel-chat .chat-rail { width: 150px; }
  #panel-chat .chat-rail-sub { display: none; }
}
