/* ========================================
   🆕 v3.1.0: ESTILOS DEL SISTEMA DE TICKETS
   ======================================== */

/* ========================================
   CONTENEDOR PRINCIPAL
   ======================================== */

.giwp-tickets-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 120px);  /* 🆕 v3.2.1: Más altura (antes era 250px) */
    min-height: 600px;
}

/* ========================================
   SIDEBAR (30%)
   ======================================== */

.giwp-tickets-sidebar {
    width: 30%;
    min-width: 280px;
    max-width: 350px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.giwp-tickets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.giwp-tickets-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.giwp-tickets-filters {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
}

.giwp-tickets-filters input,
.giwp-tickets-filters select {
    flex: 1;
    font-size: 13px;
    padding: 8px 12px;
}

.giwp-tickets-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.giwp-tickets-empty {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

/* ========================================
   ITEM DE TICKET EN LISTA
   ======================================== */

.giwp-ticket-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.giwp-ticket-item:hover {
    background: #f3f4f6;
}

.giwp-ticket-item.active {
    background: #eef2ff;
    color: #1f2937;
}

.giwp-ticket-item.active .giwp-ticket-item-meta,
.giwp-ticket-item.active .giwp-ticket-project,
.giwp-ticket-item.active .giwp-ticket-preview {
    color: #374151 !important;
}

.giwp-ticket-item.has-unread {
    background: #fef3c7;
}

.giwp-ticket-item.has-unread.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.giwp-ticket-item-status {
    flex-shrink: 0;
    padding-top: 4px;
}

.giwp-ticket-status-dot {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
}

.giwp-ticket-status-dot.closed {
    background: #6b7280;
}

.giwp-ticket-status-dot.archived {
    background: #d1d5db;
}

.giwp-ticket-item-content {
    flex: 1;
    min-width: 0;
}

.giwp-ticket-item-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.giwp-ticket-item-meta {
    font-size: 12px;
    color: #6b7280;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.giwp-ticket-project {
    font-weight: 500;
}

.giwp-ticket-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
}

/* ========================================
   ÁREA PRINCIPAL (70%)
   ======================================== */

.giwp-ticket-main {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Estado vacío */
.giwp-ticket-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    color: #6b7280;
}

.giwp-ticket-empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.giwp-ticket-empty h3 {
    margin: 0 0 10px;
    color: #1f2937;
}

/* Detalle del ticket */
.giwp-ticket-detail {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.giwp-ticket-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.giwp-ticket-detail-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.giwp-ticket-detail-title h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.giwp-project-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
}

.giwp-status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.giwp-status-badge.open {
    background: #d1fae5;
    color: #059669;
}

.giwp-status-badge.closed {
    background: #e5e7eb;
    color: #6b7280;
}

.giwp-ticket-detail-actions {
    display: flex;
    gap: 8px;
}

/* ========================================
   PESTAÑAS
   ======================================== */

.giwp-ticket-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 20px;
}

.giwp-ticket-tab {
    padding: 12px 20px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.2s;
}

.giwp-ticket-tab:hover {
    color: #667eea;
}

.giwp-ticket-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.giwp-badge-sm {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    background: #e5e7eb;
    color: #6b7280;
    margin-left: 4px;
}

/* ========================================
   TAB: CHAT
   ======================================== */

.giwp-ticket-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;  /* Crítico para que flex funcione correctamente */
}

#ticket-tab-chat {
    display: flex;
    flex-direction: column;
}

.giwp-ticket-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.giwp-messages-empty {
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

/* Mensajes */
.giwp-message {
    display: flex;
    gap: 12px;
    max-width: 80%;
}

.giwp-message-own {
    flex-direction: row-reverse;
    margin-left: auto;
}

.giwp-message-avatar {
    flex-shrink: 0;
    position: relative;
}

.giwp-message-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.giwp-agent-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 4px;
    border-radius: 4px;
}

.giwp-message-content {
    background: #f3f4f6;
    border-radius: 12px;
    padding: 12px 16px;
    max-width: 100%;
}

.giwp-message-own .giwp-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.giwp-message-agent .giwp-message-content {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
}

.giwp-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    gap: 12px;
}

.giwp-message-header strong {
    font-size: 13px;
}

.giwp-message-header time {
    font-size: 11px;
    opacity: 0.7;
}

.giwp-message-body {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.giwp-message-body p {
    margin: 0 0 8px;
}

.giwp-message-body p:last-child {
    margin-bottom: 0;
}

.giwp-message-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

/* Mensaje del sistema */
.giwp-message-system {
    max-width: 100%;
    justify-content: center;
    text-align: center;
    font-size: 12px;
    color: #6b7280;
    padding: 8px 16px;
    background: #f9fafb;
    border-radius: 20px;
    align-self: center;
}

.giwp-message-system time {
    margin-left: 8px;
    opacity: 0.7;
}

/* Mensajes internos (colapsables) */
.giwp-internal-group {
    background: #fef3c7;
    border: 1px dashed #f59e0b;
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
}

.giwp-internal-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
}

.giwp-internal-header:hover {
    background: rgba(245, 158, 11, 0.1);
}

.giwp-internal-toggle {
    margin-left: auto;
    transition: transform 0.2s;
}

.giwp-internal-group:not(.collapsed) .giwp-internal-toggle {
    transform: rotate(90deg);
}

.giwp-internal-messages {
    padding: 0 16px 16px;
    display: none;
}

.giwp-internal-group:not(.collapsed) .giwp-internal-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Input de mensaje */
.giwp-ticket-input-area {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.giwp-ticket-input-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.giwp-ticket-hint {
    font-size: 12px;
    color: #6b7280;
    margin-left: auto;
}

.giwp-ticket-input-row {
    display: flex;
    gap: 12px;
}

.giwp-ticket-input-row textarea {
    flex: 1;
    resize: none;
    font-size: 14px;
    border-radius: 8px;
}

/* ========================================
   TAB: ARCHIVOS
   ======================================== */

#ticket-tab-files {
    padding: 20px;
    overflow-y: auto;
}

.giwp-ticket-files-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.giwp-ticket-files-header h4 {
    margin: 0;
    font-size: 16px;
}

.giwp-files-empty {
    text-align: center;
    padding: 40px;
    color: #6b7280;
}

.giwp-files-category {
    margin-bottom: 24px;
}

.giwp-files-category h5 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.giwp-files-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.giwp-file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #f9fafb;
    border-radius: 8px;
    transition: background 0.2s;
}

.giwp-file-item:hover {
    background: #f3f4f6;
}

.giwp-file-icon {
    font-size: 24px;
}

.giwp-file-info {
    flex: 1;
    min-width: 0;
}

.giwp-file-name {
    display: block;
    font-weight: 500;
    color: #1f2937;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.giwp-file-name:hover {
    color: #667eea;
}

.giwp-file-meta {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

/* ========================================
   BADGE DE NOTIFICACIÓN
   ======================================== */

.giwp-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    background: #ef4444;
    color: #fff;
}

.giwp-badge.pulse {
    animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

.giwp-badge-danger {
    background: #ef4444;
}

/* ========================================
   PARTICIPANTES MODAL
   ======================================== */

.giwp-participants-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px 0;
}

.giwp-participant-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #f3f4f6;
}

.giwp-participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.giwp-participant-info {
    flex: 1;
}

.giwp-participant-info strong {
    display: block;
    font-size: 14px;
}

.giwp-participant-role {
    font-size: 12px;
    color: #6b7280;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .giwp-tickets-container {
        flex-direction: column;
        height: auto;
    }

    .giwp-tickets-sidebar {
        width: 100%;
        max-width: none;
        max-height: 300px;
    }

    .giwp-ticket-main {
        min-height: 400px;
    }

    .giwp-message {
        max-width: 95%;
    }
}

/* ========================================
   🆕 v3.2: CONTEXTO AUTOMÁTICO (Modelo WhatsApp)
   ======================================== */

/* Indicador "Respondiendo a @agente" */
.giwp-reply-context {
    background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
    border-left: 4px solid #667eea;
    padding: 10px 14px;
    margin: 0 16px 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 0 8px 8px 0;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.giwp-reply-context .reply-icon {
    font-size: 16px;
}

.giwp-reply-context .reply-text {
    flex: 1;
    font-size: 13px;
    color: #4a5568;
}

.giwp-reply-context .reply-text strong {
    color: #667eea;
    font-weight: 600;
}

.giwp-reply-context .reply-cancel {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.giwp-reply-context .reply-cancel:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #ef4444;
}

/* Badge de mención especial (Sprint 3) */
.giwp-badge.mention-badge {
    background: linear-gradient(135deg, #ff5722 0%, #ff7043 100%) !important;
    animation: pulse 1.5s infinite;
    box-shadow: 0 2px 8px rgba(255, 87, 34, 0.4);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(255, 87, 34, 0.4);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 4px 12px rgba(255, 87, 34, 0.6);
    }
}

/* Ticket con mención no leída */
.giwp-ticket-item.has-mention {
    border-left: 3px solid #ff5722;
    background: linear-gradient(90deg, rgba(255, 87, 34, 0.05) 0%, transparent 50%);
}

.giwp-ticket-item.has-mention .giwp-badge {
    background: #ff5722 !important;
}

/* ========================================
   🆕 v3.2.1: INDICADOR "PENSANDO" (Agentes procesando)
   ======================================== */

.giwp-thinking {
    opacity: 0.9;
}

.giwp-thinking-icon {
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    animation: thinking-bounce 1s infinite;
}

@keyframes thinking-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.giwp-thinking-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.giwp-thinking-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: thinking-dots 1.4s infinite ease-in-out both;
}

.giwp-thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.giwp-thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.giwp-thinking-dots span:nth-child(3) {
    animation-delay: 0;
}

@keyframes thinking-dots {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   🆕 v3.2.1: MENSAJE FALLIDO
   ======================================== */

.giwp-message-failed .giwp-message-content {
    background: #fee2e2 !important;
    border: 1px dashed #ef4444 !important;
    color: #991b1b !important;
}

.giwp-message-failed .giwp-message-content::after {
    content: ' ⚠️ Error al enviar';
    font-size: 11px;
    color: #ef4444;
    display: block;
    margin-top: 8px;
    font-style: italic;
}

/* 🆕 v3.2.1: Mensaje optimista - sin indicador visual en el mensaje del usuario */
/* El indicador de "pensando" (dots) aparece por separado cuando la IA procesa */
