/* Chat del equipo — FAB + panel a la izquierda (el asistente IA sigue a la derecha) */
.team-chat .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.team-chat {
    --tc-surface: var(--app-surface);
    --tc-border: var(--app-border);
    --tc-text: var(--app-text);
    --tc-text-soft: var(--app-text-soft);
    --tc-accent: var(--app-primary);
    --tc-radius: var(--app-radius-md);
    font-family: "Segoe UI", "Inter", system-ui, sans-serif;
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1085;
}

.team-chat__fab,
.team-chat__panel {
    pointer-events: auto;
}

.team-chat__fab {
    position: fixed;
    left: max(20px, env(safe-area-inset-left, 0px));
    bottom: max(22px, env(safe-area-inset-bottom, 0px));
    width: 58px;
    height: 58px;
    border-radius: 20px;
    border: none;
    background: linear-gradient(145deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4), 0 12px 28px rgba(15, 36, 77, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    z-index: 1086;
}

.team-chat__fab:hover {
    transform: translateY(-2px) scale(1.02);
}

.team-chat.is-open .team-chat__fab {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88);
}

.team-chat__panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: min(88dvh, 720px);
    max-height: min(88dvh, 720px);
    background: var(--tc-surface);
    border: 1px solid var(--tc-border);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(15, 36, 77, 0.12);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 1087;
    border-radius: var(--tc-radius) var(--tc-radius) 0 0;
}

.team-chat.is-open .team-chat__panel {
    transform: translateY(0);
}

@media (min-width: 768px) {
    .team-chat__panel {
        left: max(16px, env(safe-area-inset-left, 0px));
        right: auto;
        bottom: max(16px, env(safe-area-inset-bottom, 0px));
        width: min(560px, calc(100vw - 32px));
        height: min(640px, calc(100vh - 32px));
        max-height: min(640px, calc(100vh - 32px));
        border: 1px solid var(--tc-border);
        border-radius: var(--tc-radius);
        box-shadow: 0 16px 48px rgba(15, 36, 77, 0.14);
    }
}

.team-chat__header {
    flex-shrink: 0;
    padding: 1rem;
    border-bottom: 1px solid var(--tc-border);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--app-surface-alt, rgba(244, 247, 251, 0.9));
}

.team-chat__avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.team-chat__headlines {
    flex: 1;
    min-width: 0;
}

.team-chat__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--tc-text);
}

.team-chat__subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.78rem;
    color: var(--tc-text-soft);
    line-height: 1.35;
}

.team-chat__ws-status {
    flex-shrink: 0;
    margin: 0;
    padding: 0.4rem 1rem;
    font-size: 0.75rem;
    line-height: 1.35;
    border-bottom: 1px solid var(--tc-border);
    background: var(--tc-surface);
    color: var(--tc-text-soft);
}

.team-chat__ws-status.is-live {
    color: #15803d;
    background: rgba(220, 252, 231, 0.45);
}

.team-chat__ws-status.is-degraded {
    color: #92400e;
    background: #fffbeb;
}

.team-chat__close {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--tc-border);
    border-radius: 12px;
    background: var(--tc-surface);
    color: var(--tc-text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-chat__body {
    display: grid;
    grid-template-columns: minmax(0, 42%) minmax(0, 1fr);
    flex: 1;
    min-height: 0;
}

@media (max-width: 480px) {
    .team-chat__body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .team-chat__sidebar {
        max-height: 38%;
        border-bottom: 1px solid var(--tc-border);
    }
}

.team-chat__sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-right: 1px solid var(--tc-border);
    background: rgba(244, 247, 251, 0.5);
    overflow: hidden;
}

html[data-theme="dark"] .team-chat__sidebar {
    background: rgba(22, 32, 48, 0.4);
}

.team-chat__sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.5rem 0.45rem 0.65rem;
    -webkit-overflow-scrolling: touch;
}

.team-chat__section-label {
    margin: 0 0 0.35rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tc-text-soft);
}

.team-chat__section-label:not(:first-child) {
    margin-top: 0.75rem;
}

.team-chat__users-status {
    margin: 0 0 0.4rem;
    font-size: 0.76rem;
    line-height: 1.35;
    color: var(--tc-text-soft);
}

.team-chat__conv-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.team-chat__user-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.team-chat__user-list li {
    margin: 0;
}

.team-chat__user-btn {
    width: 100%;
    text-align: left;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--tc-border);
    border-radius: 10px;
    background: var(--tc-surface);
    color: var(--tc-text);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.team-chat__user-btn:hover,
.team-chat__user-btn:focus-visible {
    background: rgba(28, 79, 161, 0.08);
    border-color: rgba(28, 79, 161, 0.35);
    outline: none;
}

.team-chat__conv-item {
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.25rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--tc-text);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.team-chat__conv-item:hover,
.team-chat__conv-item:focus-visible {
    background: rgba(28, 79, 161, 0.08);
    outline: none;
}

.team-chat__conv-item.is-active {
    background: rgba(28, 79, 161, 0.14);
    color: var(--tc-accent);
}

.team-chat__thread {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.team-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.team-chat__empty {
    margin: 0;
    font-size: 0.85rem;
    color: var(--tc-text-soft);
    text-align: center;
    padding: 1rem;
}

.team-chat__row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    max-width: 100%;
}

.team-chat__row--me {
    align-items: flex-end;
}

.team-chat__bubble {
    max-width: 100%;
    padding: 0.55rem 0.75rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.35;
    word-break: break-word;
}

.team-chat__row:not(.team-chat__row--me) .team-chat__bubble {
    background: rgba(244, 247, 251, 0.95);
    border: 1px solid var(--tc-border);
    color: var(--tc-text);
}

.team-chat__row--me .team-chat__bubble {
    background: rgba(28, 79, 161, 0.12);
    border: 1px solid rgba(28, 79, 161, 0.35);
    color: var(--tc-text);
}

.team-chat__meta {
    font-size: 0.68rem;
    color: var(--tc-text-soft);
    padding: 0 0.2rem;
}

.team-chat__attach-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.team-chat__attach-link {
    font-size: 0.78rem;
    color: var(--tc-accent);
    text-decoration: none;
    word-break: break-all;
}

.team-chat__attach-link:hover {
    text-decoration: underline;
}

.team-chat__thumb {
    max-width: 200px;
    max-height: 160px;
    border-radius: 8px;
    border: 1px solid var(--tc-border);
}

.team-chat__composer {
    flex-shrink: 0;
    padding: 0.65rem 0.75rem 0.75rem;
    border-top: 1px solid var(--tc-border);
    background: var(--tc-surface);
}

.team-chat__file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.team-chat__composer-inner {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
}

.team-chat__attach-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--tc-border);
    background: var(--app-surface-alt, #f8fafc);
    color: var(--tc-text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-chat__input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 140px;
    resize: none;
    overflow-y: auto;
    border: 1px solid var(--tc-border);
    border-radius: 12px;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
    line-height: 1.45;
    font-family: inherit;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
}

.team-chat__send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--tc-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-chat__file-hint {
    margin: 0.35rem 0 0;
    font-size: 0.72rem;
    color: var(--tc-text-soft);
    min-height: 1em;
}
