/* Wing-preselected readonly/disabled shift & medium fields */
.field-readonly-disabled,
select.field-readonly-disabled:disabled {
    background-color: #e9ecef !important;
    opacity: 0.85;
    cursor: not-allowed;
}

/* Override Bootstrap validation colors to use primary color */
.form-control.is-valid,
.form-select.is-valid,
.datepicker-input.is-valid {
    border-color: var(--bs-primary) !important;
    padding-right: calc(1.5em + 0.75rem) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23005b6f' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right calc(0.375em + 0.1875rem) center !important;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) !important;
}

.form-control.is-valid:focus,
.form-select.is-valid:focus,
.datepicker-input.is-valid:focus {
    border-color: var(--bs-primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25) !important;
}

/*
 * Global table density — every table on every page (list pages, DataTables, plain tables).
 * Body base is 0.812rem (--bs-body-font-size); table cells sit one step below it.
 * This file is loaded from templates/element/new/head-css.php on every layout, so it is
 * the single place to change table text size — do not re-declare it per page.
 */
.table > :not(caption) > * > *,
.table > thead > tr > th {
    font-size: 0.75rem;
}

/* DataTables chrome (length select, search box, info line, pager) matches the cells */
.datatable-top,
.datatable-bottom,
div.dt-container .dt-length,
div.dt-container .dt-search,
div.dt-container .dt-info,
div.dt-container .dt-paging .page-link {
    font-size: 0.75rem;
}

/*
 * Long, transient tables inside a modal (for example the blocked-payment list on the
 * fee template payment sync preview): keep the modal itself a sensible height and let
 * the table scroll inside its own box.
 */
.sync-scroll-area {
    max-height: 20rem;
    overflow-y: auto;
}
/*
 * Theme badges. Templates use .badge-primary / .badge-secondary (the project's badge convention),
 * but the compiled theme does not define them, so Bootstrap's .badge rendered white text on no
 * background — the count was there but invisible. Theme variables, so dark mode follows.
 */
.badge.badge-primary {
    background-color: var(--bs-primary);
    color: #fff;
}

.badge.badge-secondary {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
    border: 1px solid var(--bs-border-color);
}

/*
 * Boxed tabs: filled active tab on a primary underline, pane boxed underneath. Opt-in modifier on top
 * of the theme's .nav-tabs-custom, so other tab bars keep the theme look. Used by Administer > Global
 * Settings and the Result Config class modal. Theme variables, so dark mode follows.
 */
.nav-tabs-custom.nav-tabs-boxed {
    border-bottom: 2px solid var(--bs-primary);
    gap: 4px;
}

.nav-tabs-custom.nav-tabs-boxed .nav-link {
    color: var(--bs-body-color);
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-weight: 500;
    padding: 10px 18px;
    transition: all 0.2s ease-in-out;
    margin-bottom: -2px;
}

.nav-tabs-custom.nav-tabs-boxed .nav-link:hover {
    color: var(--bs-primary);
    background-color: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
}

.nav-tabs-custom.nav-tabs-boxed .nav-link.active {
    color: #fff !important;
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    font-weight: 600;
    box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.08);
}

.tab-content-boxed {
    margin-top: 20px;
    padding: 15px;
    border: 1px solid var(--bs-border-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    background-color: var(--bs-body-bg);
}

/*
 * Custom merit ordering builder (element/resultConfig/merit_criteria_builder.php): two drag and drop
 * lists of criteria. Scoped to the builder; theme variables only, so dark mode follows.
 */
.merit-criteria-builder .merit-criteria-switch .form-check-input {
    width: 2.75rem;
    height: 1.4rem;
    cursor: pointer;
}

.merit-criteria-builder .merit-criteria-list {
    min-height: 3.5rem;
}

.merit-criteria-builder .merit-criterion {
    padding: 0.5rem 0.625rem;
    margin-bottom: 0.375rem;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    cursor: grab;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.merit-criteria-builder .merit-criterion:last-child {
    margin-bottom: 0;
}

.merit-criteria-builder .merit-criterion:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 1px 4px rgba(var(--bs-primary-rgb), 0.15);
}

.merit-criteria-builder .merit-criterion[data-tiebreak="1"] {
    border-style: dashed;
}

.merit-criteria-builder .merit-criterion .btn {
    --bs-btn-padding-y: 0.125rem;
    --bs-btn-padding-x: 0.4rem;
}

/* Rank circle only in "Used"; + only in "Available", × only in "Used". */
.merit-criteria-builder .merit-criterion-rank {
    display: none;
    flex: 0 0 1.6rem;
    width: 1.6rem;
    height: 1.6rem;
    line-height: 1.6rem;
    border-radius: 50%;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--bs-primary);
}

.merit-criteria-builder .merit-criteria-used .merit-criterion-rank {
    display: inline-block;
}

.merit-criteria-builder .merit-criteria-used .merit-criterion-add,
.merit-criteria-builder .merit-criteria-unused .merit-criterion-remove {
    display: none;
}

.merit-criteria-builder .merit-criteria-unused .merit-criterion {
    background-color: var(--bs-tertiary-bg);
}

.merit-criteria-builder .merit-criteria-empty {
    padding: 0.875rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    border: 1px dashed var(--bs-border-color);
    border-radius: 0.5rem;
}

.merit-criteria-builder .merit-criterion-ghost {
    opacity: 0.45;
    border-color: var(--bs-primary);
    border-style: dashed;
}

.merit-criteria-builder .merit-criteria-chips .badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.35em 0.6em;
}

/* The theme's primary is too dark to read as an outline on a dark surface. */
[data-bs-theme="dark"] .merit-criteria-builder .merit-criterion-add {
    color: var(--bs-emphasis-color);
    border-color: var(--bs-secondary-color);
}

/* ---- Result Config field tooltips (element/resultConfig/field_tip.php) ---- */
.result-config-tip {
    cursor: help;
    font-size: 0.8em;
}

.result-config-tip:hover,
.result-config-tip:focus {
    color: var(--bs-primary) !important;
    outline: none;
}

/* Several lines of Bangla text: wider than the 200px default, left aligned, a little more leading. */
.result-config-tooltip .tooltip-inner {
    max-width: 360px;
    text-align: left;
    line-height: 1.55;
    padding: 0.5rem 0.75rem;
}

[data-bs-theme="dark"] .result-config-tip:hover,
[data-bs-theme="dark"] .result-config-tip:focus {
    color: var(--bs-emphasis-color) !important;
}

/*
 * Segmented pill tabs (`.nav.nav-pills.nav-segmented`), e.g. Library Locations / Circulation desk.
 * The theme's `.nav-link` takes its colour from the sidebar (--bs-menu-link-color), which is
 * unreadable on a card in dark mode; inactive pills use the emphasis colour instead.
 */
.nav-segmented .nav-link {
    margin-bottom: 0;
    border: 0;
}

.nav-segmented .nav-link:not(.active) {
    color: var(--bs-emphasis-color);
}

.nav-segmented .nav-link:not(.active):hover,
.nav-segmented .nav-link:not(.active):focus-visible {
    color: var(--bs-primary);
    background-color: var(--bs-secondary-bg);
}

/* ---- Mark entry locked (ResultMarks get_all_students*.php) ----
   The theme's --bs-secondary-bg is white, so a disabled .form-control looks exactly like an
   editable one. When mark entry is off the fields must read as locked at a glance. */
.mark-entry-locked .form-control:disabled {
    background-color: var(--bs-gray-200);
    color: var(--bs-secondary-color);
    cursor: not-allowed;
}

.mark-entry-locked .form-check-input:disabled,
.mark-entry-locked .form-check-input:disabled ~ label,
.mark-entry-locked label:has(> .form-check-input:disabled) {
    cursor: not-allowed;
}

[data-bs-theme="dark"] .mark-entry-locked .form-control:disabled {
    background-color: var(--bs-tertiary-bg);
}

/*
 * Sticky action bar (Save / Reset) that stays visible under the fixed topbar while a long
 * settings page scrolls, e.g. Library Configuration.
 * The theme gives .page-content overflow: auto, which makes it the bar's sticky box: the bar then
 * measured its 120px offset from .page-content (which already starts below the topbar), sat 120px
 * too low on top of the content under it, and never stuck while the window scrolled. A page that
 * has a save bar lets .page-content overflow normally so the bar sticks to the window instead.
 */
.page-content:has(.sticky-savebar) {
    overflow: visible;
}

/*
 * Where the bar sticks = the topbar's bottom edge. Once the page scrolls 50px the theme (app.js)
 * gives #topbar-custom .nav-sticky, which paints its background and shrinks it by 20px; the bar
 * follows, or a 20px see-through strip shows the scrolled content between topbar and bar.
 */
:root {
    --savebar-top: var(--bs-topbar-height, 70px);
}

:root:has(.topbar-custom.nav-sticky) {
    --savebar-top: calc(var(--bs-topbar-height, 70px) - 20px);
}

.sticky-savebar {
    position: sticky;
    top: var(--savebar-top);
    z-index: 1010;
    transition: top .3s;
}

/* Option cards built from .btn-check + .btn-outline-primary: keep text left-aligned and body-coloured */
.option-card {
    text-align: left;
    white-space: normal;
    color: var(--bs-body-color);
}

.option-card .option-card-hint {
    color: var(--bs-secondary-color);
}

.btn-check:checked + .option-card .option-card-hint {
    color: inherit;
    opacity: .85;
}

/* Library barcode label preview */
.barcode-label-preview {
    border: 1px dashed var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background: var(--bs-white);
    color: var(--bs-black);
}

/*
 * Library Configuration section menu: numbered, clickable list items with a chevron, so it reads
 * as navigation. The open section keeps the solid primary colour (white text) while selected.
 * On large screens the menu sticks just below the sticky Save bar instead of sliding under it;
 * --config-savebar-height is set by the page's script from the bar's real height.
 */
@media (min-width: 992px) {
    .config-section-menu {
        position: sticky;
        top: calc(var(--savebar-top) + var(--config-savebar-height, 72px) + .75rem);
        z-index: 1;
        transition: top .3s;
    }
}

.config-section-menu .list-group-item {
    border-left: 3px solid transparent;
    color: var(--bs-body-color);
    cursor: pointer;
}

.config-section-menu .list-group-item:not(.active):hover {
    border-left-color: var(--bs-primary);
    background-color: var(--bs-tertiary-bg);
}

.config-section-menu .list-group-item.active,
.config-section-menu .list-group-item.active:hover,
.config-section-menu .list-group-item.active:focus {
    border-left-color: var(--bs-primary);
    background-color: var(--bs-primary);
    color: var(--bs-white);
    border-top-color: var(--bs-primary);
    border-bottom-color: var(--bs-primary);
}

.config-section-menu .config-step {
    width: 28px;
    height: 28px;
    font-size: .75rem;
    background-color: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
}

.config-section-menu .list-group-item.active .config-step {
    background-color: var(--bs-white);
    color: var(--bs-primary);
}

.config-section-menu .section-summary {
    color: var(--bs-secondary-color);
}

.config-section-menu .list-group-item.active .section-summary {
    color: var(--bs-white);
    opacity: .8;
}

.config-section-menu .config-chevron {
    color: var(--bs-secondary-color);
    transition: transform .15s ease-in-out;
}

.config-section-menu .list-group-item:not(.active):hover .config-chevron {
    color: var(--bs-primary);
    transform: translateX(3px);
}

.config-section-menu .list-group-item.active .config-chevron {
    color: var(--bs-white);
    transform: translateX(3px);
}

/* lets the one-line summary truncate inside the flex row */
.config-section-menu .config-section-text {
    min-width: 0;
}

/* Book Entry: headline number tiles */
.book-stat {
    background-color: var(--bs-body-bg);
}

.book-stat .book-stat-icon {
    width: 38px;
    height: 38px;
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
}

.book-stat.is-alert {
    border-color: var(--bs-danger-border-subtle) !important;
    background-color: var(--bs-danger-bg-subtle);
}

.book-stat.is-alert .book-stat-icon {
    background-color: var(--bs-danger);
    color: var(--bs-white);
}

/* Book Entry "Show" modal: cover, every field, copies with their barcode */
.book-details-cover {
    aspect-ratio: 3 / 4;
    width: 100%;
    max-width: 180px;
    color: var(--bs-secondary-color);
}

.book-details-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-details-fields dt {
    color: var(--bs-secondary-color);
    font-weight: 500;
}

.book-details-fields dd {
    word-break: break-word;
}

/* a barcode is always black on white, also in dark mode, so it stays scannable from the screen */
.book-details-barcode {
    width: 170px;
    height: 46px;
    padding: 2px 4px;
    border-radius: var(--bs-border-radius-sm);
    background-color: var(--bs-white);
}

.book-details-barcode svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Book Entry modal: each group of fields is its own small card on a shaded modal body */
.book-form-card {
    border: 1px solid var(--bs-border-color);
}

.book-form-card > .card-header {
    background-color: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
    color: var(--bs-emphasis-color);
}

.book-form-card .book-form-step {
    width: 26px;
    height: 26px;
    font-size: .75rem;
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
}

/* helper text sits tight under its input so a grid of fields stays compact */
.book-form-card .form-text {
    margin-top: .2rem;
    font-size: .7rem;
}

/* "Add new copies": no column header until the first row is added */
#manualCopiesTable:has(tbody:empty) thead {
    display: none;
}

/* Library reports: the shared student picker's list opens right under the input group,
   full width (its default offset suits a different layout and covers the input here) */
.library-report-suggest .suggest-box {
    top: calc(100% + 2px);
    left: 0;
    right: 0;
}

/* Library reports: one solid colour per loan status, the same as on the printed report —
   returned green, not returned (still within the due date) amber, overdue red */
#datatable td.library-status-cell {
    font-weight: 600;
}

#datatable td.library-status-cell.is-returned {
    background-color: var(--bs-success);
    color: #fff;
}

#datatable td.library-status-cell.is-not_returned {
    background-color: var(--bs-warning);
    color: #212529;
}

#datatable td.library-status-cell.is-overdue {
    background-color: var(--bs-danger);
    color: #fff;
}
