:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1b1e24;
  --muted: #6b7280;
  --brand: #2f6fed;
  --brand-dark: #1f52b8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); }

/* ---------- Login page ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card .login-logo {
  display: block;
  height: 100px;
  width: auto;
  margin: 0 auto 16px;
}

.login-card p.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
}

button.primary {
  background: var(--brand);
  color: #fff;
  width: 100%;
  margin-top: 20px;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: 0.6; cursor: default; }

button.secondary {
  background: #eef1f6;
  color: var(--text);
}

button.danger {
  background: #fdecec;
  color: var(--danger);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- App shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #14161c;
  color: #d7dae0;
  flex-shrink: 0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  font-weight: 700;
  color: #fff;
  font-size: 16px;
  margin-bottom: 24px;
}

.sidebar .brand-logo-box {
  background: #ffffff;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.sidebar .brand-logo-box img {
  display: block;
  max-width: 100%;
  height: 26px;
  width: auto;
}

.sidebar nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #b6bac4;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: #23262f; color: #fff; }
.sidebar nav .nav-count {
  background: #2a2d36;
  color: #b6bac4;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
}
.sidebar nav a.active .nav-count { background: #35507e; color: #fff; }
.sidebar nav .nav-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b6f79;
  margin: 18px 10px 8px;
}

.sidebar .who {
  margin-top: auto;
  font-size: 12px;
  color: #8b8f99;
  border-top: 1px solid #2a2d36;
  padding-top: 14px;
}
.sidebar .who button {
  margin-top: 8px;
  width: 100%;
  background: #23262f;
  color: #d7dae0;
}

.main {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
}

.main h1 { font-size: 20px; margin: 0 0 4px; }
.main p.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

/* The active .admin-tab section's inline style is cleared (not set to
   'block') by wireTabs() in dashboard.js specifically so this rule - or the
   mobile-only override in the media query below - is what decides its
   display, rather than an inline style always winning on specificity. */
.admin-tab { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 { font-size: 15px; margin: 0 0 14px; }

.card textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  min-height: 90px;
}

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 180px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.active { background: #e7f6ec; color: var(--success); }
.badge.inactive { background: #f3f4f6; color: var(--muted); }
.badge.open { background: #e8f0fe; color: var(--brand-dark); }
.badge.closed { background: #f3f4f6; color: var(--muted); }

/* Chatbot connection status */
.badge.connected { background: #e7f6ec; color: var(--success); }
.badge.not_connected { background: #f3f4f6; color: var(--muted); }
.badge.error { background: #fdecec; color: var(--danger); }

/* AI Chatbot is currently handling a conversation - shown in the
   Round-Robin table in place of the reassign dropdown. */
.badge.ai-active { background: #eef0ff; color: #4338ca; }

/* Client tags: for follow-up / done / regular client */
.badge.tag-follow_up { background: #fff4e5; color: #b45309; }
.badge.tag-done { background: #e7f6ec; color: var(--success); }
.badge.tag-regular { background: #eef0ff; color: #4338ca; }

select.tag-select {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
select.tag-select.tag-follow_up { background: #fff4e5; color: #b45309; border-color: #fbd8a5; }
select.tag-select.tag-done { background: #e7f6ec; color: var(--success); border-color: #b7e4c7; }
select.tag-select.tag-regular { background: #eef0ff; color: #4338ca; border-color: #c7cbfa; }

/* ---------- Facebook Page connection cards ---------- */

.fb-page-grid {
  /* Small cards, all on ONE row (scrolls sideways if there are many Pages). */
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.fb-page-card {
  position: relative;
  flex: 0 0 104px;
  width: 104px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}

.fb-page-pin {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #f3f4f6;
  border: none;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.fb-page-pin.pinned { background: #fef3c7; }
.fb-page-pin:hover { background: #e5e7eb; }
.fb-page-pin.pinned:hover { background: #fde68a; }

.fb-page-card .avatar { margin-bottom: 6px; }
.fb-page-name { font-weight: 700; font-size: 12.5px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-page-handle { color: var(--muted); font-size: 11px; margin-top: 1px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-page-disconnect { width: auto; margin-top: 8px; padding: 4px 8px; font-size: 11px; }

/* ---------- Accounts tab (system owner) ---------- */

.account-list { display: flex; flex-direction: column; gap: 10px; }
.account-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.account-main { min-width: 0; }
.account-name { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.account-email { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.account-stats { font-size: 12px; color: var(--muted); margin-top: 3px; }
.account-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.account-side button { width: auto; padding: 6px 12px; font-size: 12.5px; margin: 0; }
.badge.acct-active { background: #e7f6ec; color: var(--success); }
.badge.acct-owner { background: #e8f0fe; color: var(--brand-dark); }
.badge.acct-pending { background: #fff4e5; color: #b45309; }
.badge.acct-suspended { background: #fdecec; color: var(--danger); }
.login-alt { text-align: center; font-size: 13.5px; margin: 18px 0 0; color: var(--muted); }
.signup-card { max-width: 420px; }
.signup-card .hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.signup-agree { display: flex; align-items: flex-start; gap: 8px; margin: 14px 0 4px; font-weight: 400; font-size: 13px; }
.signup-agree input { width: auto; margin-top: 3px; }

/* ---------- Round-Robin capacity table ---------- */

#rr-capacity-table input[type="number"] { padding: 6px 8px; }

/* Wraps a wide table so it scrolls horizontally on narrow screens instead
   of squeezing its columns unreadably small. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 560px; }

/* Facebook Pages summary button (Support Agents + Round-Robin tables) - kept
   to a single line and a fixed width so a long list of Page names truncates
   with an ellipsis instead of wrapping and blowing out the row height. The
   full list is still available via the title="" hover tooltip and inside
   the popover itself. */
.fb-pages-btn {
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
  text-align: left;
}

/* Facebook Pages picker popover, triggered from a table row (Support Agents
   or Round-Robin capacity table) rather than the chat toolbar - positioned
   via inline top/left set in JS from the trigger button's bounding rect. */
.pages-popover {
  position: absolute;
  bottom: auto;
  left: auto;
  width: 260px;
  max-height: 280px;
}
.pages-popover-list { max-height: 180px; overflow-y: auto; }

/* ---------- Avatars ---------- */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  background: #dfe3ea;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
}
.avatar.small { width: 24px; height: 24px; font-size: 10px; }
.avatar.large { width: 40px; height: 40px; font-size: 14px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #14161c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #4a1414; }

/* ---------- Agent chat layout ---------- */

.chat-shell { display: flex; height: calc(100vh - 40px); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; }

.conv-list { width: 300px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.conv-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  position: relative;
}
.conv-item:hover { background: #f7f8fa; }
.conv-item.selected { background: #eef3ff; }
.conv-item .conv-item-body { flex: 1; min-width: 0; }
.conv-item .name { font-weight: 400; font-size: 14px; color: var(--text); }
.conv-item .preview { color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.conv-item .time { color: var(--muted); font-size: 11px; float: right; }

/* Unread conversations stand out: bold text + a small blue dot. */
.conv-item.unread .name { font-weight: 700; color: #0f1115; }
.conv-item.unread .preview { color: var(--text); font-weight: 600; }
.conv-item .unread-dot {
  position: absolute;
  left: 6px;
  top: 18px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--brand);
}
.conv-item.unread { padding-left: 20px; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.chat-header .chat-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-header .chat-header-actions { display: flex; align-items: center; gap: 8px; }
.chat-messages { flex: 1; overflow-y: auto; overflow-x: hidden; min-width: 0; padding: 18px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 62%; min-width: 0; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap; }
.msg .meta { white-space: normal; }
.msg a.msg-link { color: inherit; text-decoration: underline; }
.msg.customer a.msg-link { color: #1d4ed8; }
.msg.customer { background: #f0f1f4; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.agent { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.bot { background: #eef0ff; color: #312e81; border: 1px solid #c7cbfa; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  max-width: 85%;
  padding: 2px 10px;
}
.msg .meta { font-size: 10.5px; opacity: 0.65; margin-top: 4px; }

.empty-state { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }

/* ---------- Client information panel (right column) ---------- */

.client-panel {
  width: 260px;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.client-panel-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.client-panel-header .client-name { font-weight: 700; font-size: 15px; }
.client-panel-header .client-psid { font-size: 11px; word-break: break-all; }

.client-panel-section { margin-bottom: 18px; }
.client-panel-section label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.client-panel-section textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
.client-panel-section .detected-phone {
  font-size: 13.5px;
  font-weight: 600;
  background: #f7f8fa;
  border-radius: 8px;
  padding: 8px 10px;
}

/* ---------- Chat toolbar: attach / media / quick reply / emoji ---------- */

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  position: relative;
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #fff;
}
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0;
  flex: none;
  position: relative;
}
.chat-input { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 8px; }
.input-pill {
  flex: 1;
  min-width: 0;
  position: relative;
  background: #f0f2f5;
  border-radius: 22px;
}
.input-pill textarea {
  display: block;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.35;
  font-family: inherit;
  min-height: 40px;
  max-height: 120px;
  box-sizing: border-box;
}
.input-pill:has(.pill-emoji) textarea { padding-right: 42px; }
.pill-emoji { position: absolute; right: 2px; bottom: 2px; }
.send-btn {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.send-btn:hover { filter: brightness(1.08); }
.toolbar-btn {
  background: transparent;
  border: none;
  color: var(--brand);
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}
.toolbar-btn:hover { background: #f0f1f4; }

.popover {
  position: absolute;
  bottom: 46px;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  padding: 12px;
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}
.popover-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px; }

.quick-reply-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.quick-reply-item:hover { background: #f7f8fa; }
.quick-reply-item .qr-label { font-weight: 600; }
.quick-reply-item .qr-delete { color: var(--danger); font-size: 12px; background: none; padding: 2px 6px; }

.popover-add { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.popover-add input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
}

.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.emoji-grid button {
  background: none;
  border: none;
  font-size: 20px;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.emoji-grid button:hover { background: #f0f1f4; }

/* ---------- Message attachments ---------- */

.msg img.attachment { max-width: 220px; border-radius: 10px; display: block; }
.msg video.attachment { max-width: 240px; border-radius: 10px; display: block; }
.msg audio.attachment { display: block; }
.msg a.attachment-file { color: inherit; text-decoration: underline; font-weight: 600; }

/* Mobile-only chat navigation controls (back / info / close details / drawer
   backdrop). Hidden here so they never show up on desktop or tablet; the
   mobile media query below turns them on. */
.mobile-back-btn,
.mobile-info-btn,
.mobile-panel-close,
.mobile-panel-backdrop {
  display: none;
}

.nav-icon { display: none; }

/* Sidebar header row: logo + (mobile-only) action icons - avatar/greeting,
   unread bell, and (agent side only) log out. Desktop just shows the logo,
   same spacing as before this row existed. */
.sidebar-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.sidebar-topbar .brand-logo-box { flex: 1; min-width: 0; margin-bottom: 0; }
.sidebar-topbar-actions { display: none; }
.topbar-greeting { display: none; }

/* ---------- Small-screen adjustments ---------- */

@media (max-width: 640px) {
  .fb-pages-btn { max-width: 110px; }
  .pages-popover { width: 220px; }
  .row .field { min-width: 140px; }

  /* Sidebar -> horizontal top tab bar. Phones only; desktop/tablet keep the
     left sidebar untouched. */
  .app-shell { flex-direction: column; min-height: 0; }

  .sidebar {
    width: 100%;
    flex-direction: column;
    padding: 10px 12px 8px;
  }

  .sidebar-topbar {
    margin-bottom: 10px;
  }
  .sidebar .brand-logo-box {
    padding: 6px 10px;
    margin-bottom: 0;
    align-self: flex-start;
    /* Fixed/shrink-to-content, not flex:1 as on desktop - on the agent side
       .sidebar-topbar-actions (avatar/greeting/bell/logout) needs to be the
       side that grows and shrinks, so a long name truncates instead of
       squeezing the logo down to nothing. */
    flex: 0 1 auto;
  }
  .sidebar .brand-logo-box img { height: 18px; }
  .sidebar-topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 0%;
    min-width: 0;
    justify-content: flex-end;
  }
  .icon-btn {
    position: relative;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 999px;
    border: none;
    background: #23262f;
    color: #fff;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .icon-btn svg { display: block; }
  .icon-btn.active { background: var(--brand, #1a56db); }

  /* Agent side only: avatar + "Good morning, Name", inline in the top bar
     next to the logo. Shrinks/truncates first so the bell and log out
     buttons never get pushed off-screen by a long name. */
  .topbar-greeting {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
  }
  .topbar-greeting .greeting-avatar .avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
    background: linear-gradient(135deg, #2563eb, #1a56db);
    color: #fff;
    flex-shrink: 0;
  }
  .topbar-greeting .greeting-text {
    min-width: 0;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 6px;
    /* Fade out any content the horizontal scroll is hiding, so it reads as
       scrollable rather than cut off. */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
  }
  .sidebar nav a {
    flex: 0 0 auto;
    white-space: nowrap;
    margin-bottom: 0;
  }
  .sidebar nav .nav-section-label {
    flex: 0 0 auto;
    white-space: nowrap;
    margin: 0 2px;
    align-self: center;
  }

  .sidebar .who {
    margin-top: 8px;
    padding-top: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .sidebar .who button { margin-top: 0; width: auto; flex-shrink: 0; }
  /* Agent side only: "Logged in as / Agent" + its logout button move to the
     top bar as a single icon (#mobile-logout-btn) - the copy here would
     just be a redundant duplicate on a phone screen. Scoped via :has() to
     the sidebar that actually has that button, so admin's own "Logged in
     as" (unrelated - no #mobile-logout-btn there) stays untouched. */
  .sidebar:has(#mobile-logout-btn) .who { display: none; }

  .main { padding: 16px; }

  /* ============================================================
     Conversation tab (Admin) + My Inbox (Agent): Pancake-inspired
     mobile layout. One pane full-screen at a time - conversation
     list, OR the open chat, OR the client-details drawer - instead
     of the desktop's 3-column list+chat+details layout, which is
     unusable at phone widths. Applies only when the page/tab is
     flagged via the "mobile-chat-fullscreen" body class (agent.html
     always carries it; dashboard.js adds/removes it as the admin
     switches in and out of the Conversation tab) so every OTHER
     admin tab keeps its normal scrolling page.
     ============================================================ */

  body.mobile-chat-fullscreen { overflow: hidden; }
  body.mobile-chat-fullscreen .app-shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  body.mobile-chat-fullscreen .main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
  }
  /* The page title + subtitle ("Admin dashboard" / "My inbox") are
     redundant on a phone screen - the highlighted nav tab already says
     where you are, and every section has its own heading below. Dropping
     them frees up real space for content. Mobile only; desktop keeps them.
     Descendant (not child) selector so this also reaches agent.html's
     version, which sits one level deeper inside its title .row. Doesn't
     touch each tab's own in-card <h2> headings (e.g. "Support agents"). */
  .main h1,
  .main p.subtitle {
    display: none;
  }

  body.mobile-chat-fullscreen .main > .row {
    flex-shrink: 0;
    padding: 12px 12px 0;
    margin: 0;
    /* The title (h1 + subtitle) is hidden on mobile - see the rule above -
       so without this the Facebook Page filter (the only visible child)
       would be the row's sole flex item and, per .row .field's flex:1,
       stretch across the whole width instead of sitting on the left. */
    justify-content: flex-start !important;
  }
  #agent-page-filter-wrap {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: 200px !important;
  }
  #agent-page-filter-wrap label {
    font-size: 10px;
    margin: 0 0 3px;
  }
  body.mobile-chat-fullscreen #tab-conversation {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
  }
  /* (The Conversation tab's own explanatory <p class="subtitle"> is already
     covered by the ".main p.subtitle" rule above.) */
  body.mobile-chat-fullscreen #tab-conversation > .row {
    flex-shrink: 0;
    padding: 10px 12px 0;
    margin: 0;
    gap: 8px;
  }
  body.mobile-chat-fullscreen #tab-conversation > .row .field label {
    font-size: 10px;
    margin-bottom: 3px;
  }
  body.mobile-chat-fullscreen #tab-conversation > .row .field {
    min-width: 0;
    flex: 1 1 0;
  }
  /* Once a conversation is open full-screen, the list-scoped Status/Agent/
     Page filters (Admin) and the title row (Agent) don't apply anymore and
     just eat space that should go to the conversation itself - hide them
     until the user taps back. The top nav bar stays, matching the Pancake
     reference (its bottom nav stays visible inside a conversation too). */
  #tab-conversation:has(.chat-shell.mobile-chat-open) > .row,
  .main:has(.chat-shell.mobile-chat-open) > .row {
    display: none;
  }

  .chat-shell {
    flex: 1;
    min-height: 0;
    height: auto;
    border: none;
    border-radius: 0;
    position: relative;
    margin-top: 10px;
  }

  /* List pane: full width, fills the shell. */
  .chat-shell .conv-list {
    width: 100%;
    height: 100%;
  }

  /* Chat pane: hidden until a conversation is opened, then covers the list
     completely (own stacking layer, not squeezed beside it). */
  .chat-shell .chat-main {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #fff;
  }
  .chat-shell.mobile-chat-open .chat-main { display: flex; }
  .chat-shell.mobile-chat-open .conv-list { visibility: hidden; }

  .mobile-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border: none;
    background: transparent;
    font-size: 20px;
    border-radius: 999px;
    cursor: pointer;
  }
  .mobile-back-btn:hover { background: #f0f1f4; }
  .mobile-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border: none;
    background: transparent;
    font-size: 16px;
    border-radius: 999px;
    cursor: pointer;
  }
  .mobile-info-btn:hover { background: #f0f1f4; }

  .chat-header { padding: 10px 12px; gap: 6px; }
  .chat-header-actions .danger { padding: 6px 10px; font-size: 12px; }
  #chat-title, #admin-chat-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 38vw;
    display: inline-block;
    vertical-align: middle;
  }

  .msg { max-width: 82%; }

  /* Client details: a bottom sheet instead of a right-hand column. */
  .chat-shell .client-panel {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    /* Never taller than the chat area itself: the agent's tab bar above it
       is tall, so a plain 78vh pushed the sheet's top (and its Back button)
       up under the tab bar. */
    max-height: min(78vh, calc(100% - 12px));
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
    transform: translateY(105%);
    transition: transform 0.22s ease;
    z-index: 5;
    background: #fff;
    padding-top: 52px;
    /* Keep "Save client details" clear of the iPhone home indicator. */
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .chat-shell.mobile-details-open .client-panel { transform: translateY(0); }

  .mobile-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    position: absolute;
    top: 6px;
    left: 8px;
    height: 32px;
    padding: 0 12px 0 6px;
    border: none;
    background: #f3f4f6;
    color: var(--text);
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 1;
  }

  .mobile-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 17, 21, 0.4);
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .chat-shell.mobile-details-open .mobile-panel-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .popover { max-width: calc(100vw - 24px); }

  /* Conversation rows: a bit more breathing room for touch, and never let a
     long name + badge combo force horizontal scroll. */
  .conv-item { padding: 14px; }
  .conv-item .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    max-width: 100%;
  }

  /* ============================================================
     Bell badge (unread count), sitting in the top bar next to the logo on
     both the admin Conversation tab and the agent side.
     ============================================================ */

  .icon-btn .bell-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 999px;
    background: #e53e3e;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    line-height: 16px;
    text-align: center;
  }

  /* ============================================================
     Agent inbox nav: always visible (no hidden menu) as a single
     horizontally scrollable row of filter icons directly under the top
     bar, reusing the existing #inbox-nav links/counts (desktop keeps its
     own vertical-list styling - see the base rules above and .sidebar nav
     earlier in this block).
     ============================================================ */

  #inbox-nav {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: flex-start !important;
    gap: 12px;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 2px 2px 14px !important;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent) !important;
    mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent) !important;
  }
  #inbox-nav .nav-section-label { display: none; }
  /* Custom tag links sit in their own wrapper div; let them join the same
     row instead of stacking in a column at the end. */
  #inbox-nav #custom-tag-filters { display: contents; }
  #inbox-nav .nav-link {
    display: flex !important;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 68px;
    position: relative;
    padding: 2px !important;
    margin-bottom: 0;
    background: transparent !important;
    color: inherit !important;
  }
  #inbox-nav .nav-icon {
    display: flex !important;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: #23262f;
    align-items: center;
    justify-content: center;
    color: #fff;
  }
  #inbox-nav .nav-icon svg { width: 20px; height: 20px; }
  #inbox-nav .nav-link.active .nav-icon { background: var(--brand, #1a56db); }
  #inbox-nav .nav-label {
    font-size: 10.5px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    white-space: normal;
    max-width: 100%;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  #inbox-nav .nav-count {
    position: absolute;
    top: 0;
    right: 6px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    font-size: 10px;
    line-height: 16px;
  }
}

/* ============================================================
   Update 34: inbox search, quick-reply upgrades, sound toggle, reports
   ============================================================ */

/* Search box pinned to the top of the conversation list. */
.conv-search {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.conv-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #f7f8fa;
}
.conv-search input:focus { outline: none; border-color: var(--brand); background: #fff; }

/* Quick replies: two-line items with edit + remove. */
.quick-reply-item .qr-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.quick-reply-item .qr-preview {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quick-reply-item .qr-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.quick-reply-item .qr-edit { background: none; border: none; cursor: pointer; font-size: 13px; padding: 2px 4px; width: auto; }
.qr-tip { margin: 8px 0 0; font-size: 11.5px; }

/* "/" shortcut menu above the message box. */
.slash-menu {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(100% - 4px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  padding: 4px;
  z-index: 30;
  max-height: 240px;
  overflow-y: auto;
}
.slash-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; flex-direction: column; }
.slash-item span { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slash-item.active, .slash-item:hover { background: #eef3ff; }

/* Sound toggle (sidebar) - the sidebar's own ".who button" rule gives it the
   dark button look; this just dims it when muted. */
.sidebar .who button.sound-off { opacity: 0.65; }
.icon-btn.sound-off { opacity: 0.55; }

/* Reports tab */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat-tile { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: #fff; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.report-heading { font-size: 14px; margin: 22px 0 8px; }
.stat-tile + .stat-tile { margin: 0; }

/* Phones: the sound button lives in the top bar (icon only), so the
   sidebar's text version is hidden to keep the "Logged in as" row from
   overflowing. */
@media (max-width: 640px) {
  .sidebar .who #sound-toggle { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Round-Robin on/off switch + per-agent share cell */
.rr-switch-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; margin: 0; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; background: #c9ced8; border-radius: 999px; cursor: pointer; transition: background 0.15s ease;
}
.switch .slider::before {
  content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: transform 0.15s ease; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--brand); outline-offset: 2px; }
.share-cell { display: flex; flex-direction: column; gap: 3px; }
.share-cell input { max-width: 90px; }
.share-pct { margin: 0; font-size: 11.5px; }

.share-total-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.share-total { font-weight: 600; font-size: 14px; }
.share-total.ok { color: #15803d; }
.share-total.bad { color: #b91c1c; }

.push-banner { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); width: min(620px, calc(100vw - 24px)); z-index: 200; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; background: #111827; color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.28); font-size: 13.5px; line-height: 1.4; }
.push-banner-text { flex: 1 1 260px; }
.push-banner-actions { display: flex; gap: 8px; }
.push-banner-actions button { width: auto; padding: 7px 14px; font-size: 13px; }
.push-banner-actions button { height: 36px; margin: 0; line-height: 1; }

.msg img.attachment, .msg video.attachment { max-width: 100%; height: auto; }
.conv-item .preview .preview-text { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.conv-item .conv-assignee { color: var(--muted); font-size: 11px; margin-top: 2px; }
.msg a.attachment-file { display: block; margin-bottom: 4px; }


/* ============================================================
   Update 40: adjustable text size (Aa), picture viewer, no page zoom
   --ui-scale is set per account: on the whole page for agents, and only on
   the Conversation tab for the admin.
   ============================================================ */
:root { --ui-scale: 1; }

.conv-search { display: flex; align-items: center; gap: 8px; }
.conv-search input { flex: 1; min-width: 0; font-size: calc(14px * var(--ui-scale)); }
.size-btn {
  flex: none;
  width: auto;
  min-width: 38px;
  height: 36px;
  padding: 0 10px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  color: var(--brand);
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.size-btn:hover { background: #f0f1f4; }

.chat-shell .conv-item .name { font-size: calc(14px * var(--ui-scale)); }
.chat-shell .conv-item .preview { font-size: calc(12.5px * var(--ui-scale)); }
.chat-shell .conv-item .time { font-size: calc(11px * var(--ui-scale)); }
.chat-shell .conv-item .badge { font-size: calc(11px * var(--ui-scale)); }
.chat-shell .conv-item .conv-assignee { font-size: calc(11px * var(--ui-scale)); }
.chat-shell .msg { font-size: calc(14px * var(--ui-scale)); line-height: 1.4; }
.chat-shell .msg .meta { font-size: calc(10.5px * var(--ui-scale)); }
.chat-shell .msg.system { font-size: calc(12px * var(--ui-scale)); }
.chat-shell .msg img.attachment, .chat-shell .msg video.attachment { max-width: min(100%, calc(220px * var(--ui-scale))); }
.chat-shell #chat-title, .chat-shell #admin-chat-title { font-size: calc(16px * var(--ui-scale)); }
.chat-shell .input-pill textarea { font-size: calc(16px * var(--ui-scale)); }
.chat-shell .quick-reply-item { font-size: calc(13px * var(--ui-scale)); }
.chat-shell .emoji-grid button { font-size: calc(20px * var(--ui-scale)); }
.chat-shell .client-panel .client-name { font-size: calc(15px * var(--ui-scale)); }
.chat-shell .client-panel label { font-size: calc(11px * var(--ui-scale)); }
.chat-shell .client-panel input, .chat-shell .client-panel select, .chat-shell .client-panel textarea { font-size: calc(14px * var(--ui-scale)); }

/* Phones: inputs under 16px make iOS zoom the whole page when you tap them.
   Keep them at 16px or more so the screen never jumps. */
@media (max-width: 900px) {
  input:not([type=checkbox]):not([type=radio]):not([type=file]),
  select,
  textarea:not(#chat-input):not(#admin-chat-input) { font-size: 16px; }
  .chat-shell .conv-search input { font-size: calc(16px * var(--ui-scale)); }
  .chat-shell .client-panel input, .chat-shell .client-panel select, .chat-shell .client-panel textarea { font-size: calc(16px * var(--ui-scale)); }
}

/* The page itself never pinch-zooms; pictures open in the viewer instead. */
html, body { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.msg img.attachment { cursor: zoom-in; }

/* Text-size popover */
.size-popover {
  position: fixed;
  z-index: 300;
  width: min(300px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  padding: 14px;
}
.size-popover .size-title { font-weight: 700; font-size: 14px; margin-bottom: 10px; color: var(--text); }
.size-popover .size-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.size-popover .size-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px;
  height: 74px; padding: 6px 2px; margin: 0; width: auto;
  border: 2px solid var(--border); border-radius: 12px; background: #fff; color: var(--text); cursor: pointer;
}
.size-popover .size-opt .size-a { font-weight: 800; line-height: 1; }
.size-popover .size-opt .size-label { font-size: 10.5px; color: var(--muted); }
.size-popover .size-opt.active { border-color: var(--brand); background: #eef3ff; }
.size-popover .size-sample { margin-top: 12px; padding: 10px 12px; background: #f0f1f4; border-radius: 12px; line-height: 1.35; }

/* Picture viewer: pinch / double-tap / buttons to zoom in and out */
.img-viewer {
  position: fixed; inset: 0; z-index: 500; background: rgba(8, 10, 14, 0.94);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
}
.img-viewer img {
  max-width: 100vw; max-height: 100vh; max-height: 100dvh;
  transform-origin: center center; will-change: transform;
  -webkit-user-drag: none; pointer-events: none;
}
.img-viewer .iv-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: flex-end; gap: 10px; padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px; }
.img-viewer .iv-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; align-items: center; gap: 10px; padding: 12px 14px calc(16px + env(safe-area-inset-bottom, 0px)); }
.img-viewer button, .img-viewer a.iv-btn {
  width: 48px; height: 48px; margin: 0; padding: 0; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 26px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer;
}
.img-viewer button:active, .img-viewer a.iv-btn:active { background: rgba(255, 255, 255, 0.34); }
.img-viewer .iv-zoom { min-width: 64px; text-align: center; color: #fff; font-weight: 700; font-size: 15px; }
.img-viewer .iv-fit { width: auto; padding: 0 16px; border-radius: 24px; font-size: 15px; }
@media (max-width: 640px) {
  #chat-title, #admin-chat-title { max-width: 62vw; }
  .chat-header .size-btn { height: 34px; }
}

/* AI Chatbot row in the Round-Robin table: keep the name on one line. */
.bot-row td b { white-space: nowrap; }
#signup-mode { width: 100%; max-width: 360px; }

/* ---------- Pasted screenshot preview (above the chat box) ---------- */
.paste-preview {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  z-index: 5;
}
.paste-item { position: relative; }
.paste-item img {
  display: block;
  height: 72px;
  max-width: 140px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.paste-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: #444;
  color: #fff;
  font-size: 15px;
  line-height: 22px;
  cursor: pointer;
}
.paste-hint { font-size: 12px; color: var(--muted, #667085); }

/* ---------- Drag & drop files onto the chat ---------- */
.paste-file {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 96px;
  height: 72px;
  padding: 4px;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f4f6f9;
  text-align: center;
}
.paste-file-icon { font-size: 24px; line-height: 1; }
.paste-file-name { font-size: 11px; line-height: 1.2; word-break: break-all; color: var(--text); }
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.10);
  backdrop-filter: blur(1px);
  pointer-events: none;
}
.drop-overlay-box {
  padding: 26px 40px;
  border: 3px dashed #2563eb;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  color: #1d4ed8;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}
.drop-overlay-icon { font-size: 36px; margin-bottom: 6px; }

/* ---------- Custom tags ---------- */
.tag-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; }
.tag-plus { font-weight: 700; font-size: 18px; line-height: 1; }
.tagmgr-overlay {
  position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.45); padding: 16px;
}
.tagmgr {
  width: 100%; max-width: 380px; max-height: 88vh; overflow-y: auto; background: #fff; border-radius: 16px;
  padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.tagmgr-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; margin-bottom: 10px; }
.tagmgr-x { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); width: auto; padding: 0 4px; }
.tagmgr-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .03em; }
.tagmgr input[type=text] { width: 100%; box-sizing: border-box; }
.tagmgr-colors { display: flex; gap: 8px; flex-wrap: wrap; }
.tagmgr-color { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.tagmgr-color.on { box-shadow: 0 0 0 2px #111; }
.tagmgr-add { width: 100%; margin-top: 14px; }
.tagmgr-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.tagmgr-del { width: auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; padding: 4px 6px; }

/* ---------- Quick replies with pictures ---------- */
.qr-pic-row { display: flex; align-items: center; gap: 10px; }
.qr-pic-btn {
  display: inline-block; cursor: pointer; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  border: 1px dashed var(--border); background: #f8fafc; color: var(--text);
}
.qr-pic-preview { position: relative; display: inline-flex; }
.qr-pic-thumb { height: 44px; max-width: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.qr-pic-remove {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: none; background: #444; color: #fff; font-size: 14px; line-height: 20px; cursor: pointer;
}
.quick-reply-item .qr-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; flex: none; margin-right: 8px; border: 1px solid var(--border); }
.qr-shared { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 8px; background: #eef2ff; color: #4338ca; vertical-align: middle; }

/* ---------- Photo library (albums) ---------- */
.plib-overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.5); padding: 12px; }
.plib { width: 100%; max-width: 560px; height: min(640px, 92vh); display: flex; flex-direction: column; background: #fff; border-radius: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); overflow: hidden; }
.plib-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 16px; }
.plib-head .plib-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plib-head > strong:first-child { flex: 1; }
.plib-head-actions { display: flex; align-items: center; gap: 2px; }
.plib-x, .plib-back, .plib-icon { background: none; border: none; cursor: pointer; width: auto; padding: 2px 8px; font-size: 20px; line-height: 1; color: var(--text); }
.plib-x { font-size: 26px; color: var(--muted); }
.plib-actions { display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.plib-btn { display: inline-block; cursor: pointer; font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: #f4f6f9; color: var(--text); width: auto; }
.plib-btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.plib-btn.danger { color: #fff; background: #dc2626; border-color: #dc2626; }
.plib-newrow { display: flex; gap: 8px; padding: 0 14px 10px; }
.plib-newrow input { flex: 1; min-width: 0; }
.plib-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; padding: 4px 14px 14px; align-content: start; }
.plib-album { display: flex; flex-direction: column; align-items: stretch; gap: 3px; background: none; border: none; padding: 0; cursor: pointer; text-align: left; width: auto; }
.plib-cover { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; border-radius: 12px; background: #eef2f7; font-size: 34px; overflow: hidden; border: 1px solid var(--border); }
.plib-cover img, .plib-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.plib-album-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plib-album-count { font-size: 11px; color: var(--muted); }
.plib-photo { position: relative; aspect-ratio: 1; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: #eef2f7; cursor: pointer; width: auto; }
.plib-photo.sel { border-color: #2563eb; }
.plib-check { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); color: transparent; font-size: 14px; line-height: 22px; text-align: center; border: 1px solid #94a3b8; }
.plib-photo.sel .plib-check { background: #2563eb; color: #fff; border-color: #2563eb; }
.plib-foot { gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); background: #fff; }
.plib-usage { padding: 0 14px 12px; margin: 0; }

/* ---------- Hide / show the left menu and the right client panel (desktop) ---------- */
.panel-handle, .panel-toggles { display: none; }
@media (min-width: 641px) {
  body.hide-left .app-shell > .sidebar { display: none; }
  body.hide-right .chat-shell .client-panel { display: none; }
  .chat-shell { position: relative; }
  .panel-handle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 50%; transform: translateY(-50%); z-index: 30;
    width: 20px; height: 56px; padding: 0; border: none; background: var(--brand); color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); cursor: pointer; opacity: 0.9; border-radius: 0 8px 8px 0;
  }
  .panel-handle:hover { opacity: 1; background: var(--brand-dark); }
  .panel-handle svg { width: 12px; height: 12px; transition: transform 0.15s; }
  #handle-left { left: 220px; }
  body.hide-left #handle-left { left: 0; }
  body.hide-left #handle-left svg { transform: rotate(180deg); }
  #handle-right { position: absolute; border-radius: 8px 0 0 8px; right: 260px; }
  body.hide-right #handle-right { right: 0; }
  body.hide-right #handle-right svg { transform: rotate(180deg); }
  body:not(.hide-right) #handle-right svg { transform: rotate(0deg); }

  .panel-toggles { display: flex; gap: 8px; margin-left: auto; margin-right: 12px; align-self: center; }
  .panel-toggle-btn {
    width: auto; margin: 0; padding: 6px 12px; font-size: 13px; font-weight: 500; line-height: 1.2;
    background: #eef1f6; color: #334155; border: 1px solid #d5dbe5; border-radius: 8px; cursor: pointer; white-space: nowrap;
  }
  .panel-toggle-btn:hover { background: #e2e7ef; }
  .panel-toggle-btn.is-off { background: #fff3cd; border-color: #f0d98a; color: #7a5b00; }
  .panel-toggle-btn.is-off:hover { background: #ffecb0; }
}

/* ---------- Messenger-style message actions ---------- */
.chat-messages .msg { position: relative; }
.msg.has-reactions { margin-bottom: 14px; }
.msg.flash { animation: msgflash 1.3s ease; }
@keyframes msgflash { 0%, 60% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.85); } 100% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0); } }
.msg .msg-pin-mark { opacity: 0.9; }

.msg-quote { white-space: normal; cursor: pointer; margin: -2px 0 7px; padding: 4px 9px; border-left: 3px solid #94a3b8; border-radius: 6px; background: rgba(0, 0, 0, 0.07); font-size: 0.86em; line-height: 1.3; }
.msg-quote b { display: block; font-weight: 700; opacity: 0.85; }
.msg-quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; opacity: 0.9; }
.msg-quote.missing { cursor: default; font-style: italic; opacity: 0.75; }
.msg.agent .msg-quote, .msg.bot .msg-quote { border-left-color: rgba(255, 255, 255, 0.85); background: rgba(255, 255, 255, 0.18); }
.msg.bot .msg-quote { border-left-color: #818cf8; background: rgba(79, 70, 229, 0.08); }

.msg-reactions { position: absolute; bottom: -13px; display: flex; gap: 3px; white-space: nowrap; }
.msg.customer .msg-reactions { left: 8px; }
.msg.agent .msg-reactions, .msg.bot .msg-reactions { right: 8px; }
.msg-react-chip { background: #fff; color: var(--text); border: 1px solid #d5dae3; border-radius: 999px; padding: 1px 6px; font-size: 13px; font-weight: 400; line-height: 1.4; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); width: auto; }
.msg-react-chip i { font-style: normal; font-size: 11px; color: var(--muted); }
.msg-react-chip.mine { border-color: var(--brand); background: #eaf1ff; }

.msg-more { display: none; position: absolute; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; padding: 0; line-height: 1; border-radius: 50%; background: #fff; color: #64748b; border: 1px solid #d5dae3; font-size: 16px; font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.msg.customer .msg-more { left: calc(100% + 6px); }
.msg.agent .msg-more, .msg.bot .msg-more { right: calc(100% + 6px); }
@media (hover: hover) { .msg:hover .msg-more { display: block; } }
/* On a phone you hold the message instead, so keep text from being selected by the same press. */
@media (pointer: coarse) { .chat-messages .msg { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } }

.pinned-bar { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: #fffbea; border-bottom: 1px solid #f3e6a3; font-size: 12.5px; cursor: pointer; color: #5b4a05; min-width: 0; }
.pinned-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reply-bar { display: flex; align-items: center; gap: 8px; padding: 7px 14px; margin: 0; background: #f1f5fd; border-top: 1px solid var(--border); border-left: 3px solid var(--brand); }
.reply-info { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 12.5px; }
.reply-info b { color: var(--brand); }
.reply-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.reply-x { background: none; color: #64748b; width: auto; padding: 0 6px; font-size: 22px; line-height: 1; }

.msg-menu { position: fixed; z-index: 3000; min-width: 190px; background: #fff; border-radius: 12px; box-shadow: 0 10px 34px rgba(0, 0, 0, 0.28); padding: 6px; display: flex; flex-direction: column; }
.msg-menu-emojis { display: flex; justify-content: space-between; gap: 2px; padding: 4px 4px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.msg-menu-emojis button { background: none; width: auto; padding: 3px 5px; font-size: 22px; line-height: 1.1; border-radius: 8px; }
.msg-menu-emojis button:hover { background: #eef1f6; transform: scale(1.15); }
.msg-menu-emojis button.mine { background: #dbe8ff; }
.msg-menu > button[data-act] { background: none; color: var(--text); text-align: left; width: 100%; padding: 9px 10px; font-size: 14px; font-weight: 500; }
.msg-menu > button[data-act]:hover { background: #f1f3f7; }
.msg-menu > button.danger { color: var(--danger); background: none; }

.fwd { height: min(560px, 90vh); }
.fwd-preview { padding: 8px 16px; font-size: 13px; color: var(--muted); background: #f7f8fa; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd-search { padding: 10px 14px 4px; }
.fwd-search input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 16px; }
.fwd-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.fwd-item { display: block; width: 100%; text-align: left; background: none; color: var(--text); padding: 11px 10px; font-weight: 500; border-radius: 8px; }
.fwd-item:hover { background: #f1f3f7; }
