/**
 * Simba Security — global UI polish
 * Loaded after style.css; extends the design system app-wide.
 */

/* ---- Focus & selection ---- */
:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

::selection {
    background: rgb(23 20 69 / 0.18);
    color: var(--gray-900);
}

/* ---- Scrollbars (main content) ---- */
.main-content,
.page-content,
.modal-body,
.table-wrapper,
.logbook-table-wrap {
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}

.main-content::-webkit-scrollbar,
.page-content::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar,
.logbook-table-wrap::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.main-content::-webkit-scrollbar-thumb,
.page-content::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb,
.logbook-table-wrap::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: var(--radius-full);
}

/* ---- Typography polish ---- */
h1, h2, h3, h4, h5, h6 {
    letter-spacing: -0.02em;
}

.text-muted {
    color: var(--gray-500) !important;
}

/* ---- Header controls ---- */
.header-icon-btn {
    background: var(--gray-100);
    border: 1px solid var(--border-subtle);
    color: var(--gray-600);
}

.header-icon-btn:hover {
    background: var(--white);
    border-color: var(--border-default);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.user-dropdown-toggle {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.user-dropdown-menu {
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
}

.user-avatar {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    box-shadow: 0 2px 8px rgb(23 20 69 / 0.25);
}

/* ---- Cards & panels ---- */
.card-footer {
    background: var(--gray-50);
    border-top: 1px solid var(--border-subtle);
}

.card-title {
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

.card-title i {
    color: var(--primary);
    opacity: 0.85;
}

.table-wrapper {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--surface-raised);
    overflow: hidden;
}

.table-wrapper .table {
    margin: 0;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: rgb(23 20 69 / 0.03);
}

/* ---- Buttons ---- */
.btn-accent {
    background: linear-gradient(180deg, var(--accent-light) 0%, var(--accent) 100%);
    box-shadow: 0 2px 8px rgb(197 36 40 / 0.3);
}

.btn-accent:hover {
    box-shadow: 0 4px 14px rgb(197 36 40 / 0.35);
    transform: translateY(-1px);
}

.btn-outline,
.btn-outline-primary {
    border-width: 1.5px;
}

.btn-success:hover,
.btn-warning:hover,
.btn-danger:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

/* ---- Badges & alerts ---- */
.badge {
    border: 1px solid transparent;
    letter-spacing: 0.02em;
}

.badge-primary {
    background: rgb(23 20 69 / 0.08);
    border-color: rgb(23 20 69 / 0.12);
}

.alert {
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.alert-success { border-color: rgb(5 150 105 / 0.2); }
.alert-warning { border-color: rgb(217 119 6 / 0.25); }
.alert-danger { border-color: rgb(220 38 38 / 0.2); }
.alert-info { border-color: rgb(37 99 235 / 0.2); }

/* ---- Clearance cards ---- */
.clearance-card {
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
}

.clearance-card.clearance-status-cleared {
    background: linear-gradient(160deg, #ecfdf5 0%, #d1fae5 100%);
    border-left-color: var(--success);
}

.clearance-card.clearance-status-pending {
    background: linear-gradient(160deg, #fffbeb 0%, #fef3c7 100%);
    border-left-color: var(--warning);
}

.clearance-card.clearance-status-not_cleared,
.clearance-card.clearance-status-alert {
    background: linear-gradient(160deg, #fef2f2 0%, #fee2e2 100%);
    border-left-color: var(--danger);
}

.clearance-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--primary-light) 100%);
    box-shadow: inset 0 -1px 0 rgb(255 255 255 / 0.08);
}

/* ---- KPI & checklist ---- */
.kpi-item {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.kpi-item:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow);
}

.checklist-section-title {
    color: var(--gray-800);
    border-bottom-color: var(--border-default);
}

/* ---- Modals ---- */
.modal-overlay {
    backdrop-filter: blur(4px);
}

.modal {
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xl);
}

.modal-header {
    background: linear-gradient(180deg, var(--surface-raised), var(--gray-50));
}

/* ---- Timeline ---- */
.timeline-content {
    border: 1px solid var(--border-subtle);
    background: var(--surface-raised);
}

/* ---- Empty state ---- */
.empty-state {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-default);
}

/* ---- Category / report rows ---- */
.category-status-item,
.category-report-item {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.category-status-item:hover,
.category-report-item:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-sm);
}

/* ---- Page section headers (common pattern) ---- */
.page-content > .d-flex.justify-between.align-center.mb-4,
.page-content > .d-flex.justify-between.align-center.mb-3 {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 1.5rem !important;
}

.page-content > .d-flex.justify-between.align-center h2,
.page-content > .d-flex.justify-between.align-center h3 {
    margin: 0;
}

/* ---- Progress ---- */
.progress-bar {
    background: var(--gray-200);
    height: 10px;
}

/* ---- Login page ---- */
.login-language {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 2;
}

.login-logo {
    filter: drop-shadow(0 4px 12px rgb(23 20 69 / 0.12));
}

.login-title {
    letter-spacing: -0.03em;
}

.input-icon {
    position: relative;
}

.input-icon i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 1;
}

.input-icon .form-control {
    padding-left: 2.5rem;
}

.login-footer {
    margin-top: clamp(0.75rem, 2vh, 1.25rem);
    padding-top: clamp(0.5rem, 1.5vh, 1rem);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.login-footer p {
    margin-bottom: 0.5rem;
}

.forgot-password-link {
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
}

.forgot-password-link:hover {
    color: var(--accent);
}

.pin-input {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.pin-input:focus {
    box-shadow: 0 0 0 4px rgb(23 20 69 / 0.12), var(--shadow-sm);
    transform: translateY(-1px);
}

.login-card .alert {
    border-radius: var(--radius-md);
}

@media (max-height: 600px) {
    .login-header {
        margin-bottom: 0.5rem;
    }

    .login-logo {
        max-width: clamp(64px, 14vw, 100px);
        margin-bottom: 0.375rem;
    }

    .login-title {
        font-size: 1.125rem;
    }

    .login-subtitle {
        font-size: 0.8125rem;
    }

    .pin-input-wrapper {
        margin: 0.5rem 0;
    }

    .login-footer {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }
}

@media (max-width: 400px) {
    .pin-input {
        width: 2.25rem;
        height: 2.75rem;
        font-size: 1.125rem;
    }
}

/* ---- Emergency & duress banners ---- */
.emergency-banner {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
    color: white;
    padding: 1.15rem clamp(1rem, 3vw, 1.5rem);
    border-bottom: 3px solid #7f1d1d;
    animation: emergency-pulse 2s infinite;
    position: relative;
    z-index: 1000;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 4px 20px rgb(127 29 29 / 0.35);
}

@media (min-width: 1025px) {
    .emergency-banner {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }

    .duress-banner {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
}

.emergency-banner.emergency-critical {
    animation: emergency-critical-pulse 1s infinite;
}

.emergency-banner.emergency-high {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border-bottom-color: #b45309;
}

.emergency-banner.emergency-medium {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-bottom-color: #1d4ed8;
}

.emergency-banner.emergency-low {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    border-bottom-color: #374151;
}

@keyframes emergency-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.96; }
}

@keyframes emergency-critical-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgb(220 38 38 / 0.5); }
    50% { opacity: 0.92; box-shadow: 0 0 0 12px rgb(220 38 38 / 0); }
}

.emergency-content {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    max-width: var(--content-max);
    margin: 0 auto;
}

.emergency-icon {
    font-size: 2rem;
    flex-shrink: 0;
    animation: emergency-shake 0.5s infinite;
}

@keyframes emergency-shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-3px) rotate(-5deg); }
    75% { transform: translateX(3px) rotate(5deg); }
}

.emergency-text {
    flex: 1;
    min-width: 0;
}

.emergency-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
}

.emergency-priority-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    background: rgb(255 255 255 / 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.emergency-photo {
    margin-top: 0.75rem;
}

.emergency-message {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.emergency-meta {
    opacity: 0.9;
    font-size: 0.85rem;
}

.emergency-photo img {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius);
    border: 2px solid rgb(255 255 255 / 0.35);
    cursor: pointer;
    transition: transform var(--transition);
}

.emergency-photo img:hover {
    transform: scale(1.02);
}

.emergency-acknowledge-btn {
    background: rgb(255 255 255 / 0.15);
    border: 2px solid white;
    color: white;
    padding: 0.55rem 1.15rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: background var(--transition), color var(--transition), transform var(--transition);
    flex-shrink: 0;
    white-space: nowrap;
}

.emergency-acknowledge-btn:hover {
    background: white;
    color: var(--danger);
    transform: translateY(-1px);
}

.duress-banner {
    box-shadow: 0 4px 24px rgb(220 38 38 / 0.4);
}

.duress-banner a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
}

@media (max-width: 768px) {
    .emergency-content {
        flex-direction: column;
    }

    .emergency-acknowledge-btn {
        width: 100%;
    }

    .emergency-icon {
        font-size: 1.5rem;
    }
}

/* ---- Mobile menu ---- */
.mobile-menu-toggle {
    border: 1px solid var(--border-subtle);
    background: var(--surface-raised);
}

.mobile-menu-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ---- Form static / filters ---- */
.form-control-static {
    background: var(--gray-50);
    border-color: var(--border-subtle);
}

.filter-form .filter-row {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

/* ---- Spinner ---- */
.spinner {
    border-width: 3px;
    border-top-color: var(--accent);
}

/* ---- VIP portal sync with main tokens ---- */
body.vip-portal {
    --vx-bg: var(--surface-base);
}

/* ---- Print ---- */
@media print {
    body {
        background: white;
    }
}

/* ---- Checklist live filter bar ---- */
.checklist-filter {
    overflow: visible;
    border-color: var(--border-default);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.checklist-filter--active {
    border-color: rgb(23 20 69 / 0.18);
    box-shadow: var(--shadow-card), 0 0 0 1px rgb(23 20 69 / 0.06);
}

.checklist-filter.is-applying {
    border-color: var(--primary-light);
}

.checklist-filter__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.35rem;
    border-bottom: 1px solid var(--border-subtle);
    background: linear-gradient(180deg, var(--surface-raised) 0%, var(--gray-50) 100%);
}

.checklist-filter__heading {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    min-width: 0;
}

.checklist-filter__icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgb(23 20 69 / 0.22);
}

.checklist-filter__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--gray-900);
}

.checklist-filter__hint {
    margin: 0.2rem 0 0;
    font-size: 0.8125rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.checklist-filter__live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgb(5 150 105 / 0.5);
    animation: filter-live-pulse 2s ease infinite;
    flex-shrink: 0;
}

@keyframes filter-live-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgb(5 150 105 / 0.45); }
    50% { box-shadow: 0 0 0 5px rgb(5 150 105 / 0); }
}

.checklist-filter.is-applying .checklist-filter__live-dot {
    background: var(--primary-light);
    animation: none;
}

.checklist-filter__clear-all {
    flex-shrink: 0;
    white-space: nowrap;
}

.checklist-filter__chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.35rem;
    background: rgb(23 20 69 / 0.04);
    border-bottom: 1px solid var(--border-subtle);
}

.checklist-filter__chips--empty {
    display: none;
    padding: 0;
    border-bottom: none;
}

.filter-chip {
    font-family: inherit;
    cursor: pointer;
    border: 1px solid var(--border-default);
}

button.filter-chip {
    appearance: none;
}

.checklist-filter__chips-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    margin-right: 0.15rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    background: var(--surface-raised);
    border: 1px solid var(--border-default);
    color: var(--gray-800);
    font-size: 0.8125rem;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    box-shadow: var(--shadow-sm);
}

.filter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: #fff;
}

.filter-chip__label {
    color: var(--gray-500);
    font-weight: 500;
}

.filter-chip__value {
    font-weight: 650;
    color: var(--primary);
}

.filter-chip:hover .filter-chip__value {
    color: var(--accent);
}

.filter-chip__remove {
    font-size: 0.65rem;
    opacity: 0.55;
    margin-left: 0.1rem;
}

.checklist-filter__body {
    padding: 1.15rem 1.35rem 1.25rem;
}

.checklist-filter__form {
    margin: 0;
}

.checklist-filter__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem 1.15rem;
}

.checklist-filter__field {
    margin-bottom: 0;
}

.checklist-filter__field .form-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    margin-bottom: 0.4rem;
    color: var(--gray-600);
}

.checklist-filter__field .form-label i {
    width: 1rem;
    text-align: center;
    color: var(--primary);
    opacity: 0.85;
    font-size: 0.8rem;
}

.checklist-filter__field .form-control {
    min-height: 2.65rem;
}

.checklist-filter__field .form-control:focus {
    border-color: var(--primary);
}

.checklist-filter__field .form-control.is-active-filter {
    border-color: var(--primary-light);
    background: rgb(23 20 69 / 0.04);
    box-shadow: inset 0 0 0 1px rgb(23 20 69 / 0.06);
}

.checklist-filter__status {
    margin: 0.85rem 0 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checklist-filter__status[hidden] {
    display: none !important;
}

#checklistResults.is-loading {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.2s ease;
    position: relative;
}

#checklistResults.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgb(255 255 255 / 0.35);
    border-radius: inherit;
    z-index: 2;
}

@media (max-width: 992px) {
    .checklist-filter__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 576px) {
    .checklist-filter__header {
        flex-direction: column;
        align-items: stretch;
    }

    .checklist-filter__clear-all {
        width: 100%;
        justify-content: center;
    }

    .checklist-filter__grid {
        grid-template-columns: 1fr;
    }
}
