/* Use the same palette for alert categories in the modal, navbar, and sidebar. */
:is(.alert-tone-danger, .smart-alert-tab-button[data-alert-tone="danger"], .smart-alert-pane .alert-danger) {
    --notice-accent: var(--app-danger);
    --notice-ink: var(--app-danger-text);
}

:is(.alert-tone-warning, .smart-alert-tab-button[data-alert-tone="warning"], .smart-alert-pane .alert-warning, .smart-alert-modal-header) {
    --notice-accent: var(--app-warning);
    --notice-ink: var(--app-warning-text);
}

:is(.alert-tone-info, .smart-alert-tab-button[data-alert-tone="info"]) {
    --notice-accent: var(--app-info);
    --notice-ink: var(--app-info-text);
}

:is(.alert-tone-primary, .smart-alert-tab-button[data-alert-tone="primary"]) {
    --notice-accent: var(--bs-primary);
    --notice-ink: var(--app-accent-text);
}

:is(.alert-tone-success, .smart-alert-tab-button[data-alert-tone="success"], .smart-alert-pane .alert-success) {
    --notice-accent: var(--app-success);
    --notice-ink: var(--app-success-text);
}

:is(.alert-tone-pink, .smart-alert-tab-button[data-alert-tone="pink"]) {
    --notice-accent: color-mix(in srgb, var(--app-danger) 78%, var(--app-info));
    --notice-ink: color-mix(in srgb, var(--app-danger-text) 78%, var(--app-info-text));
}

:is(.alert-tone-teal, .smart-alert-tab-button[data-alert-tone="teal"]) {
    --notice-accent: color-mix(in srgb, var(--app-success) 70%, var(--app-info));
    --notice-ink: color-mix(in srgb, var(--app-success-text) 70%, var(--app-info-text));
}

:is(.alert-tone-violet, .smart-alert-tab-button[data-alert-tone="violet"]) {
    --notice-accent: color-mix(in srgb, var(--app-info) 60%, var(--bs-primary));
    --notice-ink: color-mix(in srgb, var(--app-info-text) 60%, var(--app-accent-text));
}

:is(.alert-tone-orange, .smart-alert-tab-button[data-alert-tone="orange"]) {
    --notice-accent: color-mix(in srgb, var(--app-warning) 64%, var(--app-danger));
    --notice-ink: color-mix(in srgb, var(--app-warning-text) 64%, var(--app-danger-text));
}

#mainNavbar #smartAlertLi #smartAlertButton.smart-alert-trigger,
#mainNavbar #smartAlertLi #smartAlertButton.smart-alert-trigger > i,
#sideSmartAlertAction .side-rail-icon {
    color: var(--notice-ink, var(--app-accent-text)) !important;
}

#smartAlertButton #smartAlertCount,
#sideSmartAlertAction #sideSmartAlertCount,
#sideSmartAlertSummary .side-alert-summary-pill {
    color: var(--notice-ink, var(--app-accent-text)) !important;
    background: color-mix(in srgb, var(--notice-accent, var(--bs-primary)) 18%, var(--surface-1)) !important;
    border: 1px solid color-mix(in srgb, var(--notice-accent, var(--bs-primary)) 42%, var(--bs-border-color));
}

#smartAlertButton.has-alert-cycle > i {
    animation: smart-alert-bell-glow 2.2s ease-in-out infinite;
}

@keyframes smart-alert-bell-glow {
    50% { filter: drop-shadow(0 1px 4px color-mix(in srgb, var(--notice-accent, var(--bs-primary)) 45%, transparent)); }
}

.smart-alert-modal .modal-dialog {
    --bs-modal-width: min(1280px, calc(100vw - 1.6rem));
}

.smart-alert-modal .modal-content {
    background: var(--surface-1);
    color: var(--bs-body-color);
    border-color: var(--bs-border-color);
    border-radius: 18px;
    overflow: hidden;
}

.smart-alert-modal .smart-alert-modal-header {
    padding: 1rem 1.25rem;
    background: var(--surface-1);
    color: var(--bs-heading-color);
    border-block-end: 1px solid var(--bs-border-color);
}

.smart-alert-modal-header .modal-title {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: inherit;
    font-size: 1.08rem;
}

.smart-alert-modal-header .modal-title i,
.smart-alert-tab-button i:first-child,
.smart-alert-tab-button .badge {
    color: var(--notice-ink) !important;
    background: color-mix(in srgb, var(--notice-accent) 16%, var(--surface-1)) !important;
    border: 1px solid color-mix(in srgb, var(--notice-accent) 35%, var(--bs-border-color));
}

.smart-alert-modal-header .modal-title i,
.smart-alert-tab-button i:first-child {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: .65rem;
    font-size: 1rem;
}

.smart-alert-modal-header .btn-close {
    opacity: .8;
}

[data-bs-theme="light"] .smart-alert-modal-header .btn-close {
    filter: none;
}

[data-bs-theme="dark"] .smart-alert-modal-header .btn-close {
    filter: var(--bs-btn-close-white-filter, invert(1));
}

.smart-alert-modal-header .btn-close:hover { opacity: 1; }

.smart-alert-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
    gap: .9rem;
}

.smart-alert-overview-card {
    padding: .9rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--bs-border-color);
    border-inline-start: 3px solid color-mix(in srgb, var(--bs-primary) 61%, var(--surface-2));
    border-radius: .9rem;
}

.smart-alert-overview-label {
    color: var(--bs-secondary-color);
    font-size: .8rem;
    font-weight: 700;
    margin-block-end: .35rem;
}

.smart-alert-overview-value {
    color: var(--bs-heading-color);
    font-size: clamp(1.2rem, 1.05rem + .4vw, 1.65rem);
    font-weight: 800;
    line-height: 1.25;
}

.smart-alert-overview-note {
    font-size: .9rem;
    line-height: 1.6;
}

.smart-alert-nav {
    display: flex;
    flex-wrap: nowrap;
    gap: .75rem;
    overflow-x: auto;
    align-items: stretch;
    padding: .125rem .125rem .4rem;
    scrollbar-color: var(--app-strong-border) var(--surface-2);
}

.smart-alert-nav .nav-item {
    display: flex;
    flex: 1 0 220px;
    margin: 0;
}

.smart-alert-nav .smart-alert-tab-button {
    width: 100%;
    min-height: 112px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(2.4rem, auto) auto;
    align-items: center;
    align-content: start;
    gap: .6rem .5rem;
    padding: .8rem .9rem;
    text-align: start;
    line-height: 1.3;
    border-radius: .9rem;
    border: 1px solid var(--bs-border-color);
    border-inline-start: 3px solid color-mix(in srgb, var(--notice-accent) 70%, var(--bs-border-color));
    background: color-mix(in srgb, var(--notice-accent) 8%, var(--surface-1));
    color: var(--notice-ink);
}

#smartAlertModal .smart-alert-tab-button:is(:hover, .active) {
    color: var(--notice-ink);
    border-color: var(--notice-accent);
    background: color-mix(in srgb, var(--notice-accent) 13%, var(--surface-1));
}

.smart-alert-nav .smart-alert-tab-button.active {
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--notice-accent) 45%, transparent);
}

.smart-alert-modal :is(button, a, select):focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}

.smart-alert-tab-button::after {
    content: attr(data-note);
    grid-column: 1 / -1;
    color: var(--bs-secondary-color);
    font-size: .77rem;
    font-weight: 600;
    line-height: 1.55;
}

.smart-alert-tab-button .badge {
    min-width: 2rem;
    font-size: .83rem;
}

.smart-alert-content {
    padding: 1rem;
    background: var(--surface-2);
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
}

.smart-alert-pane .table-responsive {
    background: var(--surface-1);
    border: 1px solid var(--bs-border-color);
    border-radius: .75rem;
    scrollbar-color: var(--app-strong-border) var(--surface-2);
}

.smart-alert-pane .table {
    --bs-table-bg: var(--surface-1);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-hover-bg: var(--table-hover-bg);
    margin-bottom: 0;
}

#smartAlertModal .smart-alert-pane .table thead th {
    background: var(--app-grid-heading-bg) !important;
    color: var(--app-grid-heading-text) !important;
    font-size: .88rem;
    font-weight: 800;
}

.smart-alert-pane .table :is(th, td) {
    padding-block: .78rem;
}

.smart-alert-pane :is(.alert-success, .alert-warning, .alert-danger) {
    --bs-alert-color: var(--notice-ink);
    --bs-alert-link-color: var(--notice-ink);
    --bs-alert-bg: color-mix(in srgb, var(--notice-accent) 13%, var(--surface-1));
    --bs-alert-border-color: color-mix(in srgb, var(--notice-accent) 36%, var(--bs-border-color));
}

@media (max-width: 768px) {
    .smart-alert-modal .modal-dialog {
        --bs-modal-width: calc(100vw - 1rem);
        margin: .5rem auto;
    }

    .smart-alert-modal .modal-content { max-height: calc(100dvh - 1rem); }
    .smart-alert-modal .smart-alert-modal-header { padding: .75rem .95rem; }
    .smart-alert-modal-header .modal-title { font-size: .98rem; }
    .smart-alert-modal .smart-alert-modal-body { padding: 1rem !important; }
    .smart-alert-content { padding: .6rem; }
    .smart-alert-pane .table { min-width: 680px; }
    .smart-alert-pane .table :is(th, td, .badge, .btn, select) { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    #smartAlertButton.has-alert-cycle > i { animation: none; }
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    .smart-alert-tab-button {
        transition: transform .2s ease, border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
    }

    #smartAlertModal .smart-alert-tab-button:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }
}
