/* =========================================================================
   RedRogue UI — design tokens + modern component layer
   Loaded AFTER bootstrap.css, theme.css, skins and custom.css on every page
   (include-top.php and include-top-public.php).

   Section 1 (tokens) and section 2 (opt-in rr-* components) are safe
   anywhere. Section 3 gently refines stock Bootstrap/Porto elements
   app-wide — extend it gradually and check the backend after each change.
   ========================================================================= */

/* ---------- 1. Tokens ---------- */
:root {
    --rr-red: #bd564f;
    --rr-red-hover: #a8473f;
    --rr-red-active: #94403a;
    --rr-red-soft: rgba(189, 86, 79, .18);
    --rr-charcoal: #3e4043;
    --rr-ink: #24262a;          /* body text, field values */
    --rr-heading: #3a3c40;      /* titles, labels: just under the brand charcoal */
    --rr-muted: #686d75;
    --rr-line: #d6d9df;         /* form controls */
    --rr-divider: #e8eaee;      /* structural lines: bars, sidebar, tables, tabs */
    --rr-line-hover: #b9bdc5;
    --rr-canvas: #f6f6f6;
    --rr-surface: #fff;
    --rr-danger: #c0392b;
    --rr-danger-soft: rgba(192, 57, 43, .16);
    /* Radius scale: sm = menu items, chips; base = inputs, buttons, alerts,
       dropdowns; lg = cards, panels, tab containers. */
    --rr-radius-sm: 6px;
    --rr-radius: 8px;
    --rr-radius-lg: 12px;
    --rr-font-body: "Figtree", "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    /* Titles use the body family at a semibold weight with slight negative tracking.
       Swap this token if a separate display face is wanted later. */
    --rr-font-display: var(--rr-font-body);
    --rr-title-tracking: -.015em;
    --rr-shadow-lg: 0 2px 4px rgba(20, 22, 26, .04), 0 24px 56px -12px rgba(20, 22, 26, .20);
    /* Status palette: alerts, SweetAlert icons, status text (.text-rr-*) */
    --rr-success: #12b76a;
    --rr-warning: #f79009;
    --rr-info: #2e90fa;
    --rr-error: #f04438;
}

html.dark,
html.rr-dark {
    --rr-red: #d0665f;
    --rr-red-hover: #db7d76;
    --rr-red-active: #b9544d;
    --rr-red-soft: rgba(208, 102, 95, .28);
    --rr-charcoal: #1d1f22;
    --rr-ink: #e6e7ea;
    --rr-heading: #d6d8dc;
    --rr-muted: #a0a5ad;
    --rr-line: #3d4046;
    --rr-divider: #303338;
    --rr-line-hover: #565a61;
    --rr-canvas: #2a2c30;
    --rr-surface: #222429;
    --rr-danger: #e0675a;
    --rr-danger-soft: rgba(224, 103, 90, .22);
    --rr-shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 24px 56px -12px rgba(0, 0, 0, .6);
}

/* ---------- 2. Opt-in components ---------- */

/* Field with a leading icon and optional trailing button:
   <div class="rr-field"><i class="rr-field__icon ..."></i><input class="form-control"></div> */
.rr-field {
    position: relative;
}

.rr-field__icon {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    color: #9a9fa7;
    font-size: 1rem;
    pointer-events: none;
}

.rr-field .form-control {
    padding-left: 42px;
}

.rr-field:focus-within .rr-field__icon {
    color: var(--rr-red);
}

.rr-field--action .form-control {
    padding-right: 48px;
}

.rr-field__toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: var(--rr-radius);
    background: transparent;
    color: #80858d;
    cursor: pointer;
}

.rr-field__toggle:hover { color: var(--rr-ink); background: var(--rr-canvas); }
.rr-field__toggle:focus { outline: none; }
.rr-field__toggle:focus-visible { color: var(--rr-ink); box-shadow: 0 0 0 3px var(--rr-red-soft); }

/* Label with a link on the right (e.g. "Password ... Forgot password?") */
.rr-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.rr-label-row .rr-link { font-size: .8125rem; }

/* Links */
.rr-link,
a.rr-link {
    color: var(--rr-red);
    font-weight: 600;
}

.rr-link:hover,
.rr-link:focus {
    color: var(--rr-red-hover);
    text-decoration: underline;
}

/* Primary button */
.btn-rr {
    height: 48px;
    padding: 0 24px;
    font-weight: 600;
    font-size: 1rem;
    color: #fff;
    background: var(--rr-red);
    border: 0;
    border-radius: var(--rr-radius);
    transition: background-color .15s ease, box-shadow .15s ease;
}

.btn-rr:hover { color: #fff; background: var(--rr-red-hover); }
.btn-rr:focus,
.btn-rr.focus { color: #fff; box-shadow: 0 0 0 4px var(--rr-red-soft); }
.btn-rr:not(:disabled):not(.disabled):active { color: #fff; background: var(--rr-red-active); }
.btn-rr:disabled,
.btn-rr.disabled { color: #fff; background: var(--rr-red); opacity: .65; }

/* Status text, e.g. the allocation note in the finance strip */
.text-rr-success { color: var(--rr-success) !important; }
.text-rr-danger  { color: var(--rr-error) !important; }

/* ---------- 3. App-wide refinements (low risk) ---------- */
.form-control:focus {
    border-color: var(--rr-red);
    box-shadow: 0 0 0 3px var(--rr-red-soft);
}

.custom-control-input:checked ~ .custom-control-label::before {
    background-color: var(--rr-red);
    border-color: var(--rr-red);
}

.custom-control-input:focus ~ .custom-control-label::before {
    box-shadow: 0 0 0 3px var(--rr-red-soft);
}

.custom-control-input:focus:not(:checked) ~ .custom-control-label::before {
    border-color: var(--rr-red);
}

/* Load mask (jquery.mloading) — blurred backdrop + floating card with a spinner.
   Backend (html.rr-modern) and sign-in pages (body.rr-auth). The plugin's
   icon is hidden; the spinner is drawn on .mloading-bar::before. The plugin
   centres the bar itself with inline negative margins. Text arrives as
   "Logging<br/><strong>In</strong>..." and is shown on one line. */
:is(html.rr-modern, .rr-auth) .mloading.mloading-mask {
    background: color-mix(in srgb, var(--rr-canvas) 55%, transparent);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: rr-fade-in .25s ease both;
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    min-width: 220px;
    min-height: 0;
    padding: 32px 40px 28px;
    font-family: var(--rr-font-body);
    text-align: center;
    word-break: normal;
    background: var(--rr-surface);
    border: 1px solid var(--rr-divider);
    border-radius: var(--rr-radius-lg);
    box-shadow: var(--rr-shadow-lg);
    animation: rr-pop .45s cubic-bezier(.16, 1, .3, 1) both;
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-bar::before {
    content: "";
    width: 36px;
    height: 36px;
    border: 3px solid var(--rr-red-soft);
    border-top-color: var(--rr-red);
    border-radius: 50%;
    animation: rr-spin .75s linear infinite;
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-icon {
    display: none;
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-text {
    float: none;
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    color: var(--rr-muted);
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-text br {
    display: none;
}

:is(html.rr-modern, .rr-auth) .mloading .mloading-text strong {
    margin-left: .25em;
    font-weight: 700;
    color: var(--rr-heading);
}

/* Small containers: spinner only */
:is(html.rr-modern, .rr-auth) .mloading .mloading-bar-sm {
    min-width: 0;
    padding: 16px;
}

@keyframes rr-spin {
    to { transform: rotate(360deg); }
}

@keyframes rr-fade-in {
    from { opacity: 0; }
}

@keyframes rr-pop {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
}

/* SweetAlert (bootstrap-sweetalert) — same card, backdrop and motion as the
   load mask. The plugin centres the modal with margins (and sets margin-top
   from JS), so the width and margin-left change together. */
:is(html.rr-modern, .rr-auth) .sweet-overlay {
    background: color-mix(in srgb, var(--rr-canvas) 55%, transparent);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

:is(html.rr-modern, .rr-auth) .sweet-alert {
    box-sizing: border-box;
    width: 420px;
    margin-left: -210px;
    padding: 32px 32px 28px;
    font-family: var(--rr-font-body);
    color: var(--rr-ink);
    background: var(--rr-surface);
    border: 1px solid var(--rr-divider);
    border-radius: var(--rr-radius-lg);
    box-shadow: var(--rr-shadow-lg);
}

:is(html.rr-modern, .rr-auth) .sweet-alert.showSweetAlert:not([data-animation^="slide"]) {
    animation: rr-pop .45s cubic-bezier(.16, 1, .3, 1);
}

/* Icons: keep the plugin's animated drawings, slightly smaller, in a modern palette */
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon {
    zoom: .85;
    margin: 0 auto 24px;
}

:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-error { border-color: var(--rr-error); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-error .sa-line { background-color: var(--rr-error); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-warning { border-color: var(--rr-warning); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-warning .sa-body,
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-warning .sa-dot { background-color: var(--rr-warning); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-info { border-color: var(--rr-info); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-info::before,
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-info::after { background-color: var(--rr-info); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success { border-color: var(--rr-success); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success .sa-line { background-color: var(--rr-success); }
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success .sa-placeholder { border-color: color-mix(in srgb, var(--rr-success) 20%, transparent); }

/* The success tick is revealed by masks painted in the modal colour */
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success::before,
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success::after,
:is(html.rr-modern, .rr-auth) .sweet-alert .sa-icon.sa-success .sa-fix {
    background: var(--rr-surface);
}

/* !important to beat custom.css */
:is(html.rr-modern, .rr-auth) .sweet-alert > h3 {
    margin: 0 0 8px !important;
    font-family: var(--rr-font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: var(--rr-title-tracking);
    color: var(--rr-heading);
}

:is(html.rr-modern, .rr-auth) .sweet-alert .lead {
    margin: 0;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.5;
    color: var(--rr-muted) !important; /* beats Bootstrap's .text-muted */
}

:is(html.rr-modern, .rr-auth) .sweet-alert .form-group {
    margin: 20px 0 0;
}

:is(html.rr-modern, .rr-auth) .sweet-alert .sa-button-container {
    margin-top: 28px;
}

:is(html.rr-modern, .rr-auth) .sweet-alert .sa-confirm-button-container {
    display: inline-flex;
    flex-direction: row-reverse; /* cancel left, confirm right */
    gap: 8px;
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.btn {
    min-width: 120px;
    height: 44px;
    margin: 0;
    padding: 0 22px;
    font-size: 15px;
    border-radius: var(--rr-radius);
}

/* Confirm is the brand primary whatever class the call passed (most pass
   btn-default), except destructive btn-danger confirms */
:is(html.rr-modern, .rr-auth) .sweet-alert button.confirm:not(.btn-danger) {
    color: #fff;
    background: var(--rr-red);
    border-color: var(--rr-red);
    box-shadow: 0 1px 2px rgba(20, 22, 26, .05);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.confirm:not(.btn-danger):hover,
:is(html.rr-modern, .rr-auth) .sweet-alert button.confirm:not(.btn-danger):focus {
    background: var(--rr-red-hover);
    border-color: var(--rr-red-hover);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.confirm.btn-danger {
    color: #fff;
    background: var(--rr-danger);
    border-color: var(--rr-danger);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel {
    color: var(--rr-ink);
    background: var(--rr-surface);
    border: 1px solid var(--rr-line);
    box-shadow: 0 1px 2px rgba(20, 22, 26, .05);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel:hover {
    background: var(--rr-canvas);
    border-color: var(--rr-line-hover);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button:focus {
    outline: 0;
    box-shadow: 0 0 0 4px var(--rr-red-soft);
}

/* Yes/No confirm dialogs (two buttons): Yes is always success green and No a dark
   button, whatever classes the call passed - so the two are never confused. Single
   "OK" alerts keep the brand confirm above; destructive btn-danger confirms stay red. */
:is(html.rr-modern, .rr-auth) .sweet-alert {
    --rr-swal-no-bg: var(--rr-charcoal);
    --rr-swal-no-hover: #2c2e31;
}

:is(html.rr-modern.rr-dark, html.rr-modern.dark) .sweet-alert {
    --rr-swal-no-bg: #4a4e56;
    --rr-swal-no-hover: #575c65;
}

:is(html.rr-modern, .rr-auth) .sweet-alert[data-has-cancel-button="true"] button.confirm:not(.btn-danger) {
    color: #fff !important;
    background: var(--rr-success);
    border-color: var(--rr-success);
}

:is(html.rr-modern, .rr-auth) .sweet-alert[data-has-cancel-button="true"] button.confirm:not(.btn-danger):hover,
:is(html.rr-modern, .rr-auth) .sweet-alert[data-has-cancel-button="true"] button.confirm:not(.btn-danger):focus {
    background: color-mix(in srgb, var(--rr-success) 85%, #000);
    border-color: color-mix(in srgb, var(--rr-success) 85%, #000);
}

:is(html.rr-modern, .rr-auth) .sweet-alert[data-has-cancel-button="true"] button.confirm:not(.btn-danger):focus {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--rr-success) 25%, transparent);
}

/* custom.css forces white text on .btn-primary with !important - the cause of the
   invisible "No" (most calls pass cancelButtonClass: 'btn-primary') */
:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel {
    color: #fff !important;
    background: var(--rr-swal-no-bg);
    border-color: var(--rr-swal-no-bg);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel:hover,
:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel:focus {
    background: var(--rr-swal-no-hover);
    border-color: var(--rr-swal-no-hover);
}

:is(html.rr-modern, .rr-auth) .sweet-alert button.cancel:focus {
    box-shadow: 0 0 0 4px rgba(62, 64, 67, .25);
}

@media (max-width: 767px) {
    :is(html.rr-modern, .rr-auth) .sweet-alert {
        width: auto;
        margin-left: 0;
        left: 16px;
        right: 16px;
        padding: 28px 20px 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn-rr,
    .rr-field .form-control { transition: none !important; }
    :is(html.rr-modern, .rr-auth) .mloading.mloading-mask,
    :is(html.rr-modern, .rr-auth) .mloading .mloading-bar,
    :is(html.rr-modern, .rr-auth) .sweet-alert.showSweetAlert { animation: none; }
}

/* Accordion headers (.card-header > .btn-block[data-toggle="collapse"], e.g. the public
   documents invoice history and trustee onboarding steps): a chevron on the right that
   flips when the section is open. Bootstrap keeps aria-expanded in sync on the button. */
.card-header > .btn-block[data-toggle="collapse"] {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* the markup floats its badge/status icon right - in a flex row that's done with an auto margin */
.card-header > .btn-block[data-toggle="collapse"] > .pull-right,
.card-header > .btn-block[data-toggle="collapse"] > .float-right {
    float: none !important;
    margin-left: auto;
}

.card-header > .btn-block[data-toggle="collapse"]::after {
    content: "\f078"; /* fa-chevron-down */
    flex-shrink: 0;
    margin-left: auto;
    font-family: "Font Awesome 6 Pro";
    font-weight: 400;
    font-size: 12px;
    line-height: 1;
    color: var(--rr-muted, #686d75);
    transition: transform .2s ease;
}

.card-header > .btn-block[data-toggle="collapse"]:has(> .pull-right, > .float-right)::after {
    margin-left: 4px;
}

.card-header > .btn-block[data-toggle="collapse"][aria-expanded="true"]::after {
    transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
    .card-header > .btn-block[data-toggle="collapse"]::after { transition: none; }
}
