.wb-footer
{
	padding: 0.5rem;
	/* Guaranteed minimum gap above the footer even when the content directly
	   above it fills the dialog exactly (see .wb-content below, which is
	   what actually pins this to the bottom on a fixed/auto-once-height
	   dialog - this margin is the visual breathing room once it's there).
	   Has to be margin, not padding: padding-top would sit INSIDE
	   .wb-footer's own box, between its top border and its buttons - that
	   pushes the border-top (and everything below it) flush against
	   whatever content precedes it, with no visible gap at all before the
	   footer starts. margin-top sits OUTSIDE the footer's box instead,
	   which is the actual gap this needs (this was briefly padding-top -
	   see the position:sticky rule below - over one specific worry that
	   turned out not to be a real bug: margin-top does stay put at every
	   scroll position once a dialog is actually scrolling, the ~20px change
	   that prompted the swap only ever showed up once scrolled exactly to
	   the true end of a capped dialog's content, which is .wb-footer
	   correctly settling into its natural flow position, gap and all -
	   not a jump to fix). */
	margin-top: 1.25rem;
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 0.75rem;
	border-top: 1px solid #ddd;
}

/* Opt-in via .dialog({ centerButtons: true }) */
.wb-footer.wb-footer-center
{
	justify-content: center;
}

/* Spacing between buttons is entirely down to the flex `gap` above now -
   .ui-button's own margin (meant for buttons sitting in ordinary text flow
   elsewhere on the page) would just add on top of that here, so switch it
   off within the footer. */
.wb-footer .ui-button
{
	margin: 0;
}

/*
 * Opt-in via a button descriptor's class: "wb-btn-danger" (see the buttons
 * array support in jquery.winbox.js) - for a destructive action (a dialog's
 * own Delete button) sitting in the same footer as Save/Cancel. Recolours
 * using Bootstrap's own --bs-danger rather than a hardcoded red, so it stays
 * the same red as every other danger element on the page (same convention
 * showMessageBox()'s icons already use - see theme.css) and follows dark
 * mode automatically. brightness() rather than a second named colour for
 * hover/active - simpler than hunting down an exact "darker danger" token,
 * and works the same regardless of theme.
 *
 * Selectors scoped through .wb-footer (not just .wb-btn-danger alone) so
 * this reliably beats jquery.button.css's own dark-mode override -
 * [data-bs-theme="dark"] .ui-button - on specificity rather than depending
 * on which of the two files happens to load second. Without that, dark mode
 * showed a plain grey button instead of red.
 */
.wb-footer .wb-btn-danger
{
	background: var(--bs-danger);
	border-color: var(--bs-danger);
	color: #fff;
}

[data-bs-theme="dark"] .wb-footer .wb-btn-danger
{
	background: var(--bs-danger);
	border-color: var(--bs-danger);
	color: #fff;
}

.wb-footer .wb-btn-danger:hover,
.wb-footer .wb-btn-danger.ui-state-hover,
.wb-footer .wb-btn-danger.ui-state-active,
.wb-footer .wb-btn-danger:active
{
	filter: brightness(0.9);
	color: #fff;
}

/*
 * Same opt-in convention as .wb-btn-danger above, for a button that needs to
 * stand out but isn't destructive (e.g. a dialog's Restore button, sitting
 * where Delete would otherwise be) - "wb-btn-warning" via Bootstrap's own
 * --bs-warning (orange/amber) rather than a hardcoded colour, for the same
 * dark-mode-follows-automatically reasoning as .wb-btn-danger.
 */
.wb-footer .wb-btn-warning
{
	background: var(--bs-warning);
	border-color: var(--bs-warning);
	color: #000;
}

[data-bs-theme="dark"] .wb-footer .wb-btn-warning
{
	background: var(--bs-warning);
	border-color: var(--bs-warning);
	color: #000;
}

.wb-footer .wb-btn-warning:hover,
.wb-footer .wb-btn-warning.ui-state-hover,
.wb-footer .wb-btn-warning.ui-state-active,
.wb-footer .wb-btn-warning:active
{
	filter: brightness(0.9);
	color: #000;
}

/*
 * .wb-content holds whatever the caller wrapped in .dialog() (call it "el")
 * plus .wb-footer, stacked - see jquery.winbox.js. Both used to just flow
 * normally, so on a dialog taller than its current content (a fixed-height
 * one, or one using height: "auto-once" - see jquery.winbox.js - whose
 * content later shrinks, e.g. switching to a shorter Bootstrap tab) the
 * footer rode up to sit right under whatever content happened to be there,
 * leaving dead space below it instead of at the bottom of the window like
 * every other dialog on every platform. Making this a column flexbox and
 * letting "el" (the one non-footer child - there's no consistent class to
 * target it by name, since callers wrap all sorts of things) grow to fill
 * any leftover space pins .wb-footer to the actual bottom instead.
 * min-height only, not height - a dialog genuinely taller than its fixed
 * window (auto-height's own live-tracking case) still needs .wb-body's
 * overflow:auto (see jquery.winbox.css) to take over rather than being
 * force-fitted.
 *
 * The flex/min-height part below is scoped to .winbox .wb-content, NOT bare
 * .wb-content (padding stays unscoped - see why that specifically has to
 * stay unscoped in the next comment): before a dialog is ever mounted,
 * jquery.winbox.js measures its natural size by appending this same "el" +
 * .wb-content wrapper directly to <body> (see measureNaturalSize()/
 * measureHeightAtWidth()) - nowhere near a real .winbox window yet.
 * min-height:100% on a position:absolute element with no positioned
 * ancestor resolves against the viewport, not "however tall the content
 * naturally is" - without this scope, auto-sized dialogs (the login popup,
 * every showMessageBox()) measured as viewport-height instead of their real
 * content height the moment this rule was added.
 */
.wb-content
{
	/* Deliberately NOT scoped to .winbox: this has to be identical during
	   the off-screen measurement above and the real, later mount, or the
	   measured height comes out ~2.5rem short of what the content will
	   actually need once real padding is added back - the exact gap the
	   footer then overflowed the window bottom by, the first time this rule
	   was scoped along with the rest. */
	padding: 1.25rem;
}

.winbox .wb-content
{
	display: flex;
	flex-direction: column;
	min-height: 100%;
}

.winbox .wb-content > *:not(.wb-footer)
{
	flex: 1 0 auto;
}

/*
 * Keeps the Save/Delete/Cancel row visible at the bottom of the dialog even
 * while the content above it is scrolling - see jquery.winbox.js's
 * getMaxDialogHeight(), which caps every dialog's height at the viewport
 * (previously uncapped, so a tall dialog just grew past the bottom of the
 * screen with no way to reach it - see .wb-body's own overflow:auto below).
 * Without this, the footer scrolled away with the rest of .wb-content's
 * flex column instead of staying put, since it's an ordinary child of the
 * same column .wb-body scrolls as one unit.
 *
 * position:sticky needs a background - otherwise scrolled-past content is
 * visible showing through underneath it as the user scrolls. These colours
 * match .wb-body's own (winbox.min.css's own default white in light mode;
 * our dark-mode override below), not a CSS variable, so the footer is
 * pixel-identical to the body behind it in both themes rather than
 * approximately matching.
 */
.winbox .wb-content > .wb-footer
{
	position: sticky;
	bottom: 0;
	background: #fff;
}

[data-bs-theme="dark"] .winbox .wb-content > .wb-footer
{
	background: #1e1e1e;
}

/*
 * Our own modal backdrop - a real, independent element covering the whole
 * viewport, rather than WinBox's built-in modal darkening (which is a
 * pseudo-element glued to the dialog's own box, so it moves/resizes along
 * with the dialog - see jquery.winbox.js for the full explanation). Sitting
 * as a real element also means it actually blocks clicks on the rest of the
 * page, which WinBox's own modal backdrop never did.
 */
.wb-modal-overlay
{
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: #000;
	opacity: 0.4;
	/* Real value is set inline per-instance by jquery.winbox.js (nextModalZIndex) - a stacked
	   modal needs a strictly higher z-index than any modal already open, which a single shared
	   value here can't express. This is just a sane fallback if that ever somehow doesn't run. */
	z-index: 100000;
}

/* A dialog's real z-index (modal or not) is set per-instance by jquery.winbox.js, via an
   injected <style> rule targeting that dialog's own unique "wb-dialog-instance-N" class, not
   this shared one - see nextModalZIndex there for why a single rule here (this used to carry a
   fixed "z-index: 100001 !important") can't correctly keep a SECOND dialog above a FIRST one,
   and why modeless dialogs need a slot in that same counter too (otherwise they render behind
   any modal already open). The "wb-modal" class itself is still applied to every modal window
   (see jquery.winbox.js) even though no rule here keys off it any more - left in as a plain
   marker (e.g. for document.querySelectorAll(".wb-modal") while debugging) rather than removed
   outright. */

/* Outer window: no scrolling */
.winbox
{
    overflow: visible !important;
}

/* Inner body: scroll when needed */
.winbox .wb-body
{
    overflow: auto !important;
}

/*
 * Dark mode - keyed on Bootstrap 5.3's own [data-bs-theme="dark"] attribute
 * (see theme.js for how/when that gets set). Bootstrap's own components
 * (form-control, labels, .btn, etc.) inside the dialog already re-theme
 * themselves automatically from that same attribute - this only needs to
 * cover the chrome WE built: the body background/text and footer border.
 * The title bar colour is deliberately left alone here - see content.tpl,
 * where it's driven by the same TOP_NAVBAR_STYLES value as the top navbar,
 * so admins only ever need to change it in one place.
 */
[data-bs-theme="dark"] .winbox
{
	background: #1e1e1e;
}

[data-bs-theme="dark"] .winbox .wb-body
{
	background: #1e1e1e;
	color: #e4e4e4;
}

[data-bs-theme="dark"] .wb-footer
{
	border-top-color: #3a3a3a;
}

/* A flat 0.4 opacity reads as a clear dim against a light page, but on an
   already-dark page the difference between "dimmed background" and "active
   dialog" gets harder to see - a touch more opacity keeps the contrast
   working in both modes. */
[data-bs-theme="dark"] .wb-modal-overlay
{
	opacity: 0.55;
}