/* Modal styles */

/* Bootstrap's own default is `.modal-content { overflow: hidden; }` (there
   to clip modal-header's slightly-rounded top corners to the modal-content
   box) — but it also clips any custom absolutely-positioned popover that
   pops out past the modal's edge, like the `.ap-patient-dropdown-list`
   search-suggestion dropdown used throughout the app (Cart, Catalog "Order
   for Patient" picker, Admin Order Desk customer/patient search, etc.) —
   any such dropdown near the bottom of a modal gets silently cut off.
   This app's own .modal-content override already sets border-radius:0, so
   there are no rounded corners left to protect by clipping — safe to make
   this the default everywhere instead of patching it modal-by-modal with an
   inline style="overflow:visible" (which is what fixed this the first time
   it was noticed, on a now-removed page). .modal-body below still handles
   its own internal scrolling independently via overflow-y, so this doesn't
   affect a modal's own max-height containment. */
.modal-content {
	overflow: visible;
}

.modal-body {
	max-height: 70vh;
	overflow-y: auto;
}

/* Mobile: taller modals to reduce nested scrolling */
@media (max-width: 767.98px) {
	.modal-body {
		max-height: 80vh;
	}
}

/* Phone: full-screen-like modals for complex forms */
@media (max-width: 576px) {
	.modal-body {
		max-height: 85vh;
	}

	.modal-dialog {
		margin: 0.25rem;
	}

	.modal-dialog.modal-lg,
	.modal-dialog.modal-xl {
		margin: 0;
		max-width: 100%;
		height: 100%;
	}

	.modal-dialog.modal-lg .modal-content,
	.modal-dialog.modal-xl .modal-content {
		border-radius: 0;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.modal-dialog.modal-lg .modal-body,
	.modal-dialog.modal-xl .modal-body {
		flex: 1;
		max-height: none;
	}
}

.modal-body .spinner-border {
    color: var(--sa-brand-text, var(--sa-primary-color));
}

/* Form Section Styles */
.sa-form-section {
	background: #f8f9fa;
	border-radius: 0;
	padding: 0.875rem 1rem;
	border: 1px solid #e9ecef;
}

.sa-form-section-title {
	font-size: 0.8rem;
	font-weight: 600;
	color: #495057;
	margin-bottom: 0.75rem;
	padding-bottom: 0.5rem;
	border-bottom: 1px solid #dee2e6;
	display: flex;
	align-items: center;
}

.sa-form-section-title i {
	color: var(--sa-brand-text, #667eea);
	font-size: 0.75rem;
}

/* Compact labels inside form sections */
.sa-form-section .form-label,
.sa-form-section label {
	font-size: 0.8rem;
	margin-bottom: 0.25rem;
}

.sa-form-section .form-control,
.sa-form-section .form-select {
	font-size: 0.875rem;
}

/* Mobile: form sections need more breathing room for touch */
@media (max-width: 767.98px) {
	.sa-form-section .form-label,
	.sa-form-section label {
		font-size: 0.82rem;
		margin-bottom: 0.375rem;
	}

	.sa-form-section .form-control,
	.sa-form-section .form-select {
		min-height: 40px;
	}
}

@media (max-width: 576px) {
	.sa-form-section {
		padding: 0.75rem;
	}

	.sa-form-section-title {
		font-size: 0.78rem;
	}
}

/* Extra small button — desktop only; mobile override in mobile.css section 45 */
.btn-xs {
	padding: 0.15rem 0.4rem;
	font-size: 0.7rem;
	line-height: 1.2;
	border-radius: 0;
}

@media (max-width: 767.98px) {
	.btn-xs {
		padding: 0.3rem 0.625rem;
		font-size: 0.75rem;
		min-height: 32px;
		display: inline-flex;
		align-items: center;
	}
}

/* Modal Section Styles — tokenized (--sa-*, see atlasmps-custom.css :root)
   so light/dark values come from one source instead of the separate
   `[data-theme-mode="dark"] .sa-modal-section` override this used to need. */
.sa-modal-section {
	background: var(--sa-surface-raised);
	border-radius: var(--sa-radius-sm);
	padding: var(--sa-space-4) var(--sa-space-5);
	border: 1px solid var(--sa-border);
}

.sa-modal-section__title {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--sa-body-text);
	margin-bottom: var(--sa-space-4);
	padding-bottom: var(--sa-space-3);
	border-bottom: 1px solid var(--sa-border);
	display: flex;
	align-items: center;
}

.sa-modal-section__title i {
	color: var(--sa-brand-text, #667eea);
}

/* Collapsible section styles */
.sa-modal-section--collapsible {
	background: var(--sa-surface);
	border: 1px dashed var(--sa-border);
}

.sa-modal-section--collapsible .sa-modal-section__header {
	cursor: pointer;
	padding: 0.25rem 0;
	transition: background-color var(--sa-dur) var(--sa-ease);
}

.sa-modal-section--collapsible .sa-modal-section__header:hover {
	background: var(--sa-surface-raised);
	margin: -0.25rem;
	padding: 0.5rem 0.25rem;
	border-radius: var(--sa-radius-sm);
}

.sa-modal-section--collapsible .sa-modal-section__title {
	border-bottom: none;
	margin-bottom: 0;
	padding-bottom: 0;
}

.sa-modal-section__toggle-icon {
	font-size: 0.7rem;
	color: var(--sa-muted);
	transition: transform var(--sa-dur) var(--sa-ease);
}

/* Product Lot Number Table */
.sa-product-lot-table {
	background: var(--sa-surface);
	border-radius: var(--sa-radius-sm);
	border: 1px solid var(--sa-border);
	overflow: hidden;
}

.sa-product-lot-table table {
	margin-bottom: 0;
}

.sa-product-lot-table thead th {
	background: var(--sa-surface-sunken);
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--sa-body-text);
	text-transform: uppercase;
	letter-spacing: 0.025em;
	padding: 0.625rem 0.75rem;
	border-bottom: 1px solid var(--sa-border);
}

.sa-product-lot-table tbody td {
	padding: 0.625rem 0.75rem;
	vertical-align: middle;
	font-size: 0.875rem;
	border-bottom: 1px solid var(--sa-border);
}

.sa-product-lot-table tbody tr:last-child td {
	border-bottom: none;
}

.sa-product-lot-table tbody tr:hover {
	background: var(--sa-surface-sunken);
}

/* Multiple lot number inputs container */
.sa-lot-inputs {
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
}

.sa-lot-input-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.sa-lot-input-label {
	font-size: 0.75rem;
	font-weight: 500;
	color: #6c757d;
	min-width: 1.25rem;
}

.sa-product-lot-table .lot-number-input {
	max-width: 140px;
	font-size: 0.8125rem;
}

/* Expiration date inputs (matches lot number pattern) */
.sa-exp-inputs {
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
}

.sa-product-lot-table .expiration-date-input {
	max-width: 150px;
	font-size: 0.8125rem;
}

/* Mobile: lot/expiration inputs need full width */
@media (max-width: 576px) {
	.sa-product-lot-table .lot-number-input,
	.sa-product-lot-table .expiration-date-input {
		max-width: 100%;
		width: 100%;
	}

	.sa-product-lot-table thead th {
		font-size: 0.68rem;
		padding: 0.4rem 0.5rem;
	}

	.sa-product-lot-table tbody td {
		padding: 0.4rem 0.5rem;
		font-size: 0.8rem;
	}

	.sa-lot-input-row {
		flex-wrap: wrap;
	}
}

.sa-product-lot-table .badge {
	font-size: 0.75rem;
	font-weight: 500;
}

/* ─── Dark mode ────────────────────────────────────────────── */
/* .sa-modal-section / .sa-product-lot-table no longer need overrides
   here — they're built on --sa-* tokens now (see above), which already
   carry their own dark-mode values from atlasmps-custom.css's :root. */
[data-theme-mode="dark"] .sa-form-section {
	background: #222222 !important;
	border-color: #303030 !important;
}
[data-theme-mode="dark"] .sa-form-section-title {
	color: #C8C8C8 !important;
	border-bottom-color: #303030 !important;
}
[data-theme-mode="dark"] .sa-product-lot-table tbody tr:hover {
	background: #222222 !important;
}

/* ============================================================
   MODAL SIZING / PATIENT PROFILE — responsive
   ------------------------------------------------------------
   Bootstrap only widens .modal-lg at >=992px and .modal-xl at >=1200px; between 576px and
   those widths EVERY modal is 500px wide, however wide its content was designed to be. A
   tablet or a half-width desktop window therefore got a 500px dialog holding a 3-column
   layout (patient profile: tab rail + summary + cards), wrapping text a word per line and
   clipping the right-hand card. Let lg/xl dialogs use the window instead.
   ============================================================ */
@media (min-width: 576px) {
	.modal-lg { --bs-modal-width: min(800px, calc(100vw - 2rem)); }
	.modal-xl { --bs-modal-width: min(1140px, calc(100vw - 2rem)); }
}

/* The patient profile's vertical tab rail only has room beside the content on a wide dialog.
   Below 992px stack it: tabs become a horizontal strip on top, content takes the full width. */
#modalPatientProfile #patientProfileContent { min-width: 0; }
@media (max-width: 991.98px) {
	#modalPatientProfile .modal-body > .d-flex { flex-direction: column !important; }
	#modalPatientProfile .pp-sidebar {
		min-width: 100% !important; max-width: 100% !important; width: 100%;
		border-right: none !important; border-bottom: 1px solid rgba(128, 128, 128, 0.25) !important;
	}
	#modalPatientProfile #patientProfileTabs {
		flex-direction: row !important; flex-wrap: nowrap !important;
		overflow-x: auto; padding: 0.6rem !important; gap: 0.4rem !important;
	}
	#modalPatientProfile .pp-sidebar .nav-link { white-space: nowrap; flex-shrink: 0; }
}
#modalPatientProfile #patientProfileTabs { scrollbar-width: none; }
#modalPatientProfile #patientProfileTabs::-webkit-scrollbar { display: none; }
@media (max-width: 575.98px) {
	#modalPatientProfile .modal-dialog { margin: 0 !important; max-width: 100vw !important; width: 100vw; height: 100dvh; }
	#modalPatientProfile .modal-content { border-radius: 0 !important; height: 100%; }
	/* Full-screen on a phone: the body fills the dialog edge to edge (it was inset 24px and stopped short). */
	#modalPatientProfile .modal-body { padding: 0 !important; flex: 1 1 auto; min-height: 0 !important; }
	#modalPatientProfile .modal-body > .d-flex { height: 100%; }
	#modalPatientProfile .pp-headshot { width: 96px !important; height: 96px !important; }
}

/* Patient profile -> Documents / Order History tables on a phone: the inline fixed column widths
   (100px + 90px + 110px...) add up to more than the dialog, so let the cells wrap and share the width. */
@media (max-width: 575.98px) {
	#patientProfileContent { padding: 12px !important; overflow-x: hidden; }
	#patientProfileContent .table-responsive { overflow-x: visible; }
	#patientProfileContent table { width: 100% !important; table-layout: auto; }
	#patientProfileContent table th,
	#patientProfileContent table td { width: auto !important; white-space: normal !important; padding: 0.4rem 0.35rem !important; overflow-wrap: anywhere; }
	#patientProfileContent .pp-doc-shell__content input[type="search"],
	#patientProfileContent .pp-doc-shell__content input[type="text"] { max-width: 100%; }
	#patientProfileContent .pp-doc-shell__content,
	#patientProfileContent .pp-doc-shell { min-width: 0; max-width: 100%; }
}
@media (max-width: 575.98px) {
	#patientProfileContent .nav-tabs, #patientProfileContent .pp-doc-shell__nav { scrollbar-width: none; }
	#patientProfileContent .nav-tabs::-webkit-scrollbar, #patientProfileContent .pp-doc-shell__nav::-webkit-scrollbar { display: none; }
	#patientProfileContent .nav-tabs { flex-wrap: nowrap; overflow-x: auto; }
	#patientProfileContent .nav-tabs .nav-link { white-space: nowrap; }
}
