/*
 * Chat widget — Fase 2
 * Todos los selectores prefijados con .gac-chat- para aislarlos de Bootstrap 3
 * y Tailwind. Z-index 9998 (debajo de modales que usan 9999).
 */

.gac-chat-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9998;
    font-family: 'Rubik', sans-serif;
    font-size: 14px;
    color: #2e2e2e;
}

/* ── FAB cerrado ───────────────────────────────────────────────────── */
.gac-chat-fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #159bd7;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(21, 155, 215, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
    position: relative;
}
.gac-chat-fab:hover { background: #2060ad; transform: scale(1.05); }
.gac-chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ef5046;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}
.gac-chat-fab-badge.gac-show { display: flex; }

/* ── Ventana del widget ────────────────────────────────────────────── */
.gac-chat-window {
    width: 340px;
    height: 460px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: gac-chat-pop 0.18s ease-out;
}
@keyframes gac-chat-pop {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Estado minimizado eliminado — el chat vuelve al FAB circular al minimizar. */
.gac-chat-window.gac-min {
    display: none !important;
}

/* Header */
.gac-chat-header {
    background: #004F71;
    color: #fff;
    padding: 0 12px;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex-shrink: 0;
}
.gac-chat-header *,
.gac-chat-header a,
.gac-chat-header i {
    color: #fff;
}
.gac-chat-header-title {
    flex: 1;
    font-weight: 500;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.12s;
}
.gac-chat-header-title small {
    display: block;
    font-size: 10px;
    opacity: 0.75;
    font-weight: 400;
    line-height: 1.1;
    color: #fff;
}
/* Cuando hay gestión activa, el título es navegable */
.gac-chat-header-title.gac-chat-clickable {
    cursor: pointer;
}
.gac-chat-header-title.gac-chat-clickable:hover {
    background: rgba(255,255,255,0.10);
    text-decoration: underline;
}
.gac-chat-header-title.gac-chat-clickable:focus-visible {
    outline: 2px solid rgba(255,255,255,0.5);
    outline-offset: -2px;
}
.gac-chat-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    opacity: 0.85;
    transition: background 0.12s, opacity 0.12s;
}
.gac-chat-header-btn:hover { background: rgba(255, 255, 255, 0.15); opacity: 1; }

/* Body */
.gac-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f7fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
/* Importante: el display de los paneles internos se controla por JS en
   minimize/unminimize, no aquí. Una regla CSS no puede ganarle al inline
   `style.display = 'flex'` que setView() establece. */

.gac-chat-empty {
    margin: auto;
    text-align: center;
    color: #9c9c9c;
    font-size: 12.5px;
    padding: 20px;
    line-height: 1.5;
}
.gac-chat-empty i { font-size: 28px; display: block; margin-bottom: 10px; color: #5cc2e7; }

/* Mensajes */
.gac-msg-row { display: flex; gap: 6px; align-items: flex-end; }
.gac-msg-row.gac-mine { flex-direction: row-reverse; }
.gac-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #5cc2e7;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.gac-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.gac-msg-content { max-width: 78%; min-width: 0; display: flex; flex-direction: column; }
.gac-msg-row.gac-mine .gac-msg-content { align-items: flex-end; }
.gac-msg-author { font-size: 11px; font-weight: 600; color: #2060ad; margin-bottom: 2px; }
.gac-msg-row.gac-mine .gac-msg-author { display: none; }
.gac-msg-bubble {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 7px 11px;
    font-size: 13px;
    line-height: 1.45;
    color: #2e2e2e;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    min-height: 30px;
    display: inline-block;
    max-width: 100%;
}
.gac-msg-row.gac-mine .gac-msg-bubble {
    background: #159bd7;
    color: #fff;
    border-color: #159bd7;
}
/* Mensajes que son SÓLO emoji: sin burbuja, emojis grandes */
.gac-msg-bubble.gac-emoji-only {
    background: transparent !important;
    border: none !important;
    padding: 0 2px !important;
    font-size: 32px;
    line-height: 1.1;
    min-height: 0;
}
.gac-msg-meta {
    font-size: 10px;
    color: #9c9c9c;
    margin-top: 3px;
    line-height: 1;
}
.gac-msg-row.gac-mine .gac-msg-meta { text-align: right; }
.gac-msg-meta i { margin-left: 2px; }

/* Footer / composer */
.gac-chat-footer {
    border-top: 1px solid #e5e7eb;
    padding: 8px;
    background: #fff;
    flex-shrink: 0;
    display: flex;
    gap: 6px;
    align-items: flex-end;
}
.gac-chat-textarea {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    resize: none;
    min-height: 34px;
    max-height: 90px;
    outline: none;
    font-family: inherit;
    color: #2e2e2e;
    line-height: 1.35;
}
.gac-chat-textarea:focus { border-color: #159bd7; box-shadow: 0 0 0 1px #159bd7; }
.gac-chat-send {
    background: #159bd7;
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    transition: background 0.12s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.gac-chat-send:hover { background: #2060ad; }
.gac-chat-send:disabled { background: #9c9c9c; cursor: not-allowed; }

/* Scroll discreto */
.gac-chat-body::-webkit-scrollbar { width: 6px; }
.gac-chat-body::-webkit-scrollbar-track { background: transparent; }
.gac-chat-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }
.gac-chat-body::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.35); }

/* Oculto en la página fullscreen para no duplicar UI */
body.gac-chat-fullscreen-mode .gac-chat-root { display: none !important; }

/* Mobile */
@media (max-width: 480px) {
    .gac-chat-window { width: calc(100vw - 24px); height: calc(100vh - 100px); max-height: 540px; }
    .gac-chat-root { right: 12px; bottom: 12px; }
}

/* ════════════════════════════════════════════════════════════════════
 * FASE 3 — picker, menciones, settings, toast, badge sidebar
 * ════════════════════════════════════════════════════════════════════ */

/* Header layout con grupo de acciones */
.gac-chat-header-actions { display: flex; gap: 2px; }

/* Botón "back" en chat mode */
#gacChatBtnBack { flex-shrink: 0; }

/* Avatares de distinto tamaño */
.gac-msg-avatar.gac-xs { width: 22px; height: 22px; font-size: 9px; }
.gac-msg-avatar.gac-md { width: 38px; height: 38px; font-size: 12px; }

/* ── Picker ─────────────────────────────────────────────────────── */
.gac-chat-picker {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}
.gac-chat-picker-search {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: flex; align-items: center; gap: 8px;
    background: #f7fafc;
    flex-shrink: 0;
}
.gac-chat-picker-search i { color: #9c9c9c; font-size: 12px; }
.gac-chat-picker-search input {
    flex: 1; border: none; background: transparent;
    font-size: 12.5px; outline: none; color: #2e2e2e;
    font-family: inherit;
}
.gac-chat-picker-list {
    flex: 1; overflow-y: auto;
}
.gac-chat-picker-list::-webkit-scrollbar { width: 6px; }
.gac-chat-picker-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

.gac-chat-picker-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.12s;
}
.gac-chat-picker-item:hover { background: #f0f9ff; }
.gac-chat-picker-info { flex: 1; min-width: 0; }
.gac-chat-picker-row1 {
    display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
    margin-bottom: 1px;
}
.gac-chat-picker-name {
    font-weight: 600; font-size: 12.5px; color: #2e2e2e;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.gac-chat-picker-time { font-size: 10px; color: #9c9c9c; white-space: nowrap; flex-shrink: 0; }
.gac-chat-picker-row2 {
    display: flex; align-items: center; gap: 6px; justify-content: space-between;
}
.gac-chat-picker-snippet {
    font-size: 11.5px; color: #6b7280;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1; min-width: 0;
}
.gac-chat-picker-unread {
    background: #2060ad; color: #fff;
    border-radius: 999px; font-size: 10px; font-weight: 700;
    padding: 1px 6px; min-width: 18px; text-align: center;
}
.gac-chat-picker-mention {
    background: #ef5046; color: #fff;
    border-radius: 999px; font-size: 10px; font-weight: 700;
    padding: 1px 6px;
}

/* ── Menciones en el render del mensaje ─────────────────────────── */
.gac-msg-bubble .gac-mention {
    color: #159bd7;
    font-weight: 600;
    background: rgba(21,155,215,0.08);
    padding: 0 3px;
    border-radius: 3px;
}
.gac-msg-row.gac-mine .gac-msg-bubble .gac-mention {
    color: #fff;
    background: rgba(255,255,255,0.18);
}

/* ── Dropdown del autocompletado @ ──────────────────────────────── */
.gac-chat-composer-wrap { position: relative; flex: 1; }
.gac-chat-mention-drop {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0; right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 -6px 16px rgba(0,0,0,0.08);
    max-height: 180px;
    overflow-y: auto;
    z-index: 1;
}
.gac-chat-mention-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12.5px;
}
.gac-chat-mention-item:hover,
.gac-chat-mention-item.gac-sel { background: #f0f9ff; }

/* ── Settings panel ─────────────────────────────────────────────── */
.gac-chat-settings {
    background: #f7fafc;
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 12px;
    flex-shrink: 0;
    font-size: 12.5px;
}
.gac-chat-settings-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 6px;
}
.gac-chat-settings-row:last-child { margin-bottom: 0; }
.gac-chat-settings-row label {
    display: inline-flex; align-items: center; gap: 6px;
    color: #2e2e2e; font-weight: 400; margin: 0; cursor: pointer;
}
.gac-chat-settings-row input[type="checkbox"] { cursor: pointer; }
.gac-chat-settings-row select {
    border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 2px 6px; font-size: 12px; background: #fff;
    color: #2e2e2e; font-family: inherit;
}
.gac-chat-settings-btn {
    background: #fff; border: 1px solid #e5e7eb; color: #2060ad;
    border-radius: 6px; padding: 2px 8px; font-size: 11px;
    cursor: pointer; transition: background 0.12s;
}
.gac-chat-settings-btn:hover { background: #f0f9ff; }

/* ── Toast in-widget (notificación de mención) ──────────────────── */
.gac-chat-toast {
    position: fixed;
    bottom: 92px;
    right: 20px;
    background: #fff;
    border-left: 4px solid #ef5046;
    box-shadow: 0 8px 22px rgba(0,0,0,0.16);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex; align-items: flex-start; gap: 10px;
    max-width: 320px;
    z-index: 9999;
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
}
.gac-chat-toast.gac-show { opacity: 1; transform: translateY(0); }
.gac-chat-toast > i {
    color: #ef5046; font-size: 16px; flex-shrink: 0; margin-top: 1px;
}
.gac-chat-toast-body { font-size: 12.5px; color: #2e2e2e; }
.gac-chat-toast-body strong { display: block; margin-bottom: 2px; color: #2e2e2e; }
.gac-chat-toast-body span { color: #6b7280; }

@media (max-width: 480px) {
    .gac-chat-toast { right: 12px; bottom: 84px; max-width: calc(100vw - 24px); }
}

/* ── Badge del item Chat en sidebar ─────────────────────────────── */
#gacChatSidebarBadge {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 20px; height: 20px;
    margin-left: auto;
    padding: 0 6px;
    background: #ef5046;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* ════════════════════════════════════════════════════════════════════
 * FASE 4 — adjuntos, emoji, lightbox, who-saw, autolink
 * ════════════════════════════════════════════════════════════════════ */

/* Toolbar buttons (paperclip, emoji) */
.gac-chat-toolbtn {
    background: transparent;
    border: none;
    color: #9c9c9c;
    cursor: pointer;
    width: 30px; height: 30px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: color 0.12s, background 0.12s;
}
.gac-chat-toolbtn:hover { color: #159bd7; background: #f0f9ff; }
.gac-chat-toolbtn:active { transform: scale(0.96); }

/* Autolink */
.gac-msg-bubble a.gac-link {
    color: #2060ad;
    text-decoration: underline;
    word-break: break-all;
}
.gac-msg-row.gac-mine .gac-msg-bubble a.gac-link { color: #fff; }

/* Adjuntos renderizados en mensajes */
.gac-msg-attachments {
    display: flex; flex-wrap: wrap; gap: 5px;
    margin-top: 4px;
    max-width: 100%;
}
.gac-msg-row.gac-mine .gac-msg-attachments { justify-content: flex-end; }
.gac-att-img { display: block; border-radius: 8px; overflow: hidden; line-height: 0; }
.gac-att-img img {
    display: block;
    max-width: 200px; max-height: 200px;
    cursor: zoom-in;
    border-radius: 8px;
    transition: transform 0.12s;
}
.gac-att-img img:hover { transform: scale(1.02); }
.gac-att-pdf {
    display: inline-flex; align-items: center; gap: 7px;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 5px 9px; font-size: 12px; color: #2060ad;
    text-decoration: none; max-width: 240px;
}
.gac-att-pdf i { color: #ef5046; font-size: 14px; flex-shrink: 0; }
.gac-att-pdf span {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}
.gac-att-pdf:hover { background: #f0f9ff; }
.gac-msg-row.gac-mine .gac-att-pdf {
    background: rgba(255,255,255,0.94); border-color: rgba(255,255,255,0.5);
}

/* Kebab "⋯" en mensajes */
.gac-msg-kebab {
    background: transparent; border: none; cursor: pointer;
    color: #9c9c9c; padding: 2px 6px; font-size: 13px; border-radius: 4px;
    opacity: 0; transition: opacity 0.12s, background 0.12s;
    align-self: center;
}
.gac-msg-row:hover .gac-msg-kebab { opacity: 0.7; }
.gac-msg-kebab:hover { opacity: 1; background: rgba(0,0,0,0.06); }

/* Preview de adjuntos pendientes (encima del composer) */
.gac-chat-preview {
    padding: 6px 8px;
    border-top: 1px solid #e5e7eb;
    background: #f7fafc;
    display: flex; flex-wrap: wrap; gap: 6px;
    flex-shrink: 0;
    max-height: 110px;
    overflow-y: auto;
}
.gac-att-preview {
    display: flex; align-items: center; gap: 7px;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 4px 7px; font-size: 11.5px;
    max-width: 240px;
}
.gac-att-thumb {
    width: 28px; height: 28px;
    border-radius: 5px; overflow: hidden;
    background: #f0f9ff;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.gac-att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.gac-att-thumb.gac-pdf i { color: #ef5046; font-size: 14px; }
.gac-att-thumb.gac-uploading i { color: #159bd7; }
.gac-att-info { display: flex; flex-direction: column; min-width: 0; }
.gac-att-name {
    font-weight: 500; color: #2e2e2e;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 150px;
}
.gac-att-size { color: #9c9c9c; font-size: 10px; }
.gac-att-remove {
    background: transparent; border: none; cursor: pointer;
    color: #9c9c9c; padding: 1px 5px; border-radius: 3px; font-size: 11px;
    transition: color 0.12s, background 0.12s;
}
.gac-att-remove:hover { color: #ef5046; background: rgba(239,80,70,0.08); }

/* Drop zone visual (body en drag) */
.gac-chat-body.gac-dropping {
    background: #f0f9ff !important;
    outline: 2px dashed #159bd7;
    outline-offset: -8px;
}

/* Panel emoji */
.gac-chat-emoji-panel {
    padding: 6px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 140px;
    overflow-y: auto;
    flex-shrink: 0;
}
.gac-chat-emoji-btn {
    background: transparent; border: none; cursor: pointer;
    font-size: 18px; padding: 4px; border-radius: 4px;
    transition: background 0.1s;
}
.gac-chat-emoji-btn:hover { background: #f0f9ff; }

/* ── Lightbox ───────────────────────────────────────────────────── */
.gac-chat-lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
    padding: 30px;
    animation: gac-fade 0.18s ease-out;
}
@keyframes gac-fade { from {opacity: 0;} to {opacity: 1;} }
.gac-chat-lightbox img {
    max-width: 90vw; max-height: 80vh;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    background: #000;
}
.gac-chat-lightbox-close {
    position: absolute;
    top: 16px; right: 18px;
    background: rgba(255,255,255,0.12); color: #fff;
    border: none; cursor: pointer;
    width: 38px; height: 38px; border-radius: 50%;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.12s;
}
.gac-chat-lightbox-close:hover { background: rgba(255,255,255,0.25); }
.gac-chat-lightbox-link {
    margin-top: 14px;
    color: #fff; text-decoration: none;
    font-size: 13px;
    background: rgba(255,255,255,0.1);
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.12s;
}
.gac-chat-lightbox-link:hover { background: rgba(255,255,255,0.22); }

/* ── Modal "Quién vio este mensaje" ─────────────────────────────── */
.gac-chat-saw-modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10001;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: gac-fade 0.18s ease-out;
}
.gac-chat-saw-card {
    background: #fff;
    border-radius: 12px;
    width: 100%; max-width: 380px;
    max-height: 70vh;
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.gac-chat-saw-header {
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex; align-items: center; justify-content: space-between;
    background: #f7fafc;
}
.gac-chat-saw-header strong { color: #2e2e2e; font-size: 14px; }
.gac-chat-saw-header small { display: block; color: #9c9c9c; font-size: 11px; margin-top: 1px; }
.gac-chat-saw-close {
    background: transparent; border: none; cursor: pointer;
    color: #9c9c9c; width: 28px; height: 28px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.gac-chat-saw-close:hover { background: rgba(0,0,0,0.06); color: #2e2e2e; }
.gac-chat-saw-list {
    flex: 1; overflow-y: auto;
    padding: 4px;
}
.gac-chat-saw-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
}
.gac-chat-saw-item:hover { background: #f0f9ff; }
.gac-chat-saw-info { display: flex; flex-direction: column; min-width: 0; }
.gac-chat-saw-name { font-weight: 500; color: #2e2e2e; }
.gac-chat-saw-time { font-size: 11px; color: #9c9c9c; }

@media (max-width: 480px) {
    .gac-chat-saw-card { max-width: calc(100vw - 32px); }
}
