:root {
	color-scheme: light;
	--bg-gradient-start: #f8fafc;
	--bg-gradient-end: #eef2ff;
	--surface: #ffffff;
	--surface-muted: #f1f5f9;
	--surface-strong: #e2e8f0;
	--accent: #2563eb;
	--accent-dark: #1d4ed8;
	--accent-soft: #dbeafe;
	--text-primary: #0f172a;
	--text-secondary: #475569;
	--muted: #6b7280;
	--border: #e2e8f0;
	--shadow: 0 24px 48px rgba(15, 23, 42, 0.12);
	--radius-lg: 20px;
	--radius-md: 14px;
	--radius-sm: 10px;
	--top-bar-height: 72px;
	/* Typography Scale */
	--font-size-xs: 12px;
	--font-size-sm: 14px;
	--font-size-base: 16px;
	--font-size-lg: 18px;
	--font-size-xl: 24px;
	--line-height-tight: 1.2;
	--line-height-normal: 1.5;
	--line-height-relaxed: 1.75;
	/* Spacing System (8px baseline) */
	--spacing-xs: 4px;
	--spacing-sm: 8px;
	--spacing-md: 16px;
	--spacing-lg: 24px;
	--spacing-xl: 32px;
	/* Checkbox System */
	--checkbox-size: 24px;
	--checkbox-touch-target: 44px;
	--checkbox-border-radius: 4px;
	--checkbox-transition: all 0.2s ease-in-out;
	/* Aliases for consistency */
	--primary-color: #2563eb;
	--primary-light: rgba(37, 99, 235, 0.2);
	--border-color: #e2e8f0;
	--success-color: #4caf50;
	--warning-color: #ff9800;
	--error-color: #f44336;
}

* {
	box-sizing: border-box;
}

html,
body {
	font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
	background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
	color: var(--text-primary);
	min-height: 100%;
	margin: 0;
}

body {
	min-height: 100vh;
}

a,
.btn-link {
	color: var(--accent);
	text-decoration: none;
	transition: color 0.2s ease;
}

	a:hover,
	.btn-link:hover {
		color: var(--accent-dark);
	}

button,
input,
textarea,
select {
	margin-top: 0.25rem;
	margin-bottom: 0.25rem;
	font-family: inherit;
}

button {
	cursor: pointer;
	border-radius: var(--radius-sm);
	border: 1px solid transparent;
	padding: 0.65rem 1.2rem;
	font-weight: 600;
	background: var(--surface-muted);
	color: var(--text-primary);
	transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

	button:hover {
		background: var(--accent);
		color: #ffffff;
		border-color: var(--accent);
		box-shadow: 0 12px 24px rgba(37, 99, 235, 0.18);
	}

	button:focus-visible {
		outline: 3px solid var(--accent-soft);
		outline-offset: 2px;
	}

	.primary,
	button.primary {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: 0.5rem;
		background: var(--accent);
		border-color: var(--accent);
		color: #ffffff;
		box-shadow: 0 18px 36px rgba(37, 99, 235, 0.2);
	}

		.primary:hover,
		button.primary:hover {
			background: var(--accent-dark);
			border-color: var(--accent-dark);
			transform: translateY(-1px);
		}

	button.ghost {
		background: #ffffff;
		border-color: var(--border);
		color: var(--text-primary);
	}

		button.ghost:hover {
			background: var(--accent-soft);
			border-color: var(--accent);
			color: var(--accent-dark);
		}

input,
.form-control,
.input-group input,
select,
textarea {
	width: 100%;
	padding: 0.85rem 1rem;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--surface-muted);
	color: var(--text-primary);
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

	input:focus,
	.form-control:focus,
	.input-group input:focus,
	select:focus,
	textarea:focus {
		outline: none;
		border-color: var(--accent);
		box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
	}

.app-shell {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	position: relative;
}

.top-bar {
	height: var(--top-bar-height);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 1.5rem;
	background: rgba(255, 255, 255, 0.86);
	backdrop-filter: blur(18px);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 50;
	gap: 1rem;
}

.top-bar__cluster {
	display: flex;
	align-items: center;
	gap: 1rem;
}

.menu-button {
	width: 46px;
	height: 46px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: #ffffff;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	transition: background-color 0.2s ease, border-color 0.2s ease;
}

	.menu-button span {
		display: block;
		height: 2px;
		width: 20px;
		border-radius: 999px;
		background: var(--text-primary);
		transition: transform 0.2s ease, opacity 0.2s ease;
	}

.app-shell.menu-open .menu-button span:nth-child(1) {
	transform: translateY(8px) rotate(45deg);
}

.app-shell.menu-open .menu-button span:nth-child(2) {
	opacity: 0;
}

.app-shell.menu-open .menu-button span:nth-child(3) {
	transform: translateY(-8px) rotate(-45deg);
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 0.65rem;
	padding: 0.45rem 0.75rem;
	border-radius: var(--radius-sm);
	transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

	.brand img {
		width: 34px;
		height: 34px;
	}

	.brand span {
		font-size: 1.15rem;
		font-weight: 700;
		letter-spacing: 0.02em;
	}

	.brand:hover,
	.brand:focus-visible {
		background: rgba(37, 99, 235, 0.08);
		outline: none;
	}

.flyout {
	position: fixed;
	left: 0;
	right: 0;
	top: var(--top-bar-height);
	background: #ffffff;
	border-bottom: 1px solid var(--border);
	box-shadow: 0 24px 48px rgba(15, 23, 42, 0.12);
	padding: 1.5rem 1.75rem 2rem;
	transform: translateY(-120%);
	opacity: 0;
	pointer-events: none;
	transition: transform 0.3s ease, opacity 0.3s ease;
	z-index: 40;
}

	.flyout ul {
		list-style: none;
		margin: 0;
		padding: 0;
		display: grid;
		gap: 0.75rem;
	}

	.flyout li a,
	.flyout li button.link {
		margin: 0;
		display: inline-flex;
		align-items: center;
		width: 100%;
		gap: 0.65rem;
		padding: 0.75rem 1rem;
		border-radius: var(--radius-sm);
		color: var(--text-primary);
		background: transparent;
		border: none;
		font-weight: 600;
	}

		.flyout li a:hover,
		.flyout li button.link:hover {
			background: var(--surface-muted);
			color: var(--accent);
		}

	.flyout li button.link {
		justify-content: flex-start;
		text-align: left;
	}

.app-shell.menu-open .flyout {
	transform: translateY(0);
	opacity: 1;
	pointer-events: auto;
}

.overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.35);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
	z-index: 35;
}

.app-shell.menu-open .overlay {
	opacity: 1;
	pointer-events: auto;
}

main {
	flex: 1;
	width: 100%;
	padding: 2.5rem clamp(1.25rem, 4vw, 4rem);
}

.input-group {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

	.input-group label {
		font-weight: 600;
		color: var(--text-secondary);
	}

.error,
.validation-message,
.validation-summary-errors ul li {
	color: #dc2626;
	font-weight: 600;
}

.muted {
	color: var(--muted);
}

.darker-border-checkbox.form-check-input {
	border-color: var(--surface-strong);
}

/* Modal Styles */
.modal-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.6);
	backdrop-filter: blur(4px);
	z-index: 100;
	animation: fadeIn 0.2s ease;
}

.modal-shell,
.survey-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: var(--surface);
	border-radius: var(--radius-lg);
	box-shadow: 0 48px 96px rgba(15, 23, 42, 0.3);
	z-index: 101;
	max-width: min(90vw, 800px);
	max-height: min(90vh, 600px);
	width: 100%;
	display: flex;
	flex-direction: column;
	animation: slideIn 0.3s ease;
}

	.modal-shell header,
	.survey-modal header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 1.5rem 2rem;
		border-bottom: 1px solid var(--border);
	}

	.modal-shell h2,
	.survey-modal h2 {
		margin: 0;
		font-size: 1.4rem;
	}

	.modal-shell .icon,
	.survey-modal .icon {
		padding: 0px;
		width: 40px;
		height: 40px;
		border-radius: 999px;
		background: var(--surface-muted);
		border: 1px solid var(--border);
		display: grid;
		place-items: center;
		font-size: 1.2rem;
		color: var(--text-secondary);
	}

.modal-body {
	flex: 1;
	padding: 2rem;
	overflow-y: auto;
}

.modal-shell footer {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 1rem;
	padding: 1.5rem 2rem;
	border-top: 1px solid var(--border);
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

@keyframes slideIn {
	from {
		opacity: 0;
		transform: translate(-50%, -50%) scale(0.95);
	}

	to {
		opacity: 1;
		transform: translate(-50%, -50%) scale(1);
	}
}

/* Loading State for Modal */
.loading-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	padding: 2rem;
}

.spinner {
	width: 40px;
	height: 40px;
	border: 4px solid var(--surface-muted);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* Alert/Status Messages */
.alert {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1rem 1.5rem;
	border-radius: var(--radius-md);
	margin-bottom: 1.5rem;
	font-weight: 600;
	animation: slideDown 0.3s ease;
}

	.alert.success {
		background: #d1fae5;
		color: #065f46;
		border: 1px solid #6ee7b7;
	}

	.alert.error {
		background: #fee2e2;
		color: #991b1b;
		border: 1px solid #fca5a5;
	}

	.alert button {
		background: transparent;
		border: none;
		font-size: 1.5rem;
		line-height: 1;
		padding: 0.25rem 0.5rem;
		color: inherit;
		opacity: 0.7;
		transition: opacity 0.2s ease;
	}

		.alert button:hover {
			opacity: 1;
			background: transparent;
			transform: none;
			box-shadow: none;
		}

@keyframes slideDown {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.helper {
	font-size: 0.9rem;
	color: var(--muted);
	margin: 0;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

	.field label {
		font-weight: 600;
		color: var(--text-secondary);
	}

.field-grid {
	display: grid;
	gap: 1.25rem;
}

.actions {
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
}

.success {
	color: #15803d;
	font-weight: 600;
}

.badge {
	display: inline-block;
	padding: 0.25rem 0.75rem;
	border-radius: 999px;
	background: var(--accent-soft);
	color: var(--accent-dark);
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

	.badge.error {
		background: #fee2e2;
		color: #dc2626;
	}

	.badge.accent {
		background: #dbeafe;
		color: #1d4ed8;
	}

.page-title {
	margin-bottom: 0.5rem;
}

.meta {
	display: block;
	color: var(--text-secondary);
	font-size: 0.9rem;
}

/* Search Results */
.search-results-container {
	margin-top: 1rem;
	margin-bottom: 1rem;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	overflow: hidden;
	transition: all 0.3s ease;
}

	.search-results-container.collapsed {
		max-height: 60px;
	}

.search-results-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0.75rem 1rem;
	background-color: #f5f5f5;
	cursor: pointer;
	user-select: none;
}

	.search-results-header:hover {
		background-color: #ebebeb;
	}

	.search-results-header h4 {
		margin: 0;
		font-size: 0.95rem;
		font-weight: 600;
		color: #333;
	}

.toggle-icon {
	font-size: 0.8rem;
	color: #666;
	transition: transform 0.2s ease;
}

.search-results {
	max-height: 400px;
	overflow-y: auto;
	list-style: none;
	margin: 0;
	padding: 0;
}

	.search-results li {
		padding: 0.75rem 1rem;
		border-bottom: 1px solid #f0f0f0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		gap: 1rem;
	}

		.search-results li:last-child {
			border-bottom: none;
		}

		.search-results li:hover {
			background-color: #fafafa;
		}

/* ============================================
   CHECKBOX SYSTEM - WCAG 2.5.5 Compliant
   ============================================ */

/* Hide native checkbox but keep it accessible */
input[type="checkbox"] {
	position: absolute;
	opacity: 0;
	width: var(--checkbox-size);
	height: var(--checkbox-size);
	margin: 0;
	cursor: pointer;
}

	/* Custom checkbox container */
	input[type="checkbox"] + label,
	label:has(input[type="checkbox"]) {
		position: relative;
		display: inline-flex;
		align-items: center;
		gap: 12px;
		cursor: pointer;
		user-select: none;
		min-height: var(--checkbox-touch-target);
		padding: calc((var(--checkbox-touch-target) - var(--checkbox-size)) / 2) 0;
	}

		/* Custom checkbox visual */
		input[type="checkbox"] + label::before,
		label:has(input[type="checkbox"])::before {
			content: '';
			display: inline-block;
			width: var(--checkbox-size);
			height: var(--checkbox-size);
			border: 2px solid var(--border-color);
			border-radius: var(--checkbox-border-radius);
			background: var(--surface);
			transition: var(--checkbox-transition);
			flex-shrink: 0;
		}

		/* Checkmark */
		input[type="checkbox"] + label::after,
		label:has(input[type="checkbox"])::after {
			content: '';
			position: absolute;
			left: 0px;
			top: calc((var(--checkbox-touch-target) - var(--checkbox-size)) / 2);
			width: 10px;
			height: 16px;
			border: solid white;
			border-width: 0 3px 3px 0;
			transform: rotate(45deg) scale(0);
			transition: var(--checkbox-transition);
			opacity: 0;
		}

	/* Hover state */
	input[type="checkbox"]:hover + label::before,
	label:has(input[type="checkbox"]:hover)::before {
		border-color: var(--primary-color);
		box-shadow: 0 0 0 4px var(--primary-light);
	}

	/* Focus state */
	input[type="checkbox"]:focus-visible + label::before,
	label:has(input[type="checkbox"]:focus-visible)::before {
		outline: 3px solid var(--accent-soft);
		outline-offset: 2px;
		border-color: var(--primary-color);
	}

	/* Checked state */
	input[type="checkbox"]:checked + label::before,
	label:has(input[type="checkbox"]:checked)::before {
		background: var(--primary-color);
		border-color: var(--primary-color);
	}

	input[type="checkbox"]:checked + label::after,
	label:has(input[type="checkbox"]:checked)::after {
		transform: rotate(45deg) scale(1);
		opacity: 1;
	}

	/* Disabled state */
	input[type="checkbox"]:disabled + label,
	label:has(input[type="checkbox"]:disabled) {
		opacity: 0.4;
		cursor: not-allowed;
	}

		input[type="checkbox"]:disabled + label::before,
		label:has(input[type="checkbox"]:disabled)::before {
			background: var(--surface-muted);
			cursor: not-allowed;
		}

	/* Error state */
	input[type="checkbox"].error + label::before,
	label:has(input[type="checkbox"].error)::before {
		border-color: var(--error-color);
	}

.macro-pill {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	border-radius: 12px;
	font-size: var(--font-size-xs);
	font-weight: 700;
	color: white;
}

	.macro-pill.calories {
		background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	}

	.macro-pill.protein {
		background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
	}

	.macro-pill.carbs {
		background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
	}

	.macro-pill.fat {
		background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
	}

	.macro-pill.fiber {
		background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
	}

/* Responsive Design */
@media (max-width: 480px) {
	.modal-shell,
	.survey-modal {
		max-width: 95vw;
		max-height: 95vh;
		/* Remove margin as it conflicts with transform: translate(-50%, -50%) */
	}

		.modal-shell header,
		.survey-modal header {
			padding: 1rem 1.25rem;
		}

	.modal-body {
		padding: 1.25rem;
	}

	.modal-shell footer {
		padding: 1rem 1.25rem;
	}
}

@media (min-width: 768px) {
	.top-bar {
		padding: 0 2rem;
	}

	main {
		padding: 3rem clamp(2rem, 6vw, 5rem);
	}
}

@media (min-width: 992px) {
	.menu-button {
		display: none;
	}

	.flyout {
		position: static;
		transform: none !important; /* Force override */
		opacity: 1 !important; /* Force override */
		pointer-events: auto !important; /* Force override */
		box-shadow: none;
		border: none;
		background: transparent;
		padding: 0;
	}

		.flyout ul {
			display: flex;
			gap: 1.75rem;
		}

		.flyout li a,
		.flyout li button.link {
			padding: 0.35rem 0;
			width: auto;
		}

	.overlay {
		display: none;
	}

	.top-bar {
		padding-right: clamp(2rem, 6vw, 5rem);
	}
}

@media (max-width: 600px) {
	main {
		padding: 2rem 1.25rem;
	}
}
