/**
 * Shared UI Components
 * Used across: violations.html, alerts.html, device pages
 *
 * Components:
 * - Image Lightbox
 * - Alert Snapshots
 * - Filter Bar
 * - Summary Cards
 * - Count Cards
 */

/* ==========================================================================
   IMAGE LIGHTBOX OVERLAY
   Fullscreen image viewer used in violations and alerts
   ========================================================================== */

.image-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1080; /* above Bootstrap modal backdrop (z=1050) */
}

.image-lightbox-overlay.visible {
    display: flex;
}

.image-lightbox-img {
    max-width: 95vw;
    max-height: 95vh;
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.image-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease;
}

.image-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   ALERT SNAPSHOT CONTAINER
   Image container with expand button for violations/alerts
   ========================================================================== */

.alert-snapshot-container {
    width: 100%;
    max-width: 400px;
    margin: 10px 0;
    position: relative;
}

.alert-snapshot-img {
    width: 100%;
    height: 300px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

.alert-snapshot-expand {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    border: none;
}

.alert-snapshot-container:hover .alert-snapshot-img {
    filter: blur(2px);
}

.alert-snapshot-container:hover .alert-snapshot-expand {
    opacity: 1;
}

.alert-snapshot-url {
    margin-top: 8px;
    font-size: 0.9em;
    word-break: break-all;
}

.alert-snapshot-url a {
    color: #0d6efd;
    text-decoration: none;
}

.alert-snapshot-url a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   SUMMARY SECTION & CARDS
   Used for statistics display in violations and alerts
   ========================================================================== */

.summary-section {
    margin-bottom: 25px;
}

.summary-row {
    display: grid;
    grid-template-columns: 140px 1fr 1fr 1fr;
    gap: 15px;
}

.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.chart-card h6 {
    margin-bottom: 12px;
    color: var(--color-neutral-800);
    font-weight: 600;
}

.chart-wrapper {
    height: 160px;
    position: relative;
}

/* Count Card Component */
.count-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.count-value {
    font-size: 3rem;
    font-weight: 700;
}

.count-label {
    font-size: 0.9rem;
    color: var(--color-neutral-500);
    margin-top: 5px;
}

/* Count Value Color Variants */
.count-value--violations,
.count-value--danger {
    color: #dc3545; /* Red for violations */
}

.count-value--alerts,
.count-value--warning {
    color: #ffc107; /* Yellow for alerts */
}

.count-value--success {
    color: #28a745; /* Green for success */
}

.count-value--info {
    color: #17a2b8; /* Blue for info */
}

/* Responsive Summary — small desktops */
@media (max-width: 1279px) {
    .summary-row {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    .chart-wrapper {
        height: 180px;
    }
}

@media (max-width: 992px) {
    .summary-row {
        grid-template-columns: 1fr;
    }
    .chart-wrapper {
        height: 220px;
    }
}

/* ==========================================================================
   FILTER BAR
   Compact filter controls for violations and alerts
   ========================================================================== */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    padding: 15px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 120px;
}

.filter-item label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-neutral-500);
    margin: 0;
}

.filter-item .form-control-sm {
    width: 100%;
    font-size: 0.85rem;
}

.filter-checkbox {
    flex: 0 0 auto;
    min-width: auto;
    justify-content: center;
}

.filter-checkbox .checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--color-neutral-800);
    cursor: pointer;
    white-space: nowrap;
    padding-top: 18px;
}

.filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.filter-item.filter-btn {
    flex: 0 0 auto;
    min-width: auto;
    justify-content: flex-end;
}

.filter-item .btn-sm {
    padding: 0.375rem 0.75rem;
    white-space: nowrap;
    margin-top: 18px;
    line-height: 1.5;
    font-size: 0.85rem;
}

/* Filter Bar Responsive — small desktops */
@media (max-width: 1279px) {
    .filter-item {
        flex: 1 1 calc(25% - 15px);
        min-width: 140px;
    }
}

@media (max-width: 992px) {
    .filter-item {
        flex: 1 1 calc(33.333% - 15px);
        min-width: 150px;
    }
}

@media (max-width: 768px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-item {
        flex: 1 1 100%;
        width: 100%;
    }
    .filter-checkbox .checkbox-label,
    .filter-item .btn-sm {
        padding-top: 0;
        margin-top: 0;
    }
    /* Allow date preset btn-group to wrap on mobile */
    .filter-item .btn-group {
        display: flex;
        flex-wrap: wrap;
    }
    .filter-item .btn-group .btn {
        flex: 1 1 auto;
    }
}

/* ==========================================================================
   FILTER BUTTONS (Device Pages)
   Toggle filter buttons used in device stream/monitor
   ========================================================================== */

.filter-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    background: #fff;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
}

.filter-btn.active {
    background: #0d6efd;
    border-color: #0d6efd;
    color: #fff;
}

/* ==========================================================================
   CARD BOX (Shared)
   Common card styling for device pages
   ========================================================================== */

.card-box {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-box-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-neutral-200);
    font-weight: 600;
    color: var(--color-neutral-800);
}

.card-box-body {
    padding: 20px;
}

/* ==========================================================================
   MOBILE RESPONSIVE ENHANCEMENTS
   ========================================================================== */

/* --- Summary cards and count values on small phones --- */
@media (max-width: 576px) {
    .count-value {
        font-size: 2rem;
    }
    .summary-card {
        padding: 15px;
    }
}

/* --- Very small screens (≤480px) --- */
@media (max-width: 480px) {
    .filter-bar {
        padding: 12px;
        gap: 10px;
    }
    .filter-item {
        min-width: 0;
    }
    .filter-item .btn-sm {
        width: 100%;
    }
    .alert-snapshot-container {
        max-width: 100%;
    }
    .alert-snapshot-img {
        height: 200px;
    }
}
