/*
 * Grupo de Empresas e Inversiones Palau SL
 * Estilos Corporativos y Componentes UI
 */

:root {
    --palau-navy: #1a365d;
    --palau-navy-dark: #0f233d;
    --palau-navy-light: #2a4a7f;
    --palau-gold: #c59b27;
    --palau-gold-light: #dfb547;
    --palau-bg: #f4f6fa;
    --palau-card-bg: #ffffff;
    --palau-border: #e2e8f0;
}

body {
    background-color: var(--palau-bg);
    color: #2d3748;
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar-palau {
    background-color: #1a365d !important;
    --bs-navbar-bg: #1a365d !important;
    --bs-navbar-color: rgba(255, 255, 255, 0.85) !important;
    --bs-navbar-hover-color: #ffffff !important;
    --bs-navbar-active-color: #ffffff !important;
    --bs-navbar-brand-color: #ffffff !important;
    --bs-navbar-brand-hover-color: #ffffff !important;
    border-bottom: 3px solid #c59b27 !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15) !important;
}

.navbar-palau .navbar-brand {
    color: #ffffff !important;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.5px;
}

.navbar-palau .navbar-brand span {
    color: #c59b27 !important;
}

.navbar-palau .nav-link {
    color: #e2e8f0 !important;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.navbar-palau .nav-link:hover, 
.navbar-palau .nav-link.active {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.15) !important;
}

/* Cards */
.card-palau {
    background-color: var(--palau-card-bg);
    border: 1px solid var(--palau-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-stat {
    border-left: 4px solid var(--palau-navy);
}
.card-stat.stat-warning { border-left-color: #f59e0b; }
.card-stat.stat-info { border-left-color: #3b82f6; }
.card-stat.stat-success { border-left-color: #10b981; }
.card-stat.stat-danger { border-left-color: #ef4444; }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Botones con estilo Palau */
.btn-palau {
    background-color: var(--palau-navy);
    color: #ffffff;
    border: none;
    font-weight: 600;
}
.btn-palau:hover {
    background-color: var(--palau-navy-light);
    color: #ffffff;
}

.btn-palau-gold {
    background-color: var(--palau-gold);
    color: #ffffff;
    border: none;
    font-weight: 600;
}
.btn-palau-gold:hover {
    background-color: var(--palau-gold-light);
    color: #ffffff;
}

/* Dropzone y Captura de pantalla */
.screenshot-dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background-color: #f8fafc;
    transition: all 0.2s;
    cursor: pointer;
}
.screenshot-dropzone:hover, 
.screenshot-dropzone.dragover {
    border-color: var(--palau-navy);
    background-color: #edf2f7;
}

.preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 15px;
}

.preview-item {
    position: relative;
    width: 145px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    background-color: #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
    display: inline-flex;
    flex-direction: column;
    vertical-align: top;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.preview-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.preview-item .preview-img-wrap {
    position: relative;
    width: 100%;
    height: 92px;
    background-color: #0f172a;
    overflow: hidden;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.preview-item img:hover {
    transform: scale(1.03);
}

.preview-item .preview-caption {
    padding: 6px 8px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 11px;
    line-height: 1.3;
}

.preview-item .btn-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 13px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    transition: background 0.15s ease, transform 0.15s ease;
}
.preview-item .btn-remove:hover {
    background: #dc3545;
    transform: scale(1.1);
}

/* Lista de archivos adjuntos con tamaño */
.attachment-preview-box {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
}

.attachment-preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* Timeline y Chat del Ticket */
.ticket-timeline {
    position: relative;
    padding-left: 30px;
}

.ticket-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 12px;
    width: 2px;
    background: #e2e8f0;
}

.timeline-entry {
    position: relative;
    margin-bottom: 25px;
}

.timeline-icon {
    position: absolute;
    left: -30px;
    top: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--palau-navy);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 0 0 4px var(--palau-bg);
}

.timeline-icon.icon-reply { background: #3b82f6; }
.timeline-icon.icon-internal { background: #8b5cf6; }
.timeline-icon.icon-status { background: #f59e0b; }
.timeline-icon.icon-reopen { background: #ef4444; }
.timeline-icon.icon-resolve { background: #10b981; }

.timeline-card {
    background: white;
    border: 1px solid var(--palau-border);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.timeline-card.card-internal-note {
    background-color: #faf5ff;
    border-color: #d8b4fe;
}

.timeline-card.card-reopen-notice {
    background-color: #fff5f5;
    border-color: #feb2b2;
}

/* ========================================================
   Chat estilo WhatsApp para el Hilo de Conversación
   ======================================================== */
.whatsapp-chat-container {
    background-color: #f1f5f9 !important;
    background-image: radial-gradient(#cbd5e1 0.75px, transparent 0.75px) !important;
    background-size: 16px 16px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 14px !important;
    padding: 26px 20px !important;
    margin-bottom: 26px !important;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03) !important;
}

.chat-message-row {
    display: flex !important;
    margin-bottom: 24px !important;
    width: 100% !important;
}

.chat-message-row:last-child {
    margin-bottom: 6px !important;
}

.chat-message-row.row-outgoing {
    justify-content: flex-end !important;
}

.chat-message-row.row-incoming {
    justify-content: flex-start !important;
}

.chat-message-row.row-internal,
.chat-message-row.row-reopen {
    justify-content: center !important;
}

.chat-bubble {
    position: relative !important;
    max-width: 75% !important;
    min-width: 250px !important;
    width: fit-content !important;
    padding: 14px 18px 10px 18px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.07) !important;
    word-wrap: break-word !important;
}

@media (max-width: 768px) {
    .chat-bubble {
        max-width: 92% !important;
        min-width: 200px !important;
    }
}

/* Bocadillo saliente (Mi respuesta - Verde clarito estilo WhatsApp) */
.bubble-outgoing {
    background-color: #dcf8c6 !important;
    border: 1px solid #bbf7d0 !important;
    border-radius: 18px 18px 3px 18px !important;
    color: #0f172a !important;
}

/* Bocadillo entrante (Otro usuario - Azul clarito) */
.bubble-incoming {
    background-color: #e0f2fe !important;
    border: 1px solid #bae6fd !important;
    border-radius: 18px 18px 18px 3px !important;
    color: #0f172a !important;
}

/* Bocadillo de Nota Interna (Privada / Gestor) */
.bubble-internal {
    background-color: #faf5ff !important;
    border: 1px dashed #a855f7 !important;
    border-radius: 14px !important;
    max-width: 85% !important;
    color: #3b0764 !important;
}

/* Bocadillo de Reapertura por Disconformidad */
.bubble-reopen {
    background-color: #fff1f2 !important;
    border: 1px solid #fca5a5 !important;
    border-radius: 14px !important;
    max-width: 85% !important;
    color: #881337 !important;
}

.chat-author {
    font-size: 0.88rem !important;
    font-weight: 700 !important;
    margin-bottom: 6px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex-wrap: wrap !important;
}

.bubble-outgoing .chat-author {
    color: #15803d !important;
}

.bubble-incoming .chat-author {
    color: #0369a1 !important;
}

.bubble-internal .chat-author {
    color: #7e22ce !important;
}

.bubble-reopen .chat-author {
    color: #b91c1c !important;
}

.chat-text {
    font-size: 0.96rem !important;
    line-height: 1.6 !important;
    white-space: pre-line !important;
    color: #1e293b !important;
}

.chat-meta {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    font-size: 0.74rem !important;
    margin-top: 6px !important;
    gap: 4px !important;
}

.bubble-outgoing .chat-meta {
    color: #166534 !important;
}

.bubble-incoming .chat-meta {
    color: #475569 !important;
}

.bubble-internal .chat-meta {
    color: #7e22ce !important;
}

.bubble-reopen .chat-meta {
    color: #b91c1c !important;
}

.chat-attachment-box {
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 8px;
    margin-top: 8px;
}

/* Footer */
footer {
    margin-top: auto;
    background-color: #ffffff;
    border-top: 1px solid var(--palau-border);
    padding: 15px 0;
    font-size: 0.85rem;
    color: #718096;
}

/* Estilos para Contenido Enriquecido (WYSIWYG y Tablas) */
.ticket-rich-content {
    font-size: 0.98rem;
    line-height: 1.65;
    color: #1e293b;
    word-break: break-word;
}
.ticket-rich-content p {
    margin-bottom: 0.75rem;
}
.ticket-rich-content p:last-child {
    margin-bottom: 0;
}
.ticket-rich-content table,
.wa-bubble table {
    border-collapse: collapse;
    width: 100% !important;
    max-width: 100%;
    margin: 12px 0;
    font-size: 0.90rem;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    overflow: hidden;
}
.ticket-rich-content th,
.ticket-rich-content td,
.wa-bubble th,
.wa-bubble td {
    border: 1px solid #cbd5e1;
    padding: 8px 12px;
    vertical-align: middle;
}
.ticket-rich-content th,
.wa-bubble th {
    background-color: #1a365d !important;
    color: #ffffff !important;
    font-weight: 600;
    text-align: left;
}
.ticket-rich-content tr:nth-child(even) td,
.wa-bubble tr:nth-child(even) td {
    background-color: #f8fafc;
}
.ticket-rich-content blockquote,
.wa-bubble blockquote {
    border-left: 4px solid #c59b27;
    background-color: #fffbeb;
    padding: 8px 16px;
    margin: 12px 0;
    color: #92400e;
    font-style: italic;
    border-radius: 0 6px 6px 0;
}
.ticket-rich-content ul,
.ticket-rich-content ol,
.wa-bubble ul,
.wa-bubble ol {
    padding-left: 24px;
    margin-bottom: 10px;
}

/* Enlaces limpios y clicables dentro de contenidos y mensajes */
.ticket-rich-content a,
.wa-bubble a {
    color: #1a365d;
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 500;
    word-break: break-all;
    transition: color 0.15s ease-in-out;
}
.ticket-rich-content a:hover,
.wa-bubble a:hover {
    color: #c59b27;
}

/* Contenedor responsivo para tablas en burbujas y tarjetas */
.table-responsive-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 10px 0;
}

/* Personalización CKEditor 5 */
.ck-editor {
    width: 100% !important;
}
.ck-editor__editable_inline {
    min-height: 180px;
    border-radius: 0 0 8px 8px !important;
    font-size: 0.95rem;
    font-family: inherit;
}
.ck-editor__editable_inline:focus {
    border-color: #1a365d !important;
    box-shadow: 0 0 0 0.2rem rgba(26, 54, 93, 0.15) !important;
}
.ck-toolbar {
    border-radius: 8px 8px 0 0 !important;
    background-color: #f8fafc !important;
    border-color: #cbd5e1 !important;
}
.ck-editor-compact .ck-editor__editable_inline {
    min-height: 120px;
}
