/* --- BASE STYLES --- */
body { font-family: 'Segoe UI', sans-serif; transition: background 0.3s; }
.card { border: none; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.status-dot { height: 10px; width: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.online-dot { background-color: #00d26a; }
.offline-dot { background-color: #6c757d; opacity: 0.3; }
.speed-box { font-family: 'Consolas', monospace; font-size: 0.9rem; }
.table-active-row { background-color: rgba(0, 210, 106, 0.05) !important; }

/* --- THEME VARIABLES --- */
:root {
    --card-bg: #ffffff;
    --card-border: rgba(0,0,0,0.1);
    --text-color: #212529;
    --text-muted: #6c757d;
    --accent-green: #198754;
    --accent-blue: #0d6efd;
    --chart-grid: rgba(0,0,0,0.05);
}

/* --- DARK MODE (CYBERPUNK) --- */
[data-bs-theme="dark"] {
    --card-bg: rgba(0, 20, 0, 0.4);
    --card-border: #00ff41;
    --text-color: #00ff41;
    --text-muted: #5c8a65;
    --accent-green: #00ff41;
    --accent-blue: #00f3ff;
    --chart-grid: rgba(0, 255, 65, 0.1);
}

[data-bs-theme="dark"] body {
    background-color: #050505;
    color: var(--text-color);
    font-family: 'JetBrains Mono', monospace;
}

[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .sys-stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: 0 0 15px rgba(0, 255, 65, 0.15), inset 0 0 20px rgba(0, 255, 65, 0.05);
}

[data-bs-theme="dark"] .sys-stat-value,
[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] h4,
[data-bs-theme="dark"] .fw-bold {
    text-shadow: 0 0 5px rgba(0, 255, 65, 0.7);
}

[data-bs-theme="dark"] .table {
    color: var(--text-color);
    border-color: rgba(0, 255, 65, 0.3);
}

[data-bs-theme="dark"] .table-hover tbody tr:hover {
    background-color: rgba(0, 255, 65, 0.1);
}

[data-bs-theme="dark"] .online-dot {
    box-shadow: 0 0 10px rgba(0, 210, 106, 0.6);
}

/* Neon Charts only in Dark Mode */
[data-bs-theme="dark"] canvas {
    filter: drop-shadow(0 0 4px rgba(0, 255, 65, 0.5));
}

/* CRT SCANLINE OVERLAY (Dark Mode Only) */
.crt-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 9999;
}
[data-bs-theme="dark"] .crt-overlay { display: block; }

/* --- LIGHT MODE SPECIFICS --- */
[data-bs-theme="light"] body {
    background-color: #f8f9fa;
    color: #212529;
}
[data-bs-theme="light"] .sys-stat-card {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.1);
}
[data-bs-theme="light"] .text-muted { color: #6c757d !important; }
[data-bs-theme="light"] .dl-color { color: #198754 !important; }
[data-bs-theme="light"] .ul-color { color: #0d6efd !important; }

/* --- COMMON COMPONENTS --- */
.sys-stat-card {
    border-radius: 8px;
    padding: 10px 15px;
    min-width: 120px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    transition: all 0.3s;
}
.sys-stat-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-thin { height: 6px; background: rgba(128,128,128,0.2); margin-top: 8px; border-radius: 3px; }
.traffic-bar-bg { height: 4px; width: 100%; background: rgba(128,128,128,0.2); border-radius: 2px; margin-top: 5px; }
.traffic-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-blue), var(--accent-green)); border-radius: 2px; }

/* Terminal Styling */
#terminal-container { display: none; background: #050505; color: #00ff41; font-family: 'JetBrains Mono', monospace; padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #00ff41; }
#terminal-output { max-height: 300px; overflow-y: auto; white-space: pre-wrap; font-size: 0.85rem; margin-top: 10px; }
.cmd-input { background: transparent; border: none; color: #00ff41; width: 100%; outline: none; border-bottom: 1px solid #333; font-family: 'JetBrains Mono', monospace; }

.nav-tabs .nav-link { color: var(--text-muted); border: none; }
.nav-tabs .nav-link.active { background: transparent; color: inherit; border-bottom: 2px solid var(--accent-blue); font-weight: bold; }
[data-bs-theme="dark"] .nav-tabs .nav-link.active { border-bottom-color: var(--accent-green); color: var(--accent-green); }

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { opacity: 0.8; }
.sort-icon { font-size: 0.8em; margin-left: 5px; opacity: 0.5; }
.sort-active { opacity: 1; color: var(--accent-blue); }
[data-bs-theme="dark"] .sort-active { color: var(--accent-green); }

/* --- HALL OF FAME (PODIUM & HISTORY) --- */
.hall-of-fame-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
}
.hof-title {
    text-align: center;
    font-weight: bold;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
}

/* PODIUM STYLES */
.podium-container { display: flex; justify-content: center; align-items: flex-end; gap: 15px; height: 300px; }
.podium-step {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; position: relative; padding: 15px;
    border-radius: 10px 10px 0 0; color: #212529; width: 30%;
    transition: transform 0.3s; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.podium-step:hover { transform: translateY(-5px); }

/* UPDATED HEIGHTS */
.podium-gold { background: linear-gradient(to bottom, #FFD700, #FDB931); height: 100%; z-index: 2; border: 1px solid rgba(0,0,0,0.1); }
.podium-silver { background: linear-gradient(to bottom, #E0E0E0, #BDBDBD); height: 90%; z-index: 1; }
.podium-bronze { background: linear-gradient(to bottom, #CD7F32, #A0522D); height: 80%; z-index: 0; }

[data-bs-theme="dark"] .podium-gold { background: rgba(255, 215, 0, 0.15); border: 1px solid #FFD700; color: #FFD700; box-shadow: 0 0 25px rgba(255, 215, 0, 0.3); }
[data-bs-theme="dark"] .podium-silver { background: rgba(224, 224, 224, 0.15); border: 1px solid #E0E0E0; color: #E0E0E0; box-shadow: 0 0 25px rgba(224, 224, 224, 0.3); }
[data-bs-theme="dark"] .podium-bronze { background: rgba(205, 127, 50, 0.15); border: 1px solid #CD7F32; color: #CD7F32; box-shadow: 0 0 25px rgba(205, 127, 50, 0.3); }
[data-bs-theme="dark"] .user-name { color: inherit; text-shadow: 0 0 5px currentColor; }
[data-bs-theme="dark"] .user-traffic { color: inherit; opacity: 0.8; }

.medal-icon { font-size: 2.5rem; margin-bottom: 10px; }
.penalty-badge { background: #dc3545; color: white; font-size: 0.75rem; padding: 4px 8px; border-radius: 12px; margin-top: 8px; display: inline-block; font-weight: bold; }
.user-avatar { width: 50px; height: 50px; background: rgba(255,255,255,0.9); border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.4rem; color: #333; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

/* UPDATED USER NAME: Allow wrapping */
.user-name { 
    font-weight: 800; 
    font-size: 0.95rem; 
    color: #212529;
    white-space: normal;
    line-height: 1.1;
    max-height: 2.4em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 5px;
    word-break: break-word;
}
.user-traffic { font-size: 0.85rem; opacity: 0.9; color: #212529; font-weight: 700; }

/* HISTORY LIST STYLES */
.history-list-container { height: 300px; overflow-y: auto; padding-right: 5px; }
.history-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px; border-bottom: 1px solid var(--card-border);
    margin-bottom: 5px;
}
.history-item:last-child { border-bottom: none; }
.history-date-badge {
    font-size: 0.7rem; font-weight: bold; padding: 2px 6px; border-radius: 4px;
    background: rgba(128,128,128,0.2); color: var(--text-muted); margin-right: 10px;
}
.history-winner { font-weight: bold; color: var(--accent-green); }
[data-bs-theme="dark"] .history-winner { text-shadow: 0 0 5px var(--accent-green); }

/* --- HISTORY WIDGET TABLE --- */
.history-table {
    table-layout: fixed;
    width: 100%;
    font-size: 0.75rem;
    border-spacing: 0 8px; /* Add space between rows */
    border-collapse: separate;
}

.history-table th {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    padding-bottom: 4px;
    font-weight: bold;
    letter-spacing: 1px;
}

.history-table td {
    padding: 0 4px; /* Horizontal spacing between cells */
    vertical-align: middle;
}

.history-cell-content {
    border-radius: 12px; /* ROUNDED LOOK */
    padding: 8px 4px;
    text-align: center;
    border: 1px solid transparent;
    transition: transform 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.history-cell-content:hover {
    transform: translateY(-2px);
}

.history-name {
    font-weight: 800;
    margin-bottom: 2px;
    font-size: 0.75rem;
}

.history-traffic {
    font-family: 'Consolas', monospace;
    font-size: 0.7rem;
    opacity: 0.9;
    font-weight: bold;
}

.history-limit {
    font-size: 0.6rem;
    padding: 3px 6px;
    margin-top: 4px;
    border-radius: 8px;
    font-weight: normal;
}

.empty-cell {
    background: rgba(128, 128, 128, 0.05);
    color: var(--text-muted);
    border: 1px dashed rgba(128, 128, 128, 0.2);
}

/* --- COLOR THEMES (Light & Dark Compatible) --- */

/* GOLD (1st) */
.history-rank-0 {
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.15), rgba(255, 215, 0, 0.05));
    border-color: rgba(255, 215, 0, 0.4);
    color: #b8860b; /* Dark Goldenrod for text visibility */
}
[data-bs-theme="dark"] .history-rank-0 { color: #ffd700; }
.history-rank-0 .history-limit { background: rgba(255, 215, 0, 0.3); color: inherit; }

/* SILVER (2nd) */
.history-rank-1 {
    background: linear-gradient(145deg, rgba(192, 192, 192, 0.15), rgba(192, 192, 192, 0.05));
    border-color: rgba(192, 192, 192, 0.4);
    color: #6c757d;
}
[data-bs-theme="dark"] .history-rank-1 { color: #e0e0e0; }
.history-rank-1 .history-limit { background: rgba(192, 192, 192, 0.3); color: inherit; }

/* BRONZE (3rd) */
.history-rank-2 {
    background: linear-gradient(145deg, rgba(205, 127, 50, 0.15), rgba(205, 127, 50, 0.05));
    border-color: rgba(205, 127, 50, 0.4);
    color: #a0522d;
}
[data-bs-theme="dark"] .history-rank-2 { color: #cd7f32; }
.history-rank-2 .history-limit { background: rgba(205, 127, 50, 0.3); color: inherit; }

/* Opacity Levels for History Rows */
.history-opacity-0 { opacity: 1; }
.history-opacity-1 { opacity: 0.7; }
.history-opacity-2 { opacity: 0.4; }

/* HEATMAP STYLES */
.heatmap-container { 
    width: 100%;
    overflow-x: auto; 
}

/* Custom Scrollbar for Heatmap (Subtle) */
.heatmap-container::-webkit-scrollbar { height: 4px; }
.heatmap-container::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); }
.heatmap-container::-webkit-scrollbar-thumb { background: var(--accent-green); border-radius: 2px; }

.heatmap-table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 1px; /* Tighter spacing */
    font-size: 0.75rem; 
    margin: 0 auto;
    table-layout: fixed; /* Ensures cells are equal width */
}

.heatmap-cell { 
    width: 100%; /* Fill the table cell */
    height: 20px; /* Reduced height slightly */
    border-radius: 2px; 
    background-color: rgba(128,128,128,0.1); 
    transition: transform 0.1s; 
    cursor: pointer; 
}

.heatmap-cell:hover { 
    transform: scale(1.2); 
    border: 1px solid white; 
    z-index: 10; /* Ensure hover pops over neighbors */
    position: relative;
}

/* First column (Date Label) */
.heatmap-table td:first-child, 
.heatmap-table th:first-child {
    width: 60px; /* Fixed width for date labels */
    white-space: nowrap;
}

/* Last column (Total) */
.heatmap-table td:last-child, 
.heatmap-table th:last-child {
    width: 90px; /* Fixed width for totals */
}

.heatmap-label { 
    text-align: right; 
    padding-right: 5px; 
    color: var(--text-muted); 
    font-weight: bold; 
    font-size: 0.7rem;
}

.heatmap-header { 
    text-align: center; 
    color: var(--text-muted); 
    font-size: 0.65rem; 
    padding-bottom: 2px; 
}

/* MOBILE OPTIMIZATIONS */
@media (max-width: 768px) {
    /* ... existing mobile styles ... */
    .sys-stat-card { min-width: 45%; margin-bottom: 10px; }
    .podium-container { flex-direction: column; align-items: center; gap: 20px; height: auto; }
    .podium-step { width: 100%; max-width: 100%; height: auto !important; padding: 20px; flex-direction: row; justify-content: flex-start; text-align: left; }
    .podium-step .medal-icon { margin-bottom: 0; margin-right: 15px; font-size: 2rem; }
    .podium-step .user-avatar { margin: 0 15px 0 0; }
    .podium-step .penalty-badge { margin-top: 0; margin-left: auto; }
    .mobile-hide { display: none; }
    h3 { font-size: 1.5rem; }
    
    /* Heatmap Mobile Overrides */
    .heatmap-table { min-width: 600px; } /* Force scroll on mobile */
    .heatmap-cell { height: 18px; }
    .hall-of-fame-container { margin-top: 20px; }
}
/* --- NEW REFINEMENTS --- */
@keyframes pulse-green {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0, 210, 106, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(0, 210, 106, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0, 210, 106, 0); }
}

.online-dot {
    animation: pulse-green 2s infinite;
}

@keyframes pulse-warning {
    0% { color: #ffc107; text-shadow: 0 0 5px rgba(255, 193, 7, 0.5); }
    50% { color: #dc3545; text-shadow: 0 0 15px rgba(220, 53, 69, 0.8); }
    100% { color: #ffc107; text-shadow: 0 0 5px rgba(255, 193, 7, 0.5); }
}

.health-pulse {
    animation: pulse-warning 1s infinite;
    font-weight: bold !important;
}

.table-self-row {
    border-left: 4px solid var(--accent-blue) !important;
    background-color: rgba(13, 110, 253, 0.1) !important;
}
[data-bs-theme="dark"] .table-self-row {
    border-left-color: var(--accent-green) !important;
    background-color: rgba(0, 255, 65, 0.1) !important;
}
.text-bronze { color: #CD7F32; }

/* --- OLYMPIC MEDAL TABLE REFINEMENTS --- */
.medal-table th { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.medal-row:hover { background: rgba(128, 128, 128, 0.05); }

.medal-avatar {
    width: 28px; height: 28px; border-radius: 50%; 
    background: rgba(128,128,128,0.1); display: flex; 
    align-items: center; justify-content: center; 
    font-size: 0.75rem; font-weight: bold; margin-right: 10px;
    border: 1px solid var(--card-border);
}

.badge-medal {
    display: inline-block; width: 26px; height: 26px; 
    line-height: 24px; border-radius: 50%; text-align: center; 
    font-weight: 800; font-size: 0.8rem; border: 1px solid transparent;
}

.bg-gold { background: rgba(255, 215, 0, 0.1); color: #FFD700; border-color: rgba(255, 215, 0, 0.4); box-shadow: 0 0 10px rgba(255, 215, 0, 0.2); }
.bg-silver { background: rgba(192, 192, 192, 0.1); color: #E0E0E0; border-color: rgba(192, 192, 192, 0.4); }
.bg-bronze { background: rgba(205, 127, 50, 0.1); color: #CD7F32; border-color: rgba(205, 127, 50, 0.4); }

[data-bs-theme="dark"] .bg-gold { background: rgba(255, 215, 0, 0.05); }
[data-bs-theme="dark"] .bg-silver { background: rgba(192, 192, 192, 0.05); }
[data-bs-theme="dark"] .bg-bronze { background: rgba(205, 127, 50, 0.05); }
.heatmap-avg-row td { border-top: 1px dashed rgba(128,128,128,0.3); padding-top: 8px; }

.btn-xs {
    padding: 1px 5px;
    font-size: 0.7rem;
    line-height: 1.5;
    border-radius: 3px;
}

.simulation-controls-container {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 6px;
}

/* --- BUCKET LABELS --- */
.buckets-labels-container {
    width: 100%;
    display: flex;
    height: 60px;
    background: rgba(0,0,0,0.4);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid #444;
    overflow: hidden;
    transition: height 0.3s ease;
}

.bucket-label-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-right: 1px solid rgba(255,255,255,0.1);
    font-family: 'JetBrains Mono', monospace;
    position: relative;
    overflow: hidden;
}

.bucket-label-name {
    font-weight: bold;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    width: 90%;
    text-align: center;
    margin-bottom: 2px;
}

.bucket-label-stats {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.65rem;
    line-height: 1.2;
    width: 100%;
}

.bucket-stat-row {
    white-space: nowrap;
}

/* Mobile Optimization for Buckets */
@media (max-width: 768px) {
    .buckets-labels-container {
        height: 160px; /* Increased height for full vertical stack */
        align-items: flex-end;
    }

    .bucket-label-item {
        justify-content: flex-end;
        padding-bottom: 6px;
        gap: 6px; /* Space between Name and Stats */
    }

    .bucket-label-name {
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        width: auto;
        height: auto;
        max-height: 80px;
        margin-bottom: 0;
        text-align: left;
        font-size: 0.75rem;
    }

    .bucket-label-stats {
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        font-size: 0.6rem;
        display: flex;
        flex-direction: row; /* Stacks items vertically in vertical-rl */
        gap: 8px; /* Space between DL and UL */
        width: auto;
        align-items: center;
    }

    .bucket-stat-row {
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    .bucket-label-stats i {
        font-size: 0.5rem;
    }
}
