/* Stats View Styles */
.stats-view {
    flex: 1;
    height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    min-width: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    position: relative;
}

.stats-view.hidden {
    display: none !important;
}

.stats-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 48px;
    padding-bottom: 4rem;
    min-height: min-content;
    flex: 1;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.stats-header h1 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    width: 44px;
    height: 44px;
}

.refresh-btn:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--text-secondary);
    color: var(--text-primary);
    transform: translateY(0);
    box-shadow: none;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Filter Controls */
.stats-filters {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.stats-filters h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 1rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-item label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-item select {
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    min-width: 150px;
    transition: all 0.2s;
}

.filter-item select:hover {
    border-color: var(--accent-color);
}

.filter-item select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-color-alpha);
}

.clear-filters-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    align-self: flex-end;
}

.clear-filters-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Overview Cards */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-color-alpha);
    border-radius: 12px;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Stats Sections */
.stats-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.stats-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 1rem 0;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* Force 2 columns for 2x2 layout */
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    /* More padding */
    height: 400px;
    /* Taller charts */
    position: relative;
}

/* Responsive adjustment for smaller screens */
@media (max-width: 1000px) {
    .charts-grid {
        grid-template-columns: 1fr;
        /* Stack on smaller screens */
    }
}

/* Tables */
.stats-table-container {
    overflow-x: auto;
    /* max-height removed to allow full page scroll */
    /* overflow-y removed */
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stats-table-container.recent-messages-table {
    max-height: 500px;
    /* Limit height for recent messages */
    overflow-y: auto;
    /* Enable vertical scroll */
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table thead {
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.stats-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.stats-table td {
    padding: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.stats-table tbody tr {
    transition: background 0.15s;
}

.stats-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.stats-table tbody tr:last-child td {
    border-bottom: none;
}

.preview-cell {
    max-width: 400px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

/* Scrollbar styling for tables */
.stats-table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.stats-table-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.stats-table-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.stats-table-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Loading State */
.stats-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error State */
.stats-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    text-align: center;
}

.stats-error h2 {
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.stats-error p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.retry-btn {
    padding: 0.75rem 1.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}