/* ===== Thresholds Page Styles ===== */

/* Page Header */
.thresholds-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
/* make Select2 look like Bootstrap form-control */

/* Make Select2 match Bootstrap form-control */
/* Select2 container same width as field */
.select2-selection {
    height: 38px !important;
    display: block;
    width: 100%;
    border: 1px solid #e5e7eb !important;
    border-radius: 8px !important;
    font-size: 0.9rem !important;
    color: #374151 !important;
    background-color: #fff !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
    padding: 6px 0px 0px 4px;
}

.select2-container--default .select2-results__option {
    font-family: inherit; /* same font as page */
    font-size: 14px; /* same as Bootstrap dropdown */
    color: #212529; /* default text color */
    padding: 5px 5px; /* match option spacing */
    line-height: 1.5;
}

/* Hover / active option */
.select2-container--default .select2-results__option--highlighted {
    background-color: #2f6fcd; /* blue like operator */
    color: #fff;
}

/* Selected option */
.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: #2f6fcd;
    color: #fff;
}

/* Dropdown container */
.select2-dropdown {
    border: 1px solid #ced4da;
    border-radius: .375rem;
}

/* Match scroll spacing */
.select2-results__options {
    max-height: 300px;
    padding: 0;
}

.modal-threshold .select2-dropdown .select2-results {
    height: auto !important;
    min-height: 0 !important;
}

.select2-container--default .select2-results > .select2-results__options {
    max-height: 300px !important;
    height: auto !important;
    min-height: 0 !important;
    overflow-y: auto;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    top: 5px !important;
}

/*-----------------------*/
.thresholds-header h1 {
    margin: 0;
}

.btn-add-threshold {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: #1A445A;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

    .btn-add-threshold:hover {
        background-color: #153a4d;
        color: #fff;
    }

    .btn-add-threshold i {
        font-size: 1rem;
    }

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.summary-card {
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.summary-card-content h3 {
    font-size: 0.9rem;
    font-weight: 500;
    color: #6b7280;
    margin: 0 0 20px 0;
}

.summary-card-value {
    font-size: 2.15rem;
    font-weight: 700;
    color: #111827;
    line-height: 1;
    margin-bottom: 10px;
}

.summary-card-subtitle {
    font-size: 0.9rem;
    color: #939393;
    margin: 0;
}

.summary-card-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 1.25rem;
}

/* Filter Section */
.filters-section {
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

.filters-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 12px;
    align-items: center;
}

.search-box {
    position: relative;
    flex: 0 1 280px;
    min-width: 0;
}

    .search-box i {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: #9ca3af;
        font-size: 1rem;
    }

    .search-box input {
        width: 100%;
        padding: 10px 14px 10px 40px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        font-size: 0.9rem;
        color: #374151;
        background-color: #fff;
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }

        .search-box input::placeholder {
            color: #9ca3af;
        }

        .search-box input:focus {
            outline: none;
            border-color: #1A445A;
            box-shadow: 0 0 0 3px rgba(26, 68, 90, 0.1);
        }

.filter-dropdowns {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    margin-left: auto;
    align-items: center;
    flex: 1 1 auto;
    justify-content: flex-end;
}

.filter-dropdown,
.custom-dropdown {
    position: relative;
    min-width: 0;
    flex: 0 1 160px;
}

    .filter-dropdown select {
        width: 100%;
        padding: 10px 36px 10px 14px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        font-size: 0.9rem;
        color: #374151;
        background-color: #fff;
        cursor: pointer;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        transition: border-color 0.2s ease;
    }

        .filter-dropdown select:focus {
            outline: none;
            border-color: #1A445A;
        }

/* Table Section */
.table-section {
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    overflow: hidden;
}

.table-container {
    position: relative;
}

.thresholds-table {
    width: 100%;
    border-collapse: collapse;
}

    .thresholds-table thead {
        background-color: #E1ECF2;
    }

        .thresholds-table thead th {
            padding: 14px 16px;
            text-align: left;
            font-size: 0.85rem;
            font-weight: 600;
            white-space: nowrap;
        }

            .thresholds-table thead th:last-child {
                cursor: default;
            }

    .thresholds-table tbody tr {
        border-bottom: 1px solid #f3f4f6;
        transition: background-color 0.15s ease;
    }

        .thresholds-table tbody tr:hover {
            background-color: #f9fafb;
        }

        .thresholds-table tbody tr:last-child {
            border-bottom: none;
        }

    .thresholds-table tbody td {
        padding: 14px 16px;
        font-size: 0.9rem;
        color: #374151;
        vertical-align: middle;
    }

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

    .toggle-switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #9ca3af;
    transition: 0.3s;
    border-radius: 24px;
}

    .toggle-slider:before {
        position: absolute;
        content: "";
        height: 18px;
        width: 18px;
        left: 3px;
        bottom: 3px;
        background-color: #fff;
        transition: 0.3s;
        border-radius: 50%;
    }

.toggle-switch input:checked + .toggle-slider {
    background-color: #2A9D8F;
}

    .toggle-switch input:checked + .toggle-slider:before {
        transform: translateX(20px);
    }

.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.6;
    cursor: not-allowed;
}

.toggle-switch.disabled {
    cursor: not-allowed;
}

    .toggle-switch.disabled .toggle-slider {
        opacity: 0.6;
        cursor: not-allowed;
    }

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background-color: transparent;
    color: #6b7280;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

    .btn-action:hover {
        background-color: #f3f4f6;
        color: #374151;
    }

    .btn-action.btn-edit:hover {
        color: #1A445A;
    }

    .btn-action.btn-delete:hover {
        color: #ef4444;
    }

    .btn-action.btn-disabled,
    .btn-action.btn-disabled:hover {
        color: #d1d5db;
        cursor: not-allowed;
        background-color: transparent;
    }

    .btn-action i {
        font-size: 1rem;
    }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

    .empty-state i {
        font-size: 3rem;
        margin-bottom: 16px;
        opacity: 0.5;
    }

    .empty-state h4 {
        font-size: 1.1rem;
        font-weight: 600;
        color: #374151;
        margin-bottom: 8px;
    }

    .empty-state p {
        font-size: 0.9rem;
        margin: 0;
    }

/* Custom Searchable Dropdown */
.custom-dropdown {
    min-width: 180px;
}

.custom-dropdown-toggle {
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #374151;
    background-color: #fff;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.2s ease;
}

    .custom-dropdown-toggle:hover {
        border-color: #d1d5db;
    }

    .custom-dropdown-toggle:focus {
        outline: none;
        border-color: #1A445A;
    }

.custom-dropdown.open .custom-dropdown-toggle {
    border-color: #1A445A;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.custom-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1050;
    background-color: #fff;
    border: 1px solid #1A445A;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 230px;
    overflow: hidden;
    flex-direction: column;
}

.custom-dropdown.open .custom-dropdown-menu {
    display: flex;
}

.custom-dropdown-search {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

    .custom-dropdown-search input {
        width: 100%;
        padding: 8px 12px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        font-size: 0.85rem;
        color: #374151;
        background-color: #f9fafb;
    }

        .custom-dropdown-search input::placeholder {
            color: #9ca3af;
        }

        .custom-dropdown-search input:focus {
            outline: none;
            border-color: #1A445A;
            background-color: #fff;
        }

.custom-dropdown-list {
    overflow-y: auto;
    max-height: 220px;
    flex: 1;
}

.custom-dropdown-item {
    padding: 10px 14px;
    font-size: 0.9rem;
    color: #374151;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .custom-dropdown-item:hover {
        background-color: #f3f4f6;
    }

    .custom-dropdown-item.selected {
        background-color: #E1ECF2;
        color: #1A445A;
        font-weight: 500;
    }

    .custom-dropdown-item.hidden {
        display: none;
    }

.custom-dropdown-empty {
    padding: 16px 14px;
    font-size: 0.85rem;
    color: #9ca3af;
    text-align: center;
}

/* Responsive */
/* Large tablets and smaller desktops (992px - 1199px) */
@media (max-width: 1199.98px) {
    .filters-row {
        gap: 8px;
    }

    .search-box {
        flex: 0 1 180px;
    }

    .filter-dropdowns {
        gap: 6px;
    }

    .filter-dropdown,
    .custom-dropdown {
        flex: 0 1 140px;
    }

    .filter-dropdown select,
    .custom-dropdown-toggle {
        padding: 9px 30px 9px 10px;
        font-size: 0.8rem;
    }

    .search-box input {
        padding: 9px 12px 9px 36px;
        font-size: 0.8rem;
    }

    .search-box i {
        left: 12px;
        font-size: 0.9rem;
    }
}

/* Tablets (768px - 991px) */
@media (max-width: 991.98px) {
    .filters-row {
        flex-wrap: wrap;
        gap: 12px;
    }

    .search-box {
        flex: 1 1 100%;
        max-width: 100%;
    }

    .search-box input {
        padding: 10px 14px 10px 40px;
        font-size: 0.9rem;
    }

    .search-box i {
        left: 14px;
        font-size: 1rem;
    }

    .filter-dropdowns {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 10px;
    }

    .filter-dropdown,
    .custom-dropdown {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
    }

    .filter-dropdown select,
    .custom-dropdown-toggle {
        padding: 10px 36px 10px 14px;
        font-size: 0.9rem;
    }
}

/* Small tablets and large phones (576px - 767px) */
@media (max-width: 767.98px) {
    .thresholds-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .summary-cards {
        grid-template-columns: 1fr;
    }

    .filters-row {
        flex-direction: column;
        gap: 10px;
    }

    .search-box {
        width: 100%;
        flex: none;
    }

    .filter-dropdowns {
        width: 100%;
        flex-wrap: nowrap;
        gap: 10px;
    }

    .filter-dropdown,
    .custom-dropdown {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
    }

    .custom-dropdown-menu {
        max-height: 240px;
    }

    .custom-dropdown-list {
        max-height: 180px;
    }

    .thresholds-table {
        display: block;
        overflow-x: auto;
    }
}

/* Mobile phones (< 576px) */
@media (max-width: 575.98px) {
    .filters-section {
        padding: 16px;
    }

    .filters-row {
        flex-direction: column;
        gap: 10px;
    }

    .search-box {
        width: 100%;
        flex: none;
    }

    .filter-dropdowns {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .filter-dropdown,
    .custom-dropdown {
        width: 100%;
        flex: none;
    }

    .filter-dropdown select,
    .custom-dropdown-toggle {
        width: 100%;
        padding: 12px 36px 12px 14px;
        font-size: 0.9rem;
    }
}

/* Delete Confirmation Modal */
.modal-delete .modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-delete .modal-header {
    border-bottom: none;
    padding: 24px 24px 0 24px;
}

.modal-delete .modal-title {
    font-weight: 600;
    font-size: 1.25rem;
    color: #111827;
}

.modal-delete .modal-body {
    padding: 16px 24px;
}

    .modal-delete .modal-body p {
        color: #374151;
        font-size: 0.95rem;
        margin: 0;
        line-height: 1.5;
    }

    .modal-delete .modal-body #deleteThresholdName {
        word-break: break-word;
    }

.modal-delete .modal-footer {
    border-top: none;
    padding: 0 24px 24px 24px;
    gap: 12px;
}

.btn-confirm-delete {
    padding: 12px 24px;
    background-color: #1A445A;
    border: none;
    color: #fff;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}

    .btn-confirm-delete:hover {
        background-color: #153a4d;
        color: #fff;
    }

.btn-cancel {
    padding: 12px 24px;
    background-color: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}

    .btn-cancel:hover {
        background-color: #f9fafb;
        border-color: #9ca3af;
    }

/* ===== Threshold Form Modal ===== */
.modal-threshold .modal-dialog {
    max-width: 600px;
}

.modal-threshold .modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-threshold .modal-header {
    border-bottom: none;
    padding: 24px 24px 0 24px;
}

.modal-threshold .modal-title {
    font-weight: 600;
    font-size: 1.25rem;
    color: #111827;
}

.modal-threshold .modal-body {
    padding: 20px 24px;
}

.modal-threshold .modal-footer {
    border-top: none;
    padding: 0 24px 24px 24px;
    justify-content: flex-start;
    gap: 12px;
}

/* Form Grid Layout */
.threshold-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
}

    .threshold-form-grid .form-group {
        display: flex;
        flex-direction: column;
    }

        .threshold-form-grid .form-group.full-width {
            grid-column: 1 / -1;
        }

        .threshold-form-grid .form-group label {
            font-size: 0.85rem;
            font-weight: 500;
            color: #374151;
            margin-bottom: 6px;
        }

    .threshold-form-grid .form-control {
        width: 100%;
        padding: 10px 14px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        font-size: 0.9rem;
        color: #374151;
        background-color: #fff;
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }

        .threshold-form-grid .form-control::placeholder {
            color: #9ca3af;
        }

        .threshold-form-grid .form-control:focus {
            outline: none;
            border-color: #1A445A;
            box-shadow: 0 0 0 3px rgba(26, 68, 90, 0.1);
        }

.was-validated .threshold-form-grid .form-control:invalid {
    border-color: #d30216;
    background-image: none;
}

.form-control.is-invalid {
    border-color: #d30216;
    background-image: none;
}

.was-validated .threshold-form-grid .form-control:invalid:focus {
    border-color: #d30216;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.was-validated .threshold-form-grid .form-control:valid {
    border-color: #e5e7eb;
    background-image: none;
}

.modal-threshold .form-check-label,
.modal-threshold .was-validated .form-check-input:valid ~ .form-check-label,
.modal-threshold .form-check-input.is-valid ~ .form-check-label {
    color: #374151;
}

.modal-threshold .was-validated .form-check-input:valid,
.modal-threshold .form-check-input.is-valid {
    border-color: #1A445A;
}

.threshold-form-grid select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Duration Input with Badge */
.duration-input-group {
    display: flex;
    align-items: stretch;
}

    .duration-input-group .form-control {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        flex: 1;
    }

.was-validated .duration-input-group .form-control:invalid {
    border-color: #ef4444;
}

    .was-validated .duration-input-group .form-control:invalid + .duration-badge {
        border-color: #ef4444;
    }

.duration-badge {
    display: flex;
    align-items: center;
    padding: 0 14px;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-left: none;
    border-radius: 0 8px 8px 0;
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: 500;
}

/* Alert Levels Section */
.alert-levels-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.alert-levels-title {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    margin: 0 0 4px 0;
}

.alert-levels-description {
    font-size: 0.85rem;
    color: #6b7280;
    margin: 0 0 16px 0;
}

/* Form Buttons */
.btn-primary-threshold {
    padding: 12px 24px;
    background-color: #1A445A;
    border: none;
    color: #fff;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}

    .btn-primary-threshold:hover {
        background-color: #153a4d;
        color: #fff;
    }

/* Form Validation Message */
.form-validation-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 0.9rem;
}

.form-validation-message i {
    font-size: 1rem;
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 575.98px) {
    .modal-threshold .modal-dialog {
        margin: 16px;
        max-width: calc(100% - 32px);
    }

    .threshold-form-grid {
        grid-template-columns: 1fr;
    }

        .threshold-form-grid .form-group.full-width {
            grid-column: 1;
        }
}
