/* =====================================================================
   Snaproll v2 — branded dialog (toast + alert + confirm)
   ---------------------------------------------------------------------
   Paired with frontend/js/v2/v2-dialog.js. Imported AFTER tokens.css →
   base.css → components.css on every page that loads v2-dialog.js.

   Two roots, both lazily appended to <body> by the JS:

     .v2-dlg-modal-root   ← parent for alert/confirm overlays (z-index 1000)
     .v2-dlg-toast-root   ← parent for toast chips             (z-index 1100)

   Toasts sit above modals on purpose: if a confirm-modal triggers a
   save and the save throws, the toast must surface ON TOP of the
   still-open modal so the user sees the error before they re-engage.

   Kind buckets affect ONLY the icon tint (alert/confirm) or the stripe
   colour (toast). The card itself stays neutral so the page chrome
   stays the visual anchor.
   ===================================================================== */

/* ── Roots ─────────────────────────────────────────────────────────── */
.v2-dlg-modal-root,
.v2-dlg-toast-root {
	position: fixed;
	pointer-events: none;        /* don't block the page when empty */
	z-index: 1000;
}
.v2-dlg-modal-root { inset: 0; }
.v2-dlg-toast-root {
	bottom: 22px;
	right: 22px;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 10px;
	z-index: 1100;
}

/* ── Modal: overlay + card (alert + confirm) ───────────────────────── */
.v2-dlg-overlay {
	position: fixed;
	inset: 0;
	background: var(--v2-overlay);
	backdrop-filter: blur(6px);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	pointer-events: auto;        /* re-enable for this layer */
	animation: v2-dlg-fade-in 130ms ease-out;
}
/* Honor the `hidden` attribute on markup-based overlay usage (e.g. the
   approve-result modal in admin-v2.html). Without this, `display: flex`
   above wins over the user-agent `[hidden] { display: none }` rule,
   and the modal renders visible on page load with empty data. The
   JS-driven v2dialog.alert/confirm path doesn't hit this because it
   only mounts the element when opening — but inline-markup callers do. */
.v2-dlg-overlay[hidden] { display: none; }
.v2-dlg-overlay.is-closing {
	animation: v2-dlg-fade-out 130ms ease-out forwards;
}

.v2-dlg-card {
	background: var(--v2-card);
	border-radius: var(--v2-r-3);
	padding: 26px 26px 22px;
	max-width: 440px;
	width: 100%;
	box-shadow: var(--v2-sh-4);
	max-height: calc(100vh - 40px);
	overflow-y: auto;
	outline: none;
	animation: v2-dlg-card-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.v2-dlg-overlay.is-closing .v2-dlg-card {
	animation: v2-dlg-card-out 130ms ease-out forwards;
}

.v2-dlg-head {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 10px;
}
.v2-dlg-icon {
	width: 36px;
	height: 36px;
	border-radius: var(--v2-r-2);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.v2-dlg-title {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
	letter-spacing: -0.015em;
	color: var(--v2-ink);
	line-height: 1.3;
}
.v2-dlg-msg {
	margin: 0 0 22px;
	font-size: 14px;
	color: var(--v2-ink-2);
	line-height: 1.55;
	white-space: normal;
}
/* When there's no title, the icon hangs alone — give it a tiny extra
   bit of breathing room from the message that follows. */
.v2-dlg-head:not(:has(.v2-dlg-title)) {
	margin-bottom: 14px;
}

.v2-dlg-actions {
	display: flex;
	gap: 10px;
	justify-content: flex-end;
}

/* ── Kind palette (icon backgrounds) ───────────────────────────────── */
.v2-dlg-kind-info  .v2-dlg-icon { background: var(--v2-blue-soft);    color: var(--v2-blue); }
.v2-dlg-kind-ok    .v2-dlg-icon { background: var(--v2-green-soft);   color: var(--v2-green); }
.v2-dlg-kind-warn  .v2-dlg-icon { background: var(--v2-amber-soft);   color: var(--v2-amber); }
.v2-dlg-kind-error .v2-dlg-icon { background: var(--v2-red-soft);     color: var(--v2-red); }

/* ── Toast chip (non-blocking) ─────────────────────────────────────── */
.v2-dlg-toast {
	pointer-events: auto;
	background: var(--v2-ink);
	color: var(--v2-card);
	padding: 12px 16px 12px 12px;
	border-radius: var(--v2-r-2);
	box-shadow: var(--v2-sh-3);
	font-size: 13.5px;
	font-weight: 500;
	max-width: 360px;
	display: flex;
	align-items: center;
	gap: 10px;
	cursor: pointer;
	opacity: 0;
	transform: translateY(10px);
	transition: opacity 180ms ease, transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.v2-dlg-toast.is-shown {
	opacity: 1;
	transform: translateY(0);
}
.v2-dlg-toast.is-closing {
	opacity: 0;
	transform: translateY(10px);
	transition: opacity 200ms ease, transform 200ms ease;
}

.v2-dlg-toast-icon {
	width: 24px;
	height: 24px;
	border-radius: var(--v2-r-1);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.v2-dlg-toast-msg {
	flex: 1;
	min-width: 0;
	line-height: 1.4;
	word-wrap: break-word;
}

/* Toast icon tints. Slightly lighter than the modal icon to read on the
   dark chip body. */
.v2-dlg-toast.v2-dlg-kind-info  .v2-dlg-toast-icon { background: rgba(42, 111, 219, 0.22); color: #B8D4FB; }
.v2-dlg-toast.v2-dlg-kind-ok    .v2-dlg-toast-icon { background: rgba(31, 138, 91, 0.22);  color: #9CE6BD; }
.v2-dlg-toast.v2-dlg-kind-warn  .v2-dlg-toast-icon { background: rgba(194, 138, 20, 0.22); color: #F6D27A; }
.v2-dlg-toast.v2-dlg-kind-error .v2-dlg-toast-icon { background: rgba(200, 52, 31, 0.22);  color: #F6A89B; }

/* ── Animations ────────────────────────────────────────────────────── */
@keyframes v2-dlg-fade-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}
@keyframes v2-dlg-fade-out {
	from { opacity: 1; }
	to   { opacity: 0; }
}
@keyframes v2-dlg-card-in {
	from { opacity: 0; transform: translateY(12px) scale(0.98); }
	to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes v2-dlg-card-out {
	from { opacity: 1; transform: scale(1); }
	to   { opacity: 0; transform: scale(0.98); }
}

/* ── Narrow phones ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
	.v2-dlg-toast-root {
		left: 16px;
		right: 16px;
		bottom: 16px;
		align-items: stretch;
	}
	.v2-dlg-toast { max-width: none; }
	.v2-dlg-card { padding: 22px 20px 18px; }
}

/* ── Reduced motion ────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	.v2-dlg-overlay,
	.v2-dlg-overlay.is-closing,
	.v2-dlg-card,
	.v2-dlg-overlay.is-closing .v2-dlg-card,
	.v2-dlg-toast {
		animation: none !important;
		transition: opacity 0ms !important;
	}
}
