/* ==========================================================================
   MTN NG portal - shared form field styles
   --------------------------------------------------------------------------
   Single source of truth for field shape, labels, and outline / focus /
   active / focus-within colours. Linked only by MTN NG entry points, after
   all page and vendor CSS so it wins equal-specificity ties.

   To re-brand every form, change --mtn-blue and keep --mtn-blue-rgb in sync.
   Specificity is intentional. The only force-override is the selected
   Select2 option rule, which must beat page-level !important themes.
   ========================================================================== */

:root {
    --mtn-blue: #26A9E0;
    --mtn-blue-rgb: 38, 169, 224;

    --form-focus-color: var(--mtn-blue);
    --form-focus-ring-color: rgba(var(--mtn-blue-rgb), 0.25);
    --form-focus-ring-width: 0.2rem;

    /* Field shape - mirrors the service creation form */
    --form-border-color: #e0e0e0;
    --form-border-width: 2px;
    --form-radius: 10px;
    --form-padding-y: 0.75rem;
    --form-padding-x: 1rem;

    /* Field labels */
    --form-label-color: var(--mtn-grey, #4A4A4A);
    --form-label-weight: 600;
    --form-label-spacing: 0.5rem;

    /* Selected option inside Select2 dropdowns */
    --form-selected-bg: rgba(var(--mtn-blue-rgb), 0.2);
    --form-selected-color: var(--mtn-dark, #000);
    --form-option-weight: 600;
}

/* --------------------------------------------------------------------------
   Field shape and labels
   :where() keeps specificity at (0,1,0), so Bootstrap's floating-label
   geometry (0,2,0) and .is-invalid borders (0,2,0) still win.
   -------------------------------------------------------------------------- */
/* Border shape applies to size variants too, so every field matches. */
.form-control,
.form-select,
.toolbar-select {
    border-width: var(--form-border-width);
    border-color: var(--form-border-color);
    border-radius: var(--form-radius);
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, transform 0.3s ease;
}

/* Default-size padding only, so .form-control-sm / .form-control-lg stay compact. */
.form-control:where(:not(.form-control-sm, .form-control-lg)),
.form-select:where(:not(.form-select-sm, .form-select-lg)) {
    padding: var(--form-padding-y) var(--form-padding-x);
}

/* Leave room for the native select arrow */
.form-select:where(:not(.form-select-sm, .form-select-lg)) {
    padding-right: 2.25rem;
}

/* Keep add-ons the same height and outer radius as their control */
.input-group-text {
    border-width: var(--form-border-width);
    border-radius: var(--form-radius);
    padding: var(--form-padding-y) var(--form-padding-x);
}

/* Overlap adjacent 2px borders by the border width, not Bootstrap's 1px */
.input-group> :where(.form-control, .form-select, .input-group-text):not(:first-child) {
    margin-left: calc(-1 * var(--form-border-width));
}

/* Select2 renders its own dropdown box; give it the same border shape. */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    border-width: var(--form-border-width);
    border-color: var(--form-border-color);
    border-radius: var(--form-radius);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding-left: var(--form-padding-x);
    padding-right: 2.25rem;
}

.form-label {
    color: var(--form-label-color);
    font-weight: var(--form-label-weight);
    margin-bottom: var(--form-label-spacing);
}

.form-floating label {
    font-weight: var(--form-label-weight);
}

/* --------------------------------------------------------------------------
   Bootstrap controls
   Kept at (0,2,0) specificity so Bootstrap's .is-invalid:focus (0,3,0) and
   .was-validated :invalid:focus (0,4,0) rules keep their red border and ring.
   -------------------------------------------------------------------------- */
.form-control:focus,
.form-control:focus-visible,
.form-control:active,
.form-select:focus,
.form-select:focus-visible,
.form-select:active,
.toolbar-select:focus,
.toolbar-select:focus-visible,
.toolbar-select:active,
.form-check-input:focus,
.form-check-input:focus-visible,
.form-check-input:active {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* Floating labels: :where() keeps the specificity at (0,2,0) so the invalid
   state above still wins. */
.form-floating> :where(.form-control, .form-select):focus,
.form-floating> :where(.form-control, .form-select):focus-visible,
.form-floating> :where(.form-control, .form-select):active {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* Floating labels follow the field while it is focused. */
.form-control:focus~label,
.form-select:focus~label,
.form-floating> .form-control:focus~label,
.form-floating> .form-select:focus~label {
    color: var(--form-focus-color);
}

/* Input groups: colour the addon and the control. The ring comes from the
   field rules above; :where() keeps specificity at (0,2,0). */
.input-group:focus-within :where(.form-control, .form-select, .input-group-text) {
    border-color: var(--form-focus-color);
}

/* --------------------------------------------------------------------------
   Select2 v4 (single, multiple, dropdown search)
   The inline search field is intentionally excluded: it has no border and
   would draw a ring inside the selection box.
   -------------------------------------------------------------------------- */
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default .select2-selection--single:focus,
.select2-container--default .select2-selection--multiple:focus,
.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-width: var(--form-border-width);
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* Selected option inside any Select2 dropdown.
   This is the one deliberate force-override in this file: the analytics
   page stylesheet sets its own selected colours with !important. */
body .select2-container--default .select2-results__option.select2-results__option--selected,
body .select2-dropdown .select2-results__option.select2-results__option--selected,
body .select2-results__option.select2-results__option--selected,
body .select2-results__option.is-selected-item,
body .select2-results__option.force-selected-style,
.select2-results__option.select2-results__option--selected,
.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--form-selected-bg) !important;
    background-image: none !important;
    color: var(--form-selected-color) !important;
    border-left-color: transparent !important;
    box-shadow: none !important;
    font-weight: var(--form-option-weight) !important;
}

body .select2-results__option.select2-results__option--selected:hover,
body .select2-results__option.is-selected-item:hover,
body .select2-results__option.force-selected-style:hover {
    background-color: var(--form-selected-bg) !important;
    background-image: none !important;
    color: var(--form-selected-color) !important;
    border-left-color: transparent !important;
    box-shadow: none !important;
    font-weight: var(--form-option-weight) !important;
}

/* Hovered / keyboard-focused option: keep the text legible. */
body .select2-dropdown .select2-results__option--highlighted,
body .select2-dropdown .select2-results__option.select2-results__option--highlighted {
    font-weight: var(--form-option-weight) !important;
}

/* Tick before the label of the selected option, for every Select2 dropdown on
   MTN pages — both the shared initializer and page-specific inits (audit logs,
   analytics toolbars, etc.). Only .select2-results__option--selected is used:
   Select2 also sets aria-selected="true" on the merely highlighted
   (hover/keyboard) option, which must not get a tick. The first rule reserves
   the tick's column for every option so labels stay aligned, and the colour
   follows the shared theme because page stylesheets paint the tick white. */
body .select2-results__option {
    padding-left: 1.5rem !important;
    font-weight: var(--form-option-weight) !important;
    color: #495057;
    font-size: 14px;
}

body .select2-results__option.select2-results__option--selected {
    position: relative !important;
}

body .select2-results__option.select2-results__option--selected::before {
    content: '✓';
    position: absolute !important;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--form-selected-color) !important;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Select2 fields converted by public/js/mtnng/select2-init.js.
   Scoped with .mtnng-select2 so page-specific Select2 instances keep their
   current sizing.
   -------------------------------------------------------------------------- */
select.mtnng-select2 + .select2-container {
    margin: 0;
}

/* Default-size fields: 1.5rem line + 0.75rem padding + 2px borders = 52px */
select.mtnng-select2.form-select:not(.form-select-sm):not(.toolbar-select) + .select2-container .select2-selection--single,
select.mtnng-select2.form-control:not(.form-control-sm):not(.toolbar-select) + .select2-container .select2-selection--single {
    height: calc(1.5rem + (var(--form-padding-y) * 2) + (var(--form-border-width) * 2));
}

select.mtnng-select2.form-select:not(.form-select-sm):not(.toolbar-select) + .select2-container .select2-selection__rendered,
select.mtnng-select2.form-control:not(.form-control-sm):not(.toolbar-select) + .select2-container .select2-selection__rendered {
    line-height: calc(1.5rem + (var(--form-padding-y) * 2));
}

/* Small fields */
select.mtnng-select2.form-select-sm + .select2-container .select2-selection--single,
select.mtnng-select2.form-control-sm + .select2-container .select2-selection--single {
    height: calc(1.3125rem + 0.5rem + (var(--form-border-width) * 2));
}

select.mtnng-select2.form-select-sm + .select2-container .select2-selection__rendered,
select.mtnng-select2.form-control-sm + .select2-container .select2-selection__rendered {
    line-height: calc(1.3125rem + 0.5rem);
    padding-left: 0.5rem;
    padding-right: 1.5rem;
    font-size: 0.875rem;
}

/* Compact toolbar filters */
select.mtnng-select2.toolbar-select + .select2-container .select2-selection--single {
    height: 38px;
}

select.mtnng-select2.toolbar-select + .select2-container .select2-selection__rendered {
    line-height: 36px;
    padding-left: 0.8rem;
    padding-right: 2.1rem;
    font-size: 0.875rem;
}

select.mtnng-select2 + .select2-container .select2-selection--single .select2-selection__arrow {
    top: 0;
    height: 100%;
    right: 0.75rem;
}

/* Navbar language selector: compact Select2 box matching the header. */
/* The opened panel is attached inside this wrapper (select2-init.js) rather
   than portaled to <body>, so the wrapper must be its positioning context. */
.language-selector-wrapper {
    position: relative;
}

select.mtnng-select2.language-selector + .select2-container .select2-selection--single {
    height: 38px;
}

select.mtnng-select2.language-selector + .select2-container .select2-selection__rendered {
    line-height: 36px;
    padding-left: 0.75rem;
    padding-right: 2rem;
    font-size: 0.85rem;
    font-weight: 500;
}

select.mtnng-select2.language-selector + .select2-container .select2-selection--single .select2-selection__arrow {
    top: 0;
    height: 100%;
    right: 0.5rem;
}

/* DataTables page-length control: compact Select2 box matching the toolbar. */
.dataTables_length .select2-container {
    width: 90px !important;
    min-width: 90px;
}

/* Standard form selects inside modals: match the common field height even
   when the page initialises Select2 itself (e.g. banner / campaign modals). */
.modal select.form-select:not(.form-select-sm) + .select2-container .select2-selection--single,
.modal select.form-control:not(.form-control-sm) + .select2-container .select2-selection--single {
    height: calc(1.5rem + (var(--form-padding-y) * 2) + (var(--form-border-width) * 2));
}

.modal select.form-select:not(.form-select-sm) + .select2-container .select2-selection__rendered,
.modal select.form-control:not(.form-control-sm) + .select2-container .select2-selection__rendered {
    line-height: calc(1.5rem + (var(--form-padding-y) * 2));
    padding-left: var(--form-padding-x);
    padding-right: 2.25rem;
}

.modal select.form-select:not(.form-select-sm) + .select2-container .select2-selection--single .select2-selection__arrow,
.modal select.form-control:not(.form-control-sm) + .select2-container .select2-selection--single .select2-selection__arrow {
    top: 0;
    height: 100%;
    right: 0.75rem;
}

/* Invalid state */
select.mtnng-select2.is-invalid + .select2-container .select2-selection--single,
select.mtnng-select2.is-invalid + .select2-container .select2-selection--multiple,
.was-validated select.mtnng-select2:invalid + .select2-container .select2-selection--single,
.was-validated select.mtnng-select2:invalid + .select2-container .select2-selection--multiple {
    border-color: #dc3545;
}

select.mtnng-select2.is-invalid + .select2-container.select2-container--focus .select2-selection--single,
select.mtnng-select2.is-invalid + .select2-container.select2-container--open .select2-selection--single,
.was-validated select.mtnng-select2:invalid + .select2-container.select2-container--focus .select2-selection--single {
    border-color: #dc3545;
    box-shadow: 0 0 0 var(--form-focus-ring-width) rgba(220, 53, 69, 0.25);
}

/* Hide the allowClear "x" while the blank / "All" option is selected. */
.select2-container.mtnng-select2-blank-option:not(.mtnng-select2-has-value) .select2-selection__clear {
    display: none;
}

.select2-dropdown {
    z-index: 1049;
}

/* Dropdown skin shared by every converted select */
.mtnng-select2-dropdown {
    border: var(--form-border-width) solid var(--form-border-color);
    border-radius: var(--form-radius);
    overflow: hidden;
}

.mtnng-select2-dropdown .select2-search--dropdown {
    padding: 0.5rem;
}

.mtnng-select2-dropdown .select2-search--dropdown .select2-search__field {
    border: var(--form-border-width) solid var(--form-border-color);
    border-radius: var(--form-radius);
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    outline: 0;
}

.mtnng-select2-dropdown .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--form-focus-color);
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

.mtnng-select2-dropdown .select2-results__option {
    padding: 0.5rem 0.75rem;
}

.mtnng-select2-dropdown .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--mtn-blue);
    color: #fff;
}

/* Keep Select2 dropdowns above Bootstrap 5 modals */
.modal .select2-container--open .select2-dropdown {
    z-index: 1057;
}

/* --------------------------------------------------------------------------
   DataTables filter + length controls
   -------------------------------------------------------------------------- */
.dataTables_filter input:focus,
.dataTables_filter input:focus-visible,
.dataTables_length select:focus,
.dataTables_length select:focus-visible {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* --------------------------------------------------------------------------
   Language selector (overrides the shared language-selector.css on MTN pages)
   -------------------------------------------------------------------------- */
.language-selector:focus,
.language-selector:focus-visible,
.language-selector:active {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* --------------------------------------------------------------------------
   Selects and checkboxes that were never given Bootstrap form classes
   -------------------------------------------------------------------------- */
select:focus,
select:focus-visible,
select:active,
input[type="checkbox"]:focus,
input[type="checkbox"]:focus-visible,
input[type="checkbox"]:active,
input[type="radio"]:focus,
input[type="radio"]:focus-visible,
input[type="radio"]:active {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* --------------------------------------------------------------------------
   Visual OTP boxes. .filled is styled by the page; exclude the custom .error
   state so its red treatment survives.
   -------------------------------------------------------------------------- */
.otp-inputs input:focus,
.otp-inputs input:focus-visible,
.otp-inputs input:active,
.otp-inputs input.filled:not(.error):focus,
.otp-inputs input.filled:not(.error):focus-visible {
    border-color: var(--form-focus-color);
    outline: 0;
    box-shadow: 0 0 0 var(--form-focus-ring-width) var(--form-focus-ring-color);
}

/* --------------------------------------------------------------------------
   Error / valid states
   Bootstrap only sets the shadow for .form-check-input, and its plain
   .form-control:active / .form-check-input:active border is overridden by
   the rules above, so re-assert the semantic colours explicitly.
   -------------------------------------------------------------------------- */
.form-control.is-invalid:active,
.form-control.is-invalid:focus-visible,
.form-select.is-invalid:active,
.form-select.is-invalid:focus-visible,
.form-check-input.is-invalid:focus,
.form-check-input.is-invalid:focus-visible,
.form-check-input.is-invalid:active,
.was-validated .form-control:invalid:active,
.was-validated .form-select:invalid:active,
.was-validated .form-check-input:invalid:focus,
.otp-inputs input.error:focus,
.otp-inputs input.error:focus-visible {
    border-color: #dc3545;
    box-shadow: 0 0 0 var(--form-focus-ring-width) rgba(220, 53, 69, 0.25);
}

.form-check-input.is-valid:focus,
.form-check-input.is-valid:focus-visible,
.form-check-input.is-valid:active,
.was-validated .form-check-input:valid:focus {
    border-color: #198754;
    box-shadow: 0 0 0 var(--form-focus-ring-width) rgba(25, 135, 84, 0.25);
}

/* --------------------------------------------------------------------------
   Chart canvases
   Chart.js canvases in the analytics pages are given only a CSS height in the
   markup (e.g. style="height: 300px"). Until the chart initialises, the canvas
   keeps its intrinsic 2:1 ratio and renders ~600px wide, overflowing its card
   and showing a horizontal scrollbar while the page loads. Clamp it so the
   placeholder never exceeds its container; Chart.js still controls the exact
   pixel size once it renders.
   -------------------------------------------------------------------------- */
canvas {
    max-width: 100%;
}

/* --------------------------------------------------------------------------
   Page-load overflow guard
   Pages can briefly overflow horizontally before their widgets initialise
   (DataTables columns, Chart.js canvases, Select2 fields, network-loading
   CSS). That shows a horizontal scrollbar on navigation which disappears once
   the page is ready. `clip` removes the page-level scrollbar without creating
   a scroll container, so position: sticky headers keep working and anything
   intentionally scrollable (table wrappers, code blocks) keeps its own
   scrollbar. Do not switch this to `hidden` - that breaks sticky.
   -------------------------------------------------------------------------- */
html,
body {
    overflow-x: clip;
}

/* Reserve the vertical scrollbar from the first paint. Pages often grow past
   the viewport only after their tables/charts initialise; without this the
   scrollbar appears late and shifts the whole layout sideways by its width. */
html {
    scrollbar-gutter: stable;
}

.select2-dropdown {
    z-index: 1049;
}