/**
 * MOJO Charts Components - Comprehensive CSS Styles
 * Styles for BaseChart, SeriesChart, and PieChart components
 * Built with Bootstrap 5 integration and theme support
 */

/* ==========================================================================
   CSS Custom Properties for Theming
   ========================================================================== */

:root {
    /* Light theme (default) */
    --chart-bg: #ffffff;
    --chart-content-bg: #ffffff;
    --chart-border: #dee2e6;
    --chart-text: #212529;
    --chart-text-muted: #6c757d;
    --chart-overlay-bg: rgba(255, 255, 255, 0.95);
    --chart-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --chart-hover-bg: rgba(0, 0, 0, 0.05);
    --chart-focus-ring: rgba(13, 110, 253, 0.25);
    --chart-grid-color: rgba(0, 0, 0, 0.1);
    --chart-loading-bg: rgba(248, 249, 250, 0.95);
}

/* Bootstrap 5.3 sets `data-bs-theme="dark"` on <html>; the framework's
   ThemeManager (src/core/utils/ThemeManager.js) uses the same attribute.
   This block swaps the chart palette to match. */
[data-bs-theme="dark"] {
    /* Dark theme */
    --chart-bg: #212529;
    --chart-content-bg: #2b3035;
    --chart-border: #404449;
    --chart-text: #ffffff;
    --chart-text-muted: #adb5bd;
    --chart-overlay-bg: rgba(33, 37, 41, 0.95);
    --chart-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3);
    --chart-hover-bg: rgba(255, 255, 255, 0.1);
    --chart-focus-ring: rgba(13, 110, 253, 0.4);
    --chart-grid-color: rgba(255, 255, 255, 0.1);
    --chart-loading-bg: rgba(43, 48, 53, 0.95);
}

/* ==========================================================================
   Base Chart Component Styles
   ========================================================================== */

.chart-component {
    background: var(--chart-bg);
    border: 1px solid var(--chart-border);
    border-radius: 0.375rem;
    box-shadow: var(--chart-shadow);
    color: var(--chart-text);
    padding: 1rem;
    transition: all 0.15s ease-in-out;
    min-height: 300px;
    font-family: var(--bs-font-sans-serif, system-ui, sans-serif);
}

.chart-component:hover {
    border-color: var(--bs-primary, #0d6efd);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.chart-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chart-title-section {
    flex: 0 0 auto;
}

.chart-title {
    color: var(--chart-text);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.last-updated {
    color: var(--chart-text-muted);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
}

.last-updated .timestamp {
    font-weight: 500;
    margin-left: 0.25rem;
}

/* ==========================================================================
   Chart Controls and Toolbar
   ========================================================================== */

.chart-controls {
    flex: 0 0 auto;
}

.chart-controls .btn-toolbar {
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chart-controls .btn-group {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.chart-controls .btn {
    position: relative;
    border-color: var(--chart-border);
    transition: all 0.15s ease-in-out;
}

.chart-controls .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.15);
}

.chart-controls .btn:focus {
    box-shadow: 0 0 0 0.2rem var(--chart-focus-ring);
}

.chart-controls .btn:active {
    transform: translateY(0);
}

/* Chart Type Switcher */
.chart-type-switcher .btn.active {
    background-color: var(--bs-primary, #0d6efd);
    border-color: var(--bs-primary, #0d6efd);
    color: white;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Refresh Button Animation */
.refresh-btn .bi-arrow-clockwise.spin {
    animation: spin 1s linear infinite;
}

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

/* Theme Toggle */
.theme-toggle {
    position: relative;
}

.theme-toggle:hover {
    background: var(--chart-hover-bg);
}

/* Export Dropdown */
.chart-controls .dropdown-menu {
    background: var(--chart-bg);
    border: 1px solid var(--chart-border);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.175);
}

.chart-controls .dropdown-item {
    color: var(--chart-text);
    transition: background-color 0.15s ease-in-out;
}

.chart-controls .dropdown-item:hover,
.chart-controls .dropdown-item:focus {
    background-color: var(--chart-hover-bg);
}

.chart-controls .dropdown-item i {
    width: 1rem;
    margin-right: 0.5rem;
}

/* ==========================================================================
   Chart Content Area
   ========================================================================== */

.chart-content {
    flex: 1 1 auto;
    position: relative;
    background: var(--chart-content-bg);
    border-radius: 0.25rem;
    overflow: hidden;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: transparent;
}

/* ==========================================================================
   Chart Overlays (Loading, Error, No Data)
   ========================================================================== */

.chart-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--chart-overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
    border-radius: 0.25rem;
}

/* Loading Overlay */
.chart-overlay .spinner-border {
    width: 2rem;
    height: 2rem;
    color: var(--bs-primary, #0d6efd);
}

.chart-overlay .text-muted {
    color: var(--chart-text-muted);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Error Overlay */
.chart-overlay .alert-danger {
    background: var(--bs-danger-bg-subtle, #f8d7da);
    border-color: var(--bs-danger-border-subtle, #f1aeb5);
    color: var(--bs-danger-text, #842029);
    max-width: 400px;
    margin: 1rem;
}

[data-theme="dark"] .chart-overlay .alert-danger {
    background: rgba(248, 215, 218, 0.1);
    border-color: rgba(241, 174, 181, 0.2);
    color: #f8d7da;
}

/* No Data Overlay */
.chart-overlay .display-4 {
    font-size: 3rem;
    color: var(--chart-text-muted);
}

.chart-overlay .opacity-50 {
    opacity: 0.5;
}

/* ==========================================================================
   WebSocket Status Indicator
   ========================================================================== */

.websocket-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    backdrop-filter: blur(4px);
    transition: all 0.2s ease;
}

.websocket-status.bg-success {
    background-color: rgba(25, 135, 84, 0.9) !important;
    animation: pulse-success 2s infinite;
}

.websocket-status.bg-danger {
    background-color: rgba(220, 53, 69, 0.9) !important;
    animation: pulse-danger 1s infinite;
}

.websocket-status.bg-secondary {
    background-color: rgba(108, 117, 125, 0.9) !important;
}

@keyframes pulse-success {
    0%,
    100% {
        opacity: 0.9;
    }
    50% {
        opacity: 1;
    }
}

@keyframes pulse-danger {
    0%,
    100% {
        opacity: 0.9;
    }
    50% {
        opacity: 0.6;
    }
}

/* ==========================================================================
   Chart Footer
   ========================================================================== */

.chart-footer {
    flex: 0 0 auto;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--chart-border);
    font-size: 0.75rem;
    color: var(--chart-text-muted);
}

.chart-footer .row > div {
    display: flex;
    align-items: center;
}

.chart-footer i {
    margin-right: 0.25rem;
    opacity: 0.7;
}

.refresh-status {
    font-weight: 500;
    color: var(--bs-success, #198754);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Mobile devices (portrait phones, less than 576px) */
@media (max-width: 575.98px) {
    .chart-component {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .chart-controls .btn-toolbar {
        justify-content: center;
    }

    .chart-controls .btn-group {
        margin-bottom: 0.5rem;
    }

    .chart-controls .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .chart-title {
        font-size: 1.1rem;
        text-align: center;
    }

    .chart-footer .row {
        text-align: center;
    }

    .chart-footer .col {
        margin-bottom: 0.25rem;
    }

    /* Stack chart type switcher vertically on mobile */
    .chart-type-switcher {
        flex-direction: column;
    }

    .chart-type-switcher .btn {
        margin-bottom: 0.25rem;
    }
}

/* Tablets (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .chart-component {
        padding: 0.875rem;
    }

    .chart-controls .btn-toolbar {
        justify-content: space-between;
    }
}

/* Small desktops (tablets, 768px and up) */
@media (min-width: 768px) {
    .chart-component {
        min-height: 400px;
    }

    .chart-content {
        min-height: 320px;
    }
}

/* Large desktops (992px and up) */
@media (min-width: 992px) {
    .chart-component {
        min-height: 450px;
    }

    .chart-content {
        min-height: 360px;
    }
}

/* Extra large desktops (1200px and up) */
@media (min-width: 1200px) {
    .chart-component {
        min-height: 500px;
    }

    .chart-content {
        min-height: 400px;
    }
}

/* ==========================================================================
   Animation and Transitions
   ========================================================================== */

/* Chart entrance animation */
.chart-component {
    animation: chartFadeIn 0.5s ease-out;
}

@keyframes chartFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Overlay transitions */
.chart-overlay {
    transition: opacity 0.3s ease-in-out;
}

.chart-overlay.d-none {
    opacity: 0;
    pointer-events: none;
}

/* Button hover effects */
.chart-controls .btn {
    transition: all 0.15s ease-in-out;
}

/* Canvas fade in when loaded */
.chart-canvas {
    opacity: 0;
    animation: canvasFadeIn 0.3s ease-in-out 0.2s forwards;
}

@keyframes canvasFadeIn {
    to {
        opacity: 1;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chart-component {
        border-width: 2px;
    }

    .chart-controls .btn {
        border-width: 2px;
    }

    .chart-footer {
        border-top-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .chart-component,
    .chart-canvas,
    .chart-overlay,
    .chart-controls .btn {
        animation: none !important;
        transition: none !important;
    }

    .refresh-btn .bi-arrow-clockwise.spin {
        animation: none !important;
    }
}

/* Focus indicators */
.chart-component:focus-within {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

.chart-controls .btn:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
    z-index: 1;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Specific Chart Type Styles
   ========================================================================== */

/* Series Chart specific */
.chart-component[data-chart-type="line"] .chart-canvas,
.chart-component[data-chart-type="bar"] .chart-canvas {
    cursor: crosshair;
}

.chart-component[data-chart-type="line"] .chart-canvas:hover,
.chart-component[data-chart-type="bar"] .chart-canvas:hover {
    cursor: pointer;
}

/* Pie Chart specific */
.chart-component[data-chart-type="pie"] .chart-canvas {
    cursor: pointer;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .chart-component {
        border: 1px solid #000;
        box-shadow: none;
        background: white;
        color: black;
        page-break-inside: avoid;
    }

    .chart-controls,
    .websocket-status {
        display: none !important;
    }

    .chart-overlay {
        display: none !important;
    }

    .chart-canvas {
        max-width: 100% !important;
        max-height: 100% !important;
    }

    .chart-footer {
        border-top: 1px solid #000;
        color: #666;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

/* Chart sizing utilities */
.chart-sm {
    min-height: 200px;
}

.chart-sm .chart-content {
    min-height: 150px;
}

.chart-lg {
    min-height: 600px;
}

.chart-lg .chart-content {
    min-height: 500px;
}

.chart-xl {
    min-height: 700px;
}

.chart-xl .chart-content {
    min-height: 600px;
}

/* Chart aspect ratios */
.chart-square {
    aspect-ratio: 1 / 1;
}

.chart-wide {
    aspect-ratio: 16 / 9;
}

.chart-tall {
    aspect-ratio: 3 / 4;
}

/* Loading state utilities */
.chart-loading {
    pointer-events: none;
}

.chart-loading .chart-canvas {
    opacity: 0.5;
    filter: blur(1px);
}

/* Error state utilities */
.chart-error .chart-canvas {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* Success states */
.chart-success {
    border-color: var(--bs-success, #198754);
}

.chart-success .chart-title {
    color: var(--bs-success, #198754);
}

/* Warning states */
.chart-warning {
    border-color: var(--bs-warning, #ffc107);
}

.chart-warning .chart-title {
    color: var(--bs-warning-text, #664d03);
}

/* ==========================================================================
   MetricsChart Component Styles
   ========================================================================== */

.mojo-metrics-chart {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mojo-metrics-chart-container {
    width: 100%;
    height: 100%;
}

.mojo-metrics-chart .chart-wrapper {
    flex: 1;
    min-height: 300px;
}

/* MetricsControlsView Styles */
.mojo-metrics-controls {
    background: var(--bs-light, #f8f9fa);
    border: 1px solid var(--chart-border);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

[data-bs-theme="dark"] .mojo-metrics-controls {
    background: var(--bs-dark, #212529);
    border-color: var(--chart-border);
}

.mojo-metrics-controls .form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--bs-body-color);
    margin-bottom: 0.25rem;
}

.mojo-metrics-controls .btn-group .btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
    font-weight: 500;
}

.mojo-metrics-controls .quick-range-btn.active {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    color: white;
    font-weight: 600;
}

.mojo-metrics-controls .form-control,
.mojo-metrics-controls .form-select {
    font-size: 0.875rem;
    border: 1px solid var(--chart-border);
}

.mojo-metrics-controls .form-control:focus,
.mojo-metrics-controls .form-select:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.mojo-metrics-controls .dropdown-menu {
    background: var(--chart-bg);
    border: 1px solid var(--chart-border);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.mojo-metrics-controls .form-check-input {
    margin-top: 0.125rem;
}

.mojo-metrics-controls .form-check-label {
    font-size: 0.875rem;
    color: var(--bs-body-color);
}

/* Metrics Footer */
.metrics-footer {
    border-top: 1px solid var(--chart-border);
    padding-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--chart-text-muted);
}

.metrics-footer .data-points {
    font-weight: 600;
}

.metrics-footer .last-updated {
    font-style: italic;
}

.metrics-footer .timestamp {
    font-weight: 500;
}

/* Responsive adjustments for MetricsControls */
@media (max-width: 767.98px) {
    .mojo-metrics-controls .row {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 1rem;
    }

    .mojo-metrics-controls .col-auto {
        flex: 1 1 auto;
        min-width: 0;
    }

    .mojo-metrics-controls .btn-group {
        width: 100%;
        justify-content: center;
    }

    .mojo-metrics-controls .form-control,
    .mojo-metrics-controls .form-select {
        width: 100%;
        max-width: none !important;
    }

    .mojo-metrics-controls .input-group {
        flex-wrap: wrap;
    }

    .mojo-metrics-controls .input-group .form-control {
        min-width: 140px;
    }
}

@media (max-width: 575.98px) {
    .mojo-metrics-controls {
        padding: 0.75rem;
    }

    .mojo-metrics-controls .row {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.75rem;
    }

    .mojo-metrics-controls .form-label {
        margin-bottom: 0.125rem;
    }

    .mojo-metrics-controls .btn-group .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
}

/* ==========================================================================
   Integrated Toolbar Styles for SeriesChart
   ========================================================================== */

.chart-header {
    flex: 0 0 auto;
}

.chart-toolbar-integrated {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--chart-border);
}

.mojo-toolbar-form {
    background: transparent;
    border: none;
    padding: 0;
}

.mojo-toolbar-form .row {
    --bs-gutter-x: 1rem;
    --bs-gutter-y: 0.5rem;
}

.mojo-toolbar-form .form-label-sm {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--chart-text-muted);
    margin-bottom: 0.25rem;
    display: block;
}

.mojo-toolbar-form .btn-group-sm .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    font-weight: 500;
}

.mojo-toolbar-form .form-select,
.mojo-toolbar-form .form-control {
    font-size: 0.875rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--chart-border);
}

.mojo-toolbar-form .form-select:focus,
.mojo-toolbar-form .form-control:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.mojo-toolbar-form .dropdown-menu {
    background: var(--chart-bg);
    border: 1px solid var(--chart-border);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    font-size: 0.875rem;
}

.mojo-toolbar-form .form-check-input {
    margin-top: 0.125rem;
}

.mojo-toolbar-form .form-check-label {
    font-size: 0.875rem;
    color: var(--chart-text);
}

/* Compact button group styling */
.mojo-toolbar-form .btn-group .btn.active {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    color: white;
    font-weight: 600;
}

/* Responsive adjustments for toolbar */
@media (max-width: 767.98px) {
    .chart-toolbar-integrated {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }

    .mojo-toolbar-form .row {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.75rem;
    }

    .mojo-toolbar-form .col-auto {
        flex: 1 1 auto;
        min-width: 0;
    }

    .mojo-toolbar-form .btn-group {
        width: 100%;
        justify-content: center;
    }

    .mojo-toolbar-form .form-control,
    .mojo-toolbar-form .form-select {
        width: 100%;
        max-width: none;
    }
}

@media (max-width: 575.98px) {
    .chart-toolbar-integrated {
        margin-top: 0.25rem;
        padding-top: 0.5rem;
    }

    .mojo-toolbar-form .form-label-sm {
        margin-bottom: 0.125rem;
        font-size: 0.7rem;
    }

    .mojo-toolbar-form .btn-group .btn {
        padding: 0.25rem 0.375rem;
        font-size: 0.7rem;
    }
}

/* Dark theme adjustments */
[data-theme="dark"] .mojo-toolbar-form .dropdown-menu {
    background: var(--chart-bg);
    border-color: var(--chart-border);
}

[data-bs-theme="dark"] .mojo-toolbar-form .form-check-label {
    color: var(--chart-text);
}

/* Metrics Toolbar Compact Mode */
.metrics-toolbar-compact {
    background: var(--bs-light, #f8f9fa);
    border-radius: 0.375rem;
    padding: 0.75rem;
    border: 1px solid var(--chart-border);
}

[data-bs-theme="dark"] .metrics-toolbar-compact {
    background: var(--bs-dark, #212529);
}

.metrics-toolbar-compact .row {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.5rem;
}

.metrics-toolbar-compact .form-label-sm {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--chart-text-muted);
    margin-bottom: 0.125rem;
}

.metrics-toolbar-compact .btn-group .btn {
    font-size: 0.7rem;
    padding: 0.25rem 0.375rem;
    font-weight: 500;
}

.metrics-toolbar-compact .form-select,
.metrics-toolbar-compact .form-control {
    font-size: 0.8rem;
    padding: 0.25rem 0.375rem;
    min-height: auto;
}

.metrics-toolbar-compact .dropdown-toggle {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* Extra compact for mobile */
@media (max-width: 575.98px) {
    .metrics-toolbar-compact {
        padding: 0.5rem;
    }

    .metrics-toolbar-compact .row {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.25rem;
    }

    .metrics-toolbar-compact .col-auto {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* ==========================================================================
   Mini Chart Components
   ========================================================================== */

/* Mini Chart Base */
.mini-chart {
    display: block;
    width: 100%;
}

.mini-chart-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

.mini-chart-svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Animation keyframes for mini charts */
@keyframes mini-chart-draw {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes mini-chart-bar-grow {
    to {
        transform: scaleY(1);
    }
}

/* ==========================================================================
   Metrics Mini Chart Component
   ========================================================================== */

.metrics-mini-chart-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--chart-bg);
    border: 1px solid var(--chart-border);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.metrics-mini-chart-container:hover {
    box-shadow: var(--chart-shadow);
    border-color: var(--bs-primary);
}

/* Vertical layout */
.metrics-mini-chart-vertical {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
}

.metrics-mini-chart-vertical .metrics-chart {
    margin-top: 0.5rem;
}

/* Horizontal layout (default) */
.metrics-mini-chart-horizontal {
    flex-direction: row;
    justify-content: space-between;
}

.metrics-mini-chart-subtitle {
    margin-top: calc(-0.5 * var(--bs-card-title-spacer-y));
    margin-bottom: 0;
    font-size: 0.9rem;
}

.metrics-mini-chart-subtitle span.subtitle-label {
    font-size: 0.6rem;
    padding-right: 10px;
}

.metrics-mini-chart-trending-text {
    margin-top: 3px;
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Metrics Info Section */
.metrics-info {
    flex: 1;
    min-width: 0;
}

.metrics-label {
    font-size: 0.875rem;
    color: var(--chart-text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metrics-value-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.metrics-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--chart-text);
    line-height: 1.2;
}

/* Trend Badge */
.metrics-trend {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.25rem;
    line-height: 1.5;
}

.metrics-trend.trend-up {
    color: #198754;
    background-color: rgba(25, 135, 84, 0.1);
}

.metrics-trend.trend-down {
    color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
}

.metrics-trend i {
    font-size: 0.875rem;
}

/* Metrics Chart Section */
.metrics-chart {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

/* Size Variants */
.metrics-mini-chart-sm .metrics-value {
    font-size: 1.25rem;
}

.metrics-mini-chart-sm .metrics-label {
    font-size: 0.75rem;
}

.metrics-mini-chart-sm .metrics-chart {
    width: 80px;
    height: 30px;
}

.metrics-mini-chart-md .metrics-chart {
    width: 100px;
    height: 40px;
}

.metrics-mini-chart-lg .metrics-value {
    font-size: 2rem;
}

.metrics-mini-chart-lg .metrics-label {
    font-size: 1rem;
}

.metrics-mini-chart-lg .metrics-chart {
    width: 120px;
    height: 50px;
}

/* Variant Colors */
.metrics-mini-chart-success {
    border-left: 4px solid #198754;
}

.metrics-mini-chart-success .metrics-value {
    color: #198754;
}

.metrics-mini-chart-danger {
    border-left: 4px solid #dc3545;
}

.metrics-mini-chart-danger .metrics-value {
    color: #dc3545;
}

.metrics-mini-chart-warning {
    border-left: 4px solid #ffc107;
}

.metrics-mini-chart-warning .metrics-value {
    color: #ffc107;
}

.metrics-mini-chart-info {
    border-left: 4px solid #0dcaf0;
}

.metrics-mini-chart-info .metrics-value {
    color: #0dcaf0;
}

/* Dark Theme Adjustments */
[data-theme="dark"] .metrics-trend.trend-up {
    color: #75b798;
    background-color: rgba(117, 183, 152, 0.15);
}

[data-theme="dark"] .metrics-trend.trend-down {
    color: #ea868f;
    background-color: rgba(234, 134, 143, 0.15);
}

/* Responsive Adjustments */
@media (max-width: 575.98px) {
    .metrics-mini-chart-container {
        flex-direction: column;
        align-items: flex-start;
    }

    .metrics-mini-chart-horizontal .metrics-chart {
        align-self: stretch;
    }

    .metrics-mini-chart-horizontal .mini-chart-svg {
        width: 100%;
        height: 40px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .mini-chart-svg path,
    .mini-chart-svg rect {
        animation: none !important;
    }

    .metrics-mini-chart-container {
        transition: none;
    }
}

/* Mini Chart Tooltip */
.mini-chart-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 0.375rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    line-height: 1.4;
    pointer-events: none;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mini-chart-tooltip strong {
    font-weight: 600;
}

.mini-chart-tooltip-label {
    font-size: 0.6875rem;
    opacity: 0.8;
    margin-bottom: 0.125rem;
}

[data-theme="dark"] .mini-chart-tooltip {
    background: rgba(255, 255, 255, 0.9);
    color: #212529;
}

/* ==========================================================================
   Circular Progress Component
   ========================================================================== */

/* Container */
.circular-progress {
    display: inline-block;
    font-family: var(--bs-font-sans-serif, system-ui, sans-serif);
}

.circular-progress-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}

.circular-progress-container:hover {
    transform: scale(1.02);
}

/* SVG */
.circular-progress-svg {
    display: block;
    overflow: visible;
    margin: 0 auto;
}

.circular-progress-bar,
.circular-progress-segment {
    transition: stroke-dashoffset 0.6s ease-out;
}

/* Center content overlay */
.circular-progress-center {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
}

.circular-progress-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    max-width: 70%;
}

/* Value display */
.circular-progress-value {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1;
    color: var(--chart-text, #212529);
    white-space: nowrap;
}

.circular-progress-label {
    font-size: 0.625rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--chart-text-muted, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

/* Icon display */
.circular-progress-content i {
    font-size: 1.5rem;
    color: var(--chart-text, #212529);
    line-height: 1;
}

/* Size variants */
.circular-progress-container.circular-progress-xs .circular-progress-value {
    font-size: 0.625rem;
}

.circular-progress-container.circular-progress-xs .circular-progress-label {
    font-size: 0.4rem;
}

.circular-progress-container.circular-progress-xs .circular-progress-content i {
    font-size: 0.75rem;
}

.circular-progress-container.circular-progress-sm .circular-progress-value {
    font-size: 0.875rem;
}

.circular-progress-container.circular-progress-sm .circular-progress-label {
    font-size: 0.5rem;
}

.circular-progress-container.circular-progress-sm .circular-progress-content i {
    font-size: 1rem;
}

.circular-progress-container.circular-progress-md .circular-progress-value {
    font-size: 1.125rem;
}

.circular-progress-container.circular-progress-md .circular-progress-label {
    font-size: 0.5625rem;
}

.circular-progress-container.circular-progress-md .circular-progress-content i {
    font-size: 1.25rem;
}

.circular-progress-container.circular-progress-lg .circular-progress-value {
    font-size: 1.5rem;
}

.circular-progress-container.circular-progress-lg .circular-progress-label {
    font-size: 0.6875rem;
}

.circular-progress-container.circular-progress-lg .circular-progress-content i {
    font-size: 1.75rem;
}

.circular-progress-container.circular-progress-xl .circular-progress-value {
    font-size: 2.25rem;
}

.circular-progress-container.circular-progress-xl .circular-progress-label {
    font-size: 0.8125rem;
}

.circular-progress-container.circular-progress-xl .circular-progress-content i {
    font-size: 2.5rem;
}

/* Variant colors */
.circular-progress-container.circular-progress-success .circular-progress-value {
    color: #198754;
}

.circular-progress-container.circular-progress-success .circular-progress-content i {
    color: #198754;
}

.circular-progress-container.circular-progress-danger .circular-progress-value {
    color: #dc3545;
}

.circular-progress-container.circular-progress-danger .circular-progress-content i {
    color: #dc3545;
}

.circular-progress-container.circular-progress-warning .circular-progress-value {
    color: #ffc107;
}

.circular-progress-container.circular-progress-warning .circular-progress-content i {
    color: #ffc107;
}

.circular-progress-container.circular-progress-info .circular-progress-value {
    color: #0dcaf0;
}

.circular-progress-container.circular-progress-info .circular-progress-content i {
    color: #0dcaf0;
}

/* Clickable state */
.circular-progress-clickable .circular-progress-container {
    cursor: pointer;
    transition:
        transform 0.15s ease,
        filter 0.15s ease;
}

.circular-progress-clickable .circular-progress-container:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.circular-progress-clickable .circular-progress-container:active {
    transform: scale(0.98);
}

/* Shadow variant */
.circular-progress-shadow .circular-progress-container {
    filter: drop-shadow(0 0.25rem 0.5rem rgba(0, 0, 0, 0.15));
}

/* Theme: Shadowed */
.circular-progress-theme-shadowed .circular-progress-svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.circular-progress-theme-shadowed circle[class*="progress"] {
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.2)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

.circular-progress-theme-shadowed .circular-progress-svg circle:not([class]) {
    /* Track circle - shadow effect */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Theme: Dark */
.circular-progress-theme-dark {
    background: #1f2937;
    border-radius: 0.5rem;
    padding: 1rem;
}

.circular-progress-theme-dark .circular-progress-value,
.circular-progress-theme-dark .circular-progress-label {
    color: #e5e7eb;
}

/* Theme: Light */
.circular-progress-theme-light {
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.circular-progress-theme-light .circular-progress-value,
.circular-progress-theme-light .circular-progress-label {
    color: #111827;
}

/* Pulse animation */
@keyframes circular-progress-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Dark theme adjustments */
[data-theme="dark"] .circular-progress-value {
    color: var(--chart-text, #ffffff);
}

[data-theme="dark"] .circular-progress-label {
    color: var(--chart-text-muted, #adb5bd);
}

[data-theme="dark"] .circular-progress-content i {
    color: var(--chart-text, #ffffff);
}

[data-theme="dark"] .circular-progress-success .circular-progress-value,
[data-theme="dark"] .circular-progress-success .circular-progress-content i {
    color: #75b798;
}

[data-theme="dark"] .circular-progress-danger .circular-progress-value,
[data-theme="dark"] .circular-progress-danger .circular-progress-content i {
    color: #ea868f;
}

[data-theme="dark"] .circular-progress-warning .circular-progress-value,
[data-theme="dark"] .circular-progress-warning .circular-progress-content i {
    color: #ffda6a;
}

[data-theme="dark"] .circular-progress-info .circular-progress-value,
[data-theme="dark"] .circular-progress-info .circular-progress-content i {
    color: #6edff6;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .circular-progress-bar,
    .circular-progress-segment,
    .circular-progress-container {
        transition: none !important;
        animation: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .circular-progress-container {
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }
}

/* Focus styles for accessibility */
.circular-progress-clickable .circular-progress-container:focus {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .circular-progress-container {
        break-inside: avoid;
    }

    .circular-progress-clickable .circular-progress-container {
        cursor: default;
    }
}

/* ==========================================================================
   MetricsMiniChartWidget Settings Popover
   ========================================================================== */

.metrics-chart-settings-popover {
    --bs-popover-max-width: 280px;
    --bs-popover-border-color: var(--chart-border);
    --bs-popover-header-bg: var(--bs-light, #f8f9fa);
    --bs-popover-body-padding-x: 1rem;
    --bs-popover-body-padding-y: 0.75rem;
}

[data-theme="dark"] .metrics-chart-settings-popover {
    --bs-popover-bg: var(--chart-bg);
    --bs-popover-header-bg: var(--bs-dark, #2b3035);
    --bs-popover-border-color: var(--chart-border);
}

.metrics-chart-settings-content {
    padding: 0;
}

.metrics-chart-settings-content h6 {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--chart-text);
    margin-bottom: 0.5rem;
}

.metrics-chart-settings-content .form-label {
    font-weight: 600;
    color: var(--chart-text);
}

.metrics-chart-settings-content .form-select,
.metrics-chart-settings-content .form-control {
    font-size: 0.875rem;
}

.metrics-chart-settings-content .form-select:focus,
.metrics-chart-settings-content .form-control:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* MetricsChart header — toolbar floats over the title so a long title +
 * an expanding cluster can never push each other around. Without this,
 * the toolbar would line-wrap when crowded, which moved the hover target
 * away from the cursor, collapsed the cluster, un-wrapped, and re-armed
 * the hover — an infinite flicker.
 *
 * The title gets padding-right reserving space for the collapsed toolbar
 * (granularity toggle + kebab). When the cluster expands, it overlays the
 * title — .mc-secondary-extras has an opaque background so the title text
 * underneath is hidden cleanly.
 */
.mojo-metrics-chart-container .mojo-metrics-chart-header {
    position: relative;
    min-height: 36px;
}

.mojo-metrics-chart-container .mojo-metrics-chart-title {
    /* Reserve space for the collapsed toolbar (granularity ~190px + gap +
     * kebab ~40px). At narrow chart widths the granularity collapses to a
     * <select> via the existing CQ, so the reservation drops too. */
    padding-right: 240px;
    margin: 0;
}

.mojo-metrics-chart-container .mojo-metrics-chart-toolbar {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    flex-wrap: nowrap;
    align-items: center;
    background: var(--bs-body-bg);
    z-index: 5;
}

@container (max-width: 560px) {
    .mojo-metrics-chart-container .mojo-metrics-chart-title {
        padding-right: 140px;
    }
}

/* MetricsChart toolbar — collapsing secondary cluster.
 * The kebab "⋯" trigger is always visible. The extras (gear, type, stats,
 * data, refresh) sit in a width:0 container to the LEFT of the kebab and
 * slide in when the user hovers / tabs / taps the cluster. The kebab has
 * no side-effect on click; tapping it just focuses it which fires
 * :focus-within and reveals the extras (touch-friendly). */
.mojo-metrics-chart-container .mc-secondary-actions {
    display: inline-flex;
    align-items: center;
}

.mojo-metrics-chart-container .mc-secondary-extras {
    display: inline-flex;
    align-items: center;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width 0.25s ease, opacity 0.18s ease;
    /* The toolbar floats over the title; when the cluster expands it
     * overlays the title text. A solid background keeps the title from
     * bleeding through. */
    background: var(--bs-body-bg);
}

.mojo-metrics-chart-container .mc-secondary-actions:hover .mc-secondary-extras,
.mojo-metrics-chart-container .mc-secondary-actions:focus-within .mc-secondary-extras {
    max-width: 480px; /* enough to hold gear + type-switch + stats + data + refresh */
    opacity: 1;
    /* Once expanded, let descendants escape — the gear's Bootstrap
     * dropdown is absolutely positioned and was being clipped by the
     * collapsed-state overflow:hidden. */
    overflow: visible;
}

/* Active-state polish: tinted kebab so the user knows the cluster is open. */
.mojo-metrics-chart-container .mc-secondary-actions:hover .mc-actions-trigger,
.mojo-metrics-chart-container .mc-secondary-actions:focus-within .mc-actions-trigger {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

/* Floating actions container - top right corner */
.metrics-chart-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 10;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.metrics-mini-chart-widget:hover .metrics-chart-actions {
    opacity: 1;
    visibility: visible;
}

/* Action buttons */
.metrics-chart-actions .metrics-refresh-btn,
.metrics-chart-actions .metrics-settings-btn,
.metrics-chart-actions .metrics-stats-btn,
.metrics-chart-actions .metrics-data-btn {
    width: 18px;
    height: 18px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 0.2rem;
    background: rgba(255, 255, 255, 0.9);
    transition: all 0.15s ease;
}

.metrics-chart-actions .metrics-refresh-btn:hover,
.metrics-chart-actions .metrics-settings-btn:hover,
.metrics-chart-actions .metrics-stats-btn:hover,
.metrics-chart-actions .metrics-data-btn:hover {
    transform: scale(1.25);
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.metrics-chart-actions .metrics-refresh-btn i,
.metrics-chart-actions .metrics-settings-btn i,
.metrics-chart-actions .metrics-stats-btn i,
.metrics-chart-actions .metrics-data-btn i {
    font-size: 0.7rem;
}

/* Override for colored background cards */
.metrics-mini-chart-widget .card[style*="background"] .metrics-chart-actions .metrics-refresh-btn,
.metrics-mini-chart-widget .card[style*="background"] .metrics-chart-actions .metrics-settings-btn,
.metrics-mini-chart-widget .card[style*="background"] .metrics-chart-actions .metrics-stats-btn,
.metrics-mini-chart-widget .card[style*="background"] .metrics-chart-actions .metrics-data-btn {
    background: rgba(0, 0, 0, 0.15);
}

.metrics-mini-chart-widget
    .card[style*="background"]
    .metrics-chart-actions
    .metrics-refresh-btn:hover,
.metrics-mini-chart-widget
    .card[style*="background"]
    .metrics-chart-actions
    .metrics-settings-btn:hover,
.metrics-mini-chart-widget
    .card[style*="background"]
    .metrics-chart-actions
    .metrics-stats-btn:hover,
.metrics-mini-chart-widget
    .card[style*="background"]
    .metrics-chart-actions
    .metrics-data-btn:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Refresh button spin animation */
.metrics-chart-actions .metrics-refresh-btn i.spin {
    animation: spin-refresh 1s linear infinite;
}

@keyframes spin-refresh {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Add shadow effect on card hover */
.metrics-mini-chart-widget .card {
    transition: all 0.2s ease;
}

.metrics-mini-chart-widget:hover .card {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    transform: translateY(-2px);
}

/* Responsive adjustments */
@media (max-width: 575.98px) {
    .metrics-chart-settings-popover {
        --bs-popover-max-width: 240px;
    }

    .metrics-chart-settings-content h6 {
        font-size: 0.8125rem;
    }
}


/* ==========================================================================
   Native SeriesChart (.mini-series-*)
   ========================================================================== */

.mini-series-chart { display: block; }

.mini-series-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
}

.mini-series-wrapper.mini-series-legend-top    { flex-direction: column; }
.mini-series-wrapper.mini-series-legend-bottom { flex-direction: column-reverse; }
.mini-series-wrapper.mini-series-legend-left   { flex-direction: row-reverse; }
.mini-series-wrapper.mini-series-legend-right  { flex-direction: row; }

.mini-series-svg-area {
    flex: 1 1 auto;
    position: relative;
    min-width: 0;
    min-height: 0;
}

.mini-series-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Legend */
.mini-series-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    color: var(--bs-secondary-color, #6c757d);
}

.mini-series-wrapper.mini-series-legend-left .mini-series-legend,
.mini-series-wrapper.mini-series-legend-right .mini-series-legend {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.25rem 0.75rem;
}

/* Legend justify — aligns items along the legend's main axis.
   - For top/bottom legends (horizontal flex), this is left/center/right.
   - For left/right legends (column flex), this is top/center/bottom.
   `start` (default) is also the implicit flex-content default; declared
   explicitly here so the contract is unambiguous. */
.mini-series-wrapper.mini-series-legend-justify-start  .mini-series-legend { justify-content: flex-start; }
.mini-series-wrapper.mini-series-legend-justify-center .mini-series-legend { justify-content: center; }
.mini-series-wrapper.mini-series-legend-justify-end    .mini-series-legend { justify-content: flex-end; }

.mini-series-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.15s ease;
}

.mini-series-legend-item:hover { opacity: 0.85; }

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

.mini-series-legend-swatch {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
}

.mini-series-legend-label { white-space: nowrap; }

/* Tooltip */
.mini-series-tooltip {
    position: absolute;
    z-index: 50;
    background: var(--chart-overlay-bg, rgba(255, 255, 255, 0.96));
    color: var(--bs-body-color, #212529);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.25rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.15);
    padding: 0.4rem 0.6rem;
    font-size: 0.8125rem;
    pointer-events: none;
    min-width: 120px;
}

.mini-series-tooltip-label {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.mini-series-tooltip-row {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    line-height: 1.4;
}

.mini-series-tooltip-row strong { margin-left: auto; }

.mini-series-tooltip-swatch {
    display: inline-block;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 2px;
    flex: 0 0 auto;
}

[data-bs-theme="dark"] .mini-series-tooltip {
    background: var(--chart-overlay-bg, rgba(33, 37, 41, 0.96));
    color: var(--bs-body-color, #fff);
    border-color: var(--bs-border-color, #404449);
}

/* Hover-isolated highlighting */
.mini-series-faded {
    opacity: 0.25;
    transition: opacity 120ms ease;
}

.mini-series-bar,
.mini-series-dot {
    cursor: pointer;
    transition: opacity 120ms ease;
}


/* ==========================================================================
   Native PieChart (.mini-pie-*)
   ========================================================================== */

.mini-pie-chart { display: block; }

.mini-pie-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mini-pie-wrapper.mini-pie-layout-bottom {
    flex-direction: column;
}

.mini-pie-wrapper.mini-pie-layout-right {
    flex-direction: row;
}

.mini-pie-svg-area {
    position: relative;
    flex: 0 0 auto;
}

.mini-pie-svg { display: block; }

.mini-pie-segment { cursor: pointer; transition: opacity 120ms ease; }

.mini-pie-tooltip {
    position: absolute;
    z-index: 50;
    background: var(--chart-overlay-bg, rgba(255, 255, 255, 0.96));
    color: var(--bs-body-color, #212529);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.25rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.15);
    padding: 0.4rem 0.6rem;
    font-size: 0.8125rem;
    pointer-events: none;
}

[data-bs-theme="dark"] .mini-pie-tooltip {
    background: var(--chart-overlay-bg, rgba(33, 37, 41, 0.96));
    color: var(--bs-body-color, #fff);
    border-color: var(--bs-border-color, #404449);
}

.mini-pie-legend {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: var(--bs-secondary-color, #6c757d);
}

.mini-pie-wrapper.mini-pie-layout-bottom .mini-pie-legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.mini-pie-legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.mini-pie-legend-swatch {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
}

.mini-pie-legend-label { flex: 1 1 auto; min-width: 0; }
.mini-pie-legend-value { font-variant-numeric: tabular-nums; opacity: 0.8; }


/* ==========================================================================
   SeriesChart crosshair-tracking layer
   ========================================================================== */

.mini-series-crosshair-layer {
    pointer-events: none;
}

.mini-series-crosshair-layer .mini-series-hit {
    fill: transparent;
    cursor: crosshair;
    pointer-events: all;
}

.mini-series-crosshair {
    /* `currentColor` resolves through this rule unless `crosshairColor` was
       passed explicitly (which sets `stroke` inline and wins). Matches the
       Bootstrap text-muted color and auto-adapts under data-bs-theme="dark". */
    color: var(--bs-secondary-color, #6c757d);
    opacity: 0.4;
    pointer-events: none;
}

.mini-series-ghost {
    pointer-events: none;
}

/* ==========================================================================
   KPITile / KPIStrip
   Compact dashboard tiles fed by a parent's batched fetch (KPIStrip).
   Visual contract documented in planning/mockups/security_dashboard.
   ========================================================================== */

.mojo-kpi-strip {
    display: block;
    width: 100%;
}

/* Default to 4 tiles per row at desktop, dropping to 2 on tablet and 1
   on mobile. The grid is responsive but never tries to fit 8 tiles in
   a single row — that visual is too dense to read at a glance. */
.mojo-kpi-strip-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
@media (max-width: 1100px) {
    .mojo-kpi-strip-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .mojo-kpi-strip-grid { grid-template-columns: 1fr; }
}

.mojo-kpi-strip-cell {
    min-width: 0;  /* allow grid items to shrink below content width */
    display: flex;
}

.mojo-kpi-tile {
    /* button reset */
    appearance: none;
    border: 1px solid var(--mojo-kpi-tile-border, var(--bs-border-color, #dee2e6));
    /* Tile surface — distinct from page bg via theme-aware vars.
       Dark theme overrides set a deeper near-black so the tile reads
       as a discrete card against a slightly lighter page bg. */
    background: var(--mojo-kpi-tile-bg, var(--bs-tertiary-bg, #f8f9fa));
    color: var(--mojo-kpi-tile-fg, var(--bs-emphasis-color, var(--bs-body-color)));
    font: inherit;
    cursor: pointer;

    /* layout */
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    text-align: left;
    width: 100%;
    min-height: 130px;
    padding: 14px 14px 8px;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.mojo-kpi-tile:hover {
    border-color: var(--bs-secondary-border-subtle, #adb5bd);
    transform: translateY(-1px);
    box-shadow: 0 2px 12px -4px rgba(0, 0, 0, 0.08);
}

.mojo-kpi-tile:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

/* severity stripe — 3px left bar */
.mojo-kpi-tile-critical { box-shadow: inset 3px 0 0 var(--bs-danger,  #dc3545); }
.mojo-kpi-tile-high     { box-shadow: inset 3px 0 0 var(--bs-orange,  #fd7e14); }
.mojo-kpi-tile-warn     { box-shadow: inset 3px 0 0 var(--bs-warning, #ffc107); }
.mojo-kpi-tile-info     { box-shadow: inset 3px 0 0 var(--bs-info,    #0dcaf0); }
.mojo-kpi-tile-good     { box-shadow: inset 3px 0 0 var(--bs-success, #198754); }

.mojo-kpi-tile-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--mojo-kpi-tile-label-fg, var(--bs-secondary-color, #6c757d));
}

.mojo-kpi-tile-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: 30px;
    line-height: 1.05;
    margin-top: 6px;
    letter-spacing: -0.01em;
    color: var(--mojo-kpi-tile-fg, var(--bs-emphasis-color, var(--bs-body-color)));
}

.mojo-kpi-tile-delta {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    margin-top: 6px;
    padding: 2px 9px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    border-radius: 999px;
    letter-spacing: 0.01em;
}

.mojo-kpi-tile-delta-neutral {
    color: var(--bs-secondary-color, #6c757d);
    background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.04));
}

.mojo-kpi-tile-delta-flat {
    color: var(--bs-tertiary-color, #6c757d);
    background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.03));
}

.mojo-kpi-tile-delta-bad {
    color: #b02a37;
    background: rgba(220, 53, 69, 0.12);
}

.mojo-kpi-tile-delta-good {
    color: #146c43;
    background: rgba(25, 135, 84, 0.12);
}

/* ── Dark theme: refined hover/badge tints ──
   The base tile surface, text, and border are picked up automatically
   from the framework's dark-theme tokens (--bs-tertiary-bg,
   --bs-emphasis-color, --bs-secondary-color, --bs-border-color) via the
   fallback chain on .mojo-kpi-tile. These rules just tune component-
   specific shades that don't map cleanly to a Bootstrap token. */
[data-bs-theme="dark"] .mojo-kpi-tile:hover {
    border-color: #2a3441;
}
[data-bs-theme="dark"] .mojo-kpi-tile-delta-bad {
    color: #ffb4b4;
    background: rgba(255, 77, 79, 0.16);
}
[data-bs-theme="dark"] .mojo-kpi-tile-delta-good {
    color: #b8f5d6;
    background: rgba(52, 211, 153, 0.14);
}
[data-bs-theme="dark"] .mojo-kpi-tile-delta-neutral {
    color: #9aa6b6;
    background: rgba(255, 255, 255, 0.04);
}

.mojo-kpi-tile-spark {
    /* MiniChart inside takes its declared height */
    margin-top: auto;
}

/* Pull the embedded MiniChart's wrapper flush with the tile bottom */
.mojo-kpi-tile-spark .mini-chart,
.mojo-kpi-tile-spark .mini-chart-wrapper {
    width: 100%;
}

/* ==========================================================================
   Modal drawer header — used by Modal.drawer() drill-downs
   ========================================================================== */

.modal-drawer-head {
    padding: 18px 20px 12px;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
}

.modal-drawer-eyebrow {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--bs-secondary-color, #6c757d);
    margin-bottom: 4px;
}

.modal-drawer-title {
    margin: 0 0 6px;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.005em;
    color: var(--bs-body-color);
}

.modal-drawer-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 12px;
    color: var(--bs-secondary-color, #6c757d);
}

.modal-drawer-body {
    padding: 16px 20px 20px;
}

/* ==========================================================================
   Security Dashboard layout — single-page mission-control.
   Visual contract documented in planning/mockups/security_dashboard.
   ========================================================================== */

.security-dashboard-page .security-dashboard {
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 8px;
}

/* The dashboard's dark mission-control palette is now the framework
   default — see core.css `:root[data-bs-theme="dark"]`. No page-scoped
   surface overrides are needed; everything cascades from the global
   tokens. */

.sd-page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 14px 4px 18px;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
    margin-bottom: 24px;
}

.sd-page-title {
    margin: 4px 0 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--mojo-kpi-tile-fg, var(--bs-emphasis-color, var(--bs-body-color)));
}

.sd-page-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.security-dashboard .sd-eyebrow {
    display: inline-block;
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--bs-secondary-color, #6c757d);
}

/* Generous gutters between sections — the mockup has 32px of breathing
   room between cards, which lets each section read as a unit. */
.security-dashboard .sd-section {
    margin-bottom: 32px;
}

.security-dashboard .sd-section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
    padding: 0 2px;
}

.security-dashboard .sd-section-meta {
    font-variant-numeric: tabular-nums;
}

/* grid helpers — used by SecurityDashboardPage's hero row */
.security-dashboard .sd-grid {
    display: grid;
    gap: 24px;
}
.security-dashboard .sd-grid-2 {
    grid-template-columns: 1fr 1fr;
}
.security-dashboard .sd-grid-2-3 {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
}
@media (max-width: 1100px) {
    .security-dashboard .sd-grid-2,
    .security-dashboard .sd-grid-2-3 { grid-template-columns: 1fr; }
}

/* Cards: shared mission-control surface, hairline border, subtle inner
   divider between header and body. */
.security-dashboard .sd-card {
    border-radius: 10px;
    background: var(--mojo-kpi-tile-bg, var(--bs-tertiary-bg, #ffffff));
    border: 1px solid var(--mojo-kpi-tile-border, var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08)));
    color: var(--mojo-kpi-tile-fg, var(--bs-body-color));
}

.security-dashboard .sd-card .card-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(255, 255, 255, 0.04));
}

.security-dashboard .sd-card .card-body {
    padding: 16px 20px;
}

.security-dashboard .sd-card-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--mojo-kpi-tile-fg, var(--bs-emphasis-color, var(--bs-body-color)));
}

.security-dashboard .sd-card .card-subtitle {
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--bs-secondary-color, #6c757d);
}

/* Bootstrap btn-outline-secondary needs higher contrast against the
   deep dashboard surface — bump border + text + hover saturation. */
[data-bs-theme="dark"] .security-dashboard .btn-outline-secondary {
    color: #cfd6e0;
    border-color: #2a3441;
}
[data-bs-theme="dark"] .security-dashboard .btn-outline-secondary:hover,
[data-bs-theme="dark"] .security-dashboard .btn-outline-secondary.active {
    color: var(--bs-emphasis-color, #fff);
    background: #1c232c;
    border-color: #3a4452;
}

/* Geography map + leaderboard side-by-side layout. */
.security-dashboard .sd-geo-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 2fr);
    gap: 0;
    align-items: stretch;
}
@media (max-width: 1100px) {
    .security-dashboard .sd-geo-grid { grid-template-columns: 1fr; }
}
.security-dashboard .sd-geo-map-cell {
    padding: 0;
}
.security-dashboard .sd-geo-leader {
    border-left: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
    overflow-y: auto;
    max-height: 360px;
}
/* Compact-mode leaderboard (no inline map) — full card width, no left
   border (since there's nothing to the left of it). */
.security-dashboard .sd-geo-leader-full {
    border-left: 0;
    max-height: 420px;
}
@media (max-width: 1100px) {
    .security-dashboard .sd-geo-leader {
        border-left: 0;
        border-top: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
    }
}
.security-dashboard .sd-geo-leader-row {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 14px;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.06));
    cursor: pointer;
    transition: background-color 100ms ease;
    font-size: 12.5px;
}
.security-dashboard .sd-geo-leader-row:last-child { border-bottom: 0; }
.security-dashboard .sd-geo-leader-row:hover {
    background: var(--bs-secondary-bg, rgba(0, 0, 0, 0.03));
}
.security-dashboard .sd-geo-cc {
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
    letter-spacing: 0.04em;
}
.security-dashboard .sd-geo-name {
    color: var(--bs-body-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.security-dashboard .sd-geo-num {
    color: var(--bs-secondary-color, #6c757d);
}

.security-dashboard .sd-card-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.security-dashboard .sd-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

/* Priority queue — list rows */
.security-dashboard .sd-priority-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.security-dashboard .sd-pri-row {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.06));
    cursor: pointer;
    transition: background-color 100ms ease;
}
.security-dashboard .sd-pri-row:last-child { border-bottom: 0; }
.security-dashboard .sd-pri-row:hover { background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.025)); }

.security-dashboard .sd-pri {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 3px 0;
    border-radius: 3px;
    text-align: center;
    width: 100%;
    color: #fff;
}
.security-dashboard .sd-pri-critical { background: var(--bs-danger,  #dc3545); }
.security-dashboard .sd-pri-high     { background: var(--bs-orange,  #fd7e14); }
.security-dashboard .sd-pri-warn     { background: var(--bs-warning, #ffc107); color: #1a1300; }
.security-dashboard .sd-pri-info     { background: var(--bs-info,    #0dcaf0); color: #001823; }

.security-dashboard .sd-pri-body { min-width: 0; }
.security-dashboard .sd-pri-title {
    display: block;
    font-weight: 500;
    color: var(--bs-body-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.security-dashboard .sd-pri-meta {
    display: block;
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--bs-secondary-color, #6c757d);
    font-variant-numeric: tabular-nums;
}
.security-dashboard .sd-pri-actions {
    display: inline-flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 100ms ease;
}
.security-dashboard .sd-pri-row:hover .sd-pri-actions { opacity: 1; }

/* PieChart inside a dashboard card: never let its fixed-pixel
   width (e.g. 200px) push the legend past the card edge at narrow
   viewports. Constrains the SVG area to its parent and lets the
   legend wrap naturally. */
.security-dashboard .mini-pie-chart,
.security-dashboard .mini-pie-wrapper {
    max-width: 100%;
}
.security-dashboard .mini-pie-svg-area {
    max-width: 100%;
    flex-shrink: 0;
}
.security-dashboard .mini-pie-legend {
    min-width: 0;
    flex: 1 1 auto;
}

/* Distributions — Priority Buckets (matches mockup contract).
   3-col grid: [70px label/range stack | bar | num] */
.security-dashboard .sd-bucket-list {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0;
}
.security-dashboard .sd-bucket-row {
    display: grid;
    grid-template-columns: 70px 1fr auto;
    gap: 12px;
    align-items: center;
    cursor: pointer;
}
.security-dashboard .sd-bucket-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.25;
}
.security-dashboard .sd-bucket-range {
    display: block;
    font-weight: 400;
    font-size: 10px;
    letter-spacing: 0.04em;
    opacity: 0.6;
    margin-top: 2px;
}
.security-dashboard .sd-bucket-bar {
    position: relative;
    display: block;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 999px;
    overflow: hidden;
}
.security-dashboard .sd-bucket-bar > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    transition: width 200ms ease;
}
.security-dashboard .sd-bucket-num {
    font-size: 13px;
    color: var(--mojo-kpi-tile-fg, var(--bs-body-color));
}

/* Distributions — Bouncer Funnel (matches mockup contract).
   Each row: 36px-tall track with a coloured fill that contains the
   stage label, plus the count to the right. */
.security-dashboard .sd-funnel {
    display: grid;
    gap: 10px;
}
.security-dashboard .sd-funnel-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}
.security-dashboard .sd-funnel-bar {
    position: relative;
    height: 36px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    overflow: hidden;
}
.security-dashboard .sd-funnel-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 6px;
    color: #061018;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
    transition: width 200ms ease;
}
.security-dashboard .sd-funnel-num {
    font-size: 13px;
    color: var(--mojo-kpi-tile-fg, var(--bs-body-color));
}

/* Top sources — rank rows */
.security-dashboard .sd-rank-list {
    margin: 0;
}
.security-dashboard .sd-rank-row {
    cursor: pointer;
    transition: background-color 100ms ease;
}
.security-dashboard .sd-rank-row:hover {
    background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.025));
}

/* Auth sub-tiles — small clickable tiles below the chart */
.security-dashboard .sd-auth-tile {
    appearance: none;
    background: var(--bs-body-bg);
    color: inherit;
    border-color: var(--bs-border-color);
    cursor: pointer;
    transition: border-color 120ms ease;
}
.security-dashboard .sd-auth-tile:hover {
    border-color: var(--bs-secondary-border-subtle, #adb5bd);
}
.security-dashboard .sd-auth-tile-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--bs-secondary-color, #6c757d);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.security-dashboard .sd-auth-tile-suffix {
    margin-left: 4px;
    font-weight: 500;
    opacity: 0.6;
}
.security-dashboard .sd-auth-tile-value {
    font-size: 22px;
    margin-top: 2px;
    color: var(--mojo-kpi-tile-fg, var(--bs-body-color));
}

/* Health strip */
.security-dashboard .sd-health-summary {
    cursor: pointer;
    list-style: none;
}
.security-dashboard .sd-health-summary::-webkit-details-marker { display: none; }
.security-dashboard .sd-health-card[open] .sd-health-toggle { transform: rotate(0deg); }
.security-dashboard .sd-health-card:not([open]) .sd-health-toggle { transform: rotate(180deg); }
.security-dashboard .sd-health-toggle { transition: transform 150ms ease; }

.security-dashboard .sd-health-row-link { cursor: pointer; }
.security-dashboard .sd-health-row-link:hover { background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.025)); }

.security-dashboard .sd-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bs-tertiary-color, #adb5bd);
}
.security-dashboard .sd-dot-good { background: var(--bs-success, #198754); box-shadow: 0 0 6px rgba(25, 135, 84, 0.4); }
.security-dashboard .sd-dot-warn { background: var(--bs-warning, #ffc107); box-shadow: 0 0 6px rgba(255, 193, 7, 0.4); }
.security-dashboard .sd-dot-crit { background: var(--bs-danger,  #dc3545); box-shadow: 0 0 8px rgba(220, 53, 69, 0.55); }

/* Refresh button spinner */
.bi-spin {
    animation: bi-spin-anim 1s linear infinite;
    display: inline-block;
}
@keyframes bi-spin-anim {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}


