/*
 * BO revamp overrides, loaded after the domain's sb-admin-2 theme file so a fix
 * lands once here instead of in all 4 theme copies (sb-admin-2 / -blue /
 * -purple / -turquoise).
 */

/*
 * Pin the expanded desktop sidebar and let it scroll on its own. Otherwise the
 * sidebar sets the page height on shorter pages, so opening/closing an accordion
 * group shrinks the page mid-animation and the browser clamps the scroll back
 * toward the top. Icon-only (.toggled) mode is left alone: its submenus are
 * absolutely-positioned flyouts that a scroll container would clip.
 */
@media (min-width: 768px) {
    .sidebar:not(.toggled) {
        position: sticky;
        top: 0;
        align-self: flex-start;
        height: 100vh;
        overflow-y: auto;
        flex-shrink: 0;
    }
}

/*
 * Topnav alert counters (master.blade.php). Pill shape, but the old strip's
 * colours: grey bold label, count green at zero / red when non-zero (the same
 * named colours the old inline style="color:..." used), transparent fill.
 * .is-alert is set by pgSetCounter(). Positions are fixed on purpose — ops
 * find counters by place, not by scanning.
 */
.pg-topbar {
    height: auto;
    min-height: 4.375rem;
}

.pg-counters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    padding: 0.5rem 0;
    font-size: 0.95rem;
}

.pg-counter {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.1rem 0.6rem;
    border: 1px solid #858796;
    border-radius: 999px;
    background: transparent;
    color: #858796;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}

.pg-counter:hover,
.pg-counter:focus {
    background: #f8f9fc;
    color: #858796;
    text-decoration: none;
}

.pg-counter-value {
    color: #13855c; /* same green as statuses (.pg-status-success) */
    font-variant-numeric: tabular-nums;
}

.pg-counter.is-alert .pg-counter-value,
.pg-counter.is-alert .pg-counter-note {
    color: red;
}

.pg-counter-note {
    font-weight: 400;
}

/*
 * The theme gives every .btn `margin: 5px` (sb-admin-2*.css), which knocks a
 * button attached to an input (Bootstrap .input-group) out of line with the
 * field. Attached buttons need no margin.
 */
.input-group-prepend .btn,
.input-group-append .btn {
    margin: 0;
}

/*
 * Sidebar menu items: icon column + label column (sidebar.blade.php), so a long
 * label wraps onto the next line under its own text instead of spilling out of
 * the box (the theme sets white-space: nowrap on .collapse-item).
 */
.sidebar .pg-nav-item {
    display: flex !important;
    align-items: flex-start;
    white-space: normal;
}

.sidebar .pg-nav-item .pg-nav-icon {
    flex: 0 0 1.4rem;
    text-align: center;
}

.sidebar .pg-nav-item .pg-nav-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Submenu headers keep their collapse chevron pinned to the right. */
.sidebar .pg-nav-item[data-toggle="collapse"]::after {
    margin-left: auto;
    padding-left: 0.25rem;
}

/*
 * Current page: light panel + white edge bar + bold white text. The theme's
 * own active style (blue text) is nearly invisible on the dark sidebar.
 */
.sidebar .nav-item .collapse .collapse-inner .collapse-item.active,
.sidebar .nav-item .collapsing .collapse-inner .collapse-item.active {
    background-color: rgba(255, 255, 255, 0.22);
    box-shadow: inset 4px 0 0 #fff;
    color: #fff !important;
    font-weight: 700;
}

.sidebar .nav-item .collapse .collapse-inner .collapse-item.active:hover,
.sidebar .nav-item .collapsing .collapse-inner .collapse-item.active:hover {
    background-color: rgba(255, 255, 255, 0.28);
}

/* Group / submenu header that contains the current page. */
.sidebar .nav-item .nav-link.pg-group-active,
.sidebar .nav-item .nav-link.pg-group-active i {
    color: #fff !important;
    font-weight: 700;
}

/*
 * Card header title. Pages no longer repeat the title as an <h1> above the card
 * (removed to save space), so the card title carries the page name — make it
 * read as one. Matches both markup styles used: <h6 class="m-0 font-weight-bold
 * text-primary"> and <span class="font-weight-bold text-primary">.
 */
.card-header .font-weight-bold.text-primary {
    font-size: 1.25rem;
}

/* Only the page's main card gets the large title (review F27). Cards that come after
   it (a later card, or a card in a later row / column) and cards nested inside another
   card are sections of the page: same weight and colour, body-size-plus title. */
.card ~ .card > .card-header .font-weight-bold.text-primary,
.card .card .card-header .font-weight-bold.text-primary,
.row ~ .row .card-header .font-weight-bold.text-primary,
[class*="col-"] ~ [class*="col-"] .card-header .font-weight-bold.text-primary {
    font-size: 1rem;
}

/*
 * On/Off toggle with the text inside the pill (Bootstrap's custom-switch can't
 * hold text). Border and knob are always grey; only the text colour changes
 * (green ON / red OFF). Markup: <label class="pg-toggle"><input type="checkbox" …>
 * <span class="pg-toggle-track" data-on="On" data-off="Off"></span></label>.
 * Still a real checkbox, so it submits exactly like one.
 */
.pg-toggle {
    position: relative;
    display: inline-block;
    cursor: pointer;
    user-select: none;
}

.pg-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.pg-toggle-track {
    position: relative;
    display: block;
    width: 3.9rem;
    height: 1.5rem;
    border-radius: 1rem;
    background: transparent;
    box-shadow: inset 0 0 0 1.5px #d1d3e2;
    color: #e74a3b;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.5rem;
    transition: box-shadow 0.15s ease-in-out, color 0.15s ease-in-out;
}

.pg-toggle-track::before {
    content: attr(data-off);
    position: absolute;
    right: 0.55rem;
}

.pg-toggle-track::after {
    content: '';
    position: absolute;
    top: 0.2rem;
    left: 0.2rem;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    background: #b7b9cc;
    transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.pg-toggle input:checked + .pg-toggle-track {
    color: green;
}

.pg-toggle input:checked + .pg-toggle-track::before {
    content: attr(data-on);
    right: auto;
    left: 0.6rem;
}

.pg-toggle input:checked + .pg-toggle-track::after {
    transform: translateX(2.4rem);
}

.pg-toggle input:focus-visible + .pg-toggle-track {
    outline: 2px solid rgba(78, 115, 223, 0.5);
    outline-offset: 2px;
}

/*
 * Global AJAX failure notice (master.blade.php, pgToast) and the "stale" state of
 * the top-bar counters when their refresh fails.
 */
.pg-toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1080;
    max-width: 24rem;
    margin: 0;
}

.pg-counters.is-stale {
    opacity: 0.45;
}

/* Ticket detail action row (review F4): main action first, destructive pushed right (.ml-auto). */
.pg-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
}
.pg-actions > form { margin: 0; }
.pg-actions > form .btn + .btn,
.pg-actions > form .btn + a.btn,
.pg-actions > form a.btn + .btn { margin-left: .5rem; }
/* Button hierarchy (review F11). The themes draw every .btn as an outline:
     primary action   .btn-primary.pg-main  solid, theme brand colour (--pg-brand, set per theme file)
                      .btn-success.pg-main  solid green (approve-type main action)
     secondary        .btn-primary          theme-coloured outline
     back / cancel    .btn-outline-secondary grey outline, same in every theme
     destructive      .btn-danger           red outline
   One .pg-main per view. */
.btn.pg-main,
.btn.pg-main:hover,
.btn.pg-main:focus,
.btn.pg-main:active { color: #fff !important; }
.btn-primary.pg-main { background-color: var(--pg-brand, #08807E) !important; border-color: var(--pg-brand, #08807E) !important; }
.btn-success.pg-main { background-color: #1cc88a !important; border-color: #1cc88a !important; }
.btn-danger.pg-main  { background-color: #e74a3b !important; border-color: #e74a3b !important; }
.btn.pg-main:hover, .btn.pg-main:focus { filter: brightness(.92); }
.btn.pg-main:disabled, .btn.pg-main.disabled { opacity: .65; filter: none; }

/* Links vs badges vs buttons (BO standard):
   - one of several values (tags, groups, users, bank codes) → .badge.badge-light.border,
     a link when it has a page the viewer may open, plain otherwise;
   - a single name in a table cell / field → plain text link, no badge;
   - a status (Active, Processing, Matched…) → coloured text via pgStatus() / pg_status(),
     never a link; a flag on a record (e.g. Custom) → coloured badge; when it refers to a
     record, put that record next to it as a value badge (Custom + Group: X);
   - an action → button, never a badge;
   - no ↗ markers: record links open in a new tab throughout the BO anyway.
   Linked badges underline on hover so they read as clickable. */
a.badge[href] { text-decoration: none; }
a.badge[href]:hover, a.badge[href]:focus { text-decoration: underline; filter: brightness(.92); }

/* Agent commission rate tables: this deployment's domain (paid here) shown first, tinted. */
.table .pg-rate-current { background-color: rgba(0, 0, 0, .035); }

/* Row-select checkbox column in DataTables: DataTables pads header cells on the right for
   its sort arrows (even unsortable ones), pushing a centred header checkbox off the row
   checkboxes below it. Same padding on both, checkbox centred both ways. */
.table .pg-check-col { width: 2rem; min-width: 2rem; text-align: center; vertical-align: middle; padding-left: .5rem !important; padding-right: .5rem !important; }
.table .pg-check-col input[type="checkbox"] { margin: 0; vertical-align: middle; }

/* Tables with a two-row (grouped) header, e.g. the commission rate tables. DataTables'
   Bootstrap styles assume one header row: separated borders, and no right border on each
   row's last cell, so a rowspan'd last column (Action) loses its divider and the 2px
   header line doubles. Collapse the borders and use 1px everywhere. */
.table-bordered.pg-grouped-head { border-collapse: collapse !important; }
.table-bordered.pg-grouped-head th,
.table-bordered.pg-grouped-head td { border-width: 1px !important; }
.table-bordered.pg-grouped-head thead th { vertical-align: middle; }

/* Statuses (review F10): one look everywhere, coloured text in a readable shade per
   meaning. Render with pgStatus() / pg_status(); the tones are Bootstrap's names. */
.pg-status { font-weight: 600; white-space: nowrap; }
.pg-status-success { color: #13855c; }
.pg-status-danger { color: red; }
.pg-status-warning { color: darkorange; }
.pg-status-secondary { color: #6e707e; }
.pg-status-info { color: #1a7f8e; }
.pg-status-primary { color: #4e73df; }
.pg-status-dark { color: #5a5c69; }

/* Real badges (value chips, flags such as Custom): white text on every tone. The theme's
   green and cyan are too light for white text, so they use a darker shade; yellow
   (warning) is the theme's own. */
.badge-success { background-color: #13855c; color: #fff; }
.badge-info { background-color: #1a7f8e; color: #fff; }
a.badge-success:hover, a.badge-success:focus { background-color: #0f6b4a; color: #fff; }
a.badge-info:hover, a.badge-info:focus { background-color: #156874; color: #fff; }

/* Text colours and small helpers that used to be inline styles (review F12). One shade
   per meaning, dark enough to read as text on white (the theme's badge green / yellow
   are too light for text). No !important, so a script can still set element.style.color. */
:root {
    --pg-text-red: red;
    --pg-text-green: #13855c;
    --pg-text-orange: #b7791f;
    --pg-text-grey: #6e707e;
}
.pg-required,
.pg-text-red { color: var(--pg-text-red); }
.pg-text-green { color: var(--pg-text-green); }
.pg-text-orange { color: var(--pg-text-orange); }
.pg-text-grey { color: var(--pg-text-grey); }
.pg-pointer { cursor: pointer; }
