/* Admin Metrics Dashboard Styles */

.admin-metrics-container {
    padding: 1rem 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Sticky header + cards + time range bar */
.metrics-sticky-top {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bs-body-bg, #212529);
    padding-bottom: 0.5rem;
}

/* Header */
.metrics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.metrics-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.metrics-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.metrics-controls .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.35rem;
    line-height: 1;
}

/* Live indicator (reuse admin-logs pattern) */
.admin-metrics-container .live-indicator {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    user-select: none;
}

.admin-metrics-container .live-indicator.live-active {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.12);
    animation: metrics-live-pulse 2s ease-in-out infinite;
}

.admin-metrics-container .live-indicator.live-paused {
    color: #ffc107;
    background: rgba(255, 193, 7, 0.12);
}

@keyframes metrics-live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Overview Cards */
.metrics-cards {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.metric-card {
    flex: 1 1 0;
    min-width: 140px;
    background: var(--bs-tertiary-bg, #2b3035);
    border: 1px solid var(--bs-border-color, #373b3e);
    border-radius: 0.5rem;
    padding: 1rem;
    text-align: center;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--bs-body-color);
    font-family: 'Consolas', 'Monaco', monospace;
}

.metric-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color, #9ca3af);
    margin-top: 0.25rem;
}

/* Time Range Bar */
.time-range-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    background: var(--bs-tertiary-bg, #2b3035);
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.time-presets {
    display: flex;
    gap: 0.25rem;
}

.time-presets .time-preset.active {
    background: var(--bs-primary);
    border-color: var(--bs-primary);
    color: #fff;
}

.time-custom {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #9ca3af);
}

.time-custom input {
    width: 175px;
    font-size: 0.8rem;
}

.resolution-selector {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #9ca3af);
    margin-inline-start: auto;
}

.resolution-selector select {
    width: 80px;
    font-size: 0.8rem;
}

/* Charts */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Group labels span the full grid width */
.chart-group-label {
    grid-column: 1 / -1;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bs-info, #0dcaf0);
    border-bottom: 1px solid var(--bs-border-color, #373b3e);
    padding-bottom: 0.3rem;
    margin: 0.5rem 0 -0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: auto;
    min-height: 0;
}

.chart-container {
    background: var(--bs-tertiary-bg, #2b3035);
    border: 1px solid var(--bs-border-color, #373b3e);
    border-radius: 0.5rem;
    padding: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 370px;
}

/* Focus mode: one chart fills the entire grid area */
.charts-focus-mode .chart-container:not(.chart-focused) {
    display: none;
}

.charts-focus-mode .chart-group-label {
    display: none;
}

.charts-focus-mode .chart-focused {
    grid-column: 1 / -1;
    min-height: 500px;
}

/* Focus button */
.chart-focus-btn {
    background: none;
    border: 1px solid var(--bs-border-color, #555);
    color: var(--bs-secondary-color, #9ca3af);
    border-radius: 4px;
    padding: 0;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
}

.chart-focus-btn:hover {
    color: var(--bs-body-color, #fff);
    border-color: var(--bs-info, #0dcaf0);
}

.chart-focus-btn .material-symbols-outlined {
    font-size: 16px;
}

.chart-container h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--bs-secondary-color, #9ca3af);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-container canvas {
    flex: 1 1 0;
    min-height: 200px;
}

/* External HTML legend for dynamic charts */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.6rem;
    align-items: center;
    max-height: 72px;
    overflow-y: auto;
    margin-top: 0.5rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--bs-border-color, #373b3e);
    flex-shrink: 0;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--bs-secondary-color, #ccc);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.chart-legend-item:hover {
    opacity: 0.8;
}

.chart-legend-item.chart-legend-hidden {
    opacity: 0.4;
    text-decoration: line-through;
}

.chart-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid;
    border-radius: 2px;
    flex-shrink: 0;
}

.chart-legend-toggle-all {
    font-weight: 700;
    border: 1px solid;
    border-radius: 3px;
    padding: 0 4px;
    font-size: 0.7rem;
}

/* API Usage Table */
.api-table-section {
    background: var(--bs-tertiary-bg, #2b3035);
    border: 1px solid var(--bs-border-color, #373b3e);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.api-table-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--bs-secondary-color, #9ca3af);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.api-table-section .table {
    margin-bottom: 0;
    font-size: 0.85rem;
}

.api-table-section .table th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color, #9ca3af);
    border-bottom-color: var(--bs-border-color, #373b3e);
}

.api-table-section .table td {
    border-bottom-color: var(--bs-border-color, #373b3e);
    vertical-align: middle;
}

/* Service Stats */
.service-stats-section,
.auth-stats-section {
    background: var(--bs-tertiary-bg, #2b3035);
    border: 1px solid var(--bs-border-color, #373b3e);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.service-stats-section h4,
.auth-stats-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--bs-secondary-color, #9ca3af);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.service-stats-grid {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.service-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.service-stat strong {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--bs-secondary-color, #9ca3af);
}

/* Auth Stats */
.auth-stats-grid {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.auth-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.auth-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--bs-secondary-color, #9ca3af);
}

.auth-value {
    font-family: 'Consolas', 'Monaco', monospace;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-metrics-container {
        padding: 0.5rem 0.75rem;
    }

    .metrics-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .time-range-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .time-presets {
        justify-content: center;
    }

    .time-custom {
        flex-wrap: wrap;
        justify-content: center;
    }

    .resolution-selector {
        margin-inline-start: 0;
        justify-content: center;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .metrics-cards {
        flex-direction: column;
    }

    .metric-card {
        min-width: unset;
    }

    .service-stats-grid,
    .auth-stats-grid {
        flex-direction: column;
        gap: 0.75rem;
    }
}

/* ===== Light Theme Overrides ===== */
[data-bs-theme="light"] .metrics-sticky-top {
    background: var(--bs-body-bg, #fff);
}

[data-bs-theme="light"] .admin-metrics-container .metric-card {
    background: #fff;
    border-color: #dee2e6;
}

[data-bs-theme="light"] .admin-metrics-container .time-range-bar {
    background: #f0f2f5;
}

[data-bs-theme="light"] .admin-metrics-container .chart-container {
    background: #fff;
    border-color: #dee2e6;
}

[data-bs-theme="light"] .admin-metrics-container .api-table-section {
    background: #fff;
    border-color: #dee2e6;
}

[data-bs-theme="light"] .admin-metrics-container .api-table-section .table th {
    color: #495057;
    border-bottom-color: #dee2e6;
}

[data-bs-theme="light"] .admin-metrics-container .api-table-section .table td {
    border-bottom-color: #dee2e6;
}

[data-bs-theme="light"] .admin-metrics-container .service-stats-section,
[data-bs-theme="light"] .admin-metrics-container .auth-stats-section {
    background: #fff;
    border-color: #dee2e6;
}
