/* ═══════════════════════════════════════════════════════════════════════════
   Analytics View Styles — Feature #16: Source Authority Score
   ═══════════════════════════════════════════════════════════════════════════ */

.analytics-container {
    display: flex;
    flex-direction: column;
    gap: 32px;
    margin-top: 8px;
}

/* Summary Cards Grid */
.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    transition: opacity 0.2s ease, transform 0.2s ease;
    margin-bottom: 8px;
}

#source-authority-table {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ── Analytics Card Header Optimizado ── */
.analytics-container .card {
    margin-bottom: 0;
}

.analytics-container .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px;
    gap: 24px;
    min-height: 80px;
}

.analytics-container .card-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.analytics-container .card-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.analytics-container .card-body {
    padding: 0;
}

/* ── NIVEL 1: Glassmorphism + Stagger Animations ── */
.summary-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 28px;

    /* Glassmorphism Effect */
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;

    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);

    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Entrada animada con stagger */
    opacity: 0;
    transform: translateY(20px);
    animation: slideInUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.summary-card:nth-child(1) { animation-delay: 0.1s; }
.summary-card:nth-child(2) { animation-delay: 0.2s; }
.summary-card:nth-child(3) { animation-delay: 0.3s; }
.summary-card:nth-child(4) { animation-delay: 0.4s; }

@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── NIVEL 2: Parallax Hover Effect ── */
.summary-card {
    perspective: 1000px;
    transform-style: preserve-3d;
    position: relative;
    overflow: visible;
}

.summary-card::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 18px;
    background: linear-gradient(135deg,
        rgba(124, 77, 255, 0),
        rgba(124, 77, 255, 0.2),
        rgba(124, 77, 255, 0));
    background-size: 200% 200%;
    opacity: 0;
    z-index: -1;
    transition: opacity 0.4s ease;
    animation: borderGlow 3s ease infinite;
}

@keyframes borderGlow {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.summary-card:hover::after {
    opacity: 1;
}

.summary-card:hover {
    transform: translateY(-6px) scale(1.03);
    box-shadow:
        0 16px 48px rgba(124, 77, 255, 0.25),
        0 0 0 1px rgba(124, 77, 255, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border-color: rgba(124, 77, 255, 0.4);
    background: rgba(124, 77, 255, 0.1);
}

/* Layout izquierda: ícono + label */
.summary-left {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.summary-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;

    /* Gradiente animado de fondo */
    background: linear-gradient(135deg, var(--icon-bg-1, #6366f1), var(--icon-bg-2, #8b5cf6));
    box-shadow: 0 4px 12px var(--icon-shadow, rgba(99, 102, 241, 0.3));

    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.summary-card:hover .summary-icon {
    transform: translateY(-2px) scale(1.08);
    box-shadow: 0 8px 20px var(--icon-shadow, rgba(99, 102, 241, 0.5));
}

.summary-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.2));
    opacity: 0;
    transition: opacity 0.4s ease;
}

.summary-card:hover .summary-icon::before {
    opacity: 1;
}

.summary-icon svg {
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.summary-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.summary-label {
    font-size: 0.6875rem;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.9;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.summary-card:hover .summary-label {
    opacity: 1;
    color: var(--accent);
}

/* Valor a la derecha */
.summary-value-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.summary-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    background: linear-gradient(135deg, var(--text-main), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.summary-card:hover .summary-value {
    transform: scale(1.08);
    filter: drop-shadow(0 2px 8px rgba(124, 77, 255, 0.4));
}

/* ── NIVEL 1: Premium Skeleton Loaders ── */
.skeleton-analytics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.skeleton-card {
    padding: 24px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.skeleton-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

.skeleton-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-label {
    width: 60%;
    height: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

.skeleton-value {
    width: 40%;
    height: 24px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
    animation-delay: 0.2s;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── NIVEL 3: Table Controls (Search + Export) ── */
.table-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 280px;
    max-width: 400px;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px 0 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.search-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.1);
}

.search-wrapper > i[data-lucide="search"] {
    width: 18px;
    height: 18px;
    color: var(--text-dim);
    flex-shrink: 0;
}

.source-search-input {
    flex: 1;
    height: 100%;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 0.875rem;
    outline: none;
}

.source-search-input::placeholder {
    color: var(--text-dim);
    opacity: 0.6;
}

.clear-search-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.clear-search-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.clear-search-btn i {
    width: 16px;
    height: 16px;
    color: var(--text-dim);
}

.table-actions {
    display: flex;
    gap: 10px;
}

.export-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(124, 77, 255, 0.1);
    border: 1px solid rgba(124, 77, 255, 0.2);
    border-radius: 8px;
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.export-btn:hover {
    background: rgba(124, 77, 255, 0.15);
    border-color: rgba(124, 77, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.2);
}

.export-btn i {
    width: 18px;
    height: 18px;
}

.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
}

.no-results p {
    color: var(--text-dim);
    font-size: 0.9375rem;
    margin: 0;
}

.no-results #search-term {
    color: var(--accent);
    font-weight: 600;
}

/* Source Authority Table */
.source-table-wrapper {
    overflow-x: hidden; /* Elimina scroll horizontal */
    border-radius: 12px;
}

.source-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.source-table thead th {
    text-align: left;
    padding: 16px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 2px solid rgba(124, 77, 255, 0.2);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
}

/* ── NIVEL 2: Tabla Ordenable ── */
.sortable {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    position: relative;
}

.sortable:hover {
    background: rgba(124, 77, 255, 0.08);
    color: var(--text-main);
}

.sortable .th-content {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: space-between;
}

.sort-icon {
    width: 14px;
    height: 14px;
    opacity: 0.4;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.sortable:hover .sort-icon {
    opacity: 0.7;
}

.sortable.sort-asc .sort-icon,
.sortable.sort-desc .sort-icon {
    opacity: 1;
    color: var(--accent);
}

.sortable.sort-asc {
    background: rgba(124, 77, 255, 0.1);
    color: var(--accent);
}

.sortable.sort-desc {
    background: rgba(124, 77, 255, 0.1);
    color: var(--accent);
}

/* Transición suave del tbody */
#source-table-body {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.source-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Animación inicial (solo primera carga) */
.source-table tbody.initial-load tr {
    opacity: 0;
    transform: translateX(-10px);
    animation: slideInLeft 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.source-table tbody.initial-load tr:nth-child(1) { animation-delay: 0.05s; }
.source-table tbody.initial-load tr:nth-child(2) { animation-delay: 0.1s; }
.source-table tbody.initial-load tr:nth-child(3) { animation-delay: 0.15s; }
.source-table tbody.initial-load tr:nth-child(4) { animation-delay: 0.2s; }
.source-table tbody.initial-load tr:nth-child(5) { animation-delay: 0.25s; }

@keyframes slideInLeft {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.source-table tbody tr:hover {
    background: linear-gradient(90deg, rgba(124, 77, 255, 0.08), rgba(124, 77, 255, 0.04));
    transform: translateX(4px);
    box-shadow: inset 3px 0 0 var(--accent);
}

.source-table td {
    padding: 20px 16px;
    vertical-align: middle;
}

.rank-cell {
    text-align: center;
    font-weight: 700;
    color: var(--text-dim);
    padding: 20px 12px;
}

.articles-cell {
    padding: 20px 16px;
    max-width: 0; /* Fuerza que la celda respete el width de la columna */
    overflow: hidden;
}

/* ── NIVEL 1: Premium Rank Badges ── */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    position: relative;
    animation: rankPulse 2s ease-in-out infinite;
}

.rank-badge.rank-1 {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.2), transparent);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.rank-badge.rank-2 {
    background: radial-gradient(circle, rgba(192, 192, 192, 0.2), transparent);
    box-shadow: 0 0 20px rgba(192, 192, 192, 0.3);
}

.rank-badge.rank-3 {
    background: radial-gradient(circle, rgba(205, 127, 50, 0.2), transparent);
    box-shadow: 0 0 20px rgba(205, 127, 50, 0.3);
}

@keyframes rankPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.source-cell {
    padding: 20px 16px;
}

.source-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-main);
    margin-bottom: 4px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-stats {
    font-size: 0.75rem;
    color: var(--text-dim);
    opacity: 0.7;
}

.citations-cell {
    text-align: center;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--accent);
    padding: 20px 8px;
}

/* ── NIVEL 1: Gradiente Animado en Densidad Bar ── */
/* NOTA: display:flex NO puede aplicarse a <td> porque el navegador fuerza display:table-cell */
/* La solución es usar un wrapper div DENTRO del <td> */
.density-cell {
    padding: 20px 16px;
}

.density-cell-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.density-bar-container {
    flex: 1;
    height: 10px;
    background: rgba(156, 163, 175, 0.15);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 80px;
}

.density-bar {
    height: 100%;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 6px;
    position: relative;
    overflow: hidden;

    /* Gradiente animado */
    background: linear-gradient(90deg,
        var(--bar-color-1, #22c55e),
        var(--bar-color-2, #10b981));

    box-shadow: 0 2px 8px var(--bar-shadow, rgba(34, 197, 94, 0.4));
}

.density-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent);
    animation: barShine 2s ease-in-out infinite;
}

@keyframes barShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.density-value {
    font-weight: 800;
    font-size: 0.875rem;
    min-width: 48px;
    flex-shrink: 0;
    text-align: right;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
}

/* ── NIVEL 1: Premium Details/Summary Expandable Cards ── */
.articles-toggle {
    cursor: pointer;
    width: 100%;
}

.articles-toggle summary {
    font-size: 0.8125rem;
    color: var(--accent);
    font-weight: 600;
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(124, 77, 255, 0.05);
    border: 1px solid rgba(124, 77, 255, 0.15);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
}

.articles-toggle summary::before {
    content: '▼';
    font-size: 0.65rem;
    transition: transform 0.3s ease;
    display: inline-block;
}

.articles-toggle[open] summary::before {
    transform: rotate(180deg);
}

.articles-toggle summary:hover {
    background: rgba(124, 77, 255, 0.12);
    border-color: rgba(124, 77, 255, 0.3);
}

.articles-toggle summary::-webkit-details-marker {
    display: none;
}

.articles-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    animation: expandIn 0.3s ease-out;
}

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

.cited-article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(124, 77, 255, 0.05);
    border-radius: 6px;
    border: 1px solid rgba(124, 77, 255, 0.15);
    transition: all 0.2s ease;
    position: relative;
    min-width: 0; /* Permite que flexbox respete overflow en hijos */
}

.cited-article::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cited-article:hover::before {
    opacity: 1;
}

.cited-article:hover {
    background: rgba(124, 77, 255, 0.08);
    border-color: rgba(124, 77, 255, 0.25);
}

.article-link {
    flex: 1;
    min-width: 0; /* Permite que el texto se trunque dentro del flexbox */
    font-size: 0.8125rem;
    color: var(--text-main);
    text-decoration: none;
    line-height: 1.4;
    font-weight: 400;
    transition: color 0.2s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.article-link:hover {
    color: var(--accent);
}

.citation-count {
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    background: var(--accent);
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 28px;
    text-align: center;
}

/* Filter Pills */
.filter-pills {
    display: flex;
    gap: 8px;
}

.pill-btn {
    padding: 6px 14px;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-btn:hover {
    background: rgba(124, 77, 255, 0.08);
    border-color: var(--accent);
}

.pill-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Empty & Error States */
.empty-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-dim);
}

.empty-state p,
.error-state p {
    margin-top: 16px;
    font-size: 1rem;
    font-weight: 500;
}

.empty-state small {
    margin-top: 8px;
    font-size: 0.875rem;
}

/* ── NIVEL 1: Premium Tooltips ── */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip::before,
.tooltip::after {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(4px);
}

.tooltip::before {
    content: attr(data-tooltip);
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.tooltip::after {
    content: '';
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
}

.tooltip:hover::before,
.tooltip:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Filter Pills Premium */
.filter-pills {
    display: flex;
    gap: 8px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.pill-btn {
    padding: 10px 18px;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-dim);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 1;
}

.pill-btn:hover {
    color: var(--text-main);
    border-color: rgba(124, 77, 255, 0.3);
    background: rgba(124, 77, 255, 0.1);
}

.pill-btn.active {
    color: white !important;
    font-weight: 700;
    border-color: var(--accent);
    background: linear-gradient(135deg, #7c4dff, #6a3de8);
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.4);
    position: relative;
}

/* ── NIVEL 2: Feedback Visual Premium ── */
.pill-btn:active {
    transform: scale(0.95);
}

.pill-btn.active {
    animation: pillActivate 0.3s ease;
}

@keyframes pillActivate {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.sortable:active {
    transform: scale(0.98);
}

.articles-toggle summary:active {
    transform: scale(0.98);
}
