/* ==========================================================================
   Dashboard Ranker Analytics Styling System (Natural Light Mode - Posit/Shiny)
   ========================================================================== */

:root {
    --bg-app: #f8f9fa;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;

    --primary: #007bc2;      /* Shiny Brand Blue */
    --primary-hover: #005a8f;
    --primary-light: #e6f4fc;
    
    --success: #5cb85c;      /* Shiny Success Green */
    --success-hover: #4cae4c;
    --success-light: #eef9ee;
    
    --warning: #f0ad4e;
    --warning-light: #fef8f0;
    
    --info: #5bc0de;
    --info-light: #f0fafd;
    
    --error: #d9534f;
    --error-hover: #c9302c;
    --error-light: #fdf3f3;
    
    --text-main: #1e293b;
    --text-muted: #475569;
    --text-dim: #64748b;
    
    --font-heading: 'Outfit', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: all 0.2s ease-in-out;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

.dashboard-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-back {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    text-decoration: none;
    transition: var(--transition);
    font-size: 13px;
    background: #ffffff;
}
.header-back:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 22px;
    color: var(--primary);
    line-height: 1;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.2;
    color: var(--text-main);
}

.logo-sub {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 500;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.live-status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    color: var(--success);
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--success-light);
}

.status-pulse {
    width: 6px;
    height: 6px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(92, 184, 92, 0.4);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.3; }
    100% { transform: scale(0.9); opacity: 1; }
}

.header-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
}
.header-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}
.header-btn:active {
    transform: scale(0.92);
}
.header-btn.spinning i {
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.dashboard-grid {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.glass-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    transition: var(--transition);
}
.glass-panel:hover {
    border-color: var(--border-hover);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

@media (max-width: 900px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 500px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 18px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 16px;
    flex-shrink: 0;
}

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

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 3px;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 26px;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
}
.stat-value.loading {
    opacity: 0.3;
}

.insights-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--primary-light);
    border-color: var(--border-color);
}

.insight-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--warning);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.insights-content {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
}

.insight-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-main);
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

@media (max-width: 1000px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 18px;
}

.chart-card h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.2px;
}

.chart-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.chart-wrapper {
    position: relative;
    height: 260px;
    width: 100%;
}

.data-row {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.flex-1 {
    flex: 1 1 340px;
    min-width: 0;
}
.flex-2 {
    flex: 2 2 650px;
    min-width: 0;
}

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

.table-card h3, .stream-card h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0;
}

.table-count {
    font-size: 11px;
    color: var(--text-muted);
}

.table-scroll {
    overflow-x: auto;
    margin: -4px;
    padding: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

thead th {
    padding: 10px 10px;
    color: var(--text-dim);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

tbody tr {
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
}
tbody tr:last-child {
    border-bottom: none;
}
tbody tr:hover {
    background: rgba(0, 123, 194, 0.02);
}

td {
    padding: 11px 10px;
    color: var(--text-main);
    font-size: 12px;
}

td:first-child {
    font-weight: 700;
    color: var(--text-dim);
}

.loading-cell {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.skeleton-pulse {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.3;
    animation: skeletonPulse 1.2s ease-in-out infinite;
}

@keyframes skeletonPulse {
    0%, 100% { opacity: 0.2; transform: scale(0.8); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

.stream-card {
    display: flex;
    flex-direction: column;
}

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

.stream-header h3 {
    margin-bottom: 0;
}

.badge {
    background: var(--success-light);
    border: 1px solid var(--border-color);
    color: var(--success);
    font-size: 10px;
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: 700;
    letter-spacing: 0.3px;
    font-variant-numeric: tabular-nums;
}

.activity-stream {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 420px;
    overflow-y: auto;
    padding-right: 4px;
}

.activity-item {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: slideIn 0.35s ease-out;
    transition: var(--transition);
}

.activity-item:hover {
    border-color: var(--primary);
    background: #f8fafc;
}

.activity-item.flash {
    box-shadow: 0 0 12px var(--primary-light);
    border-color: var(--primary);
}

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

.activity-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.activity-model {
    font-weight: 700;
    color: var(--text-main);
    font-size: 12px;
}

.activity-tier {
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 4px;
    color: #111;
    font-size: 10px;
}

.tier-s { background-color: #ff8b94; }
.tier-a { background-color: #ffcaa6; }
.tier-b { background-color: #ffdca3; }
.tier-c { background-color: #d8f8a8; }
.tier-d { background-color: #a8f8b4; }

.activity-feedback {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    border-left: 2px solid var(--primary);
    padding-left: 10px;
    margin: 2px 0;
    line-height: 1.4;
}

.activity-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.activity-tag {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--border-color);
    font-size: 9px;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 500;
}

.activity-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 100px;
    font-style: italic;
}

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.data-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    font-size: 11px;
    color: var(--text-dim);
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
    opacity: 0.7;
}

.back-link:hover {
    opacity: 1;
}

#last-updated {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

@media (max-width: 768px) {
    .dashboard-grid {
        padding: 16px;
        gap: 14px;
    }

    .dashboard-header {
        padding: 10px 16px;
    }

    .logo h1 {
        font-size: 16px;
    }

    .logo-sub {
        display: none;
    }

    .header-back {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .header-btn {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .live-status {
        font-size: 9px;
        padding: 4px 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 22px;
    }

    .chart-card {
        padding: 14px;
    }

    .chart-wrapper {
        height: 200px;
    }

    .data-footer {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }

    .activity-stream {
        height: 320px;
    }
}

@media (max-width: 500px) {
    .header-btn#btn-export {
        display: none;
    }
}

.correlation-matrix-card {
    grid-column: span 2;
}

@media (max-width: 1000px) {
    .correlation-matrix-card {
        grid-column: span 1;
    }
}

.correlation-matrix-container {
    width: 100%;
    overflow-x: auto;
    padding: 10px 0;
}

.correlation-matrix {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) repeat(12, 38px);
    gap: 4px;
    min-width: 610px;
    margin: 0 auto;
    font-family: var(--font-body);
}

.matrix-header-cell {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    white-space: nowrap;
    padding: 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.matrix-label-cell {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 12px;
    text-align: right;
    white-space: nowrap;
}

.matrix-data-cell {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.matrix-data-cell:hover {
    transform: scale(1.12);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.matrix-data-cell::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border-color);
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.matrix-data-cell:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

.matrix-explanation {
    margin-top: 24px;
    padding: 16px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.01);
    border: 1px solid var(--border-color);
}

.matrix-explanation h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.matrix-explanation p {
    margin: 0 0 16px 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.explanation-legend {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.legend-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

.legend-color.positive {
    background: rgba(0, 123, 194, 0.6);
    border: 1px solid rgba(0, 123, 194, 0.8);
}

.legend-color.negative {
    background: rgba(217, 83, 79, 0.6);
    border: 1px solid rgba(217, 83, 79, 0.8);
}

.legend-color.neutral {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Leaderboard Row Preview Hover styles */
#leaderboard-body tr {
    cursor: pointer;
}

.preview-card-floating {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    width: 320px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    overflow: hidden;
    display: none;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.preview-card-floating.active {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.preview-card-img-wrapper {
    width: 100%;
    height: 180px;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.preview-card-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-card-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.preview-card-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 13px;
    color: var(--text-main);
}

.preview-card-sub {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Beeswarm Chart Styles */
.beeswarm-card {
    grid-column: span 2;
}

.beeswarm-container {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    color: var(--text-muted);
}

.toggle-btn.active {
    background: #ffffff !important;
    color: var(--primary) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.beeswarm-node {
    stroke: #ffffff;
    stroke-width: 1px;
    cursor: pointer;
    transition: r 0.15s ease, stroke-width 0.15s ease;
}

.beeswarm-node:hover {
    stroke: var(--text-main);
    stroke-width: 2px;
}

.beeswarm-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 1100;
    width: 250px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border-color);
    color: #ffffff;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 11px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    line-height: 1.4;
    display: none;
    font-family: var(--font-body);
}

.beeswarm-tooltip strong {
    color: #38bdf8;
    display: block;
    margin-bottom: 3px;
    font-family: var(--font-heading);
}

.beeswarm-axis-line {
    stroke: var(--border-color);
    stroke-dasharray: 3,3;
}

.beeswarm-axis-label {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 700;
    fill: var(--text-muted);
}
