/* ══════════════════════════════════════════════════════════════
   Print Task Board — Team Chat styles
   Mounted on <body> (outside #ptb-root), so theme vars are local.
   ══════════════════════════════════════════════════════════════ */
#ptb-chat-fab, #ptb-chat, .ptb-chat-toast {
  --c-accent: #f97316;
  --c-accent-strong: #ea6c0e;
  --c-bg: #ffffff;
  --c-bg2: #f7f8fa;
  --c-head: #1d2939;
  --c-line: #e6e8ec;
  --c-ink: #1d2939;
  --c-mut: #667085;
  --c-their: #eef0f3;
  --c-their-ink: #1d2939;
  --c-w: 360px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-sizing: border-box;
}
#ptb-chat *, #ptb-chat *::before, #ptb-chat *::after { box-sizing: border-box; }

/* Make room for the panel on wide screens by shrinking the fixed board. */
@media (min-width: 900px) {
  body.ptb-chat-open #ptb-root { width: calc(100vw - var(--c-w, 360px)); }
}

/* ── Floating launcher ── */
#ptb-chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 99000;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--c-accent); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 6px 20px rgba(249,115,22,.42), 0 2px 6px rgba(0,0,0,.18);
  transition: transform .15s ease, background .15s ease;
}
#ptb-chat-fab:hover { background: var(--c-accent-strong); transform: translateY(-2px); }
#ptb-chat-fab.active { transform: scale(.92); }
#ptb-chat-fab svg { display: block; }
.ptb-chat-fab-badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px;
  background: #ef4444; color: #fff; border-radius: 999px; border: 2px solid #fff;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}
#ptb-chat-fab.has-unread { animation: ptbChatPulse 2s ease-in-out infinite; }
@keyframes ptbChatPulse { 0%,100% { box-shadow: 0 6px 20px rgba(249,115,22,.42); } 50% { box-shadow: 0 6px 26px rgba(239,68,68,.55); } }

/* ── Panel ── */
.ptb-chat-panel {
  position: fixed; top: 30px; right: 0; bottom: 0; width: var(--c-w);
  max-width: 92vw; z-index: 99000;
  background: var(--c-bg); color: var(--c-ink);
  border-left: 1px solid var(--c-line);
  box-shadow: -8px 0 28px rgba(16,24,40,.12);
  display: flex; flex-direction: column;
  transform: translateX(102%); transition: transform .22s ease;
  font-size: 14px;
}
.ptb-chat-panel.show { transform: translateX(0); }

/* ── Header ── */
.ptb-chat-head {
  flex: 0 0 auto; height: 52px; display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px; background: var(--c-head); color: #fff;
}
.ptb-chat-head-mid { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; }
.ptb-chat-title { font-weight: 700; font-size: 15px; }
.ptb-chat-logo { display: inline-flex; align-items: center; color: var(--c-accent); }
.ptb-chat-ic {
  flex: none; width: 32px; height: 32px; border-radius: 8px; border: none;
  background: transparent; color: #cdd5e0; font-size: 22px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ptb-chat-ic:hover { background: rgba(255,255,255,.12); color: #fff; }
.ptb-chat-x { font-size: 24px; }

.ptb-chat-th-head { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.ptb-chat-th-head { flex-direction: row; align-items: center; gap: 8px; }
.ptb-chat-th-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.ptb-chat-th-sub { font-size: 11.5px; color: #9aa4b2; font-weight: 500; }

/* ── Body / scroll ── */
.ptb-chat-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; }
.ptb-chat-body::-webkit-scrollbar { width: 9px; }
.ptb-chat-body::-webkit-scrollbar-thumb { background: #cdd2da; border-radius: 8px; border: 2px solid var(--c-bg); }

.ptb-chat-empty { padding: 40px 22px; text-align: center; color: var(--c-mut); font-size: 13px; line-height: 1.7; }
.ptb-chat-empty.sm { padding: 22px; }
.ptb-chat-spin {
  width: 26px; height: 26px; margin: 40px auto; border-radius: 50%;
  border: 3px solid var(--c-line); border-top-color: var(--c-accent); animation: ptbChatSpin .8s linear infinite;
}
@keyframes ptbChatSpin { to { transform: rotate(360deg); } }

/* ── New-chat / new-group action bar ── */
.ptb-chat-actions { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--c-line); }
.ptb-chat-newbtn {
  flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; border-radius: 9px; border: 1px solid var(--c-accent);
  background: var(--c-accent); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
}
.ptb-chat-newbtn:hover { background: var(--c-accent-strong); }
.ptb-chat-newbtn.ghost { background: transparent; color: var(--c-accent); }
.ptb-chat-newbtn.ghost:hover { background: color-mix(in srgb, var(--c-accent) 10%, #fff); }
.ptb-chat-newbtn span { font-size: 15px; line-height: 1; }

/* ── Conversation rows ── */
.ptb-chat-row {
  width: 100%; display: flex; align-items: center; gap: 11px; padding: 11px 14px;
  background: transparent; border: none; border-bottom: 1px solid var(--c-line);
  cursor: pointer; text-align: left;
}
.ptb-chat-row:hover { background: var(--c-bg2); }
.ptb-chat-row.unread { background: color-mix(in srgb, var(--c-accent) 7%, #fff); }
.ptb-chat-row-main { flex: 1 1 auto; min-width: 0; }
.ptb-chat-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ptb-chat-row-name { font-weight: 600; font-size: 14px; color: var(--c-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptb-chat-grouptag { color: var(--c-mut); font-weight: 500; font-size: 12px; }
.ptb-chat-row-time { flex: none; font-size: 11px; color: var(--c-mut); }
.ptb-chat-row-sub { display: block; margin-top: 2px; font-size: 12.5px; color: var(--c-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptb-chat-row.unread .ptb-chat-row-sub { color: var(--c-ink); font-weight: 500; }
.ptb-chat-row-badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--c-accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 20px; text-align: center;
}

/* ── Avatars ── */
.ptb-chat-av {
  flex: none; width: 38px; height: 38px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; letter-spacing: .3px;
}
.ptb-chat-av.sm { width: 30px; height: 30px; font-size: 11.5px; }
.ptb-chat-av.msg { width: 28px; height: 28px; font-size: 11px; align-self: flex-end; }
.ptb-chat-av.msg.ghost { background: transparent !important; }
.ptb-chat-av-group svg { color: #fff; }

/* ── People picker ── */
.ptb-chat-search { flex: 0 0 auto; padding: 10px 12px; border-bottom: 1px solid var(--c-line); }
.ptb-chat-search.inset { padding: 8px 0 0; border: none; }
.ptb-chat-search input, .ptb-chat-ginput {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--c-line);
  border-radius: 9px; font-size: 13.5px; color: var(--c-ink); background: var(--c-bg2); outline: none;
}
.ptb-chat-search input:focus, .ptb-chat-ginput:focus { border-color: var(--c-accent); background: #fff; }
.ptb-chat-prow {
  width: 100%; display: flex; align-items: center; gap: 11px; padding: 9px 14px;
  background: transparent; border: none; border-bottom: 1px solid var(--c-line); cursor: pointer; text-align: left;
}
.ptb-chat-prow:hover { background: var(--c-bg2); }
.ptb-chat-prow.sel { background: color-mix(in srgb, var(--c-accent) 10%, #fff); }
.ptb-chat-prow-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.ptb-chat-prow-name { font-weight: 600; font-size: 13.5px; color: var(--c-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptb-chat-prow-dept { font-size: 11.5px; color: var(--c-mut); }
.ptb-chat-check {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--c-line);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700;
}
.ptb-chat-prow.sel .ptb-chat-check { background: var(--c-accent); border-color: var(--c-accent); }

/* ── New group form ── */
.ptb-chat-gform { flex: 0 0 auto; padding: 12px 12px 8px; border-bottom: 1px solid var(--c-line); }
.ptb-chat-foot { flex: 0 0 auto; padding: 10px 12px; border-top: 1px solid var(--c-line); }
.ptb-chat-primary {
  width: 100%; height: 40px; border: none; border-radius: 9px; background: var(--c-accent);
  color: #fff; font-weight: 700; font-size: 14px; cursor: pointer;
}
.ptb-chat-primary.sm { height: 34px; font-size: 13px; margin-top: 8px; }
.ptb-chat-primary:hover:not(:disabled) { background: var(--c-accent-strong); }
.ptb-chat-primary:disabled { opacity: .5; cursor: not-allowed; }

/* ── Thread ── */
.ptb-chat-thread { display: flex; flex-direction: column; padding: 12px 12px 6px; background: var(--c-bg2); }
.ptb-chat-msgs { display: flex; flex-direction: column; gap: 3px; margin-top: auto; }
.ptb-chat-more { align-self: center; margin: 4px 0 10px; padding: 5px 14px; font-size: 12px; border: 1px solid var(--c-line);
  background: #fff; color: var(--c-mut); border-radius: 999px; cursor: pointer; }
.ptb-chat-more:hover { color: var(--c-accent); border-color: var(--c-accent); }
.ptb-chat-daysep { text-align: center; margin: 12px 0 8px; position: relative; }
.ptb-chat-daysep span { background: var(--c-bg2); position: relative; z-index: 1; padding: 0 10px; font-size: 11px; color: var(--c-mut); font-weight: 600; }
.ptb-chat-daysep::before { content: ""; position: absolute; left: 16px; right: 16px; top: 50%; height: 1px; background: var(--c-line); }

.ptb-chat-msg { display: flex; gap: 7px; align-items: flex-end; max-width: 100%; }
.ptb-chat-msg.mine { flex-direction: row-reverse; }
.ptb-chat-msg.grouped { margin-top: 1px; }
.ptb-chat-bub {
  position: relative; max-width: 80%; padding: 7px 11px 5px; border-radius: 14px;
  background: #fff; color: var(--c-their-ink); border: 1px solid var(--c-line);
  box-shadow: 0 1px 1px rgba(16,24,40,.04); word-wrap: break-word; overflow-wrap: anywhere;
}
.ptb-chat-msg.theirs .ptb-chat-bub { border-bottom-left-radius: 5px; }
.ptb-chat-msg.theirs.grouped .ptb-chat-bub { border-bottom-left-radius: 14px; }
.ptb-chat-msg.mine .ptb-chat-bub { background: var(--c-accent); color: #fff; border-color: var(--c-accent); border-bottom-right-radius: 5px; }
.ptb-chat-msg.mine.grouped .ptb-chat-bub { border-bottom-right-radius: 14px; }
.ptb-chat-msg-name { display: block; font-size: 11.5px; font-weight: 700; margin-bottom: 1px; }
.ptb-chat-msg-body { font-size: 13.5px; line-height: 1.42; white-space: pre-wrap; }
.ptb-chat-msg-body a { color: inherit; text-decoration: underline; }
.ptb-chat-msg.theirs .ptb-chat-msg-body a { color: var(--c-accent-strong); }
.ptb-chat-msg-time { display: inline-block; margin-left: 8px; font-size: 10px; opacity: .7; vertical-align: baseline; float: right; margin-top: 4px; }
.ptb-chat-msg.mine .ptb-chat-msg-time { color: #fff; }

/* ── Composer ── */
.ptb-chat-composer-wrap { flex: 0 0 auto; position: relative; background: var(--c-bg); }
.ptb-chat-composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 9px 10px;
  border-top: 1px solid var(--c-line); background: var(--c-bg);
}
.ptb-chat-attach {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--c-line);
  background: var(--c-bg2); color: var(--c-ink); font-size: 17px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ptb-chat-attach:hover { border-color: var(--c-accent); background: color-mix(in srgb, var(--c-accent) 10%, #fff); }
.ptb-chat-composer textarea {
  flex: 1 1 auto; resize: none; max-height: 120px; min-height: 38px; padding: 9px 12px;
  border: 1px solid var(--c-line); border-radius: 20px; font-size: 13.5px; line-height: 1.4;
  font-family: inherit; color: var(--c-ink); background: var(--c-bg2); outline: none;
}
.ptb-chat-composer textarea:focus { border-color: var(--c-accent); background: #fff; }
.ptb-chat-send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--c-accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.ptb-chat-send:hover { background: var(--c-accent-strong); }

/* Pending job-tag chips above the input */
.ptb-chat-tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; }
.ptb-chat-tagchip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 6px 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--c-accent) 12%, #fff); color: var(--c-accent-strong);
  border: 1px solid var(--c-accent-strong); font-size: 12px; font-weight: 600;
}
.ptb-chat-tagchip button { border: none; background: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }

/* Job tag chip inside a message bubble */
.ptb-chat-jobchip {
  display: inline-flex; align-items: center; gap: 4px; margin: 2px 0; padding: 2px 9px; border-radius: 999px;
  background: rgba(255,255,255,.22); color: inherit; font-weight: 600; font-size: 12.5px;
  text-decoration: none; border: 1px solid rgba(255,255,255,.5);
}
.ptb-chat-msg.theirs .ptb-chat-jobchip {
  background: color-mix(in srgb, var(--c-accent) 12%, #fff); color: var(--c-accent-strong); border-color: var(--c-accent-border);
}
.ptb-chat-jobchip:hover { filter: brightness(.97); text-decoration: none; }

/* Job picker popover */
.ptb-chat-jobpick {
  position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px); z-index: 5;
  background: var(--c-bg); border: 1px solid var(--c-line); border-radius: 12px;
  box-shadow: 0 -6px 24px rgba(16,24,40,.16); overflow: hidden; max-height: 300px; display: flex; flex-direction: column;
}
.ptb-chat-jobpick-head { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--c-line); }
.ptb-chat-jobpick-head input {
  flex: 1 1 auto; height: 34px; padding: 0 10px; border: 1px solid var(--c-line); border-radius: 8px;
  font-size: 13px; background: var(--c-bg2); color: var(--c-ink); outline: none;
}
.ptb-chat-jobpick-head input:focus { border-color: var(--c-accent); background: #fff; }
.ptb-chat-ic.dark { color: var(--c-mut); }
.ptb-chat-ic.dark:hover { background: var(--c-bg2); color: var(--c-ink); }
.ptb-chat-jobpick-list { overflow-y: auto; }
.ptb-chat-jobrow {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 12px; text-align: left;
  background: transparent; border: none; border-bottom: 1px solid var(--c-line); cursor: pointer;
}
.ptb-chat-jobrow:hover { background: var(--c-bg2); }
.ptb-chat-jobrow.added { background: color-mix(in srgb, var(--c-accent) 8%, #fff); }
.ptb-chat-jobrow-ord { font-weight: 700; font-size: 12.5px; color: var(--c-ink); white-space: nowrap; }
.ptb-chat-jobrow-title { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--c-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptb-chat-jobrow-add { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--c-accent); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.ptb-chat-jobrow.added .ptb-chat-jobrow-add { background: #16a34a; }

/* Delete message control */
.ptb-chat-del {
  position: absolute; top: 50%; transform: translateY(-50%); opacity: 0;
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--c-line);
  background: var(--c-bg); color: #dc2626; font-size: 12px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.ptb-chat-msg.mine .ptb-chat-del { left: -28px; }
.ptb-chat-msg.theirs .ptb-chat-del { right: -28px; }
.ptb-chat-msg:hover .ptb-chat-del { opacity: .85; }
.ptb-chat-del:hover { opacity: 1; background: #fef2f2; }
@media (hover: none) { .ptb-chat-del { opacity: .5; } }

/* ── Manage (group settings) ── */
.ptb-chat-manage { padding: 4px 0 16px; }
.ptb-chat-mgsec { padding: 12px 14px; border-bottom: 1px solid var(--c-line); }
.ptb-chat-mglbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--c-mut); font-weight: 700; margin-bottom: 8px; }
.ptb-chat-renamerow { display: flex; gap: 8px; }
.ptb-chat-mini { flex: none; padding: 0 14px; height: 38px; border: 1px solid var(--c-accent); background: var(--c-accent); color: #fff; border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; }
.ptb-chat-mini:hover { background: var(--c-accent-strong); }
.ptb-chat-mrow { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.ptb-chat-owner, .ptb-chat-you { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px; margin-left: 4px; }
.ptb-chat-owner { background: color-mix(in srgb, var(--c-accent) 16%, #fff); color: var(--c-accent-strong); }
.ptb-chat-you { background: #eef0f3; color: var(--c-mut); }
.ptb-chat-leave { width: 100%; height: 38px; border: 1px solid #fecaca; background: #fff; color: #dc2626; border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; }
.ptb-chat-leave:hover { background: #fef2f2; }

/* ── Toast ── */
.ptb-chat-toast {
  position: fixed; bottom: 88px; right: 20px; z-index: 99002; max-width: 320px;
  background: #1d2939; color: #fff; padding: 9px 16px; border-radius: 9px; font-size: 13px; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0,0,0,.28); opacity: 0; transform: translateY(8px); transition: .2s ease;
}
.ptb-chat-toast.show { opacity: 1; transform: translateY(0); }

/* ══════════════════════════════════════════════════════════════
   DARK THEME  (mirrors #ptb-root[data-ptb-theme="dark"])
   ══════════════════════════════════════════════════════════════ */
body.ptb-chat-dark #ptb-chat, body.ptb-chat-dark .ptb-chat-toast {
  --c-bg: #0e1117; --c-bg2: #161b22; --c-head: #0b0e13; --c-line: #232b35;
  --c-ink: #e6e9ef; --c-mut: #8a94a3; --c-their: #1c232c; --c-their-ink: #e6e9ef;
}
body.ptb-chat-dark .ptb-chat-body::-webkit-scrollbar-thumb { background: #3a444f; }
body.ptb-chat-dark .ptb-chat-search input:focus, body.ptb-chat-dark .ptb-chat-ginput:focus,
body.ptb-chat-dark .ptb-chat-composer textarea:focus { background: #1c232c; }
body.ptb-chat-dark .ptb-chat-row.unread { background: color-mix(in srgb, var(--c-accent) 14%, #0e1117); }
body.ptb-chat-dark .ptb-chat-msg.theirs .ptb-chat-bub { background: #1c232c; border-color: #2a323c; }
body.ptb-chat-dark .ptb-chat-more { background: #161b22; }
body.ptb-chat-dark .ptb-chat-newbtn.ghost:hover,
body.ptb-chat-dark .ptb-chat-prow.sel, body.ptb-chat-dark .ptb-chat-row.unread .ptb-chat-row-sub { color: var(--c-ink); }
body.ptb-chat-dark .ptb-chat-you { background: #232b35; }
body.ptb-chat-dark .ptb-chat-leave { background: #161b22; border-color: #4c1d1d; color: #f87171; }
body.ptb-chat-dark .ptb-chat-leave:hover { background: #1c232c; }
body.ptb-chat-dark .ptb-chat-attach { background: #1c232c; }
body.ptb-chat-dark .ptb-chat-jobpick-head input:focus { background: #1c232c; }
body.ptb-chat-dark .ptb-chat-del { background: #1c232c; border-color: #2a323c; }
body.ptb-chat-dark .ptb-chat-del:hover { background: #2a1414; }

/* ── Narrow screens: overlay instead of shrinking board ── */
@media (max-width: 560px) {
  .ptb-chat-panel { top: 0; width: 100vw; max-width: 100vw; }
  #ptb-chat-fab { right: 16px; bottom: 16px; }
}
