/* ══ JRP responsive layer ══
   Loaded last on every page, after the shared theme CSS, so these rules win
   without editing shared/ (that folder is re-copied from core-setup on export).
   Breakpoints follow Bootstrap 5: sm 576, md 768, lg 992, xl 1200, xxl 1400.
   Everything is scoped to body[data-static] (the static JRP copy only) and
   uses the theme's own tokens, so light, dark and every skin keep working.
   See plan/responsive.md. */

/* ── WP-1 · Off-canvas sidebar (< 992px) ── */
.rs-sidebar-backdrop {
	display: none;
}

@media (max-width: 991.98px) {
	/* AdminKit hides the rail with a negative margin that depends on its
	   width (-264px full, -74px compact). Take it out of the flow instead and
	   slide it in over the content, so the page never gets squeezed. */
	body[data-static] #sidebar {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 1045;
		height: 100vh;
		height: 100dvh;
		width: 264px !important;
		min-width: 264px !important;
		max-width: 85vw !important;
		margin-left: 0 !important;
		transform: translateX(-100%);
		visibility: hidden;
		transition: transform 0.3s ease-in-out, visibility 0s linear 0.3s !important;
	}

	body[data-static].rs-sidebar-open #sidebar {
		transform: translateX(0);
		visibility: visible;
		box-shadow: 0 0 2rem rgba(0, 0, 0, 0.35);
		transition: transform 0.3s ease-in-out, visibility 0s !important;
	}

	body[data-static] #sidebar .sidebar-content {
		width: 100% !important;
	}

	body[data-static].rs-sidebar-open .rs-sidebar-backdrop {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 1040;
		background: rgba(0, 0, 0, 0.45);
	}

	/* The page behind the open drawer must not scroll. */
	body[data-static].rs-sidebar-open .content {
		overflow: hidden;
	}

	/* The floating "›" collapse button belongs to the desktop rail. */
	body[data-static] .sidebar-collapse-btn {
		display: none !important;
	}
}

/* ── WP-2 · Header on small screens ── */
.rs-more-item,
.rs-more-panel {
	display: none;
}

/* Search: icon-only button below md instead of disappearing. */
@media (max-width: 767.98px) {
	body[data-static] .navbar .nav-item:has(> .header-search-btn) {
		display: block !important;
		margin-right: auto;
	}

	body[data-static] .header-search-btn .header-search-text,
	body[data-static] .header-search-btn .header-search-kbd {
		display: none;
	}
}

/* Toolbar: keep theme toggle and notifications visible on phones; the
   secondary actions move into the "more" panel (js/responsive.js). */
@media (max-width: 575.98px) {
	body[data-static] .toolbar-container.d-none {
		display: flex !important;
	}

	body[data-static] .rs-more-item {
		display: list-item;
		position: relative;
	}

	body[data-static] .rs-more-panel {
		position: absolute;
		top: calc(100% + 0.5rem);
		right: 0;
		z-index: 1030;
		/* Its positioning box is the narrow "more" button, so size to the icons. */
		width: max-content;
		max-width: calc(100vw - 2rem);
		flex-wrap: wrap;
		align-items: center;
		gap: 0.5rem;
		padding: 0.5rem;
		border: 1px solid var(--sk-border);
		border-radius: 0.75rem;
		background: var(--sk-surface);
		box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15);
	}

	/* The theme positions toolbar dropdown items absolutely; in the panel
	   they must sit in a row like the plain buttons. */
	body[data-static] .rs-more-panel > li.nav-item {
		position: relative !important;
	}

	body[data-static] .rs-more-item.is-open .rs-more-panel {
		display: flex;
	}

	/* Menus opened from the panel (apps, language) cannot line up with a
	   button this close to the left edge, so on phones they open as a sheet
	   across the screen under the header. !important beats Popper's inline
	   placement and the theme's .u-posabsolute utility. */
	body[data-static] .rs-more-panel .dropdown-menu.show {
		position: fixed !important;
		inset: 4rem 1rem auto 1rem !important;
		transform: none !important;
		width: auto !important;
		min-width: 0 !important;
		max-width: none !important;
		max-height: calc(100dvh - 5rem);
		margin: 0 !important;
		overflow-y: auto;
	}

	body[data-static] .navbar .navbar-nav {
		gap: 0.25rem !important;
		margin-left: 0.5rem !important;
	}
}

/* ── WP-3 · Page header (title always visible) ── */
@media (max-width: 575.98px) {
	body[data-static] .content > .container-fluid > .row:first-child > .col-auto.d-none.d-sm-block {
		display: block !important;
		flex: 0 0 100%;
		max-width: 100%;
	}

	body[data-static] .content > .container-fluid > .row:first-child > .col-auto.ms-auto {
		margin-left: 0 !important;
		text-align: left !important;
	}
}

/* ── WP-4 · Content components ── */

/* Pagination wraps instead of running off narrow cards. */
body[data-static] .pagination {
	flex-wrap: wrap;
	row-gap: 0.25rem;
}

/* Notification demos inside cards: .notify is 340px wide and only capped
   to the viewport, which is wider than a card on phones. Toasts keep their
   own viewport cap. */
body[data-static] .content .card .notify {
	max-width: 100%;
}

/* KPI cards (ticket list, ticket datatable, staff): with five per row
   beside the sidebar (1200–1366px) the value and its change badge do not
   fit on one line, so the badge wraps below instead of leaving the card. */
body[data-static] .ticket-kpi .d-flex.align-items-baseline {
	flex-wrap: wrap;
	row-gap: 0;
}

@media (max-width: 575.98px) {
	/* DataTables: search and length controls use the full row. */
	body[data-static] div.dataTables_wrapper div.dataTables_filter label,
	body[data-static] div.dataTables_wrapper div.dataTables_length label {
		display: flex;
		align-items: center;
		gap: 0.5rem;
		width: 100%;
	}

	body[data-static] div.dataTables_wrapper div.dataTables_filter input {
		flex: 1 1 auto;
		min-width: 0;
		width: auto;
		margin-left: 0;
	}

	/* Tables placed straight in a card (no .table-responsive wrapper) can be
	   wider than a phone; Firefox does not squeeze their columns as far as
	   Chrome does. The card scrolls them sideways, like .table-responsive. */
	body[data-static] .card:has(> .table) {
		overflow-x: auto;
	}

	/* Card headers: title and actions stack instead of colliding. */
	body[data-static] .card-header.d-flex {
		flex-wrap: wrap;
		gap: 0.5rem;
	}

	/* Modals use the full width with a small gutter. */
	body[data-static] .modal-dialog {
		margin: 0.5rem;
	}
}

/* ── WP-6 · Large screens ── */
@media (min-width: 1920px) {
	/* Keep long-form pages readable; dashboards stay fluid. */
	body[data-static][data-layout="fluid"] .content > .container-fluid {
		max-width: 1760px;
		margin-left: auto;
		margin-right: auto;
	}
}

@media (prefers-reduced-motion: reduce) {
	body[data-static] #sidebar,
	body[data-static].rs-sidebar-open #sidebar {
		transition: none !important;
	}
}
