/* biome-ignore-all lint/style/noDescendingSpecificity: extracted brownfield layer preserves intentional selector ordering while the CSS split remains behavior-compatible */
/* =============================================================================
	Modal And Detail Layer
	Owns medication detail and other modal-heavy detail flows that compose on top
	of the shared modal base styles.
	============================================================================= */

/* Medication Detail Modal */
.modal-content.med-detail-modal {
	padding: 0;
	width: min(100vw - 1rem, 711px);
	max-width: 711px;
	max-height: 90vh;
	background: var(--bg-primary);
	overscroll-behavior: contain;
	display: flex;
	flex-direction: column;
	overflow: visible;
}

.med-detail-modal .med-detail-body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
}

.med-detail-header {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	padding: 2rem 2rem 2rem;
	margin-bottom: 0.5rem;
	background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
	color: white;
	border-radius: 12px 12px 0 0;
}

.med-detail-header h2 {
	margin: 0;
	font-size: 1.5rem;
	text-align: center;
}

.med-detail-titles {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.25rem;
}

.med-generic-name {
	font-size: 0.95rem;
	color: rgba(255, 255, 255, 0.75);
	font-weight: 400;
}

.med-taken-by {
	font-size: 1rem;
	color: white;
	font-weight: 600;
	text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
	text-align: center;
}

.taken-by-badge {
	font-size: 0.75rem;
	color: var(--accent);
	font-weight: 500;
	margin-left: 0.35rem;
	opacity: 0.85;
}

.taken-by-badge.clickable,
.taken-by-name.clickable {
	cursor: pointer;
	transition: opacity 0.15s;
}

.taken-by-badge.clickable:hover,
.taken-by-name.clickable:hover {
	opacity: 1;
	text-decoration: underline;
}

/* User Medications Modal */
.modal-content.user-meds-modal {
	max-width: 500px;
	width: 95%;
	padding: 0;
	border-radius: 16px;
	overflow: hidden;
}

.user-meds-header {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 1.5rem 2rem;
	background: linear-gradient(135deg, var(--accent) 0%, #1e5bb8 100%);
	border-radius: 16px 16px 0 0;
}

.user-meds-header .user-avatar {
	width: 50px;
	min-width: 50px;
	height: 50px;
	min-height: 50px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.5rem;
	font-weight: 700;
	color: white;
	flex-shrink: 0;
}

.user-meds-header h2 {
	margin: 0;
	color: white;
	font-size: 1.3rem;
}

.user-meds-list {
	padding: 1rem;
	max-height: 400px;
	overflow-y: auto;
}

.user-med-item {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem;
	border-radius: 8px;
	transition: background 0.15s;
	flex-wrap: wrap;
}

.user-med-item.clickable {
	cursor: pointer;
}

.user-med-item.clickable:hover {
	background: var(--accent-bg);
}

.user-med-info {
	flex: 1;
	min-width: 150px;
}

.user-med-name {
	display: block;
	font-weight: 600;
	color: var(--text-primary);
	white-space: nowrap;
}

.user-med-generic {
	display: block;
	font-size: 0.8rem;
	color: var(--text-secondary);
}

.user-med-stats {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.25rem;
	flex-shrink: 0;
}

.user-med-pills {
	font-size: 0.85rem;
	color: var(--text-secondary);
}

.user-med-intakes {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	margin-top: 0.15rem;
}

.user-med-intake-item {
	font-size: 0.78rem;
	color: var(--text-secondary);
	line-height: 1.3;
}

.user-meds-empty {
	padding: 2rem;
	text-align: center;
	color: var(--text-secondary);
}

.user-meds-footer {
	padding: 1rem 1.5rem;
	border-top: 1px solid var(--border-primary);
	display: flex;
	justify-content: flex-start;
}

.med-detail-header .med-avatar-lg {
	width: 100px;
	height: 100px;
	font-size: 2.5rem;
	border: 3px solid rgba(255, 255, 255, 0.3);
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.med-detail-body {
	padding: 1.5rem 2rem 2rem;
	background: var(--bg-primary);
}

.med-detail-section {
	margin-bottom: 1.5rem;
	padding-bottom: 1.5rem;
	border-bottom: 1px solid var(--border-color);
}

.med-detail-section:last-child {
	margin-bottom: 0;
	padding-bottom: 0;
	border-bottom: none;
}

/* Notes content in modal - auto-sizing box */
.med-notes-content {
	background: var(--bg-secondary);
	padding: 0.75rem 1rem;
	border-radius: 8px;
	white-space: pre-wrap;
	word-wrap: break-word;
	line-height: 1.6;
	max-height: 300px;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
	font-size: 1rem;
}

/* Mobile: larger notes box with better touch scrolling */
@media (max-width: 600px) {
	.med-notes-content {
		min-height: 80px;
		max-height: 200px;
		font-size: 1rem;
		padding: 1rem;
		touch-action: pan-y; /* Enable vertical touch scrolling */
	}
}

.med-detail-section h3 {
	font-size: 0.85rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-secondary);
	margin: 0 0 0.75rem;
}

.med-detail-section h3.section-header-with-badge {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.med-detail-section h3 .status-chip.small {
	font-size: 0.7rem;
	padding: 0.2rem 0.5rem;
	text-transform: none;
	letter-spacing: normal;
}

.med-detail-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 0.75rem;
}

.prescription-detail-grid .med-detail-item {
	display: flex;
	flex-direction: column;
	align-items: start;
}

.med-detail-item {
	background: var(--bg-secondary);
	padding: 0.75rem;
	border-radius: 8px;
}

.med-detail-item.full-width {
	grid-column: 1 / -1;
}

.med-detail-label {
	display: block;
	font-size: 0.75rem;
	color: var(--text-secondary);
	margin-bottom: 0;
}

.med-detail-value {
	font-size: 1.1rem;
	font-weight: 600;
	color: var(--text-primary);
}

.med-detail-value.success-text {
	color: var(--success);
}
.med-detail-value.warning-text {
	color: var(--warning);
}
.med-detail-value.danger-text {
	color: var(--danger);
}

.med-detail-schedules {
	display: grid;
	grid-template-columns: auto auto 1fr auto auto auto;
	gap: 0.45rem 0;
}

.med-schedule-row {
	display: grid;
	grid-column: 1 / -1;
	grid-template-columns: subgrid;
	align-items: center;
	column-gap: 0.75rem;
}

.med-schedule-usage {
	font-weight: 600;
	color: var(--accent);
	white-space: nowrap;
	grid-column: 1;
}

.med-schedule-freq {
	color: var(--text-secondary);
	white-space: nowrap;
	grid-column: 2;
}

.med-schedule-person {
	color: var(--text-secondary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	grid-column: 4;
}

.med-schedule-time {
	font-weight: 700;
	white-space: nowrap;
	color: var(--text-primary);
	text-align: right;
	grid-column: 5;
}

.med-schedule-bell {
	color: var(--warning);
	display: inline-flex;
	align-items: center;
	grid-column: 6;
}

[data-theme="light"] .med-schedule-bell {
	color: #b45309;
}

@media (max-width: 700px) {
	.med-detail-schedules {
		grid-template-columns: 1fr;
	}

	.med-schedule-row {
		grid-template-columns: 1fr;
		row-gap: 0.25rem;
	}

	.med-schedule-usage,
	.med-schedule-freq,
	.med-schedule-person,
	.med-schedule-time,
	.med-schedule-bell {
		grid-column: auto;
	}
}

.med-detail-footer {
	padding: 1rem 2rem 1.5rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1rem;
	border-top: 1px solid var(--border-primary);
	background: var(--bg-primary);
	border-radius: 0 0 12px 12px;
	flex-shrink: 0;
	overflow: visible;
	position: relative;
	z-index: 1;
	padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
	margin: 0;
}

/* Mobile devices can report wide CSS viewports (e.g., 768px in device emulation).
   Use input modality instead of width-only breakpoints so the modal still fills the handset viewport. */
@media (hover: none) and (pointer: coarse) and (max-width: 500px) {
	.med-detail-overlay {
		padding: 0.4rem;
		align-items: stretch;
	}

	.modal-content.med-detail-modal {
		width: calc(100vw - 0.8rem);
		max-width: none;
		max-height: calc(100dvh - 0.8rem);
		margin: auto;
		border-radius: 12px;
	}
}

.med-detail-footer::before {
	content: none;
}

.med-detail-footer::after {
	content: none;
}

.med-detail-footer .footer-actions {
	display: flex;
	gap: 0.5rem;
	margin-left: auto;
	overflow: visible;
	position: relative;
}

.med-detail-footer .tooltip-trigger {
	position: relative;
	z-index: 1;
}

.med-detail-footer button.icon-only {
	padding: 0.5rem;
	min-width: 2.75rem;
	min-height: 2.75rem;
}

.med-detail-footer button.icon-stock-correction {
	background: color-mix(in srgb, var(--warning) 26%, var(--bg-tertiary));
	border: 1px solid color-mix(in srgb, var(--warning) 62%, var(--border-secondary));
	color: #fef3c7;
	box-shadow: none;
}

.med-detail-footer button.icon-stock-correction:hover {
	background: color-mix(in srgb, var(--warning) 36%, var(--bg-tertiary));
	border-color: color-mix(in srgb, var(--warning) 76%, var(--border-secondary));
	box-shadow: 0 0 0 1px color-mix(in srgb, var(--warning) 32%, transparent);
}

[data-theme="light"] .med-detail-footer button.icon-stock-correction {
	background: color-mix(in srgb, var(--warning) 22%, white);
	border-color: color-mix(in srgb, var(--warning) 70%, var(--border-secondary));
	color: #92400e;
}

[data-theme="light"] .med-detail-footer button.icon-stock-correction:hover {
	background: color-mix(in srgb, var(--warning) 32%, white);
	border-color: color-mix(in srgb, var(--warning) 82%, var(--border-secondary));
}

/* Clickable avatar wrapper */
.med-detail-avatar-wrapper {
	position: relative;
	display: inline-block;
}

.med-detail-avatar-wrapper.clickable {
	cursor: pointer;
}

.med-detail-avatar-wrapper.clickable:hover .med-avatar-lg {
	transform: scale(1.05);
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.med-detail-avatar-wrapper .expand-icon {
	position: absolute;
	bottom: -4px;
	right: -4px;
	background: rgba(0, 0, 0, 0.6);
	color: white;
	font-size: 0.9rem;
	width: 1.5rem;
	height: 1.5rem;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 0.2s;
}

.med-detail-avatar-wrapper.clickable:hover .expand-icon {
	opacity: 1;
}

/* Image Lightbox */
.lightbox-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.9);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2000;
	padding: 2rem;
	animation: fadeIn 0.2s ease;
}

.lightbox-container {
	position: relative;
	display: inline-flex;
}

.lightbox-close {
	position: absolute;
	top: -0.5rem;
	right: -0.5rem;
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: white;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--btn-radius-round);
	transition: background 150ms ease;
	box-shadow: none;
	padding: 0;
	z-index: 1;
}

.lightbox-close:hover {
	background: rgba(255, 255, 255, 0.35);
}

.lightbox-image {
	max-width: 50vw;
	max-height: 50vh;
	object-fit: contain;
	border-radius: 12px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
	animation: zoomIn 0.3s ease;
}

/* Mobile: larger lightbox image */
@media (max-width: 768px) {
	.lightbox-image {
		max-width: 90vw;
		max-height: 70vh;
	}
}

@keyframes zoomIn {
	from {
		opacity: 0;
		transform: scale(0.8);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

/* Clickable rows */
.table-row.clickable {
	cursor: pointer;
	transition: background 0.15s;
}

.table-row.clickable:hover {
	background: var(--bg-secondary);
}

/* Mobile adjustments for modal */
@media (max-width: 500px) {
	.med-detail-overlay {
		padding: 0.4rem;
		align-items: stretch;
	}

	.modal-content {
		max-height: 85vh;
		border-radius: 12px 12px 0 0;
		margin-top: auto;
	}

	.modal-content.med-detail-modal {
		width: calc(100vw - 0.8rem);
		max-width: none;
		max-height: calc(100dvh - 0.8rem);
		border-radius: 12px;
		margin: auto;
	}

	.med-detail-header {
		padding: 1.5rem 1.5rem 1rem;
	}

	.med-detail-header .med-avatar-lg {
		width: 80px;
		height: 80px;
		font-size: 2rem;
	}

	.med-detail-body {
		padding: 1rem 1.5rem 0;
	}

	.med-detail-footer {
		padding: 1rem 1.5rem;
		padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
		flex-direction: column;
		align-items: center;
		justify-content: center;
		flex-wrap: wrap;
		gap: 0.75rem;
		margin: 0;
	}

	.med-detail-footer > button {
		flex: 0 0 auto;
		width: min(100%, 560px);
	}

	.med-detail-footer .footer-actions {
		flex: 0 0 auto;
		width: 100%;
		justify-content: center;
		margin-left: 0;
	}

	.med-detail-footer button {
		padding: 0.6rem 0.8rem;
		font-size: 0.9rem;
	}

	.med-detail-grid {
		gap: 0.5rem;
	}
}

/* Hard mobile override for MedDetailModal: remove side frame and use full handset viewport. */
@media (max-width: 500px) {
	.modal-overlay.med-detail-overlay {
		padding: 0 !important;
		align-items: stretch;
	}

	.modal-overlay.med-detail-overlay > .modal-content.med-detail-modal {
		width: 100vw !important;
		max-width: 100vw !important;
		max-height: 100dvh !important;
		height: 100dvh;
		margin: 0 !important;
		border-radius: 0 !important;
		border-left: none;
		border-right: none;
	}

	.modal-overlay.med-detail-overlay .med-detail-header {
		padding-left: 1rem;
		padding-right: 1rem;
	}

	.modal-overlay.med-detail-overlay .med-detail-body {
		padding-left: 1rem;
		padding-right: 1rem;
	}

	.modal-overlay.med-detail-overlay .med-detail-footer {
		margin: 0;
		padding-left: 1rem;
		padding-right: 1rem;
		position: relative;
		z-index: 1;
	}
}

/* Reminder icon indicator */
.reminder-icon.info-tooltip,
.notes-icon.info-tooltip,
.prescription-icon.info-tooltip {
	width: auto;
	height: auto;
	margin: 0 !important;
	padding: 0 !important;
	font-size: 1em;
	opacity: 0.9;
	color: var(--info);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	vertical-align: baseline;
}

.prescription-icon.info-tooltip {
	color: var(--success);
}

.reminder-icon.info-tooltip,
.blister-reminder-icon {
	color: var(--warning);
}

[data-theme="light"] .reminder-icon.info-tooltip,
[data-theme="light"] .blister-reminder-icon {
	color: #b45309; /* dark amber — ~4.5:1 on light backgrounds */
}

[data-theme="light"] .notes-icon.info-tooltip {
	color: #1d4ed8; /* darker blue — strong contrast on light backgrounds */
}

[data-theme="light"] .prescription-icon.info-tooltip {
	color: #047857; /* dark emerald — strong contrast on light backgrounds */
}

.reminder-icon.info-tooltip:hover,
.notes-icon.info-tooltip:hover,
.prescription-icon.info-tooltip:hover {
	opacity: 1;
}

h3 .reminder-icon.info-tooltip {
	font-size: 0.75em;
	vertical-align: middle;
}

h3 .notes-icon.info-tooltip {
	font-size: 0.8em;
	vertical-align: middle;
}

h3 .notes-icon.notes-icon-static {
	font-size: 0.8em;
	vertical-align: middle;
	color: var(--info);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

[data-theme="light"] h3 .notes-icon.notes-icon-static {
	color: #1d4ed8;
}
