/* TR Team Messaging — floating widget (Apple-inspired, light theme) */
.dm-widget { position: fixed; right: 22px; bottom: 22px; width: 340px; max-width: calc(100vw - 44px); z-index: 1000; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.dm-widget * { box-sizing: border-box; }
.dm-launch { width: 56px; height: 56px; border-radius: 50%; background: #2563eb; color: #fff; border: none; box-shadow: 0 6px 20px rgba(37,99,235,.4); cursor: pointer; display: grid; place-items: center; margin-left: auto; transition: transform .15s ease; }
.dm-launch:hover { transform: scale(1.06); }
.dm-launch svg { width: 26px; height: 26px; stroke: #fff; fill: none; stroke-width: 2; }
.dm-panel { display: none; flex-direction: column; height: 460px; max-height: calc(100vh - 80px); background: #fff; border: 1px solid #e2e8f0; border-radius: 18px; box-shadow: 0 16px 48px rgba(6,58,83,.22); overflow: hidden; }
.dm-widget.open .dm-panel { display: flex; }
.dm-widget.open .dm-launch { display: none; }
.dm-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: linear-gradient(180deg,#f5fbfe,#eaf6fc); border-bottom: 1px solid #e2e8f0; }
.dm-head h4 { margin: 0; font-size: 14px; color: #0a5376; flex: 1; }
.dm-head .dm-min { width: 26px; height: 26px; border-radius: 50%; border: none; background: #fbbf24; cursor: pointer; }
.dm-head .dm-markall { border: 1px solid #cfe3f0; background: #fff; color: #0a5376; font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.dm-head .dm-markall:hover { background: #eaf6fc; }
.dm-tabs { display: flex; gap: 4px; padding: 8px 10px; border-bottom: 1px solid #eef2f6; }
.dm-tab { flex: 1; padding: 6px; border-radius: 9px; border: 1px solid #e2e8f0; background: #f8fafc; color: #44617a; font-size: 12px; font-weight: 700; cursor: pointer; }
.dm-tab.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.dm-people { display: flex; gap: 6px; padding: 8px 10px; flex-wrap: wrap; border-bottom: 1px solid #eef2f6; max-height: 84px; overflow-y: auto; }
.dm-person { padding: 5px 11px; border-radius: 999px; border: 1px solid #cfe3f0; background: #f5fbfe; color: #0a5376; font-size: 12px; font-weight: 600; cursor: pointer; }
.dm-person.active { background: #0a5eb8; color: #fff; border-color: #0a5eb8; }
.dm-newgroup { background: #ecfdf5; border-color: #6ee7b7; color: #047857; font-weight: 700; }
.dm-empty-people { font-size: 12px; color: #94a3b8; padding: 4px 6px; }
.dm-group-builder { padding: 10px; border-bottom: 1px solid #eef2f6; background: #f8fafc; display: flex; flex-direction: column; gap: 8px; }
.dm-group-name { padding: 7px 10px; border-radius: 8px; border: 1px solid #cbd5e1; font-size: 13px; }
.dm-group-picks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 110px; overflow-y: auto; }
.dm-group-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #334155; cursor: pointer; }
.dm-group-pick input { width: 15px; height: 15px; cursor: pointer; }
.dm-group-note { font-size: 11px; color: #94a3b8; }
.dm-group-create { padding: 8px; border-radius: 9px; border: none; background: #10b981; color: #fff; font-size: 13px; font-weight: 700; cursor: pointer; }
.dm-group-create:hover { background: #059669; }
.dm-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #fbfdff; }
.dm-msg { max-width: 80%; padding: 8px 11px; border-radius: 14px; font-size: 13px; line-height: 1.35; }
.dm-msg.them { align-self: flex-start; background: #eef2f6; color: #1f3a4d; }
.dm-msg.me { align-self: flex-end; background: #2563eb; color: #fff; }
.dm-msg.tr { align-self: flex-start; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.dm-msg .dm-who { display: block; font-size: 10px; font-weight: 800; opacity: .7; margin-bottom: 2px; }
.dm-typing { align-self: flex-start; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; max-width: 80%; padding: 9px 13px; border-radius: 14px; font-size: 13px; display: flex; align-items: center; gap: 7px; }
.dm-typing .dm-who { display: block; font-size: 10px; font-weight: 800; opacity: .7; margin-bottom: 2px; }
.dm-typing .dots { display: inline-flex; gap: 3px; }
.dm-typing .dots i { width: 6px; height: 6px; border-radius: 50%; background: #34d399; display: inline-block; animation: dm-bounce 1.2s infinite ease-in-out; }
.dm-typing .dots i:nth-child(2) { animation-delay: .18s; }
.dm-typing .dots i:nth-child(3) { animation-delay: .36s; }
@keyframes dm-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.dm-compose { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #eef2f6; }
.dm-compose input { flex: 1; padding: 9px 12px; border-radius: 12px; border: 1px solid #cfe3f0; font-size: 13px; outline: none; }
.dm-compose input:focus { border-color: #2563eb; }
.dm-compose button { padding: 9px 14px; border-radius: 12px; border: none; background: #2563eb; color: #fff; font-weight: 800; cursor: pointer; }
@media (max-width: 640px) { .dm-widget { right: 12px; bottom: 12px; width: calc(100vw - 24px); } }

/* --- Unread badges (Apple-style) --- */
.dm-launch { position: relative; }
.dm-person { position: relative; }
.dm-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: #ff3b30; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px #fff; pointer-events: none;
}
.dm-person .dm-badge { top: -7px; right: -5px; box-shadow: 0 0 0 2px #fff; }

/* Messaging rail icon badge */
.app-rail a { position: relative; }
.app-rail .rail-badge {
  position: absolute; top: 4px; right: 6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: #ff3b30; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px rgba(255,255,255,.85);
}

/* --- Attach button + compose --- */
.dm-compose { display: flex; align-items: center; gap: 6px; }
.dm-attach-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid #cfe3f0; background: #f5fbfe; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.dm-attach-btn:hover { background: #e6f4fc; }
.dm-attach-btn svg { width: 18px; height: 18px; stroke: #0a5376; fill: none; stroke-width: 2; }

/* --- Staged attachment preview chip --- */
.dm-attach-preview { padding: 6px 10px; border-top: 1px solid #eef2f6; background: #f8fafc; }
.dm-att-chip { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #cbd5e1; border-radius: 10px; padding: 5px 8px; max-width: 100%; }
.dm-att-chip-img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.dm-att-chip .dm-att-name { font-size: 12px; color: #334155; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-att-ic { font-size: 16px; }
.dm-att-remove { margin-left: auto; width: 20px; height: 20px; border-radius: 50%; border: none; background: #e2e8f0; color: #475569; font-size: 14px; line-height: 1; cursor: pointer; }
.dm-att-remove:hover { background: #fecaca; color: #b91c1c; }
.dm-att-uploading { font-size: 12px; color: #64748b; }

/* --- Rendered attachments in message bubbles --- */
.dm-att { margin-top: 6px; }
.dm-att-img { max-width: 220px; max-height: 220px; border-radius: 10px; cursor: pointer; display: block; }
.dm-att-vid { max-width: 240px; border-radius: 10px; display: block; }
.dm-att-file { display: inline-flex; align-items: center; gap: 7px; background: rgba(255,255,255,.65); border: 1px solid rgba(148,163,184,.5); border-radius: 9px; padding: 6px 9px; text-decoration: none; color: inherit; }
.dm-att-file .dm-att-name { font-size: 12px; font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-msg.me .dm-att-file { background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.4); }
