/*
 * Bootstrap 3 -> 5 compatibility layer.
 *
 * The app moved to Bootstrap 5.3. Most of the markup needed no change, because the class names that
 * dominate these views survived: col-md-*, col-sm-*, row, container, table, form-control, btn,
 * btn-primary/danger/success, alert-*, text-*, modal, modal-dialog/content/header/body/footer and the
 * modal show/hide events are all still Bootstrap 5.
 *
 * A bounded set of classes did go away. Rather than hand-edit ~500 references across 31 views with no
 * test coverage, they are defined here in terms of Bootstrap 5. Each block says what it replaces, so
 * views can be modernised piecemeal later and the corresponding block deleted.
 *
 * NOTE: this is a shim, not a finished markup migration. The stack is genuinely Bootstrap 5 - it is
 * the view vocabulary that is still partly 3.x.
 */

/* ---------------------------------------------------------------------------
 * Panels -> cards. Bootstrap 5 renamed the component; the visual design here
 * comes from base/styles.css, which targets .panel*, so keep both working.
 * --------------------------------------------------------------------------- */
.panel {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    word-wrap: break-word;
    background-color: var(--bs-body-bg);
    background-clip: border-box;
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: var(--bs-border-radius);
    margin-bottom: 20px;
}

.panel-body {
    flex: 1 1 auto;
    padding: 15px;
}

/*
 * Structure only - no padding or border. The look, and the float-left title / float-right
 * panel-buttons layout, come from plugins/bootstrap-addons.css, which is still loaded.
 * The clearfix is repeated here so a plain .panel (no .panel-theme) also contains its floats.
 */
.panel-heading::after {
    display: block;
    clear: both;
    content: "";
}

.panel-title {
    margin: 0;
    font-size: 16px;
}

.panel-footer {
    padding: 10px 15px;
    border-top: 1px solid var(--bs-border-color-translucent);
}

/* ---------------------------------------------------------------------------
 * Forms. Bootstrap 5 dropped .form-group (it was margin only), .control-label,
 * .form-horizontal and .form-control-static.
 * --------------------------------------------------------------------------- */
.form-group {
    margin-bottom: 15px;
}

/* Bootstrap 3's .form-group carried the row behaviour inside .form-horizontal. */
.form-horizontal .form-group {
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(-0.5 * var(--bs-gutter-x, 1.5rem));
    margin-left: calc(-0.5 * var(--bs-gutter-x, 1.5rem));
}

.control-label {
    margin-bottom: 0;
    padding-top: calc(0.375rem + 1px);
    padding-bottom: calc(0.375rem + 1px);
    padding-right: 10px;
    font-weight: 500;
}

.form-horizontal .control-label {
    text-align: right;
}

@media (max-width: 767.98px) {
    /* Bootstrap 3 stacked and left-aligned these below the sm breakpoint. */
    .form-horizontal .control-label {
        text-align: left;
    }
}

.form-control-static {
    padding-top: calc(0.375rem + 1px);
    padding-bottom: calc(0.375rem + 1px);
    margin-bottom: 0;
    min-height: calc(1.5em + 0.75rem + 2px);
}

/* .has-error is set by modal.js when a required field is empty. */
.has-error .form-control {
    border-color: var(--bs-danger);
}

.has-error .control-label {
    color: var(--bs-danger);
}

/* ---------------------------------------------------------------------------
 * Input groups. .input-group-addon became .input-group-text.
 * --------------------------------------------------------------------------- */
.input-group-addon {
    display: flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--bs-secondary-color);
    text-align: center;
    white-space: nowrap;
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
}

.input-group > .input-group-addon:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    margin-right: -1px;
}

/* ---------------------------------------------------------------------------
 * Buttons. .btn-default is .btn-secondary in Bootstrap 5, and .btn-xs was
 * dropped entirely (only btn-sm and btn-lg remain). The grid action columns are
 * sized for xs buttons, so the Bootstrap 3 metrics are reproduced here.
 * --------------------------------------------------------------------------- */
.btn-xs {
    --bs-btn-padding-y: 1px;
    --bs-btn-padding-x: 5px;
    --bs-btn-font-size: 12px;
    --bs-btn-line-height: 1.5;
    --bs-btn-border-radius: 3px;
}

.btn-default {
    --bs-btn-color: #333;
    --bs-btn-bg: #fff;
    --bs-btn-border-color: #ccc;
    --bs-btn-hover-color: #333;
    --bs-btn-hover-bg: #e6e6e6;
    --bs-btn-hover-border-color: #adadad;
    --bs-btn-active-color: #333;
    --bs-btn-active-bg: #dbdbdb;
    --bs-btn-active-border-color: #adadad;
    --bs-btn-disabled-color: #333;
    --bs-btn-disabled-bg: #fff;
    --bs-btn-disabled-border-color: #ccc;
}

/* ---------------------------------------------------------------------------
 * Checkbox wrappers. Bootstrap 3's .checkbox laid out a checkbox and its label;
 * Bootstrap 5 replaced it with .form-check, which needs classes on the input and
 * label too. bootstrap-checkbox.css does NOT cover this - it only styles its own
 * .cbx-* widget - so without this the wrappers collapse to no spacing.
 * --------------------------------------------------------------------------- */
.checkbox {
    display: block;
    min-height: 20px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.checkbox label {
    display: inline;
    font-weight: 400;
    cursor: pointer;
}

.checkbox input[type="checkbox"] {
    margin-right: 6px;
    vertical-align: middle;
}

/* ---------------------------------------------------------------------------
 * Input groups. Bootstrap 5 expects buttons as direct children of .input-group
 * and removed the .input-group-btn wrapper, so the button inside one gets none of
 * the seam handling. display:contents takes the wrapper out of the flex layout,
 * then the radius and overlap rules are applied to the button itself.
 * --------------------------------------------------------------------------- */
.input-group > .input-group-btn {
    display: contents;
}

.input-group > .input-group-btn > .btn {
    position: relative;
    margin-left: calc(var(--bs-border-width, 1px) * -1);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.input-group > .input-group-btn:not(:last-child) > .btn {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* ---------------------------------------------------------------------------
 * Inline lists. Bootstrap 3 made every child of .list-inline inline-block;
 * Bootstrap 5 requires .list-inline-item on each <li> instead, so without this
 * the items stack vertically.
 *
 * Padding is intentionally the Bootstrap 3 value. Where a component sets its own
 * (e.g. .report-statistics li in views/site.css, which loads after this file and
 * has equal specificity), that one still wins - as it did under Bootstrap 3.
 * --------------------------------------------------------------------------- */
.list-inline > li {
    display: inline-block;
    padding-right: 5px;
    padding-left: 5px;
}

/* ---------------------------------------------------------------------------
 * Float and offset helpers.
 * --------------------------------------------------------------------------- */
.pull-right { float: right !important; }
.pull-left { float: left !important; }

.col-md-offset-1 { margin-left: 8.33333333%; }
.col-md-offset-2 { margin-left: 16.66666667%; }
.col-md-offset-3 { margin-left: 25%; }
.col-sm-offset-2 { margin-left: 16.66666667%; }

/* ---------------------------------------------------------------------------
 * Responsive visibility. Bootstrap 5 uses .d-none / .d-{bp}-block instead.
 * --------------------------------------------------------------------------- */
/* From the dropped bootstrap-addons.css: opt an element back in as inline-block above xs. */
.hidden-xs.hidden-xs-inline {
    display: inline-block !important;
}

@media (max-width: 767.98px) {
    .hidden-xs.hidden-xs-inline,
    .hidden-xs { display: none !important; }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .hidden-sm { display: none !important; }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .hidden-md { display: none !important; }
}

/* Bootstrap 5 removed the bare .hidden utility in favour of .d-none. */
.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
 * Print visibility. These came from Bootstrap 3; views/print.css builds on them.
 * --------------------------------------------------------------------------- */
.visible-print { display: none !important; }

@media print {
    .hidden-print { display: none !important; }
    .visible-print { display: block !important; }
    img.visible-print { display: inline-block !important; }
}

/* ---------------------------------------------------------------------------
 * Close buttons. Bootstrap 5 replaced .close with .btn-close, which draws its
 * own SVG glyph rather than taking a &times; child.
 * --------------------------------------------------------------------------- */
.close {
    float: right;
    padding: 0;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
    color: #000;
    text-shadow: 0 1px 0 #fff;
    background: transparent;
    border: 0;
    opacity: 0.5;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    opacity: 0.75;
}
