:root {
    --text-main: #1a202c;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --panel-bg: #ffffff;
    --page-bg: #f7fafc;
    --brand-color: #3B82F6;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --radius-md: 0.375rem;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.alerts-page {
    background-color: transparent;
    color: var(--text-main);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100%;
}

.alerts-surface {
    max-width: var(--container, 1400px);
    margin: 0 auto;
    padding: clamp(24px, 6vw, 40px) clamp(16px, 4vw, 28px) 48px;
}

.alerts-header {
    margin-bottom: 2rem;
}

.breadcrumbs {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
}

.title {
    margin: 0.25rem 0 0;
    font-size: clamp(22px, 4vw, 28px);
    font-weight: 800;
    letter-spacing: -0.01em;
}

.subtitle {
    margin-top: 0.5rem;
    color: var(--ink-2, #4b5563);
    font-weight: 600;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.25rem;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-item label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.filter-item input,
.filter-item select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: white;
    min-width: 180px;
    font-size: 14px;
}

.filter-item--search {
    flex-grow: 1;
}

.filter-item--search input {
    width: 100%;
}

.table-container {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.history-table th,
.history-table td {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.history-table thead th {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    background-color: #f8fafc;
    cursor: pointer;
}

.history-table thead th:hover {
    background-color: #f1f5f9;
}

.history-table tbody tr:last-child td {
    border-bottom: none;
}

.history-table tbody tr:hover {
    background-color: #f8fafc;
}

.level-chip {
    display: inline-flex;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
}

.level-chip--danger {
    background-color: #fee2e2;
    color: #b91c1c;
}

.level-chip--warning {
    background-color: #ffedd5;
    color: #9a3412;
}

.level-chip--info {
    background-color: #e0f2fe;
    color: #0369a1;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--panel-bg);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.pagination button:hover:not(:disabled) {
    background-color: #f1f5f9;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination button.is-active {
    background-color: #1e3a8a;
    color: white;
    font-weight: bold;
    border-color: #1e3a8a;
}

.history-table tbody tr.clickable-row {
    cursor: pointer;
}

.history-table tbody tr.clickable-row:hover {
    background-color: #f0f4ff;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    z-index: 1000;
    padding: 20px;
    overflow: auto; /* Allow scrolling on small screens */
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 1000px;
    min-width: 900px; /* Enforce minimum width to prevent layout breaking */
    height: max-content;
    margin: auto; /* Center modal vertically and horizontally */
    display: flex;
    flex-direction: column;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    background-color: #fff;
    z-index: 10;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
}

.modal-close-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #9ca3af;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}

.modal-close-button:hover {
    color: #111827;
    background-color: #f3f4f6;
}

.modal-body {
    flex-grow: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* 1. Images Section */
.modal-images-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.image-container {
    margin: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    background-color: #f9fafb;
}

.image-container figcaption {
    padding: 10px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    background-color: #fff;
    border-bottom: 1px solid #e5e7eb;
    color: #374151;
}

.image-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    /* Enforce 16:9 aspect ratio */
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Ensure image fits within the 16:9 box */
}

/* 2. Metrics Bar */
.modal-metrics-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
}

.metric-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.metric-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.metric-divider {
    width: 1px;
    height: 40px;
    background-color: #cbd5e1;
}

/* 3. Chart Section */
.modal-chart-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 12px;
}

.chart-container {
    height: 250px;
    /* Fixed height for chart */
    width: 100%;
    position: relative;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .modal-images-section {
        grid-template-columns: 1fr;
        /* Stack images on mobile */
    }

    .modal-metrics-bar {
        flex-wrap: wrap;
        gap: 16px;
    }

    .metric-divider {
        display: none;
    }

    .metric-card {
        min-width: 45%;
        border-bottom: 1px solid #e2e8f0;
        padding-bottom: 8px;
    }
}

.filter-item--full-width {
    flex-basis: 100%;
}

.chip-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.chip {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--panel-bg);
    border-radius: 9999px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.chip:hover {
    background-color: #f0f4ff;
    border-color: #dbeafe;
}

.chip.is-active {
    background-color: var(--brand-color);
    color: white;
    border-color: var(--brand-color);
}

.custom-density-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.custom-density-inputs .density-filter {
    min-width: 100px;
    width: 100px;
}