/* Basic reset and typography */
* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
}

body {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	min-height: 100vh;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	line-height: 1.4;
	margin: 0;
	background: #f3f4f6;
	color: #111;
	overflow-x: hidden;
	overflow-y: auto;
}

/* Center the page */
.page-container {
	max-width: 2000px;
	width: 100%;
	margin: 1.5rem auto;
	padding: 1.25rem 1.5rem;
	box-shadow: 0 0 0 0 transparent;
	max-height: none;
	overflow-y: auto;
	overflow-x: hidden;
	border: 2px solid #cfcfcf;
	border-radius: 4px;
}

/* Simple box look like the attachment */
.site-header,
.site-nav,
.main-section,
.site-article,
.site-aside,
.site-footer {
	background: white;
	border: 2px solid #cfcfcf;
	padding: 1rem;
}

/* Form styling */
.parameters-form {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.form-row {
	display: flex;
	gap: 1rem;
	align-items: start;
}

.form-group {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.form-group label {
	font-weight: 500;
}

.form-group select,
.form-group input {
	padding: 0.25rem;
	border: 1px solid #ccc;
	border-radius: 3px;
	background: #fff;
	transition: all 0.2s ease-out;
}

/* Special styling for the angle inputs */
.angle-group {
	width: 100%;
}

.angle-inputs {
	display: flex;
	gap: 1rem;
}

.input-with-label {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	flex: 1;
}

.input-with-label span {
	font-size: 0.9em;
	color: #666;
}

/* Left panels (incidence angle + small inputs) */
.left-panels {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.panels-row {
	display: flex;
	gap: 1rem;
}

.panels-row .left-panels {
	flex: 0.65;
	transition: flex 0.3s ease;
}

.panels-row .right-panels {
	flex: 0.35;
	display: flex;
	flex-direction: column;
	gap: 1rem;
	align-items: stretch;
	transition: flex 0.3s ease;
}

.panel {
	border: 2px solid #cfcfcf;
	background: #f3f3f3;
	padding: 0.5rem;
}

.panel-inner {
	display: flex;
}

.range-panel .panel-left {
	width: 140px;
	background: #e6e6e6;
	display: flex;
	align-items: center;
	justify-content: center;
	border-right: 2px solid #cfcfcf;
	padding: 0.5rem;
	text-transform: none;
}

.range-panel .panel-right {
	flex: 1;
	padding: 0.25rem 0.5rem;
}

.panel-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	margin-bottom: 0.25rem;
}

.panel-key {
	width: 60px;
	background: #e6e6e6;
	padding: 0.25rem;
	text-align: center;
	border: 1px solid #cfcfcf;
}

.yellow-input {
	background: #fff9c4;
	border: 1px solid #ccc;
	padding: 0.25rem;
	flex: 1;
}

.small-panel .small-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	padding: 0.25rem 0;
}

.small-panel label {
	width: 140px;
	background: #e6e6e6;
	padding: 0.25rem;
	text-align: left;
	border: 1px solid #cfcfcf;
}

.small-panel input.yellow-input {
	width: 100%;
}

/* Material selection table */
.material-selection {
	border: 2px solid #cfcfcf;
	background: #f3f3f3;
	padding: 0.5rem;
}

.material-selection .ms-header {
	font-weight: 600;
	margin-bottom: 0.5rem;
}

.ms-grid {
	display: grid;
	grid-template-columns: 40px 1fr 160px;
	gap: 6px;
	align-items: center;
}

#rcwa-preview-root .si {
	background: #9ca3af;
	/* grey for silicon */
}

.ms-col-label {
	font-size: 0.9rem;
	font-weight: 600;
	padding: 0.25rem 0.5rem;
	background: #e6e6e6;
	border: 1px solid #cfcfcf;
}

.ms-col-number {
	padding: 0.25rem 0.5rem;
	text-align: center;
	border: 1px solid transparent;
	color: #333;
}

.layout-grid {
	/* Two-column layout: parameters on the left, right column fixed width */
	display: grid;
	grid-template-columns: 1fr 700px;
	grid-template-rows: auto auto;
	grid-template-areas:
		"section preview"
		"section preview";
	gap: 1rem;
	margin: 1rem 0;
}

@media (max-width: 1600px) {
	.layout-grid {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas:
			"section"
			"preview";
	}
}


.ms-col-material select {
	width: 100%;
	padding: 0.25rem;
	border: 1px solid #999;
	background: #eee;
}

.ms-col-thickness input {
	width: 100%;
	padding: 0.25rem;
	border: 1px solid #999;
	background: #fff9c4;
}

/* make the grid scroll if viewport small */
.material-selection .ms-grid {
	max-height: 340px;
	overflow: auto;
	display: grid;
	grid-auto-rows: minmax(32px, auto);
}

.ms-actions {
	display: flex;
	gap: 0.5rem;
	margin-top: 1rem;
	padding: 0.5rem;
	border-top: 1px solid #cfcfcf;
}

.configuration-summary {
	grid-area: summary;
	background: white;
	border: 2px solid #cfcfcf;
	padding: 1rem;
	max-height: 400px;
	/* Limit height to avoid taking too much space */
	overflow: auto;
	display: none;
	/* Hidden by default */
}

.configuration-summary.visible {
	display: block;
}

.summary-header {
	font-weight: 600;
	margin-bottom: 0.5rem;
	color: #2a4365;
}

.summary-content {
	background: #f8f9fa;
	border: 1px solid #cfcfcf;
	border-radius: 4px;
	padding: 0.75rem;
	font-size: 0.9em;
	line-height: 1.5;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 1rem;
}

.summary-section {
	min-width: 0;
}

.summary-section-title {
	font-weight: 500;
	margin-bottom: 0.25rem;
	color: #2a4365;
}

.summary-item {
	display: flex;
	justify-content: space-between;
	margin-bottom: 0.25rem;
	padding-left: 1rem;
}

.summary-item-label {
	color: #4a5568;
}

.summary-item-value {
	font-weight: 500;
}

.action-btn {
	flex: 1;
	padding: 0.5rem 1rem;
	background: #f8f9fa;
	border: 1px solid #cfcfcf;
	border-radius: 4px;
	color: #2a4365;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
}

.action-btn:hover {
	background: #e9ecef;
	border-color: #adb5bd;
}

.action-btn:active {
	background: #dee2e6;
	transform: translateY(1px);
}

/* Make buttons stack on very small screens */
@media (max-width: 480px) {
	.ms-actions {
		flex-direction: column;
	}

	.action-btn {
		width: 100%;
	}
}


/* Aside / controls */
.site-aside {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.layers-control {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 0.5rem;
}

.layers-control label {
	font-size: 0.85rem;
}

.layers-control select {
	width: 140px;
}

.options-box {
	border: 2px solid #cfcfcf;
	padding: 0.5rem;
	background: #f3f3f3;
}

.options-title {
	font-weight: 600;
	margin-bottom: 0.5rem;
}

.options-body {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.opt-check {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

.aside-controls label {
	display: block;
	font-size: 0.85rem;
	margin-top: 0.25rem;
}

.aside-controls select {
	width: 100%;
	margin-top: 0.25rem;
}

/* Radio button styling */
.radio-container {
	display: flex !important;
	flex-direction: row !important;
	gap: 2rem;
	justify-content: flex-start;
	align-items: center;
}

.radio-group {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	white-space: nowrap;
}

.radio-group input[type="radio"] {
	margin: 0;
}

.radio-group label {
	margin: 0;
	font-weight: normal;
}

/* Highlight fields with yellow background like in image */
.form-group input:focus,
.form-group select:focus {
	background: #ffd;
	outline: 1px solid #ccc;
}

.material-search:focus-within {
	background: #ffd;
	outline: 1px solid #ccc;
}

.material-search input:focus {
	background: #ffd !important;
}

.site-header {
	text-align: center;
}

.site-nav {
	margin-top: 0.75rem;
}

.site-nav ul {
	list-style: none;
	padding: 0;
	margin: 0;
	display: flex;
	gap: 1rem;
	justify-content: center;
}

.site-nav a {
	text-decoration: none;
	color: #0645ad;
}

/* Grid layout for main area handled above; responsive adjustments below */

/* Keep the parameter controls usable on laptop-width viewports. */
@media (max-width: 1600px) {
	.layout-grid {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas:
			"section"
			"preview";
	}

	.parameters-form > .form-row {
		flex-wrap: wrap;
	}

	.parameters-form > .form-row > .form-group {
		min-width: 280px;
	}

	.parameters-form > .form-row:first-child > div:last-child {
		flex: 1 1 100%;
		padding-left: 0 !important;
		flex-wrap: wrap;
	}

	.main-section .panel > div[style*="align-items:center"] {
		flex-wrap: wrap;
	}
}

.main-section {
	grid-area: section;
	min-height: 180px;
}

.structure-preview {
	grid-area: preview;
	min-height: 180px;
	background: transparent;
	padding: 0;
	width: 100%;
	/* full-width of its container */
	box-sizing: border-box;
}

/* Inside the preview area, split the space 50/50 between preview and material-selection */
/* Stack plot and response vertically instead of side-by-side */
.structure-preview {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	align-items: stretch;
}

.structure-preview>.preview,
.structure-preview>.material-selection {
	flex: 0 0 auto;
	min-width: 0;
	background: white;
	border: 2px solid #cfcfcf;
	padding: 1rem;
	box-sizing: border-box;
}

.structure-preview>.preview {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.preview-header {
	background: #e6e6e6;
	padding: 0.5rem;
	border-bottom: 2px solid #cfcfcf;
	font-weight: 600;
	margin-bottom: 0;
	font-size: 0.9rem;
}

.preview-content {
	background: #ffffff;
	border: none;
	padding: 0;
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	min-height: 200px;
}

.plot-content {
	background: #ffffff;
	border: none;
	padding: 0;
	flex: 0 0 500px;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	height: 500px;
}

.layer-stack {
	flex: 1;
	display: flex;
	flex-direction: column;
	height: 100%;
}

/* Grating split segments */
.segment {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.75em;
	font-weight: 500;
	border: 1px solid #cfcfcf;
	background: #ffffff;
	min-height: 26px;
	line-height: 1.1;
	padding: 0 4px;
}

.segment.air {
	background: #ffffff;
}

.segment.ag {
	background: #c0c0c0;
}

.segment.cu {
	background: #f59e0b;
	color: #111;
}

.segment.sio2 {
	background: #d8b4fe;
}

.segment.pdms {
	background: #fde68a;
}

.segment.noa61 {
	background: #99f6e4;
}

.segment.air {
	background: #ffffff;
}

.segment.same {
	flex: 1 !important;
}

.layer {
	padding: 8px;
	text-align: center;
	color: #2a4365;
	/* Neutral slate blue that works on both light and dark backgrounds */
	font-size: 0.9em;
	font-weight: 500;
	/* Slightly bolder to improve readability */
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.layer .material-name {
	font-weight: 500;
}

.layer .thickness {
	font-size: 0.85em;
	opacity: 0.9;
}

/* No need to override for air since the neutral color works for all */

.layer.air {
	background: white;
}

.layer.si {
	background: #a0a0a0;
	/* Silicon - metallic gray */
}

.layer.sio2 {
	background: #e4b5f9;
	/* Silicon Dioxide - light purple */
}

.layer.al {
	background: #d4d7d9;
	/* Aluminum - light metallic */
}

.layer.au {
	background: #ffd700;
	/* Gold - golden yellow */
}

.layer.ag {
	background: #c0c0c0;
	/* Silver - silvery */
}

.layer.cu {
	background: #b87333;
	/* Copper - copper brown */
}

.layer.ge {
	background: #7c7c7c;
	/* Germanium - dark gray */
}

.layer.gaas {
	background: #9370db;
	/* Gallium Arsenide - medium purple */
}

.layer.zno {
	background: #f0f8ff;
	/* Zinc Oxide - very light blue */
}

.layer.semi-infinite {
	font-style: italic;
	position: relative;
}

.layer.semi-infinite::after {
	content: '';
	position: absolute;
	left: 0;
	right: 0;
	bottom: -8px;
	height: 8px;
	background: repeating-linear-gradient(45deg,
			#ccc,
			#ccc 5px,
			#999 5px,
			#999 10px);
}

.site-aside {
	grid-area: aside;
	min-height: 320px;
}

.site-footer {
	text-align: center;
	margin-top: 0.75rem;
}

/* High-DPI screens */
@media (min-resolution: 2dppx) {

	.yellow-input,
	.form-group select,
	.aside-controls select {
		font-size: 16px;
		font-size: 14px;
		font-weight: 500;
	}

	#rcwa-preview-root .layer .material-name {
		font-size: 16px;
		font-weight: 600;
	}

	/* Increase font size for material names within grating segments (first line) */
	#rcwa-preview-root .segment>div:first-child {
		font-size: 16px;
		font-weight: 600;
	}

	.ia-key,
	.small-panel label,
	.panel-key {
		font-size: 14px;
	}
}

/* Tablet / medium screens */
@media (max-width: 1024px) {
	.panels-row .left-panels {
		flex: 0.6;
	}

	.panels-row .right-panels {
		flex: 0.4;
	}

	.panel-left {
		width: 120px;
		transition: width 0.3s ease;
	}

	.small-panel label {
		width: 110px;
		transition: width 0.3s ease;
	}

	.layers-control select {
		width: 120px;
		transition: width 0.3s ease;
	}

	.main-section .panel div[style*="align-items:center"] {
		flex-wrap: wrap;
		min-width: 0;
	}

	.main-section .panel div[style*="align-items:center"] > * {
		min-width: 0;
		flex: 1 1 220px;
	}
}

/* Small screens: stack everything */
@media (max-width: 720px) {
	.page-container {
		margin: 0.5rem 0;
		padding: 0.5rem;
	}

	.main-section,
	.parameters-form,
	.parameters-form > .form-row,
	.parameters-form > .form-row > .form-group,
	.main-section .panel,
	.main-section .structure-preview,
	.main-section .structure-preview > div {
		min-width: 0 !important;
		max-width: 100%;
	}

	.main-section input,
	.main-section select,
	.main-section button {
		max-width: 100%;
	}

	.site-header h1 {
		font-size: 1.75rem;
	}

	.parameters-form > .form-row {
		flex-direction: column;
		align-items: stretch;
	}

	.parameters-form > .form-row > .form-group,
	.parameters-form > .form-row > button,
	.parameters-form > .form-row > div {
		width: 100%;
		min-width: 0;
	}

	.parameters-form > .form-row:first-child > .form-group {
		flex-direction: column;
		align-items: stretch !important;
	}

	.parameters-form > .form-row:first-child > .form-group select {
		max-width: none !important;
	}

	.main-section .panel > div[style*="align-items:center"] {
		align-items: stretch !important;
		flex-direction: column;
		gap: 0.75rem !important;
	}

	.main-section .panel > div[style*="align-items:center"] > * {
		width: 100%;
		min-width: 0 !important;
	}

	.main-section .panel div[style*="align-items:center"] > * {
		flex: 1 1 100%;
	}

	.main-section .panel div[style*="align-items:center"] > * > label {
		white-space: normal !important;
	}

	.main-section .panel div[style*="align-items:center"] select,
	.main-section #period_input {
		width: 100% !important;
	}

	.main-section .panel > div[style*="align-items:center"] select,
	.main-section .panel > div[style*="align-items:center"] input {
		width: 100% !important;
	}

	.main-section .structure-preview > div[style*="align-items:stretch"] {
		flex-direction: column;
		gap: 0.75rem !important;
	}

	.main-section .structure-preview > div[style*="align-items:stretch"] > * {
		width: 100%;
		min-width: 0 !important;
	}

	.structure-preview .preview-header span {
		float: none !important;
		flex-wrap: wrap;
		justify-content: flex-start;
		margin-top: 0.5rem;
	}

	.structure-preview .preview-header span select {
		min-width: 0 !important;
		flex: 1 1 160px;
	}

	.panels-row {
		flex-direction: column;
	}

	.panels-row .left-panels,
	.panels-row .right-panels {
		flex: none;
		width: 100%;
	}

	/* Radio buttons wrap and become touch-friendly */
	.radio-container {
		flex-wrap: wrap;
		gap: 1rem 1.5rem;
	}

	.radio-group {
		flex: 1 1 auto;
		min-width: 160px;
	}

	.radio-group input[type="radio"] {
		width: 20px;
		height: 20px;
	}

	/* Full-width inputs with better touch targets */
	.yellow-input,
	.form-group select,
	.aside-controls select,
	.layers-control select {
		width: 100%;
		min-height: 36px;
		font-size: 16px;
		padding: 0.375rem;
	}

	.small-panel label,
	.panel-key {
		width: 100px;
	}

	/* Move layers control inline */
	.layers-control {
		justify-content: flex-start;
	}

	/* Hide empty aside */
	.site-aside {
		display: none;
	}

	.layout-grid {
		grid-template-columns: 1fr;
		grid-template-areas:
			"section"
			"preview";
		gap: 0.75rem;
	}
}

/* If the viewport is short (e.g., mobile with keyboard open), avoid centering vertically
   which can clip content — instead align at start so users can scroll from top. */
@media (max-height:700px) {
	body {
		align-items: flex-start;
	}

	.page-container {
		max-height: none;
	}
}

/* Accessibility helpers */
.skip-link:focus {
	position: static;
	left: auto;
	top: auto;
	padding: 0.25rem 0.5rem;
	background: #000;
	color: #fff;
}

/* Isolated styles for RCWA Structure Preview */
#rcwa-preview-root {
	display: block;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 14px;
	height: 100%;
}

#rcwa-preview-root *,
#rcwa-preview-root *::before,
#rcwa-preview-root *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* Container that holds the stack of layers */
#rcwa-preview-root .layer-stack {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 0;
	gap: 0;
	height: 100%;
	justify-content: space-between;
}

/* Generic full-width layer row with overlay space */
#rcwa-preview-root .layer-row {
	position: relative;
	display: block;
	overflow: hidden;
	margin: 0;
	padding: 0;
	flex: 1;
	min-height: 32px;
}

/* Split row for ridge/groove */
#rcwa-preview-root .split-row {
	display: grid;
	align-items: stretch;
	width: 100%;
	height: 100%;
	min-height: 32px;
}

/* Colored segments */
#rcwa-preview-root .segment {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 4px;
	line-height: 1.3;
	font-size: 14px;
	font-weight: 500;
	border: 0;
}

/* Last segment in split row extends to cover under overlay */
#rcwa-preview-root .split-row .segment:last-child {
	margin-right: -8px;
	padding-right: 12px;
}

/* Material color mapping */
#rcwa-preview-root .segment.air {
	background: #ffffff;
}

#rcwa-preview-root .segment.ag {
	background: #c0c0c0;
}

#rcwa-preview-root .segment.cu {
	background: #f59e0b;
}

#rcwa-preview-root .segment.pdms {
	background: #fde68a;
}

#rcwa-preview-root .segment.noa61 {
	background: #99f6e4;
}

#rcwa-preview-root .segment.sio2 {
	background: #d8b4fe;
}

/* Thickness overlay on the right */
#rcwa-preview-root .layer-row>.thickness {
	position: absolute !important;
	right: 6px;
	top: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	font-size: 14px;
	font-weight: 600;
	pointer-events: none;
	color: #000;
	text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9), -1px -1px 2px rgba(255, 255, 255, 0.9), 1px -1px 2px rgba(255, 255, 255, 0.9), -1px 1px 2px rgba(255, 255, 255, 0.9);
	width: auto;
	min-width: 0;
	white-space: nowrap;
	z-index: 2;
}

/* Thin-film thickness badge inside simple layer bar */
#rcwa-preview-root .layer .thickness {
	position: static;
	margin-left: 8px;
	font-size: 14px;
	font-weight: 600;
}

/* Incident/substrate simple bars */
#rcwa-preview-root .layer {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: 8px;
	margin: 0;
}

/* Color mapping for thin film layers */
#rcwa-preview-root .layer.air {
	background: #ffffff;
}

#rcwa-preview-root .layer.ag {
	background: #c0c0c0;
}

#rcwa-preview-root .layer.cu {
	background: #f59e0b;
}

#rcwa-preview-root .layer.pdms {
	background: #fde68a;
}

#rcwa-preview-root .layer.noa61 {
	background: #99f6e4;
}

#rcwa-preview-root .layer.sio2 {
	background: #d8b4fe;
}

/* Shared material selection */
.material-selection-panel {
	background: #fff;
	border: 2px solid #cfcfcf;
	padding: 1rem;
	min-width: 0;
}

.material-selection-title {
	font-size: 1rem;
	font-weight: 700;
	margin-bottom: 0.75rem;
}

.material-search {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.4rem 0.6rem;
	border: 1px solid #cfcfcf;
	background: #fff;
	border-radius: 4px;
}

.material-search > span {
	font-size: 1.2rem;
	line-height: 1;
	color: #4a5568;
}

.material-search input {
	width: 100%;
	min-width: 0;
	border: 0;
	outline: 0;
	font: inherit;
}

.material-list-heading {
	margin: 0.9rem 0 0.35rem;
	font-size: 0.8rem;
	font-weight: 700;
	color: #4a5568;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.material-dropdown {
	position: relative;
}

#material-dropdown-toggle {
	border: 0;
	background: transparent;
	color: #4a5568;
	padding: 0.2rem 0.4rem;
	cursor: pointer;
}

.material-dropdown .material-list[hidden] {
	display: none;
}

.material-dropdown .material-list {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	z-index: 100;
	grid-template-columns: 1fr;
	max-height: 240px;
	background: #fff;
	border: 1px solid #cfcfcf;
	border-radius: 4px;
	box-shadow: 0 6px 18px #0002;
	overscroll-behavior: contain;
}

.material-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 0.35rem;
	max-height: 210px;
	overflow: auto;
	padding: 0.15rem;
}

.material-option {
	min-width: 0;
	padding: 0.45rem 0.6rem;
	border: 1px solid #d7dce2;
	border-radius: 3px;
	background: #f8f9fa;
	color: #2a4365;
	text-align: left;
	cursor: pointer;
	overflow-wrap: anywhere;
}

.material-option:hover:not(:disabled),
.material-option.is-active {
	background: #e9ecef;
	border-color: #9aa7b5;
}

.material-option:disabled {
	background: #e8f1e8;
	color: #486048;
	cursor: default;
}

.selected-materials {
	display: flex;
	flex-wrap: wrap;
	gap: 0.45rem;
	min-height: 2rem;
}

.material-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	max-width: 100%;
	padding: 0.35rem 0.5rem 0.35rem 0.65rem;
	border: 1px solid #9db9d2;
	border-radius: 999px;
	background: #edf5fb;
	color: #23415e;
	font-size: 0.85rem;
}

.material-remove {
	width: 1.25rem;
	height: 1.25rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #536273;
	cursor: pointer;
	font-size: 1rem;
	line-height: 1;
}

.material-remove:hover {
	background: #d7e4ef;
	color: #172b3a;
}

.material-empty-state {
	padding: 0.45rem 0;
	color: #687485;
	font-size: 0.85rem;
}

.material-plot {
	padding: 0.15rem 0.4rem;
	border: 1px solid #9db9d2;
	border-radius: 3px;
	background: #fff;
	color: #23415e;
	cursor: pointer;
	font-size: 0.75rem;
}

.material-plot:hover {
	background: #dcecf8;
}

.material-chart-panel {
	margin-top: 0.85rem;
	padding-top: 0.75rem;
	border-top: 1px solid #d7dce2;
}

.material-chart-title {
	font-size: 0.85rem;
	font-weight: 600;
	color: #2a4365;
}

.material-chart-heading {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 0.5rem;
}

.material-chart-close {
	padding: 0.25rem 0.55rem;
	border: 1px solid #cfcfcf;
	border-radius: 3px;
	background: #f8f9fa;
	color: #2a4365;
	cursor: pointer;
	font-size: 0.75rem;
}

.material-chart-close:hover {
	background: #e9ecef;
}

.material-chart-wrap {
	position: relative;
	height: 260px;
	min-height: 200px;
}

.home-page .material-selection-panel {
	margin-top: 1rem;
}

.workflow-panel {
	margin-top: 1rem;
	padding: 1rem;
	border: 2px solid #cfcfcf;
	background: #fff;
}

.workflow-status {
	margin-top: 0.5rem;
	color: #687485;
	font-size: 0.85rem;
}

.material-specific-fields {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	margin-top: 0.35rem;
}

.material-specific-field {
	display: flex;
	flex: 1 1 150px;
	flex-direction: column;
	gap: 0.2rem;
	font-size: 0.75rem;
	color: #4a5568;
}

.material-specific-field .yellow-input {
	min-width: 0;
	width: 100%;
}

@media (max-width: 720px) {
	.material-list {
		grid-template-columns: 1fr;
		max-height: 180px;
	}
}

/* Home page responsive layout */
.home-page .layout-grid {
	grid-template-columns: 1fr 700px;
	grid-template-rows: auto auto;
	grid-template-areas:
		"section preview"
		"summary summary";
}

.home-page .configuration-summary {
	grid-area: summary;
	width: 100%;
}

.home-page .parameters-form,
.home-page .form-row,
.home-page .form-group,
.home-page .panels-row,
.home-page .left-panels,
.home-page .right-panels,
.home-page .structure-preview,
.home-page .preview,
.home-page .material-selection {
	min-width: 0;
}

.home-page .parameters-form > .form-row {
	flex-wrap: wrap;
}

.home-page .panels-row .left-panels,
.home-page .panels-row .right-panels {
	flex: 1 1 320px;
	width: auto;
}

.home-page .site-nav ul {
	flex-wrap: wrap;
}

.home-page .ms-grid {
	grid-template-columns: 40px minmax(0, 1fr) minmax(120px, 160px);
}

@media (max-width: 1600px) {
	.home-page .layout-grid {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto auto auto;
		grid-template-areas:
			"section"
			"preview"
			"summary";
	}
}

@media (max-width: 720px) {
	.home-page .page-container {
		margin: 0.5rem 0;
		padding: 0.5rem;
	}

	.home-page .site-header h1 {
		font-size: 1.75rem;
	}

	.home-page .form-row,
	.home-page .panels-row {
		flex-direction: column;
		align-items: stretch;
	}

	.home-page .form-group,
	.home-page .panels-row .left-panels,
	.home-page .panels-row .right-panels {
		width: 100%;
		flex: none;
	}

	.home-page .radio-container {
		flex-direction: column !important;
		align-items: stretch;
		gap: 0.75rem;
	}

	.home-page .radio-group,
	.home-page .layers-control {
		width: 100%;
		min-width: 0;
		justify-content: flex-start;
	}

	.home-page .layers-control {
		flex-wrap: wrap;
	}

	.home-page .layers-control select,
	.home-page .aside-controls select {
		width: 100%;
		min-height: 36px;
	}

	.home-page .panel-inner {
		flex-direction: column;
	}

	.home-page .range-panel .panel-left {
		width: 100%;
		border-right: 0;
		border-bottom: 2px solid #cfcfcf;
	}

	.home-page .range-panel .panel-right {
		width: 100%;
	}

	.home-page .panel-row,
	.home-page .small-panel .small-row {
		width: 100%;
	}

	.home-page .panel-key,
	.home-page .small-panel label {
		width: 100px;
		flex: 0 0 100px;
	}

	.home-page .ms-grid {
		grid-template-columns: 32px minmax(0, 1fr) minmax(80px, 1fr);
		gap: 4px;
	}

	.home-page .ms-col-label,
	.home-page .ms-col-number,
	.home-page .ms-col-material select,
	.home-page .ms-col-thickness input {
		min-width: 0;
		font-size: 0.85rem;
	}

	.home-page .ms-actions {
		flex-wrap: wrap;
	}

	.home-page .ms-actions .action-btn {
		flex: 1 1 calc(50% - 0.25rem);
		min-width: 0;
	}
}

/* Container that holds the stack of layers */
#rcwa-preview-root .layer-stack {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 0;
	gap: 0;
	height: 100%;
	justify-content: space-between;
}

/* Generic full-width layer row with overlay space */
#rcwa-preview-root .layer-row {
	position: relative;
	display: block;
	overflow: hidden;
	margin: 0;
	padding: 0;
}

/* Split row for ridge/groove */
#rcwa-preview-root .split-row {
	display: flex;
	align-items: stretch;
	width: 100%;
	min-height: 32px;
}

/* Colored segments */
#rcwa-preview-root .segment {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 4px;
	line-height: 1.3;
	font-size: 12px;
	font-weight: 500;
	border: 0;
}

/* Last segment in split row extends to cover under overlay */
#rcwa-preview-root .split-row .segment:last-child {
	margin-right: -8px;
	padding-right: 12px;
}

/* Material color mapping */
#rcwa-preview-root .segment.air {
	background: #ffffff;
}

#rcwa-preview-root .segment.ag {
	background: #c0c0c0;
}

#rcwa-preview-root .segment.cu {
	background: #f59e0b;
}

#rcwa-preview-root .segment.pdms {
	background: #fde68a;
}

#rcwa-preview-root .segment.noa61 {
	background: #99f6e4;
}

#rcwa-preview-root .segment.sio2 {
	background: #d8b4fe;
}

/* Thickness overlay on the right */
#rcwa-preview-root .layer-row .thickness {
	position: absolute;
	right: 6px;
	top: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	font-size: 12px;
	font-weight: 600;
	pointer-events: none;
	color: #000;
	text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9), -1px -1px 2px rgba(255, 255, 255, 0.9), 1px -1px 2px rgba(255, 255, 255, 0.9), -1px 1px 2px rgba(255, 255, 255, 0.9);
	width: auto;
	min-width: 0;
}

/* Thin-film thickness badge inside simple layer bar */
#rcwa-preview-root .layer .thickness {
	position: static;
	margin-left: 8px;
	font-size: 12px;
	font-weight: 600;
}

/* Incident/substrate simple bars */
#rcwa-preview-root .layer {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: 8px;
	margin: 0;
	flex: 1;
	min-height: 32px;
}

/* Color mapping for thin film layers */
#rcwa-preview-root .layer.air {
	background: #ffffff;
}

#rcwa-preview-root .layer.ag {
	background: #c0c0c0;
}

#rcwa-preview-root .layer.cu {
	background: #f59e0b;
}

#rcwa-preview-root .layer.pdms {
	background: #fde68a;
}

#rcwa-preview-root .layer.noa61 {
	background: #99f6e4;
}

#rcwa-preview-root .layer.sio2 {
	background: #d8b4fe;
}

.silicon-settings { margin-top: .5rem; padding: .6rem; border: 1px solid #cfd8e3; border-radius: 5px; background: #fff; }
.silicon-settings summary { cursor: pointer; font-weight: 600; }
.silicon-settings label { display: block; margin: .5rem 0; }
.silicon-settings input:not([type="checkbox"]), .silicon-settings select { max-width: 100%; padding: .3rem; }
.silicon-settings p { font-size: .8rem; margin: .5rem 0; }
.silicon-settings button { margin: .3rem .3rem .3rem 0; padding: .35rem; cursor: pointer; }

.layer-coherence[hidden] { display: none; }
