/**
 * App-wide: prevent button/icon/text overlap; keep modals and dropdowns closing cleanly.
 */

body .main-panel .btn,
body .content-wrapper .btn,
.modal .btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.4rem !important;
    white-space: normal !important;
    text-align: center !important;
    line-height: 1.25 !important;
    vertical-align: middle;
}

body .main-panel .btn i,
body .content-wrapper .btn i,
body .main-panel .btn .fa,
body .content-wrapper .btn .fa,
.modal .btn i {
    flex-shrink: 0 !important;
    line-height: 1 !important;
    margin: 0 !important;
}

body .main-panel .btn-sm,
body .content-wrapper .btn-sm {
    gap: 0.3rem !important;
    min-height: 2rem;
}

body .main-panel .page-header .btn,
body .content-wrapper .page-header .btn {
    flex-wrap: nowrap;
}

.modal-footer {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 0.5rem !important;
}

.modal-footer .btn {
    margin: 0 !important;
}

.modal-header .close,
.modal-header .btn-close {
    flex-shrink: 0;
    margin-left: auto;
}

/* Custom search select: text and chevron are separate flex children */
.custom-select-trigger {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.65rem !important;
    min-height: calc(1.5em + 0.75rem + 2px);
    background-image: none !important;
    padding-right: 0.75rem !important;
}

.custom-select-trigger-label {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

.custom-select-trigger-chevron {
    flex: 0 0 16px !important;
}

/* Assign elective & similar: checkbox + label text */
.modal .form-check,
.content-wrapper .form-check {
    margin-bottom: 0.65rem;
}

.modal .form-check .form-check-label.d-flex,
.content-wrapper .form-check .form-check-label.d-flex {
    gap: 0.55rem !important;
    align-items: flex-start !important;
    width: 100%;
}

.modal .form-check .form-check-label.d-flex .form-check-input,
.content-wrapper .form-check .form-check-label.d-flex .form-check-input {
    margin-top: 0.2rem !important;
}

.modal .form-check .form-check-label.d-flex > span,
.modal .form-check .form-check-label.d-flex > .subject-name {
    flex: 1;
    min-width: 0;
    line-height: 1.35;
    word-break: break-word;
}

/* Class subject & dashed action buttons */
.btn-add-outline,
.add-option-box,
[data-repeater-create].btn-add-outline {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.45rem !important;
    white-space: normal !important;
}

.add-option-box {
    text-align: center;
}

.group-header .btn-link {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.35rem !important;
    white-space: normal !important;
}

/* Keep dropdowns above rows but below modals */
.custom-select-dropdown.show {
    z-index: 1060;
}

.modal.show .custom-select-dropdown.show {
    z-index: 1065;
}

.modal-body {
    overflow-x: hidden;
    overflow-y: auto;
    max-height: calc(100vh - 12rem);
}

/* Class subject list: elective column text spacing */
.elective-subjects-cell {
    line-height: 1.5 !important;
    word-break: break-word;
    white-space: normal !important;
}

.elective-subjects-cell b {
    display: inline-block;
    margin-top: 0.15rem;
}

/* jQuery toast: long validation messages readable, no cramped overlap */
.jq-toast-wrap {
    max-width: min(440px, 94vw) !important;
}

.jq-toast-single {
    line-height: 1.45 !important;
    word-break: break-word !important;
    white-space: normal !important;
    padding: 14px 18px 14px 52px !important;
    min-height: 3rem;
}

.jq-toast-single h2 {
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    line-height: 1.45 !important;
    margin: 0 !important;
    white-space: normal !important;
    word-break: break-word !important;
}

/* Assign elective modal — checkbox before label, no theme input-helper overlap */
#editModal #available-subjects-list .assign-elective-subject-check {
    display: flex !important;
    align-items: flex-start !important;
    gap: 0.65rem !important;
    padding-left: 0 !important;
}

#editModal #available-subjects-list .assign-elective-subject-check .form-check-input {
    position: static !important;
    opacity: 1 !important;
    margin: 0.2rem 0 0 0 !important;
    flex-shrink: 0 !important;
    width: 1.05rem !important;
    height: 1.05rem !important;
}

#editModal #available-subjects-list .assign-elective-subject-check .form-check-label {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.4 !important;
    cursor: pointer;
}

/* Bootstrap-table toolbars: floating filter-menu must not overlap custom select / select2 */
.bootstrap-table .fixed-table-toolbar label.filter-menu,
.bootstrap-table .fixed-table-toolbar #toolbar label.filter-menu,
.content-wrapper #toolbar label.filter-menu {
    position: static !important;
    display: block !important;
    top: auto !important;
    left: auto !important;
    margin: 0 0 0.45rem 0 !important;
    margin-left: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    z-index: auto !important;
    border-radius: 0 !important;
    line-height: 1.35 !important;
}

.bootstrap-table .fixed-table-toolbar #toolbar .form-group,
.content-wrapper #toolbar .form-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding-top: 0 !important;
    margin-bottom: 1.1rem;
}

.bootstrap-table .fixed-table-toolbar #toolbar .custom-select-wrapper,
.content-wrapper #toolbar .custom-select-wrapper {
    width: 100%;
    margin-top: 0;
}

.bootstrap-table .fixed-table-toolbar #toolbar .custom-select-trigger,
.content-wrapper #toolbar .custom-select-trigger {
    min-height: calc(1.5em + 0.75rem + 2px);
    line-height: 1.5;
}

/* Toolbar selects use custom-search-select; hide stray select2 chrome if initialized */
.bootstrap-table .fixed-table-toolbar .custom-select-wrapper ~ .select2-container,
.content-wrapper #toolbar .custom-select-wrapper ~ .select2-container,
.bootstrap-table .fixed-table-toolbar .form-group:has(.custom-select-wrapper) .select2-container,
.content-wrapper #toolbar .form-group:has(.custom-select-wrapper) .select2-container {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
}
