/* ============================================================
   BITÁCORA DE EVENTOS DE PEDIDOS - CSS Profesional
   Tema: Claro/Oscuro | Glassmorphism | Mobile First
   ============================================================ */

/* === Variables de diseño === */
:root {
    --bg: #f8fafc;
    --bg-alt: transparent;
    --surface: rgba(255, 255, 255, 0.7);
    --surface-alt: rgba(255, 255, 255, 0.4);
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.5);
    --border-light: rgba(255, 255, 255, 0.3);
    --accent: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.25);
    --accent-soft: #dbeafe;
    --success: #059669;
    --success-soft: #d1fae5;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #7c3aed;
    --info-soft: #ede9fe;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    --radius-sm: 0.5rem;
    --radius: 0.875rem;
    --radius-lg: 1.25rem;
    --radius-xl: 1.75rem;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* === Tema oscuro === */
[data-theme="dark"] {
    --bg: #0a0f1a;
    --bg-alt: transparent;
    --surface: rgba(26, 34, 54, 0.7);
    --surface-alt: rgba(31, 42, 65, 0.5);
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.1);
    --border-light: rgba(255, 255, 255, 0.05);
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.3);
    --accent-soft: #1e3a5f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 4px 16px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);
}

/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }

/* === Fondo Glassmorphism === */
.glass-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: var(--bg);
}

.shape {
    position: absolute;
    filter: blur(80px);
    border-radius: 50%;
    animation: float 20s infinite alternate;
    opacity: 0.6;
}

.shape-1 {
    top: -10%; left: -10%; width: 50vw; height: 50vw;
    background: radial-gradient(circle, var(--info) 0%, rgba(124,58,237,0) 70%);
}

.shape-2 {
    bottom: -20%; right: -10%; width: 60vw; height: 60vw;
    background: radial-gradient(circle, var(--accent) 0%, rgba(37,99,235,0) 70%);
    animation-delay: -5s;
}

.shape-3 {
    top: 40%; left: 40%; width: 40vw; height: 40vw;
    background: radial-gradient(circle, var(--success) 0%, rgba(5,150,105,0) 70%);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 10%) scale(1.1); }
}

[data-theme="dark"] .shape { opacity: 0.3; }

/* === Contenedores Glass Global === */
.search-card, .stat-card, .ai-summary, .ai-data-card, .ai-events-card, .ai-actions, .autocomplete-list, .tab-nav, .tabla-proveedor th, .tabla-proveedor td {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* === App wrapper === */
.app-wrapper {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 1rem 3rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* === Top Bar === */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    margin: 0 -1rem;
    padding: 0 1rem;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), border var(--transition);
}
.top-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 0;
    max-width: 860px;
    margin: 0 auto;
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.logo-icon {
    font-size: 2rem;
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}
.logo-text h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
    line-height: 1.2;
}
.logo-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
}
.theme-btn {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 2rem;
    width: 2.6rem;
    height: 2.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.theme-btn:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    transform: scale(1.05);
}
.theme-sun, .theme-moon { transition: all 0.3s; position: absolute; }
[data-theme="dark"] .theme-sun { opacity: 1; transform: scale(1); }
[data-theme="dark"] .theme-moon { opacity: 0; transform: scale(0.5); }
[data-theme="light"] .theme-sun { opacity: 0; transform: scale(0.5); }
[data-theme="light"] .theme-moon { opacity: 1; transform: scale(1); }

/* === Main area === */
.tab-nav {
    margin-top: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    z-index: 90;
    transition: all var(--transition);
}

@media (min-width: 769px) {
    .tab-nav {
        position: sticky;
        top: 80px; /* Adjust based on top-bar height */
        background: var(--bg); /* To prevent transparency overlapping */
        padding-top: 0.5rem;
        border-radius: var(--radius);
    }
}

.main-area {
    flex: 1;
    padding-top: 0.5rem;
}

/* === Search Panel === */
.search-panel { margin-bottom: 1.5rem; }
.search-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.75rem 1.5rem;
    box-shadow: var(--shadow);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.search-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), #8b5cf6, var(--accent));
    background-size: 200% 100%;
    animation: shimmer 3s ease infinite;
}
@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
.search-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
}
.search-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.2px;
}
.search-icon { font-size: 1.3rem; }
.search-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.4rem;
}
.search-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.1rem;
    margin-bottom: 1.5rem;
}
.input-pedido { grid-column: 1 / -1; }

.input-group { display: flex; flex-direction: column; gap: 0.35rem; }
.input-group label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.label-icon { font-size: 0.95rem; }
.search-input {
    background: var(--surface-alt);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text);
    transition: all var(--transition);
    outline: none;
    width: 100%;
}
.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    background: var(--surface);
}
.input-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
}
.error-msg {
    font-size: 0.78rem;
    color: var(--danger);
    min-height: 1.1rem;
    font-weight: 500;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 500px;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Scrollbars */
/* Botón consultar */
.btn-search {
    width: 100%;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-search:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
}
.btn-search:active { transform: scale(0.98); }
.btn-search:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}
.btn-content, .btn-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.btn-loading { gap: 0.6rem; }
.spinner-small {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* === Loader Global === */
.loader-global {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}
.loader-orb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    animation: orbPulse 1.4s ease-in-out infinite;
}
.loader-orb:nth-child(2) { animation-delay: 0.2s; }
.loader-orb:nth-child(3) { animation-delay: 0.4s; }
@keyframes orbPulse {
    0%, 100% { transform: scale(0.6); opacity: 0.4; }
    50% { transform: scale(1.2); opacity: 1; }
}
.loader-message {
    font-weight: 600;
    color: var(--text);
    font-size: 1.05rem;
}
.loader-submessage {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* === Result Area === */
.result-area { animation: fadeInUp 0.5s ease; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Panel KPI === */
.kpi-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    transition: all var(--transition);
    position: relative;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.kpi-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.kpi-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.3px;
}
.kpi-accent { color: var(--accent); }
.kpi-success { color: var(--success); }
.kpi-warning { color: var(--warning); }
.kpi-card.kpi-highlight {
    border-left: 4px solid var(--accent);
}

/* === Status Alert === */
.status-alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.95rem;
    animation: fadeInUp 0.4s ease;
}
.status-alert.pendiente {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.3);
}
.status-alert.finalizado {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(5, 150, 105, 0.3);
}

/* === Timeline === */
.timeline-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem 1.25rem;
    box-shadow: var(--shadow);
}
.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}
.timeline-header h3 { font-size: 1.15rem; font-weight: 700; }
.timeline-count {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.3rem 0.75rem;
    border-radius: 2rem;
    font-weight: 700;
    font-size: 0.8rem;
}
.timeline-container {
    position: relative;
    padding-left: 2.8rem;
}
.timeline-container::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 12px;
    bottom: 12px;
    width: 3px;
    background: var(--border);
    border-radius: 2px;
}

/* Evento individual */
.event-block {
    position: relative;
    margin-bottom: 1.6rem;
    padding: 1.15rem 1.3rem;
    background: var(--surface-alt);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
.event-block:hover {
    border-color: var(--border);
    box-shadow: var(--shadow);
    transform: translateX(2px);
}
.event-block:last-child { margin-bottom: 0; }
.event-dot {
    position: absolute;
    left: -2.15rem;
    top: 1.4rem;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 4px var(--accent);
    background: var(--accent);
    z-index: 2;
}
.event-dot.success { background: var(--success); box-shadow: 0 0 0 4px rgba(5,150,105,0.25); }
.event-dot.warning { background: var(--warning); box-shadow: 0 0 0 4px rgba(217,119,6,0.25); }
.event-dot.info { background: var(--info); box-shadow: 0 0 0 4px rgba(124,58,237,0.25); }
.event-dot.danger { background: var(--danger); box-shadow: 0 0 0 4px rgba(220,38,38,0.25); }

.event-header {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.event-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}
.event-meta {
    flex: 1;
    min-width: 0;
}
.event-state {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    letter-spacing: -0.2px;
}
.event-datetime {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 0.15rem;
}
.event-description {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
    line-height: 1.5;
}
.event-details {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.event-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}
.event-tag strong { color: var(--text); font-weight: 600; }
.event-link-gmail {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.6rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all var(--transition);
}
.event-link-gmail:hover {
    text-decoration: underline;
    gap: 0.5rem;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}
.empty-art { font-size: 4rem; margin-bottom: 1rem; animation: float 3s ease-in-out infinite; }
.empty-state h3 { font-size: 1.3rem; margin-bottom: 0.4rem; font-weight: 700; }
.empty-state p { color: var(--text-secondary); font-size: 0.9rem; }
.empty-hint { font-size: 0.8rem !important; color: var(--text-muted) !important; margin-top: 0.5rem; }

/* ============================================================
   FOOTER PERSONALIZADO - Alfredo Bolaños
   ============================================================ */
.app-footer {
    margin-top: auto;
    padding: 1.5rem 0 1rem;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 1.2rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    max-width: 650px;
    margin: 0 auto;
    transition: background var(--transition), border var(--transition);
}

.footer-brand-logo {
    width: 150px;
    height: auto;
    flex-shrink: 0;
    opacity: 0.9;
    transition: opacity 0.3s;
}

.footer-brand-logo:hover {
    opacity: 1;
}

.footer-info {
    text-align: left;
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.footer-creator {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.footer-creator strong {
    color: var(--accent);
    font-weight: 700;
}

.footer-source {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.footer-source strong {
    color: var(--text);
    font-weight: 600;
}

.footer-version {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    opacity: 0.8;
}

/* Responsive footer */
@media (max-width: 600px) {
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.8rem;
        padding: 1rem;
    }
    .footer-info {
        text-align: center;
    }
    .footer-brand-logo {
        width: 110px;
    }
}



/* ============================================================
   NUEVOS ESTILOS - Información del correo en la timeline
   Agregar ANTES de la sección Responsive
   ============================================================ */

/* Información del correo dentro del evento */
.event-correo-info {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.correo-asunto {
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}

.correo-remitente {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.correo-extracto {
    margin-top: 0.3rem;
    padding: 0.5rem 0.7rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.5;
    border-left: 3px solid var(--accent);
    font-size: 0.78rem;
    max-height: 150px;
    overflow-y: auto;
    word-break: break-word;
}

.correo-extracto strong {
    font-style: normal;
    color: var(--text);
}

/* ============================================================
   BADGES DE TIPO DE CORREO (Sistema vs Conversación)
   ============================================================ */
.event-tipo-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.event-tipo-badge.sistema {
    background: var(--info-soft);
    color: var(--info);
    border: 1px solid rgba(124, 58, 237, 0.2);
}

.event-tipo-badge.conversacion {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.2);
}

/* Borde izquierdo de color según tipo */
.event-block.tipo-sistema {
    border-left: 3px solid var(--info);
}

.event-block.tipo-conversacion {
    border-left: 3px solid var(--warning);
}

/* Indicador de mismo hilo */
.thread-continuacion {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.25rem 0.6rem;
    border-radius: 1rem;
    display: inline-block;
    margin-bottom: 0.4rem;
}

/* Extracto más amplio */
.correo-extracto {
    max-height: 250px;  /* Antes 150px */
}


/* ============================================================
   BADGES DE BUZÓN (Sistema / Aprobaciones / Personal)
   ============================================================ */
.event-buzon-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

/* Buzón Sistema */
.buzon-sistema {
    border-left: 3px solid #7c3aed !important;
}
.event-buzon-badge.buzon-sistema {
    background: #ede9fe;
    color: #7c3aed;
    border: 1px solid rgba(124, 58, 237, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-sistema {
    background: #3b2f5c;
    color: #a78bfa;
}

/* Buzón Aprobaciones */
.buzon-aprobaciones {
    border-left: 3px solid #059669 !important;
}
.event-buzon-badge.buzon-aprobaciones {
    background: #d1fae5;
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-aprobaciones {
    background: #064e3b;
    color: #6ee7b7;
}

/* Buzón Personal */
.buzon-personal {
    border-left: 3px solid #d97706 !important;
}
.event-buzon-badge.buzon-personal {
    background: #fef3c7;
    color: #d97706;
    border: 1px solid rgba(217, 119, 6, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-personal {
    background: #78350f;
    color: #fbbf24;
}

/* Buzón Otro */
.buzon-otro {
    border-left: 3px solid #94a3b8 !important;
}

/* Badge de adjunto */
.adjunto-badge {
    font-size: 0.72rem;
    color: #7c3aed;
    background: #ede9fe;
    padding: 0.3rem 0.7rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    border: 1px dashed rgba(124, 58, 237, 0.3);
}
[data-theme="dark"] .adjunto-badge {
    background: #3b2f5c;
    color: #a78bfa;
    border-color: rgba(124, 58, 237, 0.4);
}

/* Thread continuacion */
.thread-continuacion {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.25rem 0.6rem;
    border-radius: 1rem;
    display: inline-block;
    margin-bottom: 0.4rem;
}

/* Extracto más amplio */
.correo-extracto {
    max-height: 250px;
}

/* ============================================================
   DOS TIMELINES SEPARADAS
   ============================================================ */

/* Sección de timeline */
.timeline-section {
    margin-bottom: 1.5rem;
}

.timeline-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    font-weight: 700;
}

.timeline-section-header h3 {
    font-size: 1.05rem;
    margin: 0;
}

.timeline-section-count {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-weight: 600;
}

/* Header del Sistema */
.sistema-header {
    background: #ede9fe;
    color: #7c3aed;
    border: 1px solid rgba(124, 58, 237, 0.2);
}
.sistema-header .timeline-section-count {
    background: #c4b5fd;
    color: #5b21b6;
}
[data-theme="dark"] .sistema-header {
    background: #3b2f5c;
    color: #a78bfa;
    border-color: rgba(124, 58, 237, 0.3);
}
[data-theme="dark"] .sistema-header .timeline-section-count {
    background: #5b3f9e;
    color: #c4b5fd;
}

/* Header de Conversaciones */
.conversaciones-header {
    background: #fef3c7;
    color: #d97706;
    border: 1px solid rgba(217, 119, 6, 0.2);
}
.conversaciones-header .timeline-section-count {
    background: #fde68a;
    color: #92400e;
}
[data-theme="dark"] .conversaciones-header {
    background: #78350f;
    color: #fbbf24;
    border-color: rgba(217, 119, 6, 0.3);
}
[data-theme="dark"] .conversaciones-header .timeline-section-count {
    background: #92400e;
    color: #fde68a;
}

/* Timeline vacío */
.timeline-empty {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    background: var(--surface-alt);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

/* ============================================================
   BADGES DE BUZÓN
   ============================================================ */
.event-buzon-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.buzon-sistema {
    border-left: 3px solid #7c3aed !important;
}
.event-buzon-badge.buzon-sistema {
    background: #ede9fe;
    color: #7c3aed;
    border: 1px solid rgba(124, 58, 237, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-sistema {
    background: #3b2f5c;
    color: #a78bfa;
}

.buzon-aprobaciones {
    border-left: 3px solid #059669 !important;
}
.event-buzon-badge.buzon-aprobaciones {
    background: #d1fae5;
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-aprobaciones {
    background: #064e3b;
    color: #6ee7b7;
}

.buzon-personal {
    border-left: 3px solid #d97706 !important;
}
.event-buzon-badge.buzon-personal {
    background: #fef3c7;
    color: #d97706;
    border: 1px solid rgba(217, 119, 6, 0.3);
}
[data-theme="dark"] .event-buzon-badge.buzon-personal {
    background: #78350f;
    color: #fbbf24;
}

.buzon-otro {
    border-left: 3px solid #94a3b8 !important;
}

/* Badge de adjunto */
.adjunto-badge {
    font-size: 0.72rem;
    color: #7c3aed;
    background: #ede9fe;
    padding: 0.3rem 0.7rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    border: 1px dashed rgba(124, 58, 237, 0.3);
}
[data-theme="dark"] .adjunto-badge {
    background: #3b2f5c;
    color: #a78bfa;
    border-color: rgba(124, 58, 237, 0.4);
}

.thread-continuacion {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.25rem 0.6rem;
    border-radius: 1rem;
    display: inline-block;
    margin-bottom: 0.4rem;
}

.correo-extracto {
    max-height: 250px;
}


/* ============================================================
   BOTÓN DE INSTALACIÓN PWA
   ============================================================ */
.btn-instalar {
    width: 100%;
    background: linear-gradient(135deg, #059669, #10b981);
    color: #ffffff;
    border: none;
    border-radius: var(--radius);
    padding: 0.8rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all var(--transition);
    margin-top: 1rem;
    box-shadow: 0 4px 16px rgba(5, 150, 105, 0.3);
    animation: pulse-install 2s ease-in-out infinite;
}

.btn-instalar:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(5, 150, 105, 0.4);
    background: linear-gradient(135deg, #10b981, #34d399);
}

@keyframes pulse-install {
    0%, 100% { box-shadow: 0 4px 16px rgba(5, 150, 105, 0.3); }
    50% { box-shadow: 0 4px 24px rgba(5, 150, 105, 0.5); }
}

.btn-instalar.hidden {
    display: none !important;
}



/* === Responsive === */
@media (max-width: 600px) {
    .search-grid { grid-template-columns: 1fr; }
    .kpi-panel { grid-template-columns: 1fr 1fr; }
    .kpi-card { padding: 0.85rem 0.9rem; }
    .kpi-value { font-size: 1.1rem; }
    .search-card { padding: 1.3rem 1rem; }
    .timeline-wrapper { padding: 1.2rem 0.9rem; }
    .timeline-container { padding-left: 2.4rem; }
    .event-dot { left: -1.9rem; width: 14px; height: 14px; }
    .timeline-container::before { left: 18px; }
    .logo-text h1 { font-size: 1rem; }
    .logo-icon { font-size: 1.6rem; }
    .btn-search { font-size: 0.9rem; padding: 0.85rem; }
    .event-block { padding: 0.9rem 1rem; }
}

/* ============================================================
   BOTÓN DE INSTALACIÓN PWA
   ============================================================ */
.btn-instalar {
    width: 100%;
    background: linear-gradient(135deg, #059669, #10b981);
    color: #ffffff;
    border: none;
    border-radius: var(--radius);
    padding: 0.8rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all var(--transition);
    margin-top: 1rem;
    box-shadow: 0 4px 16px rgba(5, 150, 105, 0.3);
    animation: pulse-install 2s ease-in-out infinite;
}

.btn-instalar:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(5, 150, 105, 0.4);
    background: linear-gradient(135deg, #10b981, #34d399);
}

@keyframes pulse-install {
    0%, 100% { box-shadow: 0 4px 16px rgba(5, 150, 105, 0.3); }
    50% { box-shadow: 0 4px 24px rgba(5, 150, 105, 0.5); }
}

.btn-instalar.hidden {
    display: none !important;
}
/* ============================================================
   PESTAÑAS DE NAVEGACIÓN
   ============================================================ */
.tab-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0 0.5rem;
    flex-wrap: wrap;
}

.tab-btn {
    flex: 1;
    min-width: 180px;
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tab-btn.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

[data-theme="dark"] .tab-btn:hover {
    background: var(--accent-soft);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeInUp 0.4s ease;
}

/* ============================================================
   TABLA DE PROVEEDORES
   ============================================================ */
.tabla-proveedor {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.tabla-proveedor thead {
    background: var(--accent-soft);
}

.tabla-proveedor th {
    padding: 0.75rem 0.8rem;
    text-align: left;
    font-weight: 700;
    color: var(--accent);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--accent);
}

[data-theme="dark"] .tabla-proveedor thead {
    background: var(--accent-soft);
}

.tabla-proveedor td {
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

.tabla-proveedor tbody tr {
    transition: background var(--transition);
}

.tabla-proveedor tbody tr:hover {
    background: var(--surface-alt);
}

.tabla-proveedor .estado-costeado {
    color: var(--success);
    font-weight: 700;
}

.tabla-proveedor .estado-pendiente {
    color: var(--warning);
    font-weight: 600;
}

.tabla-proveedor .estado-sinrecepcion {
    color: var(--danger);
    font-weight: 600;
}

.tabla-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive tabla */
@media (max-width: 600px) {
    .tab-nav {
        flex-direction: column;
    }
    .tab-btn {
        min-width: 100%;
    }
    .tabla-proveedor {
        font-size: 0.75rem;
    }
    .tabla-proveedor th,
    .tabla-proveedor td {
        padding: 0.5rem 0.4rem;
    }
}

/* ============================================================
   AUTOCOMPLETADO DE PROVEEDORES
   ============================================================ */
.autocomplete-wrapper {
    position: relative;
    width: 100%;
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 250px;
    overflow-y: auto;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.autocomplete-item {
    padding: 0.7rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text);
    transition: background var(--transition);
    border-bottom: 1px solid var(--border-light);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.autocomplete-item strong {
    color: var(--accent);
    font-weight: 700;
}

.autocomplete-no-results {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

/* ============================================================
   ANALIZADOR IA GEMINI
   ============================================================ */
.ai-textarea {
    min-height: 200px;
    resize: vertical;
    font-family: var(--font);
    font-size: 0.9rem;
    line-height: 1.5;
}

.btn-ai {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
}
.btn-ai:hover {
    box-shadow: 0 8px 30px rgba(124, 58, 237, 0.6);
}

.ai-card {
    border-top: 4px solid #7c3aed;
}

/* Resultados IA */
.ai-summary {
    background: var(--surface-alt);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    border-left: 4px solid #7c3aed;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.6;
}
.ai-summary h3 { margin-bottom: 0.5rem; color: var(--text); font-size: 1.1rem; }

.ai-classification {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border-radius: 2rem;
    background: var(--info-soft);
    color: var(--info);
    font-weight: 700;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    border: 1px solid rgba(124, 58, 237, 0.2);
}

.ai-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.ai-data-card, .ai-events-card, .ai-actions {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.ai-data-card h4, .ai-events-card h4, .ai-actions h4 {
    margin-bottom: 1rem;
    color: var(--text);
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.5rem;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-data-list {
    list-style: none;
    padding: 0;
}
.ai-data-list li {
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--border-light);
    display: flex;
    flex-direction: column;
}
.ai-data-list li:last-child { border-bottom: none; }
.ai-data-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
.ai-data-value { font-weight: 500; color: var(--text); }

.ai-actions {
    background: var(--warning-soft);
    border-color: rgba(217, 119, 6, 0.3);
}

.ai-actions h4 {
    color: var(--warning);
    border-bottom-color: rgba(217, 119, 6, 0.2);
}

.ai-actions-list {
    padding-left: 1.2rem;
    color: var(--warning);
    font-weight: 500;
}
.ai-actions-list li { margin-bottom: 0.4rem; }

.ai-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.btn-ai {
    flex: 2;
}

.btn-clear {
    flex: 1;
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}
.btn-clear:hover {
    background: var(--surface);
    border-color: var(--text-muted);
}

/* Clasificaciones Candidatas */
.ai-candidates-section {
    margin-bottom: 1.5rem;
}
.ai-candidates-section > h4 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text);
}
.ai-candidates-hint {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.ai-candidates-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-candidate {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: all var(--transition);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}
.ai-candidate:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: translateY(-2px);
}
.ai-candidate-top {
    border-color: var(--success);
    background: var(--success-soft);
}
.ai-candidate-selected {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-glow), 0 8px 24px var(--accent-glow) !important;
    transform: translateY(-2px);
}
.ai-candidate-selected::after {
    content: '✅ Seleccionada';
    display: block;
    margin-top: 0.75rem;
    text-align: center;
    font-weight: 700;
    color: var(--accent);
    font-size: 0.85rem;
}

.ai-candidate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.ai-candidate-badge {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.ai-candidate-confidence {
    font-size: 1.25rem;
    font-weight: 800;
}

.ai-candidate-code {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.ai-candidate-bar {
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}
.ai-candidate-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.ai-candidate-reason {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    font-style: italic;
}

/* ============================================================ */
/* EMAIL ANALYZER PRO STYLES */
/* ============================================================ */

.ap-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.ap-state-strip {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(0, 2fr) minmax(150px, 1fr);
    gap: 1rem;
    background: rgba(15, 23, 42, 0.85); /* Darker glass */
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ap-state-strip {
    background: rgba(10, 15, 26, 0.85);
}

.ap-state-cell {
    min-width: 0;
}

.ap-state-label {
    display: block;
    color: #94a3b8;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.ap-state-value {
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.ap-state-detail {
    color: #dbeafe;
    line-height: 1.5;
    font-size: 0.9rem;
    margin: 0;
    overflow-wrap: anywhere;
}

.ap-risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    width: fit-content;
    max-width: 100%;
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
}

.ap-risk-bajo { background: rgba(5, 150, 105, 0.2); color: #34d399; border: 1px solid rgba(5, 150, 105, 0.5); }
.ap-risk-medio { background: rgba(217, 119, 6, 0.2); color: #fbbf24; border: 1px solid rgba(217, 119, 6, 0.5); }
.ap-risk-alto { background: rgba(220, 38, 38, 0.2); color: #f87171; border: 1px solid rgba(220, 38, 38, 0.5); }

.ap-content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.ap-timeline {
    position: relative;
    display: grid;
    gap: 1rem;
    padding-left: 1.5rem;
}

.ap-timeline::before {
    content: "";
    position: absolute;
    left: 0.4rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 2px;
    background: var(--accent-glow);
}

.ap-timeline-item {
    position: relative;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    backdrop-filter: blur(16px);
}

.ap-timeline-item::before {
    content: "";
    position: absolute;
    left: -1.45rem;
    top: 1.2rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--surface);
}

.ap-timeline-date {
    color: var(--accent);
    font-weight: 800;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.ap-timeline-title {
    color: var(--text);
    font-weight: 800;
    line-height: 1.35;
    margin-bottom: 0.25rem;
}

.ap-timeline-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

.ap-emails-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.75rem;
}

.ap-email-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: start;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.ap-email-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    display: grid;
    place-items: center;
    font-size: 1.2rem;
}

.ap-email-subject {
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.ap-email-meta {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.ap-email-snippet {
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 1024px) {
    .ap-content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .ap-state-strip { grid-template-columns: 1fr; }
    .ap-email-item { grid-template-columns: 32px minmax(0, 1fr); }
}

@media (max-width: 768px) {
    .ai-grid { grid-template-columns: 1fr; }
    .ai-buttons { flex-direction: column-reverse; }
}