/* ===================================
   Chat Coverage - CSS Principal
   Diseño tipo ChatGPT moderno y limpio
   Note: Header and controls use page-structure.css
   =================================== */

.chat-coverage-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    max-height: calc(100vh - 200px);
    background: #f8f9fa;
    overflow: hidden;
}

/* Date Range Selector - specific to chat */
.date-range-selector {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.date-range-selector .custom-range {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    border-left: 1px solid #e5e7eb;
    padding-left: 0.75rem;
    margin-left: 0.25rem;
}

.date-range-selector input[type="date"] {
    width: 140px;
}

/* =================== MAIN CONTAINER =================== */

.chat-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: white;
}

/* =================== SIDEBAR =================== */

.chat-sidebar {
    width: 280px;
    border-right: 1px solid #e5e7eb;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

.sidebar-header h6 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.threads-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.loading-threads {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    gap: 0.75rem;
    color: #6b7280;
}

.thread-item {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.thread-item:hover {
    background: #f3f4f6;
    border-color: #3b82f6;
}

.thread-item.active {
    background: #eff6ff;
    border-color: #3b82f6;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.1);
}

.thread-item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.thread-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
    flex: 1;
}

.thread-date {
    font-size: 0.75rem;
    color: #9ca3af;
    white-space: nowrap;
}

.thread-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: #6b7280;
}

.thread-messages-count {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.thread-actions {
    display: flex;
    gap: 0.25rem;
}

.thread-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.thread-actions .btn:hover {
    opacity: 1;
}

.thread-actions .btn-delete-thread {
    color: #dc2626;
    border: 1px solid #dc2626;
}

.thread-actions .btn-delete-thread:hover {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}

/* =================== MAIN CHAT AREA =================== */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Importante para que flex funcione con scroll */
    position: relative;
    padding-bottom: 55px; /* Espacio para el input */
}

/* Empty State */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    overflow-y: auto;
    min-height: 0;
}

.empty-icon {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.empty-icon i {
    font-size: 3rem;
    color: white;
}

.chat-empty-state h3 {
    font-size: 1.75rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.75rem;
}

.chat-empty-state p {
    font-size: 1.125rem;
    color: #6b7280;
    margin-bottom: 1.5rem;
}

.capabilities-list {
    list-style: none;
    padding: 0;
    margin: 0 0 2rem 0;
    text-align: left;
    max-width: 400px;
}

.capabilities-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    font-size: 1rem;
    color: #374151;
}

.capabilities-list i {
    color: #10b981;
    font-size: 1.25rem;
}

/* Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0; /* Importante para que flex funcione con scroll */
    scroll-behavior: smooth;
}

/* Message Bubble */
.message {
    display: flex;
    gap: 0.75rem;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.message-content {
    flex: 1;
    max-width: 75%;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-role {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.875rem;
}

.message-time {
    font-size: 0.75rem;
    color: #9ca3af;
}

.message-body {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: #374151;
}

.message.user .message-body {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.message.assistant .message-body {
    background: white;
    border-color: #e5e7eb;
}

/* Markdown Styling dentro de mensajes */
.message-body h1, .message-body h2, .message-body h3,
.message-body h4, .message-body h5, .message-body h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #1f2937;
}

.message-body h1 { font-size: 1.5rem; }
.message-body h2 { font-size: 1.25rem; }
.message-body h3 { font-size: 1.125rem; }

.message-body p {
    margin-bottom: 0.75rem;
}

.message-body ul, .message-body ol {
    margin: 0.5rem 0 0.75rem 1.25rem;
}

.message-body li {
    margin-bottom: 0.25rem;
}

.message-body code {
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    color: #dc2626;
}

.message-body pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-body pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.875rem;
}

.message-body table th,
.message-body table td {
    border: 1px solid #e5e7eb;
    padding: 0.5rem;
    text-align: left;
}

.message-body table th {
    background: #f3f4f6;
    font-weight: 600;
}

.message-body blockquote {
    border-left: 4px solid #3b82f6;
    margin: 0.75rem 0;
    padding-left: 1rem;
    color: #6b7280;
}

/* Message Attachments */
.message-attachments {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.attachment-image {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.attachment-image:hover {
    transform: scale(1.02);
}

/* File Attachments (PDF, Excel, etc.) */
.file-attachment {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.file-attachment:hover {
    background: #f3f4f6;
    border-color: #3b82f6;
}

.file-attachment .btn {
    white-space: nowrap;
}

.file-attachment small {
    font-size: 0.75rem;
}

/* Loading Indicator */
.message.loading .message-body {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.typing-indicator {
    display: flex;
    gap: 0.375rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* =================== INPUT AREA =================== */

.chat-input-area {
    border-top: 1px solid #e5e7eb;
    background: white;
    padding: 1rem 1.5rem;
    flex-shrink: 0; /* Evita que se comprima */
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: end;
}

.input-wrapper textarea {
    flex: 1;
    resize: none;
    border-color: #d1d5db;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.input-wrapper textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-actions {
    display: flex;
    gap: 0.5rem;
}

.input-hints {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f3f4f6;
}

.input-hints i {
    color: #fbbf24;
}

/* =================== RESPONSIVE =================== */

@media (max-width: 1024px) {
    .chat-sidebar {
        position: absolute;
        left: -280px;
        height: 100%;
        z-index: 10;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-sidebar.show {
        left: 0;
    }
    
    .message-content {
        max-width: 90%;
    }
}

/* Móviles (menos de 768px) */
@media (max-width: 767px) {
    .chat-coverage-wrapper {
        height: calc(100vh - 250px);
        max-height: calc(100vh - 250px);
    }
    
    .date-range-selector {
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    
    .date-range-selector .btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }
    
    .date-range-selector .custom-range {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        border-top: 1px solid #e5e7eb;
        padding-top: 0.5rem;
        margin-top: 0.5rem;
        flex-wrap: wrap;
        width: 100%;
    }
    
    .date-range-selector input[type="date"] {
        width: 120px;
        font-size: 0.8rem;
    }
    
    .chat-container {
        flex-direction: column;
    }
    
    .chat-sidebar {
        position: static;
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .chat-main {
        width: 100%;
    }
    
    .chat-empty-state h3 {
        font-size: 1.25rem;
    }
    
    .chat-empty-state p {
        font-size: 0.9rem;
    }
    
    .chat-empty-state .capabilities-list {
        font-size: 0.85rem;
    }
    
    .message-content {
        max-width: 95%;
        font-size: 0.9rem;
    }
    
    .user-message .message-content {
        padding: 0.75rem 1rem;
    }
    
    .assistant-message .message-content {
        padding: 0.75rem 1rem;
    }
    
    .chat-input-area textarea {
        font-size: 0.9rem;
        min-height: 60px;
    }
}

/* Móviles muy pequeños (menos de 576px) */
@media (max-width: 576px) {
    .date-range-selector .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
    
    .date-range-selector input[type="date"] {
        width: 110px;
        font-size: 0.75rem;
    }
    
    .chat-empty-state h3 {
        font-size: 1.1rem;
    }
    
    .chat-empty-state .btn {
        font-size: 0.9rem;
        padding: 0.6rem 1.2rem;
    }
    
    .message-content {
        font-size: 0.85rem;
    }
    
    .chat-input-area textarea {
        font-size: 0.85rem;
        min-height: 50px;
    }
    
    .input-actions .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
    }
}

/* =================== LOADING OVERLAY =================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 1rem;
}

.loading-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

.loading-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    background: #f9fafb;
    transition: all 0.3s ease;
}

.loading-step.active {
    background: #eff6ff;
    border-left: 3px solid #3b82f6;
}

.loading-step.completed {
    background: #f0fdf4;
    border-left: 3px solid #10b981;
}

.loading-step-icon {
    font-size: 1.25rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-step.active .loading-step-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading-step-text {
    flex: 1;
    font-size: 0.875rem;
    color: #6b7280;
}

.loading-step.active .loading-step-text {
    color: #1f2937;
    font-weight: 500;
}

.loading-step.completed .loading-step-text {
    color: #059669;
}

/* =================== UTILITIES =================== */

.hidden {
    display: none !important;
}

.text-error {
    color: #dc2626;
}

.text-success {
    color: #10b981;
}

.badge-new {
    background: #3b82f6;
    color: white;
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-weight: 500;
}

/* Scrollbar personalizado */
.chat-messages::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

