/* Chat - Teams-style messaging. Uses ADS design tokens (--green, --gray-*, --shadow-*) and existing .ts-btn buttons. */
#page-chat { padding: 0; }
.chat-shell { display: grid; grid-template-columns: 330px minmax(0, 1fr); height: calc(100vh - var(--header-h, 60px) - 36px);
    min-height: 460px; background: var(--white); border: 1px solid var(--gray-200); border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden; }
.chat-side { display: flex; flex-direction: column; border-right: 1px solid var(--gray-200); background: var(--gray-50); min-width: 0; min-height: 0; }
.chat-side-head, .chat-thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--gray-200); background: var(--white); }
.chat-title { font-size: 17px; font-weight: 700; color: var(--gray-900); flex: 1; display: flex; gap: 8px; align-items: center; }
.chat-title i { color: var(--green); }
.chat-icon-btn { border: 0; background: transparent; color: var(--gray-600); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px; flex: none; }
.chat-icon-btn:hover, .chat-icon-btn:focus-visible { background: var(--green-lite); color: var(--green-dark); outline: none; }
.chat-icon-btn.is-on { color: var(--red-dark); }
.chat-search { display: flex; align-items: center; gap: 8px; margin: 10px 12px; padding: 0 12px; border: 1px solid var(--gray-200); border-radius: 10px; background: var(--white); }
.chat-search i { color: var(--gray-400); font-size: 13px; }
.chat-search input { border: 0; outline: none; background: transparent; padding: 9px 0; width: 100%; font-size: 14px; color: var(--text); }
.chat-search:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-lite); }
.chat-list { overflow-y: auto; flex: 1; min-height: 0; padding: 4px 6px 10px; }
.chat-empty { padding: 28px 16px; text-align: center; color: var(--gray-600); font-size: 14px; }
.chat-item { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: transparent; text-align: left; padding: 10px; border-radius: 10px; cursor: pointer; color: inherit; font: inherit; }
.chat-item:hover { background: var(--gray-100); }
.chat-item.active { background: var(--green-lite); }
.chat-item:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item-name { font-weight: 600; color: var(--gray-900); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .chat-item-name { font-weight: 800; }
.chat-item-time { font-size: 11px; color: var(--gray-400); flex: none; }
.chat-item-prev { font-size: 12.5px; color: var(--gray-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.chat-item.unread .chat-item-prev { color: var(--gray-900); font-weight: 600; }
.chat-badge { background: var(--green); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 10px; padding: 0 6px; flex: none; }
.chat-item .fa-bell-slash { color: var(--gray-400); font-size: 11px; }
.chat-avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; user-select: none; }
.chat-avatar.group { border-radius: 12px; }
.chat-avatar.sm { width: 28px; height: 28px; font-size: 11px; }

.chat-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--white); }
.chat-placeholder { margin: auto; text-align: center; color: var(--gray-600); padding: 24px; }
.chat-placeholder i { font-size: 44px; color: var(--green-mid); margin-bottom: 10px; }
.chat-placeholder h3 { margin: 4px 0; color: var(--gray-900); }
.chat-thread { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }
.chat-thread-titles { flex: 1; min-width: 0; }
.chat-thread-title { font-weight: 700; color: var(--gray-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-sub { font-size: 12px; color: var(--gray-600); min-height: 15px; }
.chat-thread-actions { display: flex; gap: 2px; }
.chat-back { display: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px 18px; background: var(--gray-50); min-height: 0; }
.chat-day { text-align: center; margin: 14px 0 8px; font-size: 11.5px; color: var(--gray-600); }
.chat-day span { background: var(--gray-200); padding: 3px 12px; border-radius: 999px; }
.chat-sys { text-align: center; font-size: 12px; color: var(--gray-600); margin: 8px 0; }
.chat-row { display: flex; gap: 8px; margin: 2px 0; align-items: flex-end; }
.chat-row.mine { flex-direction: row-reverse; }
.chat-row.first { margin-top: 10px; }
.chat-row .chat-avatar { visibility: hidden; }
.chat-row.last:not(.mine) .chat-avatar { visibility: visible; }
.chat-bubble-wrap { max-width: min(640px, 78%); min-width: 0; position: relative; }
.chat-bubble { background: var(--white); border: 1px solid var(--gray-200); border-radius: 14px 14px 14px 4px; padding: 7px 12px; box-shadow: var(--shadow-sm); overflow-wrap: anywhere; white-space: pre-wrap; font-size: 14px; line-height: 1.45; color: var(--text); }
.chat-row.mine .chat-bubble { background: var(--green-lite); border-color: var(--green-mid); border-radius: 14px 14px 4px 14px; }
.chat-who { font-size: 12px; font-weight: 700; color: var(--green-dark); margin-bottom: 1px; }
.chat-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; text-align: right; white-space: normal; }
.chat-deleted { color: var(--gray-400); font-style: italic; }
.chat-quote { border-left: 3px solid var(--green); background: rgba(0,0,0,.04); border-radius: 6px; padding: 4px 8px; margin-bottom: 5px; font-size: 12px; color: var(--gray-600); cursor: pointer; white-space: normal; }
.chat-quote strong { color: var(--gray-900); display: block; }
.chat-mention { background: #dbeafe; color: #1d4ed8; border-radius: 4px; padding: 0 3px; font-weight: 600; }
.chat-mention.me { background: #fde68a; color: #92400e; }
.chat-bubble a { color: var(--blue); text-decoration: underline; }
.chat-atts { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; white-space: normal; }
.chat-att-img { max-width: 260px; max-height: 220px; border-radius: 10px; display: block; cursor: zoom-in; border: 1px solid var(--gray-200); background: var(--gray-100); }
.chat-att-file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: 10px; background: var(--white); color: var(--text); text-decoration: none !important; }
.chat-att-file:hover { background: var(--gray-100); }
.chat-att-file i { font-size: 22px; color: var(--green-dark); }
.chat-att-file small { display: block; color: var(--gray-600); }
.chat-att-file span { min-width: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 600; }
.chat-reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-react { border: 1px solid var(--gray-200); background: var(--white); border-radius: 999px; padding: 1px 8px; font-size: 12px; cursor: pointer; }
.chat-react.mine { background: var(--green-lite); border-color: var(--green); }
.chat-tools { position: absolute; top: -14px; right: 6px; display: none; gap: 2px; background: var(--white); border: 1px solid var(--gray-200); border-radius: 10px; box-shadow: var(--shadow-md); padding: 2px; z-index: 3; }
.chat-row.mine .chat-tools { right: auto; left: 6px; }
.chat-bubble-wrap:hover .chat-tools, .chat-bubble-wrap:focus-within .chat-tools { display: flex; }
.chat-tools button { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; color: var(--gray-600); }
.chat-tools button:hover { background: var(--green-lite); color: var(--green-dark); }
.chat-picker { position: absolute; top: 18px; z-index: 5; background: var(--white); border: 1px solid var(--gray-200); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; display: flex; gap: 2px; }
.chat-picker button { border: 0; background: transparent; font-size: 18px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.chat-picker button:hover { background: var(--gray-100); }
.chat-edit { width: 100%; font: inherit; border: 1px solid var(--green); border-radius: 8px; padding: 6px 8px; resize: vertical; min-height: 44px; }
.chat-edit-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.chat-jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: 118px; background: var(--green); color: #fff; border: 0; border-radius: 999px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-md); z-index: 4; }
.chat-typing { min-height: 18px; padding: 0 20px 2px; font-size: 12px; color: var(--gray-600); font-style: italic; background: var(--gray-50); }
.chat-compose { border-top: 1px solid var(--gray-200); background: var(--white); padding: 8px 12px 12px; position: relative; }
.chat-compose.drag { outline: 2px dashed var(--green); outline-offset: -4px; background: var(--green-lite); }
.chat-compose-row { display: flex; gap: 6px; align-items: flex-end; }
#chat-input { flex: 1; resize: none; border: 1px solid var(--gray-200); border-radius: 12px; padding: 9px 12px; font: inherit; font-size: 14px; max-height: 140px; outline: none; background: var(--gray-50); }
#chat-input:focus { border-color: var(--green); background: var(--white); box-shadow: 0 0 0 3px var(--green-lite); }
.chat-send { height: 38px; min-width: 42px; }
.chat-reply-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-left: 3px solid var(--green); background: var(--green-lite); border-radius: 8px; padding: 4px 8px; margin-bottom: 6px; font-size: 12px; }
.chat-reply-bar strong { margin-right: 6px; }
.chat-pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chat-pending:empty { display: none; }
.chat-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--gray-200); background: var(--gray-50); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12px; max-width: 100%; }
.chat-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.chat-chip button { border: 0; background: transparent; cursor: pointer; color: var(--gray-600); }
.chat-emoji { position: absolute; bottom: 62px; left: 12px; background: var(--white); border: 1px solid var(--gray-200); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 6; }
.chat-emoji button { border: 0; background: transparent; font-size: 20px; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
.chat-emoji button:hover { background: var(--gray-100); }
.chat-seen { text-align: right; font-size: 11px; color: var(--gray-400); margin: 2px 4px 0; }

/* modals */
.chat-modal { position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.chat-modal-card { background: var(--white); width: min(460px, 100%); max-height: 86vh; overflow: auto; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-modal-head { display: flex; justify-content: space-between; align-items: center; }
.chat-modal-head h3 { margin: 0; font-size: 17px; }
.chat-modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.chat-tabs { display: flex; background: var(--gray-100); border-radius: 10px; padding: 3px; }
.chat-tab { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--gray-600); }
.chat-tab.active { background: var(--white); color: var(--green-dark); box-shadow: var(--shadow-sm); }
.chat-input { border: 1px solid var(--gray-200); border-radius: 10px; padding: 9px 12px; font: inherit; width: 100%; box-sizing: border-box; }
.chat-input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px var(--green-lite); }
.chat-people { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-person { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; cursor: pointer; border: 0; background: transparent; text-align: left; font: inherit; width: 100%; }
.chat-person:hover { background: var(--gray-100); }
.chat-person small { color: var(--gray-600); display: block; font-size: 11.5px; }
.chat-person .grow { flex: 1; min-width: 0; }
.chat-chosen { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-chosen:empty { display: none; }
.chat-rename { display: flex; gap: 8px; }

@media (max-width: 768px) {
    .chat-shell { grid-template-columns: 1fr; height: calc(100vh - var(--header-h, 60px) - 12px); border-radius: 10px; }
    .chat-shell[data-view="list"] .chat-main { display: none; }
    .chat-shell[data-view="thread"] .chat-side { display: none; }
    .chat-back { display: inline-block; }
    .chat-bubble-wrap { max-width: 88%; }
    .chat-tools { display: flex; position: static; box-shadow: none; border: 0; background: transparent; margin-top: 2px; }
    .chat-row.mine .chat-tools { justify-content: flex-end; }
    .chat-jump { bottom: 128px; }
    .chat-emoji { grid-template-columns: repeat(6, 1fr); }
}
@media (prefers-reduced-motion: no-preference) { .chat-item, .chat-icon-btn { transition: background .15s; } }
