/* ==================== */
/* Teammates Chat       */
/* ==================== */

.tm-container {
    display: flex;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* -- Left sidebar (conversation list) -- */
/* Overlays on top of content so the workspace always stays centered */
.tm-sidebar {
    width: 15%;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
    background: var(--color-bg);
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 5;
    transition: transform 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}

.tm-sidebar.tm-collapsed {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.tm-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 24px;
}

.tm-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 400;
    color: var(--color-text);
    font-family: inherit;
    transition: background 0.15s ease;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
}

.tm-sidebar-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.tm-sidebar-item svg {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

/* Conversation list */
.tm-conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* Collapsible section headers */
.tm-section-header {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 10px 8px 4px 8px;
    cursor: pointer;
    user-select: none;
}

.tm-section-toggle {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    padding: 0;
    flex-shrink: 0;
    pointer-events: none;
}

.tm-toggle-arrow {
    transition: transform 0.2s ease;
}

.tm-section-toggle.collapsed .tm-toggle-arrow {
    transform: rotate(-90deg);
}

.tm-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-faint);
    flex: 1;
}

/* Conversation items (Google Chat style — slim, no preview/timestamp) */
.tm-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 12px 6px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
    border-radius: 0 var(--radius-full) var(--radius-full) 0;
    margin-right: 8px;
}

.tm-conv-item:hover {
    background: var(--color-bg-muted);
}

.tm-conv-item.active {
    background: var(--color-primary-bg);
}

.tm-conv-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.tm-conv-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.tm-conv-channel-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-lg);
    background: var(--color-primary-bg);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
}

.tm-conv-group-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-bg-muted);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tm-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: #22c55e;
    border: 2px solid var(--color-bg);
}

.tm-online-dot-inline {
    width: 8px;
    height: 8px;
    min-width: 8px;
    border-radius: var(--radius-full);
    background: #22c55e;
    margin-right: 6px;
}

.tm-conv-hash {
    color: var(--color-text-secondary);
    font-weight: 600;
    margin-right: 4px;
    font-size: 14px;
}

.tm-conv-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.tm-conv-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.tm-pin-icon {
    color: var(--color-text-faint);
}

/* Show all / Browse spaces links */
.tm-show-all,
.tm-browse-spaces {
    padding: 8px 16px 8px 52px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-primary);
    cursor: pointer;
    transition: background 0.15s ease;
}

.tm-show-all:hover,
.tm-browse-spaces:hover {
    background: var(--color-bg-muted);
}

.tm-empty-list,
.tm-empty-section {
    padding: 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

/* Context Menu */
.tm-context-menu {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--color-border);
    padding: 4px 0;
    min-width: 200px;
    animation: tmMenuFadeIn 0.12s ease-out;
}

@keyframes tmMenuFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.tm-context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 400;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease;
}

.tm-context-menu-item:hover {
    background: var(--color-bg-muted);
}

.tm-context-menu-danger {
    color: var(--color-error, #ef4444);
}

.tm-context-menu-danger:hover {
    background: rgba(239, 68, 68, 0.08);
}

.tm-context-menu-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tm-context-menu-sub {
    margin-left: auto;
    font-size: 12px;
    color: var(--color-text-faint);
}

.tm-context-menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: 4px 0;
}

/* -- Right panel (thread) -- */
.tm-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    margin-left: 15%; /* account for absolutely-positioned sidebar */
    transition: margin-left 0.25s ease;
}

/* Remove margin when sidebar is collapsed */
.tm-container:has(.tm-sidebar.tm-collapsed) .tm-thread {
    margin-left: 0;
}

.tm-thread-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    color: var(--color-text-muted);
}

.tm-thread-empty p {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.tm-thread-empty span {
    font-size: 14px;
    opacity: 0.6;
}

.tm-thread-active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.tm-thread-active.hidden {
    display: none;
}

/* Thread header */
.tm-thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    flex-shrink: 0;
}

.tm-back-btn {
    display: none;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
}

.tm-thread-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.tm-thread-channel-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-lg);
    background: var(--color-primary-bg);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.tm-thread-info {
    display: flex;
    flex-direction: column;
}

.tm-thread-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
}

.tm-thread-status {
    font-size: 12px;
    color: var(--color-text-muted);
}

.tm-thread-status.online {
    color: #22c55e;
}

/* Messages area */
.tm-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tm-msg {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageSlide 0.3s ease-out;
}

.tm-msg.sent {
    align-self: flex-end;
}

.tm-msg.received {
    align-self: flex-start;
}

.tm-msg-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 2px;
    margin-top: 8px;
    padding-left: 2px;
}

.tm-msg-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.tm-msg.sent .tm-msg-bubble {
    background: linear-gradient(135deg, rgba(224, 231, 255, 0.8) 0%, rgba(199, 210, 254, 0.6) 100%);
    color: var(--color-text);
    border-bottom-right-radius: 4px;
}

.tm-msg.received .tm-msg-bubble {
    background: var(--color-bg-muted);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}

.tm-msg-time {
    font-size: 11px;
    color: var(--color-text-faint);
    margin-top: 2px;
    padding: 0 4px;
}

.tm-msg.sent .tm-msg-time {
    text-align: right;
}

/* Date separator */
.tm-date-sep {
    text-align: center;
    font-size: 12px;
    color: var(--color-text-faint);
    padding: 12px 0;
    position: relative;
}

.tm-date-sep::before,
.tm-date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 60px);
    height: 1px;
    background: var(--color-border);
}

.tm-date-sep::before { left: 0; }
.tm-date-sep::after  { right: 0; }

/* Compose bar */
.tm-compose {
    padding: 0 40px 16px;
    background: transparent;
    flex-shrink: 0;
}

.tm-compose-wrapper {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #f6f7f8 0%, #eff0f2 100%);
    border-radius: 24px;
    padding: 14px 18px 10px 18px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.04),
        0 1px 0 rgba(255, 255, 255, 0.8);
    transition: border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.tm-compose-wrapper:focus-within {
    border-color: rgba(79, 70, 229, 0.3);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.04),
        0 0 0 3px rgba(79, 70, 229, 0.1);
}

.tm-file-preview {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 8px;
}

.tm-compose-input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0 0 8px 0;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    color: var(--color-text);
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

.tm-compose-input::placeholder {
    color: #6b6b6b;
}

.tm-toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tm-attach-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b6b6b;
    transition: all 0.15s ease;
}

.tm-attach-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text);
}

.tm-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #1a1a1a;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tm-send-btn:hover:not(:disabled) {
    background: #333333;
    transform: scale(1.05);
}

.tm-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.tm-send-btn:disabled {
    background: #c5c8cc;
    cursor: not-allowed;
    color: #ffffff;
}

/* -- DM Picker Modal -- */
.tm-dm-picker {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tm-dm-picker.hidden {
    display: none;
}

.tm-dm-picker-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
}

.tm-dm-picker-panel {
    position: relative;
    width: 340px;
    max-height: 420px;
    background: var(--color-bg);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}

.tm-dm-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
}

.tm-dm-picker-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.tm-dm-picker-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0 4px;
    line-height: 1;
}

.tm-dm-picker-close:hover {
    color: var(--color-text);
}

.tm-dm-picker-search {
    padding: 0;
}

.tm-dm-picker-input {
    width: 100%;
    padding: 10px 20px;
    border: none;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    color: var(--color-text);
    background: var(--color-bg-subtle);
    box-sizing: border-box;
}

.tm-dm-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.tm-dm-picker-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.tm-dm-picker-row:hover {
    background: var(--color-bg-muted);
}

.tm-dm-picker-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.tm-dm-picker-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    flex: 1;
}

.tm-dm-picker-check {
    width: 18px;
    height: 18px;
    color: var(--color-primary);
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.tm-dm-picker-row.selected {
    background: var(--color-primary-bg);
}

.tm-dm-picker-row.selected .tm-dm-picker-check {
    opacity: 1;
}

.tm-dm-picker-empty {
    padding: 24px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
}

/* Multi-select chips */
.tm-dm-picker-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0 20px 8px;
    min-height: 0;
}

.tm-dm-picker-selected:empty {
    display: none;
}

.tm-dm-picker-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--color-primary-bg);
    color: var(--color-primary);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
}

.tm-dm-picker-chip-remove {
    cursor: pointer;
    width: 14px;
    height: 14px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s ease;
}

.tm-dm-picker-chip-remove:hover {
    background: rgba(79, 70, 229, 0.2);
}

/* Picker footer */
.tm-dm-picker-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
}

.tm-dm-picker-footer.hidden {
    display: none;
}

.tm-dm-picker-start-btn {
    width: 100%;
    padding: 10px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}

.tm-dm-picker-start-btn:hover {
    filter: brightness(1.1);
}

/* -- Mobile responsive -- */
@media (max-width: 768px) {
    .tm-sidebar {
        width: 100%;
        min-width: 100%;
    }

    .tm-thread {
        position: absolute;
        inset: 0;
        margin-left: 0;
        background: var(--color-bg);
        z-index: 5;
        display: none;
    }

    .tm-thread.tm-thread-visible {
        display: flex;
    }

    .tm-back-btn {
        display: flex;
    }

    .tm-container {
        position: relative;
    }
}

