/* One SVG source is shared by the login and navigation. Its colors follow data-bs-theme. */
.apecom-logo-frame {
    display: inline-flex;
    max-width: 100%;
    line-height: 0;
}

.apecom-logo-frame > .apecom-logo {
    display: block;
    width: 100%;
    height: auto;
}

.app-header .navbar-brand .admin-navbar-logo {
    width: 134px;
    flex-shrink: 0;
}

/* Shared tokens for the Color Admin shell, Bootstrap and Backpack fields. */
:root,
html[data-bs-theme="light"] {
    color-scheme: light;
    --admin-bg: #F4F4F5;
    --admin-surface: #FFFFFF;
    --admin-hover: #F4F4F5;
    --admin-selected: #E4E4E7;
    --admin-border: #E4E4E7;
    --admin-border-rgb: 228, 228, 231;
    --admin-input-border: #71717A;
    --admin-text-primary: #18181B;
    --admin-text-primary-rgb: 24, 24, 27;
    --admin-text-secondary: #52525B;
    --admin-text-secondary-rgb: 82, 82, 91;
    --admin-text-muted: #71717A;
    --admin-accent: #2563EB;
    --admin-accent-rgb: 37, 99, 235;
    --admin-accent-hover: #1D4ED8;
    --admin-surface-rgb: 255, 255, 255;
    --admin-bg-rgb: 244, 244, 245;
}

html[data-bs-theme="dark"] {
    color-scheme: dark;
    --admin-bg: #000000;
    --admin-surface: #000000;
    --admin-hover: #111113;
    --admin-selected: #18181B;
    --admin-border: #27272A;
    --admin-border-rgb: 39, 39, 42;
    --admin-input-border: #71717A;
    --admin-text-primary: #FFFFFF;
    --admin-text-primary-rgb: 255, 255, 255;
    --admin-text-secondary: #A1A1AA;
    --admin-text-secondary-rgb: 161, 161, 170;
    --admin-text-muted: #71717A;
    --admin-accent: #60A5FA;
    --admin-accent-rgb: 96, 165, 250;
    --admin-accent-hover: #93C5FD;
    --admin-surface-rgb: 0, 0, 0;
    --admin-bg-rgb: 0, 0, 0;
    --bs-success-text-emphasis: #4ADE80;
    --bs-warning-text-emphasis: #FBBF24;
    --bs-danger-text-emphasis: #F87171;
}

/*
 * Name Khmer fonts before the generic family. Roboto (the theme font) has no Khmer glyphs, and
 * Firefox on Linux looks up Khmer text in "sans-serif" through fontconfig for every new text run:
 * with many fonts installed that took about 70 ms per run, and the list table lays out new copies
 * of its rows several times while it loads (15 s for 25 products). Named fonts are matched at once.
 * Noto Sans Khmer is the storefront's Khmer font; the others ship with Linux, Windows and macOS.
 */
:root,
[data-bs-theme] {
    --bs-font-sans-serif: "Roboto", "Noto Sans Khmer", "Khmer OS System", "Khmer OS", "Khmer UI", "Khmer Sangam MN", sans-serif;
}

/* Keep framework variables in sync so dynamically added controls inherit. */
html[data-bs-theme] {
    --bs-body-bg: var(--admin-bg);
    --bs-body-bg-rgb: var(--admin-bg-rgb);
    --bs-body-color: var(--admin-text-primary);
    --bs-body-color-rgb: var(--admin-text-primary-rgb);
    --bs-emphasis-color: var(--admin-text-primary);
    --bs-emphasis-color-rgb: var(--admin-text-primary-rgb);
    --bs-secondary-color: var(--admin-text-secondary);
    --bs-secondary-color-rgb: var(--admin-text-secondary-rgb);
    --bs-tertiary-color: var(--admin-text-muted);
    --bs-secondary-bg: var(--admin-selected);
    --bs-tertiary-bg: var(--admin-hover);
    --bs-heading-color: var(--admin-text-primary);
    --bs-link-color: var(--admin-accent);
    --bs-link-color-rgb: var(--admin-accent-rgb);
    --bs-link-hover-color: var(--admin-accent-hover);
    --bs-border-color: var(--admin-border);
    --bs-border-color-rgb: var(--admin-border-rgb);
    --bs-border-color-translucent: var(--admin-border);
    --bs-muted: var(--admin-text-muted);
    --bs-component-bg: var(--admin-surface);
    --bs-component-bg-rgb: var(--admin-surface-rgb);
    --bs-component-color: var(--admin-text-primary);
    --bs-component-color-rgb: var(--admin-text-primary-rgb);
    --bs-component-secondary-bg: var(--admin-selected);
    --bs-component-tertiary-bg: var(--admin-hover);
    --bs-component-border-color: var(--admin-border);
    --bs-component-border-color-rgb: var(--admin-border-rgb);
    --bs-component-border-color-transparent: var(--admin-border);
    --bs-component-dropdown-bg: var(--admin-surface);
    --bs-component-dropdown-bg-rgb: var(--admin-surface-rgb);
    --bs-component-dropdown-border-color: var(--admin-border);
    --bs-component-dropdown-hover-bg: var(--admin-hover);
    --bs-component-modal-bg: var(--admin-surface);
    --bs-component-modal-border-color: var(--admin-border);
    --bs-component-hover-bg: var(--admin-hover);
    --bs-component-hover-color: var(--admin-text-primary);
    --bs-component-hover-border-color: var(--admin-input-border);
    --bs-component-focus-border-color: var(--admin-accent);
    --bs-component-disabled-bg: var(--admin-hover);
    --bs-component-disabled-color: var(--admin-text-muted);
    --bs-component-disabled-border-color: var(--admin-border);
    --bs-component-table-border-color: var(--admin-border);
    --bs-component-table-separator-color: var(--admin-border);
    --bs-app-header-bg: var(--admin-surface);
    --bs-app-header-bg-rgb: var(--admin-surface-rgb);
    --bs-app-header-color: var(--admin-text-primary);
    --bs-app-header-color-rgb: var(--admin-text-primary-rgb);
    --bs-app-header-input-bg: var(--admin-hover);
    --bs-app-header-input-border: var(--admin-border);
    --bs-app-header-divider-bg: var(--admin-border);
    --bs-app-sidebar-bg: var(--admin-surface);
    --bs-app-sidebar-bg-rgb: var(--admin-surface-rgb);
    --bs-app-sidebar-component-color: var(--admin-text-primary);
    --bs-app-sidebar-component-color-rgb: var(--admin-text-primary-rgb);
    --bs-app-sidebar-component-active-bg: var(--admin-selected);
    --bs-app-sidebar-component-active-color: var(--admin-text-primary);
    --bs-app-sidebar-menu-header-color: var(--admin-text-secondary);
    --bs-app-sidebar-menu-link-color: var(--admin-text-secondary);
    --bs-app-sidebar-menu-link-hover-color: var(--admin-text-primary);
    --bs-app-sidebar-menu-link-hover-bg: var(--admin-hover);
    --bs-app-sidebar-menu-submenu-link-color: var(--admin-text-secondary);
    --bs-app-sidebar-menu-submenu-link-hover-color: var(--admin-text-primary);
    --bs-app-sidebar-menu-divider-bg: var(--admin-border);
    --bs-app-sidebar-profile-bg: var(--admin-surface);
    --bs-app-sidebar-profile-bg-rgb: var(--admin-surface-rgb);
    --bs-app-sidebar-profile-color: var(--admin-text-primary);
    --bs-app-sidebar-profile-color-rgb: var(--admin-text-primary-rgb);
    --bs-app-sidebar-profile-bg-cover: none;
    --bs-app-sidebar-float-submenu-bg: var(--admin-surface);
    --bs-app-sidebar-minify-btn-bg: var(--admin-hover);
    --bs-app-sidebar-minify-btn-hover-bg: var(--admin-selected);
    --tblr-body-color: var(--admin-text-primary);
    --tblr-body-bg: var(--admin-bg);
    --tblr-border-color: var(--admin-border);
    --tblr-muted: var(--admin-text-secondary);
    --tblr-icon-color: var(--admin-text-secondary);
    --ck-color-base-background: var(--admin-surface);
    --ck-color-base-foreground: var(--admin-hover);
    --ck-color-base-border: var(--admin-input-border);
    --ck-color-text: var(--admin-text-primary);
    --ck-color-toolbar-background: var(--admin-surface);
    --ck-color-toolbar-border: var(--admin-input-border);
    --ck-color-panel-background: var(--admin-surface);
    --ck-color-panel-border: var(--admin-input-border);
    --ck-color-input-background: var(--admin-surface);
    --ck-color-input-text: var(--admin-text-primary);
    --ck-color-input-border: var(--admin-input-border);
    --ck-color-list-background: var(--admin-surface);
    --ck-color-button-default-hover-background: var(--admin-hover);
    --ck-color-button-on-background: var(--admin-selected);
    --ck-color-button-on-color: var(--admin-accent);
}

html[data-bs-theme] body,
html[data-bs-theme] .app-body {
    background-color: var(--admin-bg);
    color: var(--admin-text-primary);
}

.app-sidebar {
    border-inline-end: 1px solid var(--admin-border);
}

html[data-bs-theme] .app-sidebar-bg,
html[data-bs-theme] .app-sidebar .menu .menu-profile .menu-profile-cover {
    background: var(--admin-surface);
}

html[data-bs-theme] .app-sidebar .menu .menu-profile {
    border-bottom: 1px solid var(--admin-border);
}

html[data-bs-theme] .nav-tabs .nav-link {
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .nav-tabs .nav-link:is(.active, :hover) {
    color: var(--admin-text-primary);
}

html[data-bs-theme] .nav-tabs .nav-link.active {
    box-shadow: inset 0 -2px var(--admin-accent);
}

html[data-bs-theme] .card,
html[data-bs-theme] .panel,
html[data-bs-theme] .tab-content,
html[data-bs-theme] .app-footer {
    background: var(--admin-surface);
    color: var(--admin-text-primary);
    border-color: var(--admin-border);
}

html[data-bs-theme] .card,
html[data-bs-theme] .panel {
    border: 1px solid var(--admin-border);
}

html[data-bs-theme] .app-loader {
    background: var(--admin-bg);
}

html[data-bs-theme="dark"] .card[class*="bg-"] {
    background: var(--admin-surface) !important;
}

html[data-bs-theme] .table {
    --bs-table-bg: var(--admin-surface);
    --bs-table-color: var(--admin-text-primary);
    --bs-table-border-color: var(--admin-border);
    --bs-table-striped-bg: var(--admin-hover);
    --bs-table-striped-color: var(--admin-text-primary);
    --bs-table-active-bg: var(--admin-selected);
    --bs-table-active-color: var(--admin-text-primary);
    --bs-table-hover-bg: var(--admin-hover);
    --bs-table-hover-color: var(--admin-text-primary);
}

html[data-bs-theme] .table thead th,
html[data-bs-theme] .card-header,
html[data-bs-theme] .card-footer,
html[data-bs-theme] .panel-heading {
    background-color: var(--admin-surface);
    color: var(--admin-text-primary);
    border-color: var(--admin-border);
}

html[data-bs-theme] .text-secondary,
html[data-bs-theme] .text-body-secondary,
html[data-bs-theme] .form-text,
html[data-bs-theme] .help-block,
html[data-bs-theme] .breadcrumb-item,
html[data-bs-theme] .dataTables_info {
    color: var(--admin-text-secondary) !important;
}

html[data-bs-theme] .text-muted {
    color: var(--admin-text-muted) !important;
}

html[data-bs-theme] .text-gray-800 {
    color: var(--admin-text-primary) !important;
}

html[data-bs-theme] .text-gray-300 {
    color: var(--admin-text-secondary) !important;
}

html[data-bs-theme] .flot-text,
html[data-bs-theme] .legendLabel {
    color: var(--admin-text-secondary) !important;
}

html[data-bs-theme] .flot-tooltip {
    background: var(--admin-surface);
    color: var(--admin-text-primary);
    border-color: var(--admin-border);
    opacity: 1;
}

html[data-bs-theme="dark"] .bg-white,
html[data-bs-theme="dark"] .bg-light,
html[data-bs-theme="dark"] .bg-body,
html[data-bs-theme="dark"] .bg-body-tertiary {
    background-color: var(--admin-surface) !important;
}

html[data-bs-theme="dark"] .text-dark,
html[data-bs-theme="dark"] .text-black {
    color: var(--admin-text-primary) !important;
}

html[data-bs-theme] .form-control,
html[data-bs-theme] .form-select,
html[data-bs-theme] .input-group-text {
    border-color: var(--admin-input-border);
}

html[data-bs-theme] :is(input, textarea)::placeholder {
    color: var(--admin-text-secondary);
    opacity: 1;
}

html[data-bs-theme] .form-control:focus,
html[data-bs-theme] .form-select:focus {
    border-color: var(--admin-accent);
    box-shadow: 0 0 0 3px rgba(var(--admin-accent-rgb), .2);
}

html[data-bs-theme] .form-control.is-invalid,
html[data-bs-theme] .form-select.is-invalid {
    border-color: var(--bs-form-invalid-border-color);
}

html[data-bs-theme] .form-control.is-valid,
html[data-bs-theme] .form-select.is-valid {
    border-color: var(--bs-form-valid-border-color);
}

html[data-bs-theme="dark"] input:-webkit-autofill,
html[data-bs-theme="dark"] textarea:-webkit-autofill {
    -webkit-text-fill-color: var(--admin-text-primary);
    -webkit-box-shadow: 0 0 0 1000px var(--admin-surface) inset;
    caret-color: var(--admin-text-primary);
}

/* The app uses success buttons for its primary save actions. */
html[data-bs-theme] .btn-primary,
html[data-bs-theme] body .btn-success {
    --bs-btn-color: #FFFFFF;
    --bs-btn-bg: #2563EB;
    --bs-btn-border-color: #2563EB;
    --bs-btn-hover-color: #FFFFFF;
    --bs-btn-hover-bg: #1D4ED8;
    --bs-btn-hover-border-color: #1D4ED8;
    --bs-btn-active-color: #FFFFFF;
    --bs-btn-active-bg: #1D4ED8;
    --bs-btn-active-border-color: #1D4ED8;
    --bs-btn-disabled-color: #FFFFFF;
    --bs-btn-disabled-bg: #2563EB;
    --bs-btn-disabled-border-color: #2563EB;
    --bs-btn-focus-shadow-rgb: 96, 165, 250;
}

html[data-bs-theme] :is(.btn-default, .btn-white, .btn-light, .btn-outline-secondary) {
    color: var(--admin-text-primary);
    background: var(--admin-surface);
    border-color: var(--admin-input-border);
}

html[data-bs-theme] :is(.btn-default, .btn-white, .btn-light, .btn-outline-secondary):is(:hover, :focus-visible, :active, .active) {
    /* Color Admin's more specific outline hover rule otherwise forces white text. */
    color: var(--admin-text-primary) !important;
    background: var(--admin-hover);
    border-color: var(--admin-text-secondary);
}

/* Field packages can load their own light styles after the page head. */
html[data-bs-theme] body .select2-container .select2-selection,
html[data-bs-theme] body .select2-dropdown,
html[data-bs-theme] body .select2-search__field,
html[data-bs-theme] .daterangepicker,
html[data-bs-theme] .datepicker-dropdown,
html[data-bs-theme] .dt-button-collection,
html[data-bs-theme] .swal-modal,
html[data-bs-theme] .swal-content__input {
    color: var(--admin-text-primary);
    background-color: var(--admin-surface);
    border-color: var(--admin-input-border);
}

html[data-bs-theme] body .select2-container .select2-selection__rendered,
html[data-bs-theme] .swal-title,
html[data-bs-theme] .swal-text {
    color: var(--admin-text-primary);
}

html[data-bs-theme] body .select2-container .select2-selection__placeholder {
    color: var(--admin-text-secondary);
}

html[data-bs-theme] body .select2-container .select2-selection__choice,
html[data-bs-theme] body .select2-results__option[aria-selected="true"],
html[data-bs-theme] .daterangepicker .calendar-table,
html[data-bs-theme] .daterangepicker .ranges li:hover {
    background-color: var(--admin-hover);
    color: var(--admin-text-primary);
    border-color: var(--admin-border);
}

html[data-bs-theme] body .select2-results__option--highlighted[aria-selected] {
    background-color: var(--admin-selected);
    color: var(--admin-text-primary);
}

/* Its dialogs can be moved outside the page builder by Bootstrap. */
html[data-bs-theme],
html[data-bs-theme] .component-field-wrapper {
    --crud-primary-color: var(--admin-accent);
    --crud-primary-hover: var(--admin-accent-hover);
    --crud-border-color: var(--admin-border);
    --crud-canvas-bg: var(--admin-surface);
    --crud-component-bg: var(--admin-surface);
    --crud-component-header-bg: var(--admin-surface);
    --crud-placeholder-border: var(--admin-input-border);
    --crud-text-dark: var(--admin-text-primary);
    --crud-text-medium: var(--admin-text-secondary);
    --crud-text-light: var(--admin-text-muted);
    --crud-radius: 6px;
}

html[data-bs-theme] .add-section-btn {
    background-color: #2563EB;
    border-color: #2563EB;
}

html[data-bs-theme] .add-section-btn:hover {
    background-color: #1D4ED8;
    border-color: #1D4ED8;
}

html[data-bs-theme] .content-block-item,
html[data-bs-theme] .content-block-header,
html[data-bs-theme] .upload-placeholder-btn,
html[data-bs-theme] .backstrap-file-label,
html[data-bs-theme] .backstrap-file-label::after {
    background-color: var(--admin-surface);
    color: var(--admin-text-primary);
    border-color: var(--admin-border);
}

html[data-bs-theme] .data-type-label,
html[data-bs-theme] .upload-placeholder-btn:hover,
html[data-bs-theme] .add-content-placeholder:hover {
    background-color: var(--admin-hover);
    color: var(--admin-text-secondary);
}

html[data-bs-theme] :is(button, a, input, select, textarea):focus-visible {
    outline: 2px solid var(--admin-accent);
    outline-offset: 3px;
}

.admin-theme-switcher {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--admin-border);
    border-radius: 10px;
    background: var(--admin-surface);
}

.admin-theme-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 44px;
    min-height: 38px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--admin-text-secondary);
    font: inherit;
    cursor: pointer;
}

.admin-theme-option:hover {
    background: var(--admin-hover);
    color: var(--admin-text-primary);
}

html[data-bs-theme="light"] [data-admin-theme="light"],
html[data-bs-theme="dark"] [data-admin-theme="dark"] {
    background: var(--admin-selected);
    color: var(--admin-text-primary);
    border-color: var(--admin-input-border);
}

.admin-theme-option svg {
    flex-shrink: 0;
}

.admin-auth-appearance {
    position: absolute;
    inset-block-start: 20px;
    inset-inline-end: 24px;
    z-index: 1;
}

html[data-bs-theme] .admin-auth {
    padding: 0;
}

.admin-auth > .container > .row.min-vh-100 {
    min-height: calc(100vh - 70px) !important;
    padding-block: 90px 32px;
}

html[data-bs-theme] .admin-auth .app-footer {
    margin: 0;
    border-top: 1px solid var(--admin-border);
    text-align: center;
    color: var(--admin-text-secondary);
}

@media (max-width: 575.98px) {
    .app-header .admin-theme-option {
        min-height: 38px;
        padding-inline: 10px;
    }

    .app-header .admin-theme-option span {
        display: none;
    }

    .admin-auth-appearance {
        inset-block-start: 16px;
        inset-inline-end: 16px;
    }
}

/* ==========================================================================
   Portal layout: navigation, page headers, list screens, forms, detail pages.
   Built on the --admin-* tokens above so both themes follow automatically.
   ========================================================================== */

:root,
html[data-bs-theme="light"] {
    --portal-radius: 10px;
    --portal-success: #15803D;
    --portal-success-bg: #DCFCE7;
    --portal-warning: #B45309;
    --portal-warning-bg: #FEF3C7;
    --portal-danger: #B91C1C;
    --portal-danger-bg: #FEE2E2;
    --portal-info: #0E7490;
    --portal-info-bg: #CFFAFE;
    --portal-primary: #1D4ED8;
    --portal-primary-bg: #DBEAFE;
    --portal-secondary: #52525B;
    --portal-secondary-bg: #F4F4F5;
}

html[data-bs-theme="dark"] {
    --portal-success: #4ADE80;
    --portal-success-bg: rgba(74, 222, 128, .14);
    --portal-warning: #FBBF24;
    --portal-warning-bg: rgba(251, 191, 36, .14);
    --portal-danger: #F87171;
    --portal-danger-bg: rgba(248, 113, 113, .14);
    --portal-info: #22D3EE;
    --portal-info-bg: rgba(34, 211, 238, .14);
    --portal-primary: #93C5FD;
    --portal-primary-bg: rgba(96, 165, 250, .16);
    --portal-secondary: #A1A1AA;
    --portal-secondary-bg: #18181B;
}

/* --- Sidebar: one flat list, grouped by task ----------------------------- */
html[data-bs-theme] .app-sidebar .menu {
    padding-bottom: 24px;
}

html[data-bs-theme] .app-sidebar .menu > .menu-item:first-child {
    margin-top: 14px;
}

html[data-bs-theme] .app-sidebar .menu .menu-header {
    padding: 20px 24px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--admin-text-muted);
}

html[data-bs-theme] .app-sidebar .menu .menu-item .menu-link {
    padding-top: 7px;
    padding-bottom: 7px;
}

html[data-bs-theme] .app-sidebar .menu .menu-item .menu-icon {
    margin-right: 12px;
    font-size: 19px;
}

html[data-bs-theme] .app-sidebar .menu .menu-item .menu-link .portal-menu-badge {
    margin-left: auto;
    min-width: 22px;
    padding: 0 7px;
    line-height: 20px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--portal-warning);
    background: var(--portal-warning-bg);
}

.portal-user-avatar {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    color: var(--admin-accent) !important;
    background: rgba(var(--admin-accent-rgb), .14) !important;
}

/* --- Page header ------------------------------------------------------------ */
html[data-bs-theme] .portal-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin: 0;
    padding: 4px 0 20px;
}

.portal-page-header-text {
    min-width: 0;
}

.portal-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--admin-text-secondary);
    text-decoration: none;
}

.portal-back-link:hover {
    color: var(--admin-accent);
}

.portal-page-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

html[data-bs-theme] .portal-page-title {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -.01em;
    color: var(--admin-text-primary);
}

.portal-page-title-entry {
    font-weight: 500;
    color: var(--admin-text-secondary);
}

.portal-page-description {
    max-width: 780px;
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--admin-text-secondary);
}

.portal-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* --- Badges ----------------------------------------------------------------- */
.portal-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    white-space: nowrap;
    color: var(--portal-secondary);
    background: var(--portal-secondary-bg);
}

.portal-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.portal-badge-success { color: var(--portal-success); background: var(--portal-success-bg); }
.portal-badge-warning { color: var(--portal-warning); background: var(--portal-warning-bg); }
.portal-badge-danger { color: var(--portal-danger); background: var(--portal-danger-bg); }
.portal-badge-info { color: var(--portal-info); background: var(--portal-info-bg); }
.portal-badge-primary { color: var(--portal-primary); background: var(--portal-primary-bg); }
.portal-badge-secondary { color: var(--portal-secondary); background: var(--portal-secondary-bg); }

.portal-page-title-row .portal-badge {
    font-size: 13px;
    padding: 3px 12px;
}

/* --- List screens ----------------------------------------------------------- */
.portal-list-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.portal-list-buttons .btn {
    margin: 0 !important;
}

.portal-list-search {
    width: 320px;
    max-width: 100%;
}

.portal-list-search .form-control {
    border-radius: 8px;
}

html[data-bs-theme] .navbar-filters {
    padding: 0 0 12px !important;
    background: transparent !important;
    border: 0 !important;
    min-height: 0;
}

html[data-bs-theme] .navbar-filters .navbar-nav {
    flex-wrap: wrap;
    gap: 6px;
}

html[data-bs-theme] .navbar-filters .navbar-nav > .nav-item > .nav-link {
    padding: 5px 12px !important;
    border: 1px solid var(--admin-border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--admin-text-primary);
    background: var(--admin-surface);
}

html[data-bs-theme] .navbar-filters .navbar-nav > .nav-item.active > .nav-link {
    border-color: var(--admin-accent);
    color: var(--admin-accent);
    background: rgba(var(--admin-accent-rgb), .08);
}

html[data-bs-theme] .navbar-filters .navbar-nav > .nav-item > #remove_filters_button {
    border-color: transparent;
    background: transparent;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .navbar-filters > .nav-item {
    margin-right: 8px;
    color: var(--admin-text-muted);
}

html[data-bs-theme] #crudTable {
    --bs-table-striped-bg: transparent;
    overflow: hidden;
    border: 1px solid var(--admin-border) !important;
    border-radius: var(--portal-radius) !important;
    box-shadow: none !important;
}

/* The second selector is the sticky copy of the header row; see "Sticky column headers". */
html[data-bs-theme] #crudTable thead th,
html[data-bs-theme] .dtfh-floatingparent > table > thead > tr > th {
    padding: 11px 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--admin-text-secondary);
    background: var(--admin-hover);
    border-bottom: 1px solid var(--admin-border);
}

html[data-bs-theme] #crudTable tbody td {
    padding: 12px;
    vertical-align: middle;
    border-color: var(--admin-border);
}

html[data-bs-theme] #crudTable tfoot {
    display: none;
}

html[data-bs-theme] #crudTable_wrapper .table-footer {
    font-size: 13px;
    color: var(--admin-text-secondary);
}

/* --- Standard list screen (crud::portal_list) ------------------------------
   Four regions on one left edge, top to bottom: page header with the action
   buttons, filter bar with the search box, data table, pagination.
   Controllers opt in with PortalCrud::useStandardListLayout(). */
.portal-list {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* The page header has no side padding; drop the content's so every region starts at the title. */
.container-fluid:has(> .portal-list) {
    padding-left: 0;
    padding-right: 0;
}

/* 1. Page header: title on the left, action buttons on the right. */
html[data-bs-theme] .portal-page-header.portal-list-header {
    align-items: center;
    padding-bottom: 16px;
}

.portal-list-header .portal-list-buttons {
    align-items: center;
}

html[data-bs-theme] .portal-list-header .portal-list-buttons .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 14px;
    border-radius: 8px !important;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* 2. Filter bar: filters, applied-filter summary and "Remove filters" on the left, search on the right. */
html[data-bs-theme] .portal-list-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 12px;
    padding: 8px 8px 8px 12px;
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
}

.portal-list-filters-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding-right: 12px;
    border-right: 1px solid var(--admin-border);
    font-size: 13px;
    font-weight: 600;
    line-height: 30px;
    white-space: nowrap;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .portal-list .navbar-filters {
    flex: 0 0 auto;
    min-width: 0;
    padding: 0 !important;
}

/* The bar has its own "Filters" label; Backpack's icon is redundant. */
.portal-list .navbar-filters > .nav-item.d-lg-block {
    display: none !important;
}

.portal-list .navbar-filters .navbar-toggler {
    margin: 0 !important;
    padding: 5px 12px;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--admin-text-primary);
}

/* Applied filters, between the filter buttons and "Remove filters": up to two values, then
   "and 1 more filter applied". The values shrink with "…" so the bar keeps one line;
   hover or focus shows every filter in .portal-filter-details. */
.portal-filter-summary {
    position: relative;
    display: inline-flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding-left: 12px;
    border-left: 1px solid var(--admin-border);
    border-radius: 0;
    font-size: 13px;
    line-height: 30px;
    white-space: nowrap;
    color: var(--admin-text-primary);
    cursor: default;
    outline: none;
}

.portal-filter-summary[hidden],
.portal-filter-summary-more[hidden] {
    display: none;
}

.portal-filter-summary-values {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.portal-filter-summary-more {
    flex-shrink: 0;
    color: var(--admin-accent);
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.portal-filter-summary:focus-visible .portal-filter-summary-values {
    outline: 2px solid var(--admin-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

html[data-bs-theme] .portal-filter-details {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    z-index: 1050;
    min-width: 240px;
    max-width: 360px;
    padding: 10px 12px 12px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
    box-shadow: var(--portal-shadow-pop, 0 12px 32px -8px rgba(15, 23, 42, .22));
    white-space: normal;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .12s ease, transform .12s ease, visibility 0s linear .12s;
    pointer-events: none;
}

.portal-filter-summary:is(:hover, :focus) .portal-filter-details {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
}

.portal-filter-details-title {
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--admin-text-muted);
}

.portal-filter-details-list {
    display: grid;
    gap: 6px;
    margin: 0;
}

.portal-filter-details-row {
    display: grid;
    grid-template-columns: minmax(80px, max-content) 1fr;
    gap: 12px;
}

.portal-filter-details-row dt {
    font-weight: 400;
    color: var(--admin-text-secondary);
}

.portal-filter-details-row dd {
    margin: 0;
    font-weight: 600;
    color: var(--admin-text-primary);
}

.portal-list-filters-end {
    display: flex;
    align-items: center;
    gap: 2px;
}

.portal-list-filters-end:empty {
    display: none;
}

/* "Remove filters": an outlined button, as tall as the filter buttons but square-cornered
   so it reads as an action rather than another filter. */
html[data-bs-theme] .portal-list-filters-end #remove_filters_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    color: var(--admin-text-primary);
    background: var(--admin-surface);
    transition: background-color .12s ease, border-color .12s ease;
}

html[data-bs-theme] .portal-list-filters-end #remove_filters_button:hover {
    border-color: var(--admin-input-border);
    background: var(--admin-hover);
}

html[data-bs-theme] .portal-list-filters-end #remove_filters_button:focus-visible {
    outline: 2px solid var(--admin-accent);
    outline-offset: 1px;
}

.portal-list-filters-end #remove_filters_button i {
    font-size: 15px;
    color: var(--admin-text-secondary);
}

/* Compact bar, switched on by the list script when the items would not fit on one line:
   "Filters" and "Remove filters" keep only their icons (their names stay as tooltips). */
.portal-list-filters.is-compact .portal-compact-hide {
    display: none;
}

html[data-bs-theme] .portal-list-filters.is-compact .portal-list-filters-end #remove_filters_button {
    width: 32px;
    padding: 0;
}

/* Backpack hides it with .invisible (keeps its space); here it should take no room. */
.portal-list-filters-end #remove_filters_button.invisible {
    display: none !important;
}

/* At least 200px, up to 320px when there is room. On wider screens the bar never wraps
   (see the media query below); the summary gives way instead. */
.portal-list .portal-list-search {
    flex: 1 0 200px;
    width: auto;
    max-width: 320px;
    margin-left: auto;
}

@media (min-width: 768px) {
    html[data-bs-theme] .portal-list-filters {
        flex-wrap: nowrap;
    }

    .portal-list .navbar-filters .navbar-nav {
        flex-wrap: nowrap;
    }

    /* Compact bar: tighter spacing and a narrower search leave more room for the summary. */
    html[data-bs-theme] .portal-list-filters.is-compact {
        gap: 8px;
    }

    html[data-bs-theme] .portal-list-filters.is-compact .navbar-filters .navbar-nav > .nav-item > .nav-link {
        padding-left: 9px !important;
        padding-right: 9px !important;
    }

    .portal-list-filters.is-compact .portal-list-search {
        flex-basis: 160px;
    }

    .portal-list-filters.is-compact .portal-list-filters-label,
    .portal-list-filters.is-compact .portal-filter-summary {
        padding-left: 0;
        padding-right: 8px;
    }

    .portal-list-filters.is-compact .portal-filter-summary {
        padding-left: 8px;
        padding-right: 0;
    }

    /* More filter buttons than one line can hold: let them wrap rather than overflow. */
    html[data-bs-theme] .portal-list-filters.is-overfull .navbar-filters {
        flex-shrink: 1;
    }

    .portal-list-filters.is-overfull .navbar-filters .navbar-nav {
        flex-wrap: wrap;
    }
}

html[data-bs-theme] .portal-list .portal-list-search .form-control {
    height: 36px;
    border-color: var(--admin-border);
    background: var(--admin-surface);
}

html[data-bs-theme] .portal-list .portal-list-search .form-control:hover {
    border-color: var(--admin-input-border);
}

/* 3. Data table: the card is the wrapper, so the table itself has no frame. */
html[data-bs-theme] .portal-list-table {
    position: relative;
    min-width: 0;
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
}

/* Table menu ("⋮"): Export and Column visibility, centred in the 43px header row after "Actions".
   The menu box covers the card and lets clicks through to the table. The button inside is sticky, so it
   stays in the header row while the sticky header shows and stops with it at the end of the table.
   The box is above the sticky header (999); open row menus (also 1000) come later in the page, so they
   still draw over it. */
.portal-table-menu {
    position: absolute;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
}

.portal-table-menu > * {
    pointer-events: auto;
}

/* The page wrapper fades in with animation-fill-mode "both", which keeps it a stacking context after
   the fade and traps the menu's z-index under the sticky header (attached to <body>). "backwards"
   still starts the fade from transparent but lets go of the wrapper once it ends. */
.container-fluid.animated:has(> .portal-list) {
    animation-fill-mode: backwards;
}

/* The sticky header copies each column's content width, so its padding has to match too. */
html[data-bs-theme] .portal-list-table:has(> .portal-table-menu) #crudTable > thead > tr > th:last-child,
html[data-bs-theme] body:has(.portal-list-table > .portal-table-menu) .dtfh-floatingparent > table > thead > tr > th:last-child {
    padding-right: 52px;
}

/* --portal-sticky-top is the sticky header's offset (the phone/tablet top bar), set in crud/list.blade.php.
   The 6.5px margins above and below make the margin box the 43px header row, so the button stops
   exactly where the header does. */
html[data-bs-theme] .portal-table-menu-toggle {
    position: sticky;
    top: calc(var(--portal-sticky-top, 0px) + 6.5px);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin: 6.5px 8px 6.5px auto;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--admin-text-secondary);
    background: transparent;
}

html[data-bs-theme] .portal-table-menu-toggle:is(:hover, :focus-visible, [aria-expanded="true"]) {
    border-color: var(--admin-border);
    color: var(--admin-text-primary);
    background: var(--admin-surface);
}

html[data-bs-theme] .portal-table-menu-toggle:focus-visible {
    outline: 2px solid var(--admin-accent);
    outline-offset: 1px;
}

html[data-bs-theme] .portal-table-menu-list {
    min-width: 220px;
    max-height: min(520px, 70vh);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
    box-shadow: var(--portal-shadow-pop, 0 12px 32px -8px rgba(15, 23, 42, .22));
}

html[data-bs-theme] .portal-table-menu-list .dropdown-header {
    padding: 6px 10px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--admin-text-muted);
}

html[data-bs-theme] .portal-table-menu-list .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--admin-text-primary);
    cursor: pointer;
}

html[data-bs-theme] .portal-table-menu-list .dropdown-item:is(:hover, :focus-visible) {
    color: var(--admin-text-primary);
    background: var(--admin-hover);
}

.portal-table-menu-list .dropdown-item > i {
    width: 18px;
    font-size: 18px;
    text-align: center;
    color: var(--admin-text-secondary);
}

.portal-table-menu-check .form-check-input {
    flex-shrink: 0;
    margin: 0;
}

.portal-table-menu-list .dropdown-divider {
    margin: 6px 4px;
    border-color: var(--admin-border);
}

.portal-list-table .dataTables_wrapper > .row {
    margin: 0;
}

.portal-list-table .dataTables_wrapper > .row > [class*="col-"] {
    padding: 0;
}

/* Backpack resets the processing card and gives it a hardcoded white backdrop. */
html[data-bs-theme] #crudTable_processing.dataTables_processing.card {
    background: rgba(var(--admin-surface-rgb), .9);
    color: var(--admin-text-primary);
}

/* The vendor spinner is a dark SVG image; preserve its animated opacity on dark surfaces. */
html[data-bs-theme="dark"] #crudTable_processing.dataTables_processing.card > img {
    filter: brightness(0) invert(1);
}

html[data-bs-theme] .portal-list #crudTable {
    width: 100% !important;
    margin: 0 !important;
    overflow: visible;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent;
}

html[data-bs-theme] .portal-list #crudTable > thead > tr > th,
html[data-bs-theme] .dtfh-floatingparent > table > thead > tr > th {
    padding-top: 12px;
    padding-bottom: 12px;
}

html[data-bs-theme] .portal-list #crudTable > :is(thead, tbody) > tr > :first-child,
html[data-bs-theme] .dtfh-floatingparent > table > thead > tr > :first-child {
    padding-left: 16px !important;
}

html[data-bs-theme] .portal-list #crudTable > :is(thead, tbody) > tr > :last-child,
html[data-bs-theme] .dtfh-floatingparent > table > thead > tr > :last-child {
    padding-right: 16px;
}

/* Round the corner cells to match the card instead of clipping it, so row dropdowns can overflow. */
html[data-bs-theme] .portal-list #crudTable > thead > tr > th:first-child {
    border-top-left-radius: calc(var(--portal-radius) - 1px);
}

html[data-bs-theme] .portal-list #crudTable > thead > tr > th:last-child {
    border-top-right-radius: calc(var(--portal-radius) - 1px);
}

html[data-bs-theme] .portal-list #crudTable > tbody > tr:last-child > td {
    border-bottom: 0;
}

html[data-bs-theme] .portal-list #crudTable > tbody > tr:last-child > td:first-child {
    border-bottom-left-radius: calc(var(--portal-radius) - 1px);
}

html[data-bs-theme] .portal-list #crudTable > tbody > tr:last-child > td:last-child {
    border-bottom-right-radius: calc(var(--portal-radius) - 1px);
}

/* Sticky column headers. Once the header row scrolls off, DataTables FixedHeader moves the <thead>
   into a copy of the table that it attaches to <body> and pins to the top of the window (below the
   phone/tablet top bar, see crud/list.blade.php). The copy has no #crudTable id and sits outside
   .portal-list, so the header-cell rules above name it separately. The strip spans the card between
   its side borders, with square corners and a soft shadow over the rows passing under it.
   It stays under open row menus (1000) and the phone/tablet top bar (1020); Color Admin puts it at 1020. */
html[data-bs-theme] .dtfh-floatingparenthead {
    z-index: 999 !important;
    box-shadow: 0 6px 12px -6px rgba(15, 23, 42, .16);
}

html[data-bs-theme] .dtfh-floatingparenthead > table {
    margin: 0 !important;
    border: 0 !important;
    background: var(--admin-surface);
}

/* Backpack's rules for the "select all" checkbox and the sort arrows are scoped to #crudTable_wrapper,
   which the copy is outside of (vendor/backpack/crud/src/resources/assets/css/common.css). */
.dtfh-floatingparent > table.dataTable .crud_bulk_actions_checkbox {
    margin: 0 .6rem 0 .45rem;
}

.dtfh-floatingparent > table.dataTable :is(.sorting, .sorting_asc, .sorting_desc, .sorting_asc_disabled, .sorting_desc_disabled)::before {
    right: .4em;
    top: 1em;
    content: "\f0d8";
    font: normal normal normal 14px/1 "Line Awesome Free";
    font-weight: 900;
}

.dtfh-floatingparent > table.dataTable :is(.sorting, .sorting_asc, .sorting_desc, .sorting_asc_disabled, .sorting_desc_disabled)::after {
    right: .4em;
    content: "\f0d7";
    font: normal normal normal 14px/1 "Line Awesome Free";
    font-weight: 900;
}

html[data-bs-theme] .portal-list #crudTable > tbody > tr > td.dataTables_empty {
    padding: 48px 16px !important;
    font-size: 14px;
    text-align: center;
    white-space: normal;
    color: var(--admin-text-secondary);
    background: var(--admin-surface);
}

.portal-list #crudTable td.dataTables_empty::before {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    margin: 0 auto 12px;
    background: var(--admin-text-muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z'/%3E%3Cpath d='M4 13h3l3 3h4l3-3h3'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z'/%3E%3Cpath d='M4 13h3l3 3h4l3-3h3'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* 4. Pagination: count and bulk buttons on the left, rows per page and pages on the right. */
.portal-list-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    margin-top: 12px;
}

.portal-list-pagination-start,
.portal-list-pagination-end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 20px;
}

.portal-list-bulk {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.portal-list-bulk .btn {
    margin: 0 !important;
}

.portal-list-count {
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--admin-text-secondary);
}

.portal-list-count .dataTables_info {
    padding: 0 !important;
    white-space: nowrap;
}

.portal-list-pagination .dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 13px;
    white-space: nowrap;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .portal-list-pagination .dataTables_length select {
    width: auto;
    height: 32px;
    padding: 0 30px 0 10px;
    border-color: var(--admin-border);
    border-radius: 8px;
    font-size: 13px;
    background-color: var(--admin-surface);
}

.portal-list-pagination .pagination {
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
}

html[data-bs-theme] .portal-list-pagination .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 8px !important;
    font-size: 13px;
    font-weight: 500;
    color: var(--admin-text-primary);
    background: transparent;
    box-shadow: none;
}

html[data-bs-theme] .portal-list-pagination :is(.previous, .next) .page-link {
    border-color: var(--admin-border);
    background: var(--admin-surface);
}

html[data-bs-theme] .portal-list-pagination .page-item:not(.active, .disabled) .page-link:hover {
    border-color: var(--admin-border);
    background: var(--admin-hover);
}

html[data-bs-theme] .portal-list-pagination .page-item.active .page-link {
    border-color: #2563EB;
    color: #FFFFFF;
    background: #2563EB;
}

html[data-bs-theme] .portal-list-pagination .page-item.disabled .page-link {
    color: var(--admin-text-muted);
    opacity: .55;
}

/* Backpack folds the filters behind a toggle below lg; tablets have room for them inline. */
@media (min-width: 768px) and (max-width: 991.98px) {
    .portal-list .navbar-filters .navbar-toggler {
        display: none;
    }

    .portal-list .navbar-filters .navbar-collapse {
        display: flex !important;
        flex-basis: auto;
    }

    .portal-list .navbar-filters .navbar-nav {
        flex-direction: row;
    }

    .portal-list .navbar-filters .navbar-nav .dropdown-menu {
        position: absolute;
    }
}

@media (max-width: 767.98px) {
    /* Backpack's own "Filters" toggle button takes over. */
    .portal-list-filters-label {
        display: none;
    }

    /* Phones: the summary shares the first line with the "Filters" button and takes what is left. */
    .portal-filter-summary {
        flex: 1 1 0;
    }

    /* The search gets its own line. */
    .portal-list .portal-list-search {
        flex: 1 0 100%;
        max-width: none;
        margin-left: 0;
    }

    .portal-list-pagination {
        flex-direction: column;
        align-items: stretch;
    }

    .portal-list-pagination-start,
    .portal-list-pagination-end {
        justify-content: space-between;
    }
}

@media (max-width: 575.98px) {
    /* Phones: previous, current page, next. The count line above gives the position. */
    .portal-list-pagination .paginate_button:not(.previous, .next, .active) {
        display: none;
    }
}

/* Row buttons: labelled, quiet, consistent across every list. */
html[data-bs-theme] .portal-row-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 500;
    line-height: 20px;
    text-decoration: none;
    color: var(--admin-text-primary);
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: 7px;
}

html[data-bs-theme] .portal-row-action:hover {
    color: var(--admin-text-primary);
    background: var(--admin-hover);
    border-color: var(--admin-input-border);
}

html[data-bs-theme] .portal-row-action i {
    font-size: 15px;
}

html[data-bs-theme] .portal-row-action-danger,
html[data-bs-theme] .portal-row-action-danger:hover {
    color: var(--portal-danger);
}

html[data-bs-theme] .portal-row-action-danger:hover {
    background: var(--portal-danger-bg);
    border-color: transparent;
}

html[data-bs-theme] .portal-row-more-toggle {
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
}

html[data-bs-theme] .portal-row-more-toggle[aria-expanded="true"] {
    background: var(--admin-hover);
    border-color: var(--admin-input-border);
}

html[data-bs-theme] .portal-row-more-toggle:focus-visible {
    outline: 2px solid var(--admin-accent);
    outline-offset: 2px;
}

html[data-bs-theme] .portal-row-more-menu {
    min-width: 140px;
}

html[data-bs-theme] .portal-row-more-menu .portal-row-action-danger,
html[data-bs-theme] .portal-row-more-menu .portal-row-action-danger > i {
    color: var(--portal-danger);
}

html[data-bs-theme] .portal-row-more-menu .portal-row-action-danger:is(:hover, :focus-visible) {
    color: var(--portal-danger);
    background: var(--portal-danger-bg);
}

/* Cells built by the list closures. */
.portal-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.portal-cell-text {
    min-width: 0;
}

.portal-cell-title {
    display: block;
    font-weight: 600;
    line-height: 1.35;
    white-space: normal;
    color: var(--admin-text-primary);
    text-decoration: none;
}

a.portal-cell-title:hover {
    color: var(--admin-accent);
    text-decoration: underline;
}

/* The bulk-select checkbox shares the first cell; keep the content beside it. */
#crudTable td .portal-cell {
    display: inline-flex;
    vertical-align: middle;
}

#crudTable td .crud_bulk_actions_checkbox {
    vertical-align: middle;
    margin-right: 6px;
}

.portal-cell-sub {
    display: block;
    margin-top: 2px;
    font-size: 12.5px;
    line-height: 1.35;
    white-space: normal;
    color: var(--admin-text-secondary);
}

.portal-money {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.portal-money-old {
    margin-left: 6px;
    font-size: 12.5px;
    font-weight: 400;
    text-decoration: line-through;
    color: var(--admin-text-muted);
}

.portal-muted {
    color: var(--admin-text-muted);
}

.portal-thumb {
    flex-shrink: 0;
    object-fit: cover;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    background: var(--admin-hover);
}

.portal-thumb-sm { width: 36px; height: 36px; }
.portal-thumb-md { width: 48px; height: 48px; }
.portal-thumb-lg { width: 96px; height: 96px; }
.portal-thumb-xl { width: 100%; height: auto; aspect-ratio: 1; }

.portal-thumb-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--admin-text-muted);
}

/* --- Forms ------------------------------------------------------------------ */
html[data-bs-theme] form .form-group > label,
html[data-bs-theme] form .form-group > .d-inline-flex > label {
    margin-bottom: 6px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--admin-text-primary);
}

html[data-bs-theme] form .help-block {
    display: block;
    margin: 5px 0 0;
    font-size: 12.5px;
    line-height: 1.45;
}

.portal-form-section {
    margin-top: 22px;
    margin-bottom: 4px;
    padding-top: 20px;
    border-top: 1px solid var(--admin-border);
}

.portal-form-section.portal-form-section-first {
    margin-top: 0;
    padding-top: 2px;
    border-top: 0;
}

html[data-bs-theme] .portal-form-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--admin-text-primary);
}

.portal-form-section-title i {
    font-size: 19px;
    color: var(--admin-accent);
}

.portal-form-section-description {
    margin: 4px 0 6px;
    font-size: 13px;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] form .card,
html[data-bs-theme] #form_tabs .tab-content {
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    box-shadow: none;
}

html[data-bs-theme] #form_tabs .nav-tabs {
    gap: 2px;
    border-bottom: 0;
}

html[data-bs-theme] #form_tabs .nav-tabs .nav-link {
    padding: 10px 16px;
    font-weight: 500;
    border-radius: 8px 8px 0 0;
}

html[data-bs-theme] #form_tabs .tab-content {
    border-top-left-radius: 0;
    padding: 24px 28px;
}

html[data-bs-theme] #form_tabs .nav-tabs .nav-link.text-danger {
    color: var(--portal-danger) !important;
}

/* Keep the product photo and crop workspace compact inside the Photos tab. */
.portal-product-photo > .row {
    align-items: flex-start;
    gap: 16px;
    margin: 0 0 12px;
}

.portal-product-photo [data-handle="previewArea"] {
    flex: 0 0 auto;
    width: 96px;
    max-width: 100%;
    padding: 0;
}

.portal-product-photo [data-handle="previewArea"]:first-child {
    width: 220px;
    aspect-ratio: 1;
    margin-bottom: 0 !important;
    overflow: hidden;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    background: var(--admin-hover);
}

.portal-product-photo [data-handle="mainImage"]:not(.cropper-hidden) {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Backpack shows both preview areas even before the cropper is active. */
.portal-product-photo:not(:has(.cropper-container)) [data-handle="previewArea"] + [data-handle="previewArea"] {
    display: none !important;
}

.portal-product-photo .img-preview {
    width: 96px;
    height: 96px;
    margin: 0;
    border-radius: 8px;
}

.portal-product-photo > .btn-group {
    max-width: 100%;
    flex-wrap: wrap;
}

/* Keep Save / Cancel in reach on long forms. */
html[data-bs-theme] #saveActions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 16px 0 0 !important;
    padding: 12px 16px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: rgba(var(--admin-surface-rgb), .94);
    backdrop-filter: blur(6px);
}

html[data-bs-theme] #saveActions .float-end {
    margin-left: auto;
}

/* Switch field: Bootstrap 5 styling for Backpack's markup. */
html[data-bs-theme] .form-switch.switch {
    display: inline-flex;
    align-items: center;
    padding-left: 0;
}

html[data-bs-theme] .form-switch.switch .switch-input {
    width: 2.6em;
    height: 1.4em;
    margin: 0;
    float: none;
    cursor: pointer;
}

html[data-bs-theme] .form-switch.switch .switch-slider {
    display: none;
}

html[data-bs-theme] .form-switch.switch .switch-input:checked {
    border-color: var(--admin-accent);
    background-color: var(--admin-accent);
}

html[data-bs-theme] [bp-field-type="switch"] .d-inline-flex > label {
    margin: 0 0 0 10px !important;
}

/* Product variant rows (custom editor on the Variants tab). */
html[data-bs-theme] .portal-variant-row {
    position: relative;
    margin: 0 0 12px;
    padding: 12px 6px 4px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
}

.portal-variant-row > .controls {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    padding: 0 6px 4px;
}

/* --- Detail pages (order, customer, product, and crud::show for the rest) -- */
.portal-detail {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
    gap: 20px;
    align-items: start;
}

@media (max-width: 1199.98px) {
    .portal-detail {
        grid-template-columns: 1fr;
    }
}

html[data-bs-theme] .portal-card {
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
}

.portal-card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 14px;
}

html[data-bs-theme] .portal-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--admin-text-primary);
}

.portal-card-title i {
    font-size: 18px;
    color: var(--admin-text-secondary);
}

.portal-dl {
    display: grid;
    grid-template-columns: minmax(110px, 38%) minmax(0, 1fr);
    gap: 9px 16px;
    margin: 0;
}

.portal-dl dt {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--admin-text-secondary);
}

.portal-dl dd {
    margin: 0;
    word-break: break-word;
    color: var(--admin-text-primary);
}

.portal-empty {
    margin: 0;
    padding: 6px 0;
    font-size: 14px;
    color: var(--admin-text-muted);
}

html[data-bs-theme] .portal-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
}

html[data-bs-theme] .portal-table th {
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    text-align: left;
    text-transform: uppercase;
    color: var(--admin-text-secondary);
    border-bottom: 1px solid var(--admin-border);
}

html[data-bs-theme] .portal-table td {
    padding: 10px;
    vertical-align: middle;
    border-bottom: 1px solid var(--admin-border);
}

html[data-bs-theme] .portal-table tr:last-child td {
    border-bottom: 0;
}

.portal-table .text-end {
    text-align: right;
}

.portal-totals {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 24px;
    max-width: 340px;
    margin: 14px 0 0 auto;
    font-size: 14px;
}

.portal-totals dt {
    font-weight: 500;
    color: var(--admin-text-secondary);
}

.portal-totals dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.portal-totals .portal-totals-grand {
    padding-top: 8px;
    border-top: 1px solid var(--admin-border);
    font-size: 16px;
    font-weight: 700;
    color: var(--admin-text-primary);
}

/* Order progress: Pending → Accepted → Out for delivery → Completed. */
.portal-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-step {
    position: relative;
    padding-top: 30px;
    text-align: center;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--admin-text-muted);
}

.portal-step::before {
    content: "";
    position: absolute;
    top: 9px;
    left: calc(-50% + 14px);
    right: calc(50% + 14px);
    height: 2px;
    background: var(--admin-border);
}

.portal-step:first-child::before {
    display: none;
}

.portal-step-dot {
    position: absolute;
    top: 0;
    left: 50%;
    width: 20px;
    height: 20px;
    margin-left: -10px;
    border: 2px solid var(--admin-border);
    border-radius: 50%;
    background: var(--admin-surface);
}

.portal-step.is-done,
.portal-step.is-current {
    color: var(--admin-text-primary);
}

.portal-step.is-done::before,
.portal-step.is-current::before {
    background: var(--portal-success);
}

.portal-step.is-done .portal-step-dot {
    border-color: var(--portal-success);
    background: var(--portal-success);
}

.portal-step.is-current .portal-step-dot {
    border-color: var(--admin-accent);
    background: var(--admin-accent);
    box-shadow: 0 0 0 4px rgba(var(--admin-accent-rgb), .2);
}

.portal-status-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.portal-status-actions form {
    margin: 0;
}

.portal-status-actions .btn {
    width: 100%;
    text-align: left;
}

.portal-status-help {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--admin-text-secondary);
}

.portal-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

html[data-bs-theme] .portal-stat {
    padding: 14px 16px;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
}

.portal-stat-label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .portal-stat-value {
    margin-top: 4px;
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--admin-text-primary);
}

/* A second line under a headline number, e.g. a total split by currency (…៛ · $…). */
.portal-stat-sub {
    margin-top: 2px;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    color: var(--admin-text-secondary);
}

.portal-receipt {
    display: block;
    max-width: 100%;
    max-height: 360px;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
}

.portal-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 10px;
}

.portal-gallery img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
}

.portal-rich-text {
    line-height: 1.6;
    color: var(--admin-text-primary);
}

.portal-rich-text > :last-child {
    margin-bottom: 0;
}

.portal-address {
    padding: 12px 0;
    border-bottom: 1px solid var(--admin-border);
}

.portal-address:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.portal-address:first-child {
    padding-top: 0;
}

@media print {
    .app-sidebar,
    .app-header,
    .portal-status-actions,
    .portal-page-actions,
    .portal-back-link {
        display: none !important;
    }

    .app-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* --- Detail pages: long text, lists of linked items, JSON ------------------- */
.portal-prewrap {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.55;
}

.portal-plain-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-plain-list > li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--admin-border);
}

.portal-plain-list > li:last-child {
    border-bottom: 0;
}

.portal-plain-list > li > span {
    min-width: 0;
}

.portal-thumb-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.portal-code {
    margin: 0;
    padding: 12px;
    max-height: 360px;
    overflow: auto;
    font-size: 12.5px;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    background: var(--admin-hover);
    color: var(--admin-text-primary);
    white-space: pre-wrap;
}

/* --- Detail pages: shared layout (crud::show) -------------------------------
   Every screen without a hand-made detail page. Cards come from the controller
   (PortalCrud::addDetailCard); these rules cover the pieces inside them. */
.portal-detail.portal-detail-single {
    grid-template-columns: minmax(0, 1fr);
    max-width: 960px;
}

.portal-card-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.portal-detail-block + .portal-detail-block,
.portal-dl + .portal-detail-block,
.portal-detail-block + .portal-dl {
    margin-top: 18px;
}

html[data-bs-theme] .portal-detail-block-title {
    margin: 0 0 8px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--admin-text-secondary);
}

/* A picture beside its facts, e.g. a team member's photo next to their profile. */
.portal-media {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 20px;
}

.portal-media-figure {
    flex: 0 0 auto;
    width: 120px;
    max-width: 100%;
}

.portal-media-body {
    flex: 1 1 260px;
    min-width: 0;
}

/* A missing or broken image keeps its box instead of showing the alt text. */
img.portal-thumb {
    overflow: hidden;
    font-size: 0;
    color: transparent;
}

/* Nested lists of links: menu links, sub-categories, spec groups. */
.portal-tree,
.portal-tree ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-tree ul {
    margin-left: 18px;
    padding-left: 14px;
    border-left: 1px solid var(--admin-border);
}

.portal-tree li {
    padding: 7px 0;
}

.portal-tree li + li {
    border-top: 1px solid var(--admin-border);
}

.portal-tree ul > li:first-child {
    margin-top: 7px;
    border-top: 1px solid var(--admin-border);
}

.portal-tree-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 12px;
}

.portal-tree-row .portal-cell-sub {
    margin: 0;
    overflow-wrap: anywhere;
}

/* Banner slides: the image as the website shows it, with its texts below. */
.portal-slides {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

html[data-bs-theme] .portal-slide {
    overflow: hidden;
    border: 1px solid var(--admin-border);
    border-radius: var(--portal-radius);
    background: var(--admin-surface);
}

.portal-slide-image {
    position: relative;
    display: block;
    aspect-ratio: 16 / 7;
    overflow: hidden;
    font-size: 0;
    color: transparent;
    background: var(--admin-hover);
}

.portal-slide-image > a {
    position: absolute;
    inset: 0;
}

.portal-slide-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.portal-slide-image > .is-broken {
    display: none;
}

/* A gallery photo that cannot be loaded keeps an empty tile. */
.portal-gallery > a.is-broken {
    aspect-ratio: 1;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    background: var(--admin-hover);
}

.portal-gallery > a.is-broken img {
    display: none;
}

.portal-slide-image .la {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--admin-text-muted);
}

.portal-slide-number {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    min-width: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, .6);
}

.portal-slide-body {
    padding: 12px 14px 14px;
}

.portal-slide-body .portal-cell-sub {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.portal-slide-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 12.5px;
    color: var(--admin-text-secondary);
    overflow-wrap: anywhere;
}

/* A table of all records of a kind with this one marked (delivery fees, order value ranges). */
html[data-bs-theme] .portal-table tr.is-current > td {
    font-weight: 600;
    background: rgba(var(--admin-accent-rgb), .08);
}

/* What a team member may do: one row per screen, in two columns where there is room. */
.portal-access-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    column-gap: 28px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-access-list > li {
    padding: 8px 0;
    border-bottom: 1px solid var(--admin-border);
}

.portal-access-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 10px;
}

.portal-badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* --- Dashboard ---------------------------------------------------------------- */
html[data-bs-theme] .portal-section-heading {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--admin-text-secondary);
}

html[data-bs-theme] .portal-action-tile {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}

html[data-bs-theme] .portal-action-tile:hover,
html[data-bs-theme] .portal-action-tile:focus-visible {
    border-color: var(--admin-accent);
    box-shadow: 0 0 0 3px rgba(var(--admin-accent-rgb), .12);
    color: inherit;
}

.portal-action-tile > span:last-child {
    display: flex;
    flex-direction: column;
}

.portal-action-tile-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    font-size: 22px;
    border-radius: 10px;
    color: var(--admin-text-secondary);
    background: var(--admin-hover);
}

.portal-action-tile-warning .portal-action-tile-icon {
    color: var(--portal-warning);
    background: var(--portal-warning-bg);
}

.portal-status-list > li {
    justify-content: space-between;
}

.portal-status-count {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--admin-text-primary);
}

/* Long text in list cells wraps instead of widening the table (which hides the action buttons). */
.portal-wrap {
    display: block;
    min-width: 220px;
    white-space: normal;
    overflow-wrap: anywhere;
}
