/**
 * Risk Register Styles
 * Matches the evidence table (#userEvidenceTable) styling
 */

/* Table view container: position relative so loader overlays; hide content until ready */
#risk-table-view {
    position: relative;
    min-height: 280px;
}
#risk-table-view:has(.no-risks) {
    min-height: 0;
}
#risk-table-view.risk-table-view-loading #risk-table-container {
    opacity: 0;
    pointer-events: none;
}

/* Add Risk modal loader - same animation as risk table / evidence, overlays modal body until Select2 ready */
#newRiskModal .modal-body {
    position: relative;
    min-height: 320px;
}
.new-risk-modal-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 9999;
    --point-color: #5789bb;
    --size: 3px;
}
.new-risk-modal-loader .container {
    display: flex;
    align-items: center;
    align-content: center;
    justify-content: center;
    height: 100%;
}
.new-risk-modal-loader .loader_element {
    border-radius: 100%;
    border: var(--size) solid var(--point-color);
    margin: calc(var(--size) * 2);
}
.new-risk-modal-loader .loader_element:nth-child(1) {
    animation: preloader .6s ease-in-out alternate infinite;
}
.new-risk-modal-loader .loader_element:nth-child(2) {
    animation: preloader .6s ease-in-out alternate .2s infinite;
}
.new-risk-modal-loader .loader_element:nth-child(3) {
    animation: preloader .6s ease-in-out alternate .4s infinite;
}

/* Custom orange background for High rating */
.bg-orange {
    background-color: #fd7e14 !important;
}

/* Status badge colors */
.bg-status-under-review { background-color: #0dcaf0 !important; }
.bg-status-open        { background-color: #314D76 !important; }
.bg-status-accepted    { background-color: #5789BB !important; }
.bg-status-closed      { background-color: #BABFC6 !important; }
.bg-status-archived    { background-color: #6c757d !important; }

/* Threat rating scale (4 levels): Low → Critical, green → red */
.bg-rating-low      { background-color: #16a34a !important; }  /* green */
.bg-rating-moderate { background-color: #d97706 !important; }  /* amber */
.bg-rating-high     { background-color: #ea580c !important; }   /* orange */
.bg-rating-critical { background-color: #dc2626 !important; }   /* red */

/* Risk actions container - match evidence table */
.risk-actions {
    display: flex;
    gap: 4px;
    justify-content: center;
    align-items: center;
}

/* Risk action buttons - same icon-only style as evidence table, 28px max */
.risk-edit {
    background: url('../icons/pencil-grey.svg') center/contain no-repeat;
    border: none;
    background-color: transparent;
    width: 28px;
    height: 14px;
    max-width: 28px;
    max-height: 14px;
    padding: 0;
    cursor: pointer;
}

.risk-delete {
    background: url('../icons/trash-grey.svg?v2') center/contain no-repeat;
    border: none;
    background-color: transparent;
    width: 28px;
    height: 14px;
    max-width: 28px;
    max-height: 14px;
    padding: 0;
    cursor: pointer;
}

/* Risk table badge styling */
.risk-table .badge {
    font-size: 0.85em;
    font-weight: 500;
}

/* Filter dropdown - sits next to search in datatable-top */
.risk-filter-container {
    margin-left: 10px;
}

#risk-filter-btn i {
    border-radius: 20px;
    border: 1px solid #c8c8c8;
    padding: 10px;
    font-size: 1.2em;
    color: #9c9c9c;
}

.risk-filter-container .dropdown-menu {
    width: 220px;
    overflow-y: auto;
}

/* Style the "All" filter option with a bottom border separator */
.risk-filter-container .list-group-item:first-child {
    border-bottom: 2px solid #dee2e6;
}

/* Responsive table wrapper */
.responsive-table.risk-table {
    width: 100%;
}

/* Allow the filter dropdown to overflow the datatable containers */
.risk-table .datatable-wrapper .datatable-top {
    overflow: visible;
}

.risk-table .datatable-wrapper .datatable-container {
    overflow-x: visible;
}

/* ============================================================
   Table styling
   The table now uses simple-datatables (same as evidence table).
   It has class="datatable-table" which inherits borders, padding,
   hover, and box-shadow from style.css / custom-datatables.css.
   Only risk-specific overrides remain here.
   ============================================================ */

#userRisksTable {
    width: 100% !important;
}

/* First column (Name) - fixed width to match evidence table */
#userRisksTable thead th:first-child,
#userRisksTable tbody td:first-child {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
}

/* Center all columns except the first (Name) */
#userRisksTable thead th:not(:first-child),
#userRisksTable tbody td:not(:first-child) {
    text-align: center;
}

#userRisksTable .risk-actions-header {
    width: 100px;
}

/* ============================================================
   No-risks empty state
   ============================================================ */



.no-risks h3 {
    margin-bottom: 15px;
    color: #333;
}

.no-risks p {
    color: #666;
}

/* ============================================================
   Risk modal styling
   ============================================================ */

#newRiskModal .modal-body,
#editRiskModal .modal-body {
    max-height: 80vh;
    overflow-y: auto;
}

#newRiskModal .card,
#editRiskModal .card {
    border: 1px solid rgba(0, 0, 0, 0.125);
    margin-bottom: 1rem;
}

#newRiskModal .card-header,
#editRiskModal .card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
    padding: 0.75rem 1rem;
}

#newRiskModal .card-header h6,
#editRiskModal .card-header h6 {
    font-weight: 600;
    color: #333;
}

#newRiskModal .card-body,
#editRiskModal .card-body {
    padding: 1rem;
}

#newRiskModal textarea.form-control,
#editRiskModal textarea.form-control {
    min-height: 100px;
}

#newRiskModal .form-select,
#editRiskModal .form-select {
    max-width: 100%;
}

/* Text display areas on single risk page */
.single-risk .card-body .bg-light.rounded {
    min-height: 100px;
}

/* Required field indicator */
.form-label .text-danger {
    font-weight: bold;
}

#riskOwner, #riskOwnerEmail, #editRiskOwner, #editRiskOwnerEmail {
    min-height: 44px;
}

/* ============================================================
   Threat assessment sliding scale (single-risk page)
   ============================================================ */

.threat-scale-segment {
    min-width: 0;
    cursor: default;
}

/* Active segment highlight */
.threat-scale-segment.threat-scale-active {
    background-color: rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    margin: 2px 1px;
}

.threat-scale-segment.threat-scale-active .threat-scale-label {
    letter-spacing: 0.02em;
}

/* Select wrapper for consistent styling */
.select-wrapper {
    position: relative;
}

.btn-red-underline {
    color: red;
    text-decoration: underline red;
    padding: 3px 0;
}

/* ============================================================
   Select2 Bootstrap 5 integration for risk modals
   ============================================================ */

/* Restore inline search input hidden by select2.min.css */
#newRiskModal .select2-search.select2-search--inline,
#editRiskModal .select2-search.select2-search--inline {
    width: auto !important;
    display: inline-block !important;
}

#newRiskModal .select2-search.select2-search--inline .select2-search__field,
#editRiskModal .select2-search.select2-search--inline .select2-search__field {
    width: auto !important;
    min-width: 150px;
}

/* Container takes full width */
#newRiskModal .select2-container,
#editRiskModal .select2-container {
    width: 100% !important;
}

/* Match Bootstrap form-select styling for the selection box */
#newRiskModal .select2-container--default .select2-selection--multiple,
#editRiskModal .select2-container--default .select2-selection--multiple {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    min-height: 42px;
    padding: 5px 6px;
    background-color: #fff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

#newRiskModal .select2-container--default.select2-container--focus .select2-selection--multiple,
#editRiskModal .select2-container--default.select2-container--focus .select2-selection--multiple,
#newRiskModal .select2-container--default.select2-container--open .select2-selection--multiple,
#editRiskModal .select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
    outline: 0;
}

/* Selected tag styling */
#newRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice,
#editRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #5789bb;
    border: none;
    color: #fff;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 5px 10px 5px 30px;
}

/* Remove button on tags */
#newRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice__remove,
#editRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: rgba(255, 255, 255, 0.7);
    border-right: 1px solid #7fa9d4;
    font-weight: bold;
    padding: 5px 8px;
}

#newRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover,
#editRiskModal .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #fff;
    background: #274462;
}

/* Search input inside multi-select */
#newRiskModal .select2-container--default .select2-search--inline .select2-search__field,
#editRiskModal .select2-container--default .select2-search--inline .select2-search__field {
    margin-top: 4px;
    font-size: 0.875rem;
    color: #212529;
}

/* Dropdown styling */
#newRiskModal .select2-dropdown,
#editRiskModal .select2-dropdown,
.select2-container--open .select2-dropdown {
    border-color: #86b7fe;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* Search box in dropdown */
#newRiskModal .select2-container--default .select2-search--dropdown .select2-search__field,
#editRiskModal .select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Dropdown results */
#newRiskModal .select2-results__option,
#editRiskModal .select2-results__option {
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
}

#newRiskModal .select2-container--default .select2-results__option--highlighted[aria-selected],
#editRiskModal .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #0d6efd;
    color: #fff;
}

#newRiskModal .select2-container--default .select2-results__option[aria-selected="true"],
#editRiskModal .select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: #e9ecef;
    color: #212529;
}

/* Max height for dropdown results */
#newRiskModal .select2-container--default .select2-results > .select2-results__options,
#editRiskModal .select2-container--default .select2-results > .select2-results__options {
    max-height: 250px;
}

/* Ensure dropdown appears above modal content */
.modal-open .select2-container--open {
    z-index: 99999;
}

/* Delete risk modal - same styling as delete evidence modal (#deleteConfirmModal) */
#deleteRiskModal .modal-body,
#deleteRiskModal .modal-footer {
    text-align: center;
}
#deleteRiskModal .modal-body {
    padding: 25px 15px;
}
#deleteRiskModal .modal-footer {
    justify-content: center;
}
#deleteRiskModal #deleteRiskTitle {
    word-break: break-word;
}

/* Toast notifications */
.toast-container {
    z-index: 9999;
}

.toast {
    min-width: 250px;
}

.new-project-btn-container {
    width: 100%;
    display: flex;
    justify-content: end;       
}

.new-project-btn {
    margin-left: 0;
}

.risk-table .datatable-search input {
    width: 280px;
}

/* ============================================================
   Risk register header (projects-style: flex, left/right columns)
   ============================================================ */

.risk-register-header {
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

#risk-table-view .risk-register-header {
    border-bottom: 1px solid transparent;
}

.risk-header-left {
    flex: 1;
}

.risk-header-left input[type="search"] {
    border-radius: 4px;
    font-size: 14px;
    max-width: 280px;
}

.risk-header-left input[type="search"]:focus {
    outline: none;
    border-color: #0061f2;
    box-shadow: 0 0 0 2px rgba(0, 97, 242, 0.1);
}

/* ============================================================
   View toggle and chart view
   ============================================================ */

.view-toggle-btn {
    background: transparent;
    border: 1px solid #dee2e6;
    padding: 9px 12px;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-toggle-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.view-toggle-btn:last-child {
    border-radius: 0 4px 4px 0;
    border-left: none;
}

.view-toggle-btn:hover {
    background: #f8f9fa;
    color: #333;
}

.view-toggle-btn.active {
    background: #5589bb;
    border-color: #5589bb;
    color: #fff;
}

.view-toggle-group {
    display: inline-flex;
}

.risk-chart-header {
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

.risk-charts-row {
    margin-top: 0.5rem;
}

.risk-chart-card .card-header {
    text-align: center;
}

.risk-chart-card .card-body.risk-chart-wrapper {
    padding: 1rem;
}

.risk-chart-wrapper canvas {
    max-height: 280px;
}

/* ============================================================
   Responsive adjustments
   ============================================================ */

@media (max-width: 768px) {
    .risk-filter-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    .risk-filter-controls select {
        width: 100% !important;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

    #newRiskModal .modal-dialog,
    #editRiskModal .modal-dialog {
        margin: 0.5rem;
    }
}
