/* =============================================================================
   Refill Modal & History
   ============================================================================= */
.refill-modal {
	max-width: 500px;
	padding: 1.5rem;
}

.refill-modal h2 {
	font-size: 1.25rem;
	margin-bottom: 0.25rem;
}

.refill-med-name {
	color: var(--text-secondary);
	margin-bottom: 1.5rem;
}

.refill-form {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	margin-bottom: 1.5rem;
}

.refill-form label {
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
	font-weight: 500;
}

.refill-form input {
	padding: 0.75rem;
	border: 1px solid var(--border-primary);
	border-radius: 8px;
	background: var(--bg-input);
	color: var(--text-primary);
	font-size: 1rem;
}

.refill-footer-right {
	display: flex;
	align-items: center;
	gap: 1rem;
}

.refill-footer-right .refill-preview {
	height: 42px;
}

/* Refill modal footer mobile */
@media (max-width: 640px) {
	.refill-modal .modal-footer {
		flex-direction: column;
		gap: 0.75rem;
	}

	.refill-modal .modal-footer > button,
	.refill-modal .modal-footer .refill-footer-right {
		width: 100%;
	}

	.refill-modal .modal-footer .refill-footer-right {
		justify-content: space-between;
	}

	.refill-modal .modal-footer .refill-footer-right button {
		flex: 1;
	}
}

/* Refill: submit row (button + pill preview) */
.refill-submit-row {
	display: flex;
	align-items: center;
	gap: 1rem;
}

.refill-submit-row button {
	height: 42px;
	padding: 0 2rem;
	min-width: 120px;
	flex-shrink: 0;
}

/* Refill: prescription toggle row */
.refill-prescription-row {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding-top: 0.25rem;
	border-top: 1px solid var(--border-primary);
}

.refill-prescription-row .refill-prescription-toggle {
	display: grid;
	grid-template-columns: 18px minmax(0, 1fr);
	align-items: start;
	gap: 0.6rem;
	margin: 0;
	text-transform: none;
	letter-spacing: normal;
	line-height: 1.2;
	font-size: 0.95rem;
	color: var(--text-primary);
	cursor: pointer;
	white-space: normal;
	width: 100%;
}

.refill-prescription-row .refill-prescription-toggle input {
	width: 18px;
	height: 18px;
	min-width: 18px;
	margin: 0;
	flex-shrink: 0;
}

.refill-prescription-label-text {
	min-width: 0;
	overflow-wrap: anywhere;
}

.refill-prescription-row .refill-prescription-toggle input:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.refill-remaining-badge {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--success);
	margin-left: auto;
}

.refill-preview {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 42px;
	padding: 0 0.75rem;
	background: transparent;
	border: 1px dashed var(--success);
	border-radius: 6px;
	color: var(--success);
	font-size: 0.85rem;
	font-weight: 600;
	flex-shrink: 0;
	align-self: flex-end;
	box-sizing: border-box;
}

.refill-section {
	margin-top: 0;
}

.refill-section .refill-title {
	font-size: 1rem;
	font-weight: 600;
	color: var(--text-primary);
	margin: 0 0 0.75rem 0;
}

.refill-section .refill-submit-row button {
	background: var(--success);
	color: white;
	border: none;
}

.refill-section .refill-submit-row button:hover:not(:disabled) {
	background: var(--success-hover, #3aa865);
	filter: brightness(1.1);
}

.refill-section .refill-submit-row button:disabled {
	background: var(--bg-tertiary);
	color: var(--text-tertiary);
	cursor: not-allowed;
}

.refill-unavailable {
	grid-column: 1 / -1;
	margin: 0;
	padding: 0.6rem 0.75rem;
	border-radius: 8px;
	border: 1px dashed var(--border-secondary);
	color: var(--text-secondary);
	font-size: 0.88rem;
}

/* =============================================================================
   Edit Stock Modal (Correction)
   ============================================================================= */
.edit-stock-modal {
	max-width: 500px;
	padding: 1.5rem;
}

.edit-stock-modal h2 {
	font-size: 1.25rem;
	margin-bottom: 0.25rem;
}

.edit-stock-med-name {
	color: var(--text-secondary);
	margin-bottom: 0.5rem;
}

.edit-stock-hint {
	font-size: 0.85rem;
	color: var(--warning);
	background: var(--warning-bg);
	padding: 0.75rem 1rem;
	border-radius: 8px;
	margin-bottom: 1.5rem;
	border: 1px solid rgba(252, 211, 77, 0.2);
}

.edit-stock-cap-info {
	margin: 0 0 0.75rem;
	font-size: 0.85rem;
	color: var(--text-secondary);
}

.edit-stock-live-breakdown {
	color: var(--text-primary);
	background: var(--bg-tertiary);
	border: 1px solid var(--border-primary);
	border-radius: 8px;
	padding: 0.6rem 0.75rem;
}

.edit-stock-cap-warning {
	margin: -0.25rem 0 1rem;
	font-size: 0.85rem;
	color: var(--warning);
	background: var(--warning-bg);
	border: 1px solid rgba(252, 211, 77, 0.25);
	border-radius: 8px;
	padding: 0.5rem 0.75rem;
}

.edit-stock-form {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	margin-bottom: 1.5rem;
}

.edit-stock-form label {
	display: flex;
	flex-direction: column;
	gap: 0;
	font-weight: 500;
}

.edit-stock-form label .hint-text {
	font-weight: 400;
	color: var(--text-secondary);
	font-size: 0.85rem;
}

.edit-stock-form input {
	padding: 0.75rem;
	border: 1px solid var(--border-primary);
	border-radius: 8px;
	background: var(--bg-input);
	color: var(--text-primary);
	font-size: 1rem;
}

.edit-stock-form input[type="number"]::-webkit-outer-spin-button,
.edit-stock-form input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.edit-stock-form input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

.number-stepper {
	display: grid;
	grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
	align-items: stretch;
	border: 1px solid var(--border-primary);
	border-radius: 12px;
	overflow: hidden;
	background: var(--bg-input);
}

.number-stepper input {
	margin: 0;
	border: none;
	border-radius: 0;
	text-align: center;
	font-size: 1.1rem;
	font-weight: 600;
	padding: 0.75rem 0.5rem;
	min-height: 2.75rem;
	background: transparent;
}

.number-stepper input[type="number"]::-webkit-outer-spin-button,
.number-stepper input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.number-stepper input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

.number-stepper input:focus {
	outline: none;
	box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}

.stepper-btn {
	border: none;
	border-right: 1px solid var(--border-primary);
	background: color-mix(in srgb, var(--bg-tertiary) 85%, transparent);
	color: var(--text-secondary);
	min-width: 2.75rem;
	min-height: 2.75rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition:
		background 0.15s ease,
		color 0.15s ease,
		opacity 0.15s ease;
}

.stepper-btn svg {
	width: 1.15rem;
	height: 1.15rem;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	flex-shrink: 0;
}

.stepper-btn.increment {
	border-right: none;
	border-left: 1px solid var(--border-primary);
	color: var(--success);
}

.stepper-btn.decrement {
	color: var(--danger);
}

.stepper-btn:hover:not(:disabled) {
	background: color-mix(in srgb, var(--accent) 14%, var(--bg-tertiary));
}

.stepper-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

[data-theme="light"] .stepper-btn.increment {
	color: #0f766e;
}

[data-theme="light"] .stepper-btn.decrement {
	color: #b91c1c;
}

@media (max-width: 640px) {
	.number-stepper {
		grid-template-columns: 3rem minmax(0, 1fr) 3rem;
	}

	.number-stepper input {
		font-size: 1.2rem;
		min-height: 3rem;
	}

	.stepper-btn {
		min-width: 3rem;
		min-height: 3rem;
	}
}

@media (min-width: 641px) {
	.number-stepper {
		display: flex;
		align-items: stretch;
	}

	.number-stepper input {
		order: 1;
		flex: 1 1 auto;
		min-width: 0;
		text-align: left;
		padding-left: 0.9rem;
	}

	.number-stepper .stepper-btn {
		flex: 0 0 2.9rem;
		min-width: 2.9rem;
		border-right: none;
		border-left: 1px solid var(--border-primary);
		color: var(--text-primary);
	}

	.number-stepper .stepper-btn.decrement {
		order: 2;
		background: color-mix(in srgb, var(--danger) 74%, var(--bg-secondary));
		color: #fff;
	}

	.number-stepper .stepper-btn.increment {
		order: 3;
		background: color-mix(in srgb, var(--success) 72%, var(--bg-secondary));
		color: #fff;
	}

	.number-stepper .stepper-btn:hover:not(:disabled) {
		filter: brightness(1.08);
	}

	.number-stepper .stepper-btn:disabled {
		opacity: 0.55;
	}

	[data-theme="light"] .number-stepper .stepper-btn.decrement {
		background: #dc2626;
	}

	[data-theme="light"] .number-stepper .stepper-btn.increment {
		background: #0f766e;
	}
}

/* Keep refill modal stepper on legacy visual style (before desktop clustered correction style). */
.refill-number-stepper {
	display: grid;
	grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
}

.refill-number-stepper input {
	order: 0;
	text-align: center;
	padding: 0.75rem 0.5rem;
}

.refill-number-stepper .stepper-btn {
	flex: 0 0 auto;
	border-right: 1px solid var(--border-primary);
	border-left: none;
	background: color-mix(in srgb, var(--bg-tertiary) 85%, transparent);
	color: var(--text-secondary);
}

.refill-number-stepper .stepper-btn.decrement {
	order: -1;
	background: color-mix(in srgb, var(--danger) 22%, var(--bg-tertiary));
	color: var(--danger);
}

.refill-number-stepper .stepper-btn.increment {
	order: 1;
	border-right: none;
	border-left: 1px solid var(--border-primary);
	background: color-mix(in srgb, var(--success) 22%, var(--bg-tertiary));
	color: var(--success);
}

.refill-number-stepper .stepper-btn:hover:not(:disabled) {
	filter: none;
}

.refill-number-stepper .stepper-btn.decrement:hover:not(:disabled) {
	background: color-mix(in srgb, var(--danger) 36%, var(--bg-tertiary));
}

.refill-number-stepper .stepper-btn.increment:hover:not(:disabled) {
	background: color-mix(in srgb, var(--success) 36%, var(--bg-tertiary));
}

@media (min-width: 641px) {
	.refill-number-stepper {
		display: grid;
		grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
	}

	.refill-number-stepper input {
		padding-left: 0.5rem;
	}

	[data-theme="light"] .refill-number-stepper .stepper-btn.decrement {
		background: color-mix(in srgb, #dc2626 18%, white);
		color: #b91c1c;
	}

	[data-theme="light"] .refill-number-stepper .stepper-btn.increment {
		background: color-mix(in srgb, #0f766e 18%, white);
		color: #0f766e;
	}
}

@media (max-width: 640px) {
	.refill-number-stepper {
		grid-template-columns: 3rem minmax(0, 1fr) 3rem;
	}
}

/* Form stepper keeps symmetric - value + layout in all contexts (desktop/mobile). */
.form-number-stepper {
	display: grid;
	grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
}

.form-number-stepper input {
	order: 0;
	text-align: center;
	padding: 0.75rem 0.5rem;
	min-width: 0;
	width: 100%;
	color: var(--text-primary);
}

.form-number-stepper .stepper-btn {
	flex: 0 0 auto;
	border-right: 1px solid var(--border-primary);
	border-left: none;
	background: color-mix(in srgb, var(--bg-tertiary) 85%, transparent);
	color: var(--text-secondary);
}

.form-number-stepper .stepper-btn.decrement {
	order: -1;
	background: color-mix(in srgb, var(--danger) 22%, var(--bg-tertiary));
	color: var(--danger);
}

.form-number-stepper .stepper-btn.increment {
	order: 1;
	border-right: none;
	border-left: 1px solid var(--border-primary);
	background: color-mix(in srgb, var(--success) 22%, var(--bg-tertiary));
	color: var(--success);
}

.form-number-stepper .stepper-btn:hover:not(:disabled) {
	filter: none;
}

.form-number-stepper .stepper-btn.decrement:hover:not(:disabled) {
	background: color-mix(in srgb, var(--danger) 36%, var(--bg-tertiary));
}

.form-number-stepper .stepper-btn.increment:hover:not(:disabled) {
	background: color-mix(in srgb, var(--success) 36%, var(--bg-tertiary));
}

/* Highlight both controls when the center value field is focused (keyboard/click). */
.form-number-stepper:has(input:focus) .stepper-btn.decrement:not(:disabled),
.form-number-stepper:has(input:focus-visible) .stepper-btn.decrement:not(:disabled) {
	background: color-mix(in srgb, var(--danger) 36%, var(--bg-tertiary));
}

.form-number-stepper:has(input:focus) .stepper-btn.increment:not(:disabled),
.form-number-stepper:has(input:focus-visible) .stepper-btn.increment:not(:disabled) {
	background: color-mix(in srgb, var(--success) 36%, var(--bg-tertiary));
}

/* Dense schedule grids need a compact variant so the middle value stays visible. */
.blister-inputs .form-number-stepper,
.mobile-edit-form .blister-row .form-number-stepper {
	grid-template-columns: 2.35rem minmax(2rem, 1fr) 2.35rem;
}

.blister-inputs .form-number-stepper input,
.mobile-edit-form .blister-row .form-number-stepper input {
	min-height: 2.35rem;
	padding: 0.5rem 0.35rem;
}

.blister-inputs .form-number-stepper .stepper-btn,
.mobile-edit-form .blister-row .form-number-stepper .stepper-btn {
	min-width: 2.35rem;
	min-height: 2.35rem;
}

@media (min-width: 641px) {
	.form-number-stepper {
		display: grid;
		grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
	}

	.form-number-stepper input {
		padding-left: 0.5rem;
	}

	[data-theme="light"] .form-number-stepper .stepper-btn.decrement {
		background: color-mix(in srgb, #dc2626 18%, white);
		color: #b91c1c;
	}

	[data-theme="light"] .form-number-stepper .stepper-btn.increment {
		background: color-mix(in srgb, #0f766e 18%, white);
		color: #0f766e;
	}
}

@media (max-width: 640px) {
	.form-number-stepper {
		grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
	}
}

.edit-stock-summary {
	display: flex;
	gap: 0.5rem;
	margin-bottom: 1.5rem;
}

.edit-stock-summary .summary-row {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.25rem;
	background: var(--bg-tertiary);
	border-radius: 10px;
	padding: 0.75rem 0.5rem;
}

.edit-stock-summary .summary-row span:first-child {
	font-size: 0.72rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-secondary);
}

.edit-stock-summary .summary-row span:last-child {
	font-size: 1rem;
	font-weight: 700;
	color: var(--text-primary);
}

.edit-stock-summary .summary-row.difference {
	background: transparent;
	border: 1.5px solid var(--border-primary);
}

.edit-stock-summary .summary-row.difference.positive span:last-child {
	color: var(--success);
}

.edit-stock-summary .summary-row.difference.negative span:last-child {
	color: var(--danger);
}

/* Clickable section header (for expand/collapse) */
.section-header-clickable {
	cursor: pointer;
	user-select: none;
}

.section-header-clickable:hover {
	color: var(--accent);
}

/* Refill history in detail modal */
.refill-history-header {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	cursor: pointer;
	user-select: none;
}

.refill-history-header .collapse-icon {
	font-size: 0.75rem;
	color: var(--text-secondary);
}

.refill-history-header .refill-count {
	font-weight: normal;
	font-size: 0.875rem;
	color: var(--text-secondary);
}

.refill-history-list {
	margin-top: 0.75rem;
}

.refill-history-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0.5rem 0;
	border-bottom: 1px solid var(--border-primary);
}

.refill-history-item:last-child {
	border-bottom: none;
}

.refill-date {
	font-size: 0.875rem;
	color: var(--text-secondary);
}

.refill-details {
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--success);
}

/* Nested modal overlay */
.modal-overlay.nested {
	background: rgba(0, 0, 0, 0.6);
}

.modal-overlay.nested-confirm {
	z-index: 1200;
}
