/* ============================================================================
 * PMD Modal System — GoOrganic edition
 * Tokens fall back to the GoOrganic design system values from style-guide.php.
 * Override any token on :root to retheme for a different project.
 * ============================================================================ */

:root {
	/* Surfaces */
	--pmd-modal-bg:        var(--bg,  #ffffff);          /* white — card surface */
	--pmd-modal-surface:   var(--s1,  #f9fafb);          /* gray-50 */
	--pmd-modal-surface-2: var(--s2,  #f3f4f6);          /* gray-100 */

	/* Text */
	--pmd-modal-text:      var(--t,   #111827);          /* gray-900 — primary text */
	--pmd-modal-text-mute: var(--tm,  #4b5563);          /* gray-600 — body text */
	--pmd-modal-text-dim:  var(--td,  #9ca3af);          /* gray-400 — muted / icons */

	/* Borders */
	--pmd-modal-border:    var(--bd,  #e5e7eb);          /* gray-200 */

	/* Brand */
	--pmd-modal-accent:    var(--ac,  #2d6a4f);          /* olive */
	--pmd-modal-accent-h:  var(--ach, #245c43);          /* olive — hover */
	--pmd-modal-accent-bg: var(--acbg,rgba(45,106,79,.08)); /* olive/8 — focus ring fill */

	/* Status */
	--pmd-modal-success:   var(--gn,  #15803d);          /* green-700 */
	--pmd-modal-warning:   var(--am,  #b45309);          /* amber-700 */
	--pmd-modal-danger:    var(--rd,  #b91c1c);          /* red-700 */
	--pmd-modal-info:      var(--bl,  #1d4ed8);          /* blue-700 */

	/* Status bg tints (for toasts) */
	--pmd-modal-success-bg: rgba(21, 128, 61, .08);
	--pmd-modal-warning-bg: rgba(180, 83, 9, .08);
	--pmd-modal-danger-bg:  rgba(185, 28, 28, .08);
	--pmd-modal-info-bg:    rgba(29, 78, 216, .08);

	/* Radius — matches style guide scale */
	--pmd-modal-radius:    var(--rm, 16px);              /* rounded-2xl — modal card */
	--pmd-modal-radius-sm: var(--r,  12px);              /* rounded-xl  — inputs, buttons, toasts */

	/* Typography */
	--pmd-modal-font:      var(--f,  'Inter',  system-ui, sans-serif);
	--pmd-modal-font-h:    var(--fd, 'Lexend', system-ui, sans-serif);

	/* Shadow */
	--pmd-modal-shadow:    0 25px 60px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.10);

	/* Z-index */
	--pmd-modal-z: 9999;
}

/* ── Backdrop ───────────────────────────────────────────────────────────── */
.pmd-modal-back {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, .5);           /* bg-black/50 — matches style guide */
	z-index: var(--pmd-modal-z);
	align-items: center;
	justify-content: center;
	padding: 24px;
	-webkit-backdrop-filter: blur(4px);      /* backdrop-blur-sm */
	        backdrop-filter: blur(4px);
}
.pmd-modal-back.is-open {
	display: flex;
	animation: pmd-modal-fade-in .18s ease;
}
@keyframes pmd-modal-fade-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}

/* ── Modal box ──────────────────────────────────────────────────────────── */
.pmd-modal {
	background: var(--pmd-modal-bg);
	color: var(--pmd-modal-text);
	border-radius: var(--pmd-modal-radius);  /* rounded-2xl = 16px */
	padding: 28px 30px;
	max-width: 540px;
	width: 100%;
	max-height: 90vh;
	overflow-y: auto;
	box-shadow: var(--pmd-modal-shadow);
	font-family: var(--pmd-modal-font);
	font-size: .9375rem;                     /* ~15px — between text-sm and text-base */
	animation: pmd-modal-pop-in .22s cubic-bezier(.2, .9, .25, 1.05);
}
.pmd-modal--sm { max-width: 400px; }
.pmd-modal--md { max-width: 540px; }
.pmd-modal--lg { max-width: 720px; }
.pmd-modal--xl { max-width: 960px; }

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

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

.pmd-modal__title {
	font-family: var(--pmd-modal-font-h);    /* Lexend */
	font-size: 1.25rem;                      /* ~text-xl */
	font-weight: 700;
	color: var(--pmd-modal-text);            /* gray-900 */
	margin: 0 0 4px;
	line-height: 1.3;
}
.pmd-modal__sub {
	font-size: .875rem;                      /* text-sm */
	color: var(--pmd-modal-text-mute);       /* gray-600 */
	margin: 0;
	line-height: 1.5;
}

.pmd-modal__close {
	background: transparent;
	border: 0;
	color: var(--pmd-modal-text-dim);        /* gray-400 */
	font-size: 1.35rem;
	line-height: 1;
	cursor: pointer;
	padding: 4px 8px;
	border-radius: var(--pmd-modal-radius-sm); /* rounded-xl */
	flex-shrink: 0;
	transition: background .15s, color .15s;
}
.pmd-modal__close:hover {
	background: var(--pmd-modal-surface);    /* gray-50 */
	color: var(--pmd-modal-text);            /* gray-900 */
}

/* ── Form fields ────────────────────────────────────────────────────────── */
.pmd-modal__group { margin-bottom: 16px; }

.pmd-modal__row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 14px;
}
.pmd-modal__row .pmd-modal__group { margin-bottom: 0; }
.pmd-modal__row--3 { grid-template-columns: repeat(3, 1fr); }

/* Label — matches style guide: text-sm font-medium text-gray-700 */
.pmd-modal__label {
	display: block;
	font-size: .875rem;                      /* text-sm = 14px */
	font-weight: 500;                        /* font-medium */
	color: var(--pmd-modal-text-mute);       /* gray-600 ≈ gray-700 */
	margin-bottom: 8px;                      /* mb-2 */
	letter-spacing: 0;
	text-transform: none;
}
.pmd-modal__label--required::after {
	content: ' *';
	color: var(--pmd-modal-danger);
}

/* Inputs — matches style guide: px-4 py-2.5 border-gray-200 rounded-xl focus:border-olive focus:ring-2 */
.pmd-modal__input,
.pmd-modal__select,
.pmd-modal__textarea {
	width: 100%;
	padding: 10px 16px;                      /* py-2.5 px-4 */
	border: 1px solid var(--pmd-modal-border); /* border-gray-200 */
	border-radius: var(--pmd-modal-radius-sm); /* rounded-xl = 12px */
	background: var(--pmd-modal-bg);         /* white */
	color: var(--pmd-modal-text);            /* gray-900 */
	font-family: var(--pmd-modal-font);      /* Inter */
	font-size: .9375rem;
	box-sizing: border-box;
	transition: border-color .15s, box-shadow .15s;
}
.pmd-modal__input::placeholder,
.pmd-modal__textarea::placeholder {
	color: var(--pmd-modal-text-dim);        /* gray-400 */
}
.pmd-modal__input:focus,
.pmd-modal__select:focus,
.pmd-modal__textarea:focus {
	outline: none;
	border-color: var(--pmd-modal-accent);   /* olive */
	box-shadow: 0 0 0 3px var(--pmd-modal-accent-bg); /* ring-2 ring-olive/10 */
}
.pmd-modal__select {
	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='%239ca3af' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 14px center;
	padding-right: 38px;
}
.pmd-modal__textarea {
	resize: vertical;
	min-height: 80px;
}
.pmd-modal__hint {
	font-size: .8125rem;                     /* between text-xs and text-sm */
	color: var(--pmd-modal-text-dim);        /* gray-400 */
	margin-top: 5px;
	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);   /* olive 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;
	gap: 10px;
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid var(--pmd-modal-border); /* gray-200 */
	align-items: center;
}
.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: 10px 20px;                      /* py-2.5 px-5 */
	border: 1px solid transparent;
	border-radius: var(--pmd-modal-radius-sm); /* rounded-xl = 12px */
	font-family: var(--pmd-modal-font);      /* Inter */
	font-weight: 500;                        /* font-medium */
	font-size: .9375rem;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	transition: background .15s, border-color .15s, color .15s, opacity .15s;
	line-height: 1;
}
.pmd-modal__btn:disabled { opacity: .5; cursor: not-allowed; }

/* Primary — bg-olive text-white hover:bg-olive/90 */
.pmd-modal__btn--primary {
	background: var(--pmd-modal-accent);
	color: #ffffff;
	border-color: var(--pmd-modal-accent);
}
.pmd-modal__btn--primary:hover:not(:disabled) {
	background: var(--pmd-modal-accent-h);
	border-color: var(--pmd-modal-accent-h);
}

/* Secondary — bg-white border-gray-200 text-gray-700 hover:bg-gray-50 */
.pmd-modal__btn--secondary {
	background: #ffffff;
	color: var(--pmd-modal-text-mute);       /* gray-600 */
	border-color: var(--pmd-modal-border);   /* gray-200 */
}
.pmd-modal__btn--secondary:hover:not(:disabled) {
	background: var(--pmd-modal-surface);    /* gray-50 */
	color: var(--pmd-modal-text);            /* gray-900 */
}

/* Danger — bg-red-50 border-red-100 text-red-700 hover:bg-red-100 */
.pmd-modal__btn--danger {
	background: rgba(185, 28, 28, .06);
	color: var(--pmd-modal-danger);
	border-color: rgba(185, 28, 28, .2);
}
.pmd-modal__btn--danger:hover:not(:disabled) {
	background: rgba(185, 28, 28, .12);
}

/* 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; padding: 20px 20px 28px; }
	.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; }
}
