/**
 * Organic Growth - app shell layout.
 *
 * The member area sits inside the site's own theme, between its header and
 * footer. The theme keeps your branding and navigation; everything between is
 * ours.
 *
 * ON MOBILE the left rail becomes a bottom bar. That is not decoration: most of
 * this platform's members are on Android phones held in one hand, and the
 * bottom of the screen is the only area a thumb reaches comfortably. A hamburger
 * menu at the top would put every primary action out of reach.
 *
 * @package OrganicGrowth\Core
 * @since   1.4.0
 */

.og-app {
	display: block;
	max-width: var(--og-content-max);
	margin: 0 auto;
	padding: var(--og-space-5) var(--og-space-4);
}

.og-shell {
	display: grid;
	grid-template-columns: var(--og-rail-width) minmax(0, 1fr);
	gap: var(--og-space-5);
	align-items: start;
}

/* ---------------------------------------------------------- The rail */

.og-rail {
	position: sticky;
	top: var(--og-space-4);
	padding: var(--og-space-3);
	background: var(--og-bg-raised);
	border: 1px solid var(--og-border);
	border-radius: var(--og-radius-lg);
}

.og-rail__section + .og-rail__section {
	margin-top: var(--og-space-4);
	padding-top: var(--og-space-4);
	border-top: 1px solid var(--og-border);
}

.og-rail__heading {
	padding: 0 var(--og-space-3) var(--og-space-2);
	font-size: var(--og-text-2xs);
	font-weight: var(--og-weight-semibold);
	letter-spacing: var(--og-tracking-wide);
	text-transform: uppercase;
	color: var(--og-text-subtle);
}

.og-rail__link {
	display: flex;
	align-items: center;
	gap: var(--og-space-3);
	min-height: 44px;
	padding: 0 var(--og-space-3);
	border-radius: var(--og-radius);
	color: var(--og-text-muted);
	font-size: var(--og-text-sm);
	font-weight: var(--og-weight-medium);
	text-decoration: none;
	transition: background var(--og-transition), color var(--og-transition);
}

.og-rail__link:hover {
	background: var(--og-bg-sunken);
	color: var(--og-text);
	text-decoration: none;
}

.og-rail__link.is-active {
	background: var(--og-primary-soft);
	color: var(--og-primary);
	font-weight: var(--og-weight-semibold);
}

.og-rail__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	flex-shrink: 0;
	opacity: 0.8;
	transition: opacity var(--og-transition);
}

.og-rail__link:hover .og-rail__icon,
.og-rail__link.is-active .og-rail__icon {
	opacity: 1;
}

/*
 * The active item carries a short bar on its leading edge. It marks position
 * rather than decorating: on a rail of five identical rows, colour alone is not
 * enough for someone who cannot distinguish it.
 */
.og-rail__link.is-active {
	position: relative;
}

.og-rail__link.is-active::before {
	content: "";
	position: absolute;
	left: 0;
	top: 50%;
	transform: translateY(-50%);
	width: 3px;
	height: 18px;
	border-radius: 0 3px 3px 0;
	background: var(--og-primary);
}

.og-rail__count {
	margin-left: auto;
	padding: 1px 7px;
	border-radius: var(--og-radius-full);
	background: var(--og-danger);
	color: #fff;
	font-size: var(--og-text-2xs);
	font-weight: var(--og-weight-semibold);
}

/* -------------------------------------------------------- The topbar */

.og-topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--og-space-4);
	min-height: var(--og-topbar-height);
	margin-bottom: var(--og-space-5);
	padding: var(--og-space-3) var(--og-space-4);
	background: var(--og-bg-raised);
	border: 1px solid var(--og-border);
	border-radius: var(--og-radius-lg);
}

.og-topbar__title {
	margin: 0;
	font-size: var(--og-text-lg);
	font-weight: var(--og-weight-semibold);
	letter-spacing: var(--og-tracking-tight);
}

.og-topbar__actions {
	display: flex;
	align-items: center;
	gap: var(--og-space-2);
	margin-left: auto;
}

/*
 * The balance lives in the topbar on every screen. A member should never have
 * to navigate anywhere to answer "how many Coins do I have?".
 */
.og-topbar__balance {
	display: flex;
	align-items: center;
	gap: var(--og-space-2);
	padding: var(--og-space-2) var(--og-space-3);
	border: 1px solid transparent;
	border-radius: var(--og-radius);
	background: var(--og-coin-soft);
	transition: border-color var(--og-transition);
}

.og-topbar__balance:hover {
	border-color: var(--og-coin);
}

.og-topbar__balance-label {
	font-size: var(--og-text-2xs);
	font-weight: var(--og-weight-semibold);
	letter-spacing: var(--og-tracking-wide);
	text-transform: uppercase;
	color: var(--og-text-subtle);
}

/* --------------------------------------------------------- Page head */

.og-page__header {
	margin-bottom: var(--og-space-5);
}

.og-page__title {
	margin: 0 0 var(--og-space-1);
	font-size: var(--og-text-xl);
}

.og-page__lead {
	margin: 0;
	color: var(--og-text-muted);
	font-size: var(--og-text-sm);
	max-width: 62ch;
}

/* -------------------------------------------------- Theme switch */

.og-theme-switch {
	display: inline-flex;
	padding: 3px;
	border: 1px solid var(--og-border);
	border-radius: var(--og-radius-full);
	background: var(--og-bg-sunken);
}

.og-theme-switch__option {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 38px;
	height: 32px;
	padding: 0 var(--og-space-2);
	border: none;
	border-radius: var(--og-radius-full);
	background: transparent;
	color: var(--og-text-subtle);
	font-family: inherit;
	font-size: var(--og-text-xs);
	font-weight: var(--og-weight-medium);
	cursor: pointer;
	transition: background var(--og-transition), color var(--og-transition);
}

.og-theme-switch__option:hover {
	color: var(--og-text);
}

.og-theme-switch__option.is-active {
	background: var(--og-bg-raised);
	color: var(--og-text);
	box-shadow: var(--og-shadow-sm);
}

/* ------------------------------------------------------- Responsive */

@media ( max-width: 860px ) {

	.og-app {
		padding: var(--og-space-4) var(--og-space-3);
		/* Room for the bottom bar plus the phone's own home indicator. */
		padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
	}

	.og-shell {
		grid-template-columns: minmax(0, 1fr);
		gap: var(--og-space-4);
	}

	/* The rail leaves the flow and becomes a thumb-reachable bottom bar. */
	.og-rail {
		position: fixed;
		inset: auto 0 0;
		top: auto;
		z-index: var(--og-z-sticky);
		display: flex;
		gap: 0;
		padding: var(--og-space-1) var(--og-space-2)
			calc(var(--og-space-1) + env(safe-area-inset-bottom, 0px));
		border: none;
		border-top: 1px solid var(--og-border);
		border-radius: 0;
		box-shadow: var(--og-shadow-lg);
		overflow-x: auto;
	}

	.og-rail__section + .og-rail__section {
		margin: 0;
		padding: 0;
		border: none;
	}

	.og-rail__section {
		display: flex;
		flex: 1;
	}

	.og-rail__heading {
		display: none;
	}

	.og-rail__link {
		flex: 1;
		flex-direction: column;
		gap: 2px;
		min-width: 64px;
		min-height: 56px;
		padding: var(--og-space-1);
		font-size: var(--og-text-2xs);
		text-align: center;
	}

	.og-rail__link.is-active {
		background: transparent;
	}

	/* On a bottom bar the marker belongs above the icon, not beside it. */
	.og-rail__link.is-active::before {
		left: 50%;
		top: 0;
		transform: translateX(-50%);
		width: 20px;
		height: 3px;
		border-radius: 0 0 3px 3px;
	}

	.og-rail__count {
		position: absolute;
		transform: translate(14px, -10px);
	}

	.og-topbar {
		flex-wrap: wrap;
		margin-bottom: var(--og-space-4);
	}

	.og-topbar__title {
		font-size: var(--og-text-base);
	}
}

@media ( max-width: 420px ) {

	.og-topbar__balance-label {
		display: none;
	}
}

/*
 * The column beside the rail. min-width:0 matters: without it a wide table or a
 * long unbroken string inside would push the whole grid wider than the screen
 * and produce sideways scrolling on a phone.
 */
.og-shell__main {
	min-width: 0;
}
