/* ============================================================================
 * PMD Modal System — Purple Moon Systems
 * Tokens fall back to the Purple Moon Systems defaults in style.css / style-guide.php.
 * Override any token on :root to retheme for a different project.
 * ============================================================================ */

:root {
	/* Surfaces */
	--pmd-modal-bg:        var(--bg,  #ffffff);
	--pmd-modal-surface:   var(--s1,  #F4F6FA);          /* canvas */
	--pmd-modal-surface-2: var(--s2,  #EEF3FB);

	/* Text */
	--pmd-modal-text:      var(--t,   #101A2B);          /* ink */
	--pmd-modal-text-mute: var(--tm,  #38475F);          /* ink-700 */
	--pmd-modal-text-dim:  var(--td,  #64748B);          /* ink-500 */
	--pmd-modal-text-ph:   var(--td2, #94A3B8);          /* ink-300 */

	/* Borders */
	--pmd-modal-border:    var(--bd,  #E2E7F0);          /* line */

	/* Brand */
	--pmd-modal-accent:    var(--ac,  #17458F);          /* royal */
	--pmd-modal-accent-h:  var(--ach, #123770);          /* royal-700 */
	--pmd-modal-accent-bg: var(--acbg,#EEF3FB);
	--pmd-modal-focus:     var(--azure, var(--ac2, #0067C8));

	/* Status */
	--pmd-modal-success:   var(--gn,  #047857);
	--pmd-modal-warning:   var(--am,  #B77C08);
	--pmd-modal-danger:    var(--rd,  #D41367);
	--pmd-modal-info:      var(--bl,  #0067C8);

	--pmd-modal-success-bg: #ecfdf5;
	--pmd-modal-warning-bg: #FEF7E8;
	--pmd-modal-danger-bg:  #FDEAF2;
	--pmd-modal-info-bg:    #EEF3FB;

	/* Radius */
	--pmd-modal-radius:    var(--rm, 16px);              /* panels / modal */
	--pmd-modal-radius-sm: var(--r,  8px);               /* controls */

	/* Typography — Open Sans throughout */
	--pmd-modal-font:      var(--font-body, 'Open Sans', system-ui, sans-serif);
	--pmd-modal-font-h:    var(--font-heading, 'Open Sans', system-ui, sans-serif);

	--pmd-modal-ease:      var(--ease, cubic-bezier(0.23, 1, 0.32, 1));
	--pmd-modal-shadow:    var(--shadow-md, 0 2px 4px rgba(16,26,43,.04), 0 18px 40px -24px rgba(16,26,43,.35));
	--pmd-modal-z: 9999;
}

/* ── Backdrop ───────────────────────────────────────────────────────────── */
.pmd-modal-back {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(16, 26, 43, .5);        /* ink/50 */
	z-index: var(--pmd-modal-z);
	align-items: flex-start;
	justify-content: center;
	padding: 16px;
	overflow-y: auto;
}
@media (min-width: 640px) {
	.pmd-modal-back { align-items: center; }
}
.pmd-modal-back.is-open {
	display: flex;
	animation: pmd-modal-fade-in .15s var(--pmd-modal-ease);
}
@keyframes pmd-modal-fade-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}

/* ── Modal box ──────────────────────────────────────────────────────────── */
.pmd-modal {
	position: relative;
	z-index: 1;
	background: var(--pmd-modal-bg);
	color: var(--pmd-modal-text);
	border-radius: var(--pmd-modal-radius);
	padding: 0;
	max-width: 36rem;                        /* max-w-xl */
	width: 100%;
	max-height: 90vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow: var(--pmd-modal-shadow);
	font-family: var(--pmd-modal-font);
	font-size: 14px;
	animation: pmd-modal-pop-in .2s var(--pmd-modal-ease);
}
.pmd-modal--sm { max-width: 28rem; }
.pmd-modal--md { max-width: 36rem; }
.pmd-modal--lg { max-width: 48rem; }
.pmd-modal--xl { max-width: 60rem; }

.pmd-modal__accent {
	display: block;
	height: 4px;
	width: 100%;
	background: var(--pmd-modal-accent);
	flex-shrink: 0;
}
.pmd-modal--accent-cranberry .pmd-modal__accent { background: var(--cranberry, #D41367); }
.pmd-modal--accent-turquoise .pmd-modal__accent { background: var(--turquoise, #00A7A0); }
.pmd-modal--accent-gold .pmd-modal__accent { background: var(--gold, #F7A81B); }

@keyframes pmd-modal-pop-in {
	from { opacity: 0; transform: translateY(12px) scale(.98); }
	to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.pmd-modal__head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 16px;
	margin: 0;
	padding: 16px 20px;
	border-bottom: 1px solid var(--pmd-modal-border);
	flex-shrink: 0;
}
.pmd-modal__head-text { flex: 1; min-width: 0; }

.pmd-modal__title {
	font-family: var(--pmd-modal-font-h);
	font-size: 16px;
	font-weight: 700;
	color: var(--pmd-modal-text);
	margin: 0;
	line-height: 1.3;
}
.pmd-modal__sub {
	font-size: 14px;
	color: var(--pmd-modal-text-dim);
	margin: 2px 0 0;
	line-height: 1.5;
}

.pmd-modal__close {
	background: transparent;
	border: 0;
	color: var(--pmd-modal-text-dim);
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	padding: 6px;
	border-radius: var(--pmd-modal-radius-sm);
	flex-shrink: 0;
	transition: background .15s, color .15s;
}
.pmd-modal__close:hover {
	background: var(--pmd-modal-surface);
	color: var(--pmd-modal-text);
}

.pmd-modal__body {
	padding: 16px 20px;
	overflow-y: auto;
	max-height: 65vh;
}
.pmd-modal > form {
	display: flex;
	flex-direction: column;
	min-height: 0;
	flex: 1;
	padding: 16px 20px 0;
	overflow-y: auto;
	max-height: 65vh;
}
.pmd-modal > form > .pmd-modal__actions {
	margin: 16px -20px 0;
}
.pmd-modal > .pmd-modal__group,
.pmd-modal > .pmd-modal__row,
.pmd-modal > .pmd-modal__error {
	margin-left: 20px;
	margin-right: 20px;
}
.pmd-modal > .pmd-modal__group:first-of-type,
.pmd-modal > .pmd-modal__row:first-of-type {
	margin-top: 16px;
}

/* ── Form fields — floating label (style guide) ─────────────────────────── */
.pmd-modal__group { margin-bottom: 16px; }
.pmd-modal__body .pmd-modal__group:last-child { margin-bottom: 0; }

.pmd-modal__row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 16px;
	margin-bottom: 16px;
	align-items: start;
}
.pmd-modal__row .pmd-modal__group,
.pmd-modal__row .pmd-modal__select,
.pmd-modal__row .pmd-modal__wrap,
.pmd-modal__row .pmd-modal__input { width: 100%; }
.pmd-modal__row .pmd-modal__group { margin-bottom: 0; }
.pmd-modal__row--3 { grid-template-columns: repeat(3, 1fr); }

.pmd-modal__wrap { position: relative; display: block; }

.pmd-modal__label {
	position: absolute;
	left: 12px;
	top: 6px;
	z-index: 1;
	pointer-events: none;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--pmd-modal-text-dim);
	transition: top .15s ease-out, font-size .15s ease-out, color .15s ease-out;
}
.pmd-modal__label--required::after {
	content: ' *';
	color: var(--pmd-modal-danger);
}

.pmd-modal__input,
.pmd-modal__textarea {
	width: 100%;
	min-height: 48px;
	padding: 20px 12px 6px;
	border: 1px solid var(--pmd-modal-border);
	border-radius: var(--pmd-modal-radius-sm);
	background: var(--pmd-modal-bg);
	color: var(--pmd-modal-text);
	font-family: var(--pmd-modal-font);
	font-size: 14px;
	box-sizing: border-box;
	transition: border-color .15s var(--pmd-modal-ease);
}
.pmd-modal__input::placeholder,
.pmd-modal__textarea::placeholder { color: transparent; }
.pmd-modal__input:focus::placeholder,
.pmd-modal__textarea:focus::placeholder { color: var(--pmd-modal-text-ph); }
.pmd-modal__input:focus,
.pmd-modal__textarea:focus,
.pmd-modal__select:focus {
	outline: none;
	border-color: var(--pmd-modal-focus);
}
.pmd-modal__input:placeholder-shown:not(:focus) + .pmd-modal__label,
.pmd-modal__textarea:placeholder-shown:not(:focus) + .pmd-modal__label {
	top: 13px;
	font-size: 14px;
	font-weight: 400;
	letter-spacing: normal;
	text-transform: none;
	color: var(--pmd-modal-text-ph);
}
.pmd-modal__input:focus + .pmd-modal__label,
.pmd-modal__textarea:focus + .pmd-modal__label,
.pmd-modal__group--raised .pmd-modal__label {
	top: 6px;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
}
.pmd-modal__input:focus + .pmd-modal__label,
.pmd-modal__textarea:focus + .pmd-modal__label { color: var(--pmd-modal-accent-h); }

.pmd-modal .screen-reader-text,
.pmd-modal__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
.pmd-modal__group--select { position: relative; width: 100%; }
.pmd-modal__select {
	display: block;
	width: 100%;
	height: 48px;
	min-height: 48px;
	padding: 0 36px 0 12px;
	border: 1px solid var(--pmd-modal-border);
	border-radius: var(--pmd-modal-radius-sm);
	background-color: var(--pmd-modal-bg);
	color: var(--pmd-modal-text);
	font-family: var(--pmd-modal-font);
	font-size: 14px;
	line-height: 48px;
	box-sizing: border-box;
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
	transition: border-color .15s var(--pmd-modal-ease);
}
.pmd-modal__textarea {
	resize: vertical;
	min-height: 88px;
}
.pmd-modal__hint {
	font-size: 12px;
	color: var(--pmd-modal-text-dim);
	margin: 4px 4px 0;
	display: block;
}

/* Date / time — entire input area opens the picker, not just the icon */
.pmd-modal__input[type="date"],
.pmd-modal__input[type="datetime-local"],
.pmd-modal__input[type="time"] {
	cursor: pointer;
	position: relative;                      /* anchor for the indicator overlay */
}
/* Webkit: stretch the invisible calendar indicator across the full input */
.pmd-modal__input[type="date"]::-webkit-calendar-picker-indicator,
.pmd-modal__input[type="datetime-local"]::-webkit-calendar-picker-indicator,
.pmd-modal__input[type="time"]::-webkit-calendar-picker-indicator {
	position: absolute;
	inset: 0;
	width: auto;
	height: auto;
	margin: 0;
	padding: 0;
	background: transparent;
	opacity: 0;
	cursor: pointer;
}

.pmd-modal__checkbox-row {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: .9375rem;
	color: var(--pmd-modal-text);
	cursor: pointer;
}
.pmd-modal__checkbox-row input[type="checkbox"] {
	margin: 0;
	accent-color: var(--pmd-modal-accent);   /* accent checkmark */
}

/* ── Error zone ─────────────────────────────────────────────────────────── */
.pmd-modal__error {
	color: var(--pmd-modal-danger);
	font-size: .875rem;
	margin: 10px 0 0;
	padding: 10px 14px;
	background: var(--pmd-modal-danger-bg);
	border: 1px solid rgba(185, 28, 28, .2);
	border-radius: var(--pmd-modal-radius-sm); /* rounded-xl */
	display: none;
}
.pmd-modal__error.is-visible { display: block; }

/* ── Actions row ────────────────────────────────────────────────────────── */
.pmd-modal__actions {
	display: flex;
	justify-content: flex-end;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 12px 20px;
	border-top: 1px solid var(--pmd-modal-border);
	background: var(--pmd-modal-surface);
	align-items: center;
	flex-shrink: 0;
}
.pmd-modal__actions--between { justify-content: space-between; }
.pmd-modal__actions--start   { justify-content: flex-start; }

/* ── Buttons — match style guide exactly ────────────────────────────────── */
.pmd-modal__btn {
	padding: 8px 16px;
	border: 1px solid transparent;
	border-radius: var(--pmd-modal-radius-sm);
	font-family: var(--pmd-modal-font);
	font-weight: 600;
	font-size: 14px;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 40px;
	transition: background .15s, border-color .15s, color .15s, opacity .15s;
	line-height: 1;
	text-decoration: none;
	box-sizing: border-box;
}
.pmd-modal__btn:disabled { opacity: .4; cursor: not-allowed; }

button.pmd-modal__btn.pmd-modal__btn--primary,
.pmd-modal__btn.pmd-modal__btn--primary {
	background-color: var(--pmd-modal-accent);
	background-image: none;
	color: #ffffff;
	border-color: var(--pmd-modal-accent);
}
button.pmd-modal__btn.pmd-modal__btn--primary:hover:not(:disabled),
.pmd-modal__btn.pmd-modal__btn--primary:hover:not(:disabled) {
	background-color: var(--pmd-modal-accent-h);
	border-color: var(--pmd-modal-accent-h);
	color: #ffffff;
}

.pmd-modal__btn--secondary {
	background: #ffffff;
	color: var(--pmd-modal-text-mute);
	border-color: var(--pmd-modal-border);
}
.pmd-modal__btn--secondary:hover:not(:disabled) {
	background: var(--pmd-modal-surface);
	color: var(--pmd-modal-text);
}

.pmd-modal__btn--danger {
	background: var(--pmd-modal-danger-bg);
	color: var(--pmd-modal-danger);
	border-color: transparent;
}
.pmd-modal__btn--danger:hover:not(:disabled) {
	background: var(--pmd-modal-danger);
	border-color: var(--pmd-modal-danger);
	color: #ffffff;
}

/* Ghost — text-gray-600 hover:bg-gray-100 */
.pmd-modal__btn--ghost {
	background: transparent;
	color: var(--pmd-modal-text-mute);
	border-color: transparent;
}
.pmd-modal__btn--ghost:hover:not(:disabled) {
	background: var(--pmd-modal-surface-2);  /* gray-100 */
	color: var(--pmd-modal-text);
}

/* Ghost danger — text-red-600 hover:bg-red-50 */
.pmd-modal__btn--ghost-danger {
	background: transparent;
	color: var(--pmd-modal-danger);
	border-color: transparent;
}
.pmd-modal__btn--ghost-danger:hover:not(:disabled) {
	background: rgba(185, 28, 28, .06);
}

/* Loading spinner */
.pmd-modal__btn-loading::after {
	content: '';
	width: 13px;
	height: 13px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: pmd-modal-spin .75s linear infinite;
	margin-left: 6px;
}
@keyframes pmd-modal-spin {
	to { transform: rotate(360deg); }
}

/* ── Body scroll lock ───────────────────────────────────────────────────── */
body.pmd-modal-locked { overflow: hidden; }

/* ── Toasts ─────────────────────────────────────────────────────────────── */
.pmd-toasts {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: calc(var(--pmd-modal-z) + 10);
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-width: min(380px, calc(100vw - 48px));
	pointer-events: none;
}

/* Toast card — matches style guide card: bg-white rounded-xl border border-gray-100 */
.pmd-toast {
	background: #ffffff;
	color: var(--pmd-modal-text);            /* gray-900 */
	border: 1px solid var(--pmd-modal-surface-2); /* gray-100 */
	border-left: 4px solid var(--pmd-modal-info);
	border-radius: var(--pmd-modal-radius-sm); /* rounded-xl */
	padding: 12px 16px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, .10), 0 1px 4px rgba(0, 0, 0, .06);
	font-family: var(--pmd-modal-font);      /* Inter */
	font-size: .9375rem;
	line-height: 1.5;
	pointer-events: auto;
	display: flex;
	align-items: flex-start;
	gap: 10px;
	animation: pmd-toast-in .25s cubic-bezier(.2, .9, .25, 1.05);
}

/* Status left-border colors — matches style guide status palette */
.pmd-toast--success { border-left-color: var(--pmd-modal-success); } /* green-700 */
.pmd-toast--error   { border-left-color: var(--pmd-modal-danger);  } /* red-700 */
.pmd-toast--warning { border-left-color: var(--pmd-modal-warning); } /* amber-700 */
.pmd-toast--info    { border-left-color: var(--pmd-modal-info);    } /* blue-700 */

.pmd-toast.is-leaving { animation: pmd-toast-out .2s ease forwards; }

.pmd-toast__msg  { flex: 1; min-width: 0; }
.pmd-toast__close {
	background: transparent;
	border: 0;
	color: var(--pmd-modal-text-dim);        /* gray-400 */
	cursor: pointer;
	font-size: 1rem;
	line-height: 1;
	padding: 2px 4px;
	flex-shrink: 0;
	border-radius: 4px;
	transition: color .15s;
}
.pmd-toast__close:hover { color: var(--pmd-modal-text); }

@keyframes pmd-toast-in {
	from { opacity: 0; transform: translateX(16px); }
	to   { opacity: 1; transform: translateX(0); }
}
@keyframes pmd-toast-out {
	to { opacity: 0; transform: translateX(16px); }
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media screen and (max-width: 640px) {
	.pmd-modal-back  { padding: 12px; align-items: flex-end; }
	.pmd-modal       { max-width: 100%; max-height: 95vh; border-radius: var(--pmd-modal-radius) var(--pmd-modal-radius) 0 0; }
	.pmd-modal__row  { grid-template-columns: 1fr; gap: 0; }
	.pmd-modal__row .pmd-modal__group { margin-bottom: 16px; }
	.pmd-toasts      { bottom: 12px; right: 12px; left: 12px; max-width: none; }
}
