/* ---------------------------------------------------------------------------
 * App shell and sidebar.
 *
 * Linked by resources/views/layouts/base.blade.php after the theme, so it can
 * override the theme's sidenav rules. Scoped to .app-shell, #sidenav-main and
 * the burger/backdrop this layout owns.
 *
 * From 1200px up the sidebar is a sticky column that scrolls on its own; below
 * that it is an off-canvas drawer opened by the burger (openNav() in main.js).
 * ------------------------------------------------------------------------- */

#sidenav-main {
	--sn-ink: #2c306e;
	--sn-text: #344767;
	--sn-muted: #8392ab;
	--sn-line: #eceef3;
	--sn-hover: #f4f5f9;
	--sn-active: #eceefa;
	--sn-tile: #f1f3f7;
	--sn-gradient: linear-gradient(50deg, #2c306e, #5cabc7);
	--sn-width: 264px;
}

/* ---------------------------------------------------------------------------
 * Shell
 * ------------------------------------------------------------------------- */

/* The wrapper was pinned to 100vh, so the page height came from whichever
   column overflowed it - usually the sidebar. Let it grow with the content. */
.app-shell {
	height: auto;
	min-height: 100vh;
	align-items: flex-start;
}

/* Fill what the sidebar leaves instead of a fixed 78% / 90% / 95%. */
.app-shell > .main-content {
	flex: 1 1 0%;
	width: auto;
	min-width: 0;
}

/* Most pages put .rows straight inside their own <div class="main-content">,
   with no container to absorb the row's -12px gutters, so every list page ran
   12px past the right edge and scrolled sideways. */
.app-shell .main-content .main-content > .row {
	margin-left: 0;
	margin-right: 0;
}

/* The theme makes every .card width: 100%, and the list pages add mx-4 on top,
   so each list card stuck out past the right edge by its own margins. */
.app-shell .card.mx-4 {
	width: calc(100% - 3rem);
}

.app-shell .card.mx-3 {
	width: calc(100% - 2rem);
}

/* Laravel's pagination is one long row of page links; on a phone it ran about
   600px wide and dragged the whole page sideways. */
.app-shell .pagination {
	flex-wrap: wrap;
	row-gap: 4px;
}

/* The theme fixes .alert at 75vw, so the "Manage ..." banners stopped short of
   the right edge on tablets and would overflow anything narrower than that. */
.app-shell .alert {
	width: auto;
}

/* The theme sized every card to 85vw on phones, so they started at the
   content's left edge but stopped short of the right one - off centre. */
@media (max-width: 575.98px) {
	.app-shell .card {
		width: auto;
	}

	/* One 16px gutter on phones: the column's 12px plus 4px, and 16px for the
	   page banners that sit outside a column. */
	.app-shell .card.mx-4,
	.app-shell .card.mx-3 {
		width: calc(100% - .5rem);
		margin-left: .25rem !important;
		margin-right: .25rem !important;
	}

	.app-shell .alert.mx-4 {
		margin-left: 1rem !important;
		margin-right: 1rem !important;
	}

	/* The bundled bootstrap.min.css has had the left half of the row gutter
	   removed (.row > * pads only the right), so columns hug the left edge.
	   On a phone that 0 vs 12px is most of the visible margin; put it back. */
	.app-shell .row > * {
		padding-left: calc(var(--bs-gutter-x) * .5);
	}
}

/* ---------------------------------------------------------------------------
 * Sidebar frame
 * ------------------------------------------------------------------------- */

#sidenav-main.app-sidenav {
	display: flex;
	flex-direction: column;
	flex: none;
	width: var(--sn-width);
	max-width: none;
	padding: 0;
	overflow: hidden;
	background: #fff;
	border-radius: 20px;
	box-shadow: 0 1px 2px rgba(20, 23, 60, .04), 0 8px 24px rgba(20, 23, 60, .06);
}

/* The theme narrows the sidebar on hover, which made the whole page jump. */
#sidenav-main.app-sidenav:hover {
	max-width: none;
}

/* The scrolling column. The theme pulled it up 80px and stretched it to 180%
   of the sidebar, which is what made the page scroll to reach the bottom. */
#sidenav-main #sidenav-collapse-main {
	display: block;
	flex: 1 1 auto;
	width: 100% !important;
	height: auto;
	min-height: 0 !important;
	margin: 0 !important;
	padding: 0 0 16px !important;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	border-radius: 0;
	box-shadow: none !important;
	scrollbar-width: thin;
	scrollbar-color: #d5d8e2 transparent;
}

#sidenav-main #sidenav-collapse-main::-webkit-scrollbar {
	width: 6px;
}

#sidenav-main #sidenav-collapse-main::-webkit-scrollbar-thumb {
	border-radius: 6px;
	background: #d5d8e2;
}

#sidenav-main #sidenav-collapse-main > hr {
	display: none;
}

/* ---------------------------------------------------------------------------
 * Header: logo, plus a close button on the drawer
 * ------------------------------------------------------------------------- */

#sidenav-main .sidenav-header {
	position: sticky;
	top: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	height: 72px;
	padding: 0 14px 0 22px;
	background: #fff;
	border-bottom: 1px solid var(--sn-line);
}

#sidenav-main .sidenav-header .navbar-brand {
	display: flex;
	align-items: center;
	margin: 0;
	padding: 0 !important;
}

#sidenav-main .sidenav-header .navbar-brand-img {
	display: block;
	width: auto;
	height: auto !important;
	max-width: 150px !important;
	max-height: 38px !important;
}

#sidenav-main .sidenav-close {
	display: none;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 10px;
	background: var(--sn-tile);
	color: var(--sn-text);
	cursor: pointer;
	transition: background-color .15s ease;
}

#sidenav-main .sidenav-close:hover {
	background: #e6e9f0;
}

#sidenav-main .sidenav-close svg {
	width: 18px;
	height: 18px;
}

/* ---------------------------------------------------------------------------
 * Search: pinned under the logo bar; main.js filters the links
 * ------------------------------------------------------------------------- */

#sidenav-main .sidenav-search {
	position: sticky;
	top: 72px;
	z-index: 2;
	display: flex;
	align-items: center;
	padding: 12px 12px 4px;
	background: #fff;
}

#sidenav-main .sidenav-search-input {
	width: 100%;
	height: 38px;
	padding: 0 36px 0 36px;
	border: 1px solid #e4e7f2;
	border-radius: 12px;
	background: #f5f6fb;
	color: var(--sn-text);
	font-size: .8125rem;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

#sidenav-main .sidenav-search-input::placeholder {
	color: var(--sn-muted);
}

#sidenav-main .sidenav-search-input:focus {
	outline: none;
	border-color: #b9bfe0;
	background: #fff;
	box-shadow: 0 0 0 3px rgba(44, 48, 110, .1);
}

/* The page draws its own clear button. */
#sidenav-main .sidenav-search-input::-webkit-search-cancel-button,
#sidenav-main .sidenav-search-input::-webkit-search-decoration {
	-webkit-appearance: none;
	display: none;
}

#sidenav-main .sidenav-search-icon {
	position: absolute;
	left: 24px;
	width: 16px;
	height: 16px;
	color: var(--sn-muted);
	pointer-events: none;
}

#sidenav-main .sidenav-search-key {
	position: absolute;
	right: 22px;
	display: none;
	min-width: 20px;
	padding: 1px 5px;
	border: 1px solid #dfe2ec;
	border-radius: 6px;
	background: #fff;
	box-shadow: none;
	color: var(--sn-muted);
	font-family: inherit;
	font-size: .6875rem;
	font-weight: 600;
	line-height: 1.4;
	text-align: center;
	pointer-events: none;
}

#sidenav-main .sidenav-search-clear {
	position: absolute;
	right: 18px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--sn-muted);
	cursor: pointer;
	transition: background-color .15s ease, color .15s ease;
}

#sidenav-main .sidenav-search-clear:hover {
	background: var(--sn-tile);
	color: var(--sn-text);
}

#sidenav-main .sidenav-search-clear svg {
	width: 14px;
	height: 14px;
}

#sidenav-main .sidenav-search-empty {
	margin: 18px 22px 0;
	color: var(--sn-muted);
	font-size: .8125rem;
	text-align: center;
}

/* While searching, every group holding a match is open whatever its own state,
   and Bootstrap's collapse classes are left alone so clearing restores them. */
#sidenav-main.is-searching .submenu {
	display: block !important;
	height: auto !important;
}

#sidenav-main.is-searching .dropdown-toggle::after {
	margin-top: 3px;
	transform: rotate(-135deg);
}

#sidenav-main .nav-link-text mark {
	padding: 0;
	border-radius: 3px;
	background: rgba(92, 171, 199, .28);
	color: inherit;
}

/* ---------------------------------------------------------------------------
 * Links
 * ------------------------------------------------------------------------- */

#sidenav-main .navbar-nav {
	padding: 10px 12px 0;
}

#sidenav-main .navbar-nav .nav-item {
	padding-bottom: 2px !important;
}

#sidenav-main .navbar-nav .nav-link {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0;
	padding: 6px 10px;
	border-radius: 10px;
	color: var(--sn-text);
	font-size: .8125rem;
	font-weight: 500;
	line-height: 1.3;
	white-space: normal;
	box-shadow: none;
	transition: background-color .15s ease, color .15s ease;
}

#sidenav-main .navbar-nav .nav-link:hover {
	background: var(--sn-hover);
	color: var(--sn-ink);
}

#sidenav-main .navbar-nav .nav-link:focus-visible {
	outline: 2px solid rgba(44, 48, 110, .35);
	outline-offset: 1px;
}

#sidenav-main .navbar-nav .nav-link .icon {
	flex: none;
	width: 30px;
	height: 30px;
	min-width: 30px;
	margin: 0 !important;
	padding: 0;
	border-radius: 8px !important;
	background: var(--sn-tile) !important;
	box-shadow: none !important;
	transition: background .15s ease;
}

/* top: the theme drops .ni icons 14px unless they sit directly under .navbar-nav > .nav-item,
   which the Recent list's copies don't. */
#sidenav-main .navbar-nav .nav-link .icon i {
	top: 0;
	min-width: 0;
	padding: 0 !important;
	font-size: .8rem !important;
	line-height: 1;
	color: var(--sn-ink) !important;
}

#sidenav-main .navbar-nav .nav-link .nav-link-text {
	margin: 0 !important;
}

#sidenav-main .navbar-nav .nav-link.active {
	background: var(--sn-active) !important;
	color: var(--sn-ink) !important;
	font-weight: 600;
	box-shadow: none;
}

#sidenav-main .navbar-nav .nav-link.active .icon {
	background: var(--sn-gradient) !important;
}

#sidenav-main .navbar-nav .nav-link.active .icon i {
	color: #fff !important;
}

/* ---------------------------------------------------------------------------
 * Groups (Reports, Settings) and their sub-groups
 * ------------------------------------------------------------------------- */

/* Top-level group headers (Reports, Settings): a tinted button with an icon
   tile while closed, the brand gradient while open. These are .nav-links too,
   hence the .navbar-nav to outrank the link rules. */
#sidenav-main .navbar-nav .toggle-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 12px 0 4px !important;
	padding: 7px 10px !important;
	border: 1px solid #e4e7f2;
	border-radius: 12px;
	background: #f5f6fb !important;
	color: var(--sn-ink) !important;
	font-size: .8125rem !important;
	font-weight: 700;
	letter-spacing: .01em;
	text-transform: none !important;
	user-select: none;
	transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
}

#sidenav-main .navbar-nav .toggle-bar:hover {
	border-color: #d9ddef;
	background: #eceefa !important;
	color: var(--sn-ink) !important;
}

#sidenav-main .navbar-nav .toggle-bar[aria-expanded="true"] {
	border-color: transparent;
	background: var(--sn-gradient) !important;
	color: #fff !important;
	box-shadow: 0 8px 18px -8px rgba(44, 48, 110, .55);
}

#sidenav-main .sidenav-group-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	background: var(--sn-gradient);
	color: #fff;
	transition: background .2s ease;
}

#sidenav-main .sidenav-group-icon i {
	font-size: .8rem;
	line-height: 1;
}

#sidenav-main .toggle-bar[aria-expanded="true"] .sidenav-group-icon {
	background: rgba(255, 255, 255, .2);
}

#sidenav-main .sidenav-group-label {
	flex: 1 1 auto;
	min-width: 0;
}

/* The open group's links sit just under its header. */
#sidenav-main .navbar-nav > .has-submenu > .submenu {
	padding-top: 4px !important;
}

/* Sections inside Operations and Reports: a quiet caption over their links. */
#sidenav-main .sidenav-subtitle {
	display: block;
	margin: 12px 10px 4px;
	color: var(--sn-muted);
	font-size: .6875rem;
	font-weight: 700;
	letter-spacing: .06em;
	line-height: 1.3;
	text-transform: uppercase;
}

#sidenav-main .sidenav-section:first-child > .sidenav-subtitle {
	margin-top: 4px;
}

/* Recent pages, between Dashboard and the groups. Its links are copies of ones in the
   groups, so it steps aside while a search is listing those. */
#sidenav-main .sidenav-recent {
	padding-bottom: 2px;
}

#sidenav-main .sidenav-recent > .sidenav-subtitle {
	margin-top: 10px;
}

#sidenav-main.is-searching .sidenav-recent {
	display: none !important;
}

/* Sub-groups inside Settings read as rows, not shouting labels. */
#sidenav-main .nav-sub-setting {
	margin: 0 !important;
}

#sidenav-main .navbar-nav .toggle-bar1 {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 0 !important;
	padding: 8px 10px !important;
	border-radius: 10px;
	color: var(--sn-text) !important;
	font-size: .8125rem !important;
	font-weight: 600 !important;
	text-transform: none !important;
	user-select: none;
}

#sidenav-main .toggle-bar1[aria-expanded="true"] {
	color: var(--sn-ink) !important;
}

/* Ring for keyboard focus only; a mouse click left a square box behind. */
#sidenav-main .toggle-bar:focus,
#sidenav-main .toggle-bar1:focus {
	outline: none;
}

#sidenav-main .toggle-bar:focus-visible,
#sidenav-main .toggle-bar1:focus-visible {
	outline: 2px solid rgba(44, 48, 110, .35);
	outline-offset: 2px;
}

/* Chevron in place of the dropdown caret; main.js keeps aria-expanded current. */
#sidenav-main .dropdown-toggle::after {
	flex: none;
	width: 7px;
	height: 7px;
	margin: -3px 4px 0 10px;
	border: 0;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	vertical-align: 0;
	transform: rotate(45deg);
	transition: transform .2s ease, margin .2s ease;
}

#sidenav-main .dropdown-toggle[aria-expanded="true"]::after {
	margin-top: 3px;
	transform: rotate(-135deg);
}

/* Links inside a sub-group hang off a guide line. */
#sidenav-main .nav-sub-setting > .submenu {
	margin: 2px 0 6px 14px !important;
	padding-left: 8px !important;
	border-left: 1px solid var(--sn-line);
}

/* ---------------------------------------------------------------------------
 * Burger and backdrop
 * ------------------------------------------------------------------------- */

.burger-menu {
	padding-top: 0;
}

.sidenav-burger {
	display: inline-flex;
	flex-direction: column;
	justify-content: center;
	gap: 4px;
	width: 40px;
	height: 40px;
	padding: 0 11px;
	border: 0;
	border-radius: 12px;
	background: #2c306e;
	box-shadow: 0 4px 12px rgba(44, 48, 110, .25);
	cursor: pointer;
	transition: background-color .15s ease;
}

.sidenav-burger:hover {
	background: #383d86;
}

.sidenav-burger:focus-visible {
	outline: 3px solid rgba(44, 48, 110, .35);
	outline-offset: 2px;
}

.sidenav-burger span {
	display: block;
	height: 2px;
	border-radius: 2px;
	background: #fff;
}

.sidenav-backdrop {
	display: none;
}

/* ---------------------------------------------------------------------------
 * Wide screens: sticky column
 * ------------------------------------------------------------------------- */

@media (min-width: 1200px) {
	#sidenav-main.app-sidenav {
		position: sticky;
		top: 16px;
		height: calc(100vh - 32px);
		margin: 16px 0 16px 16px;
	}

	/* The "/" shortcut hint, until the field is in use. Touch drawers have no keyboard. */
	#sidenav-main .sidenav-search-input:placeholder-shown:not(:focus) ~ .sidenav-search-key {
		display: block;
	}
}

/* ---------------------------------------------------------------------------
 * Below 1200px: off-canvas drawer
 * ------------------------------------------------------------------------- */

@media (max-width: 1199.98px) {
	#sidenav-main.app-sidenav {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 1060;
		width: min(300px, 86vw);
		height: 100vh;
		height: 100dvh;
		margin: 0;
		border-radius: 0 20px 20px 0;
		box-shadow: none;
		visibility: hidden;
		transform: translateX(-100%);
		transition: transform .28s cubic-bezier(.2, .7, .2, 1), box-shadow .28s ease, visibility 0s linear .28s;
	}

	body.sidenav-open #sidenav-main.app-sidenav {
		visibility: visible;
		transform: none;
		box-shadow: 0 24px 60px rgba(15, 17, 48, .28);
		transition: transform .28s cubic-bezier(.2, .7, .2, 1), box-shadow .28s ease, visibility 0s;
	}

	#sidenav-main .sidenav-close {
		display: inline-flex;
	}

	.sidenav-backdrop {
		position: fixed;
		inset: 0;
		z-index: 1055;
		display: block;
		background: rgba(15, 17, 48, .45);
		opacity: 0;
		visibility: hidden;
		transition: opacity .25s ease, visibility 0s linear .25s;
	}

	body.sidenav-open .sidenav-backdrop {
		opacity: 1;
		visibility: visible;
		transition: opacity .25s ease, visibility 0s;
	}

	/* Keep the page behind the drawer still. */
	body.sidenav-open {
		overflow: hidden;
	}

	/* Burger on the left, actions on the right, on one row. */
	#navbarBlur {
		flex-wrap: nowrap;
		justify-content: space-between !important;
		gap: 8px;
		padding-left: 16px !important;
		padding-right: 16px !important;
	}

	#navbarBlur > .container-fluid {
		flex: none;
		width: auto !important;
		padding-left: 0 !important;
		padding-right: 0 !important;
	}

	#navbarBlur > #navbar {
		flex: 1 1 auto;
		min-width: 0;
		margin: 0 !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	#sidenav-main.app-sidenav,
	.sidenav-backdrop,
	#sidenav-main .dropdown-toggle::after {
		transition-duration: .01ms !important;
	}
}
