/* ================================================================
   JBH Platform Engine — Modern Notification System (v1.0.0)
   ================================================================
   Inherits the JBH brand palette via CSS custom properties.
   Uses --jbh-dm-* bridge vars for automatic dark/light adaptation.
   Supports: toast shapes, glassmorphism, rich hover, action buttons.
   ================================================================ */

/* ── Core Notice Variables ──────────────────────────────────────── */
:root {
	/* Surface / Text — light defaults */
	--jbh-notice-bg:         var(--jbh-dm-card, #ffffff);
	--jbh-notice-text:       var(--jbh-dm-text, #1f2937);
	--jbh-notice-muted:      var(--jbh-dm-muted, #6b7280);
	--jbh-notice-shadow:     0 10px 25px -5px rgba(0,0,0,0.10),
	                         0  8px 10px -6px rgba(0,0,0,0.06);
	--jbh-notice-radius:     12px;
	--jbh-notice-font:       var(--jbh-font-sans, 'Inter', system-ui, sans-serif);

	/* Semantic Colors — inherits JBH brand */
	--jbh-notice-success:    var(--jbh-dm-accent, var(--jbh-teal, #2A9D8F));
	--jbh-notice-success-bg: rgba(42,157,143,0.08);
	--jbh-notice-error:      var(--jbh-dm-coral, var(--jbh-coral, #D64F42));
	--jbh-notice-error-bg:   rgba(214,79,66,0.08);
	--jbh-notice-info:       #3b82f6;
	--jbh-notice-info-bg:    rgba(59,130,246,0.08);
	--jbh-notice-warning:    #f59e0b;
	--jbh-notice-warning-bg: rgba(245,158,11,0.08);
}

/* ── Dark Mode (JBH theme toggle) ──────────────────────────────── */
html[data-theme="dark"], html.dark {
	--jbh-notice-bg:         var(--jbh-dm-card, #1A1A1A);
	--jbh-notice-text:       var(--jbh-dm-text, #F0EAD6);
	--jbh-notice-muted:      var(--jbh-dm-muted, #9CA3AF);
	--jbh-notice-shadow:     0 10px 25px -5px rgba(0,0,0,0.50),
	                         0  8px 10px -6px rgba(0,0,0,0.40);
	--jbh-notice-success-bg: rgba(42,157,143,0.14);
	--jbh-notice-error-bg:   rgba(214,79,66,0.14);
	--jbh-notice-info-bg:    rgba(59,130,246,0.14);
	--jbh-notice-warning-bg: rgba(245,158,11,0.14);
}

/* ── Light Mode (explicit) ─────────────────────────────────────── */
html[data-theme="light"], html.light {
	--jbh-notice-bg:         var(--jbh-dm-card, #FFFFFF);
	--jbh-notice-text:       var(--jbh-dm-text, #121212);
	--jbh-notice-muted:      var(--jbh-dm-muted, #4B5563);
	--jbh-notice-shadow:     0 10px 25px -5px rgba(0,0,0,0.08),
	                         0  8px 10px -6px rgba(0,0,0,0.04);
	--jbh-notice-success-bg: rgba(42,157,143,0.07);
	--jbh-notice-error-bg:   rgba(214,79,66,0.07);
	--jbh-notice-info-bg:    rgba(59,130,246,0.07);
	--jbh-notice-warning-bg: rgba(245,158,11,0.07);
}

/* ── Dark Mode (OS preference fallback) ────────────────────────── */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]):not(.light) {
		--jbh-notice-bg:         var(--jbh-dm-card, #1A1A1A);
		--jbh-notice-text:       var(--jbh-dm-text, #F0EAD6);
		--jbh-notice-muted:      var(--jbh-dm-muted, #9CA3AF);
		--jbh-notice-shadow:     0 10px 25px -5px rgba(0,0,0,0.50),
		                         0  8px 10px -6px rgba(0,0,0,0.40);
	}
}


/* ================================================================
   A. INLINE NOTICE STYLING (WooCommerce)
   ================================================================
   Targets .woocommerce-message, .woocommerce-info, .woocommerce-error
   when NOT inside the toast container.
   ================================================================ */

.woocommerce-notices-wrapper .woocommerce-message,
.woocommerce-notices-wrapper .woocommerce-info,
.woocommerce-notices-wrapper .woocommerce-error {
	font-family: var(--jbh-notice-font);
	border-radius: var(--jbh-notice-radius) !important;
	padding: 16px 24px !important;
	margin-bottom: 16px !important;
	display: flex !important;
	align-items: flex-start !important;
	gap: 12px !important;
	font-size: 0.9rem;
	line-height: 1.5;
	font-weight: 500;
	box-shadow: var(--jbh-notice-shadow);
	list-style: none !important;
	position: relative;
}

.woocommerce-notices-wrapper .woocommerce-message::before,
.woocommerce-notices-wrapper .woocommerce-info::before,
.woocommerce-notices-wrapper .woocommerce-error::before {
	content: none !important;
}

.woocommerce-notices-wrapper .woocommerce-message {
	background: var(--jbh-notice-success-bg) !important;
	color: var(--jbh-notice-text) !important;
	border: 1px solid rgba(42,157,143,0.20) !important;
	border-left: 4px solid var(--jbh-notice-success) !important;
}

.woocommerce-notices-wrapper .woocommerce-info {
	background: var(--jbh-notice-info-bg) !important;
	color: var(--jbh-notice-text) !important;
	border: 1px solid rgba(59,130,246,0.20) !important;
	border-left: 4px solid var(--jbh-notice-info) !important;
}

.woocommerce-notices-wrapper .woocommerce-error,
.woocommerce-notices-wrapper .woocommerce-error li {
	background: var(--jbh-notice-error-bg) !important;
	color: var(--jbh-notice-error) !important;
	border: 1px solid rgba(214,79,66,0.20) !important;
	border-left: 4px solid var(--jbh-notice-error) !important;
}

/* Button inside WC notices (e.g. "View cart") */
.woocommerce-notices-wrapper .woocommerce-message a.button,
.woocommerce-notices-wrapper .woocommerce-message .restore-item {
	background: var(--jbh-notice-success) !important;
	color: #fff !important;
	border-radius: 8px !important;
	padding: 8px 16px !important;
	font-size: 0.8rem !important;
	font-weight: 600;
	text-decoration: none !important;
	margin-left: auto;
	white-space: nowrap;
	transition: opacity 0.2s ease;
}
.woocommerce-notices-wrapper .woocommerce-message a.button:hover {
	opacity: 0.85;
}


/* ================================================================
   B. TOAST CONTAINER
   ================================================================ */

.jbh-toast-container {
	position: fixed;
	z-index: 999999;
	display: flex;
	flex-direction: column;
	gap: 12px;
	pointer-events: none;
	max-width: min(420px, calc(100vw - 32px));
	max-height: calc(100vh - 64px);
	overflow: hidden;
}

/* Positions */
.jbh-toast-bottom-right  { bottom: 32px; right: 32px;  align-items: flex-end;   }
.jbh-toast-bottom-left   { bottom: 32px; left: 32px;   align-items: flex-start; }
.jbh-toast-top-right     { top: 32px;    right: 32px;  align-items: flex-end;   }
.jbh-toast-top-left      { top: 32px;    left: 32px;   align-items: flex-start; }

/* ── Individual Toast ─────────────────────────────────────────── */

.jbh-toast {
	pointer-events: auto;
	background: var(--jbh-notice-bg);
	color: var(--jbh-notice-text);
	box-shadow: var(--jbh-notice-shadow);
	border-radius: var(--jbh-notice-radius);
	padding: 14px 20px 14px 16px;
	display: flex;
	align-items: flex-start;
	gap: 12px;
	font-family: var(--jbh-notice-font);
	font-size: 0.875rem;
	line-height: 1.5;
	font-weight: 500;
	min-width: 280px;
	max-width: 420px;
	position: relative;
	overflow: hidden;
	border-left: 4px solid var(--jbh-notice-success);
	will-change: transform, opacity;
	animation: jbh-toast-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	transition: box-shadow 0.25s ease, transform 0.25s ease;
}

/* Glassmorphism mode (class added by JS based on admin setting) */
.jbh-toast-glass .jbh-toast {
	background: rgba(255,255,255,0.72);
	border: 1px solid rgba(255,255,255,0.20);
	border-left-width: 4px;
}
html[data-theme="dark"] .jbh-toast-glass .jbh-toast,
html.dark .jbh-toast-glass .jbh-toast {
	background: rgba(26,26,26,0.80);
	border-color: rgba(255,255,255,0.08);
	border-left-width: 4px;
}

/* Toast shape variants (class on container) */
.jbh-toast-shape-sharp .jbh-toast  { --jbh-notice-radius: 0; }
.jbh-toast-shape-rounded .jbh-toast { --jbh-notice-radius: 12px; }
.jbh-toast-shape-pill .jbh-toast    { --jbh-notice-radius: 999px; }

/* Hover lift effect */
.jbh-toast:hover {
	box-shadow: var(--jbh-notice-shadow), 0 0 0 1px rgba(42,157,143,0.15);
	transform: translateY(-2px) scale(1.005);
}

/* Accent gradient strip on left border */
.jbh-toast-success { border-image: linear-gradient(180deg, var(--jbh-notice-success), rgba(42,157,143,0.4)) 1; border-image-slice: 1; border-left-style: solid; border-left-width: 4px; }
.jbh-toast-error   { border-image: linear-gradient(180deg, var(--jbh-notice-error),   rgba(214,79,66,0.4))  1; border-image-slice: 1; border-left-style: solid; border-left-width: 4px; }
.jbh-toast-info    { border-image: linear-gradient(180deg, var(--jbh-notice-info),    rgba(59,130,246,0.4)) 1; border-image-slice: 1; border-left-style: solid; border-left-width: 4px; }
.jbh-toast-warning { border-image: linear-gradient(180deg, var(--jbh-notice-warning), rgba(245,158,11,0.4)) 1; border-image-slice: 1; border-left-style: solid; border-left-width: 4px; }

.jbh-toast.jbh-toast-success { border-left-color: var(--jbh-notice-success); }
.jbh-toast.jbh-toast-error   { border-left-color: var(--jbh-notice-error);   }
.jbh-toast.jbh-toast-info    { border-left-color: var(--jbh-notice-info);    }
.jbh-toast.jbh-toast-warning { border-left-color: var(--jbh-notice-warning); }

/* Icon — pill background */
.jbh-toast-icon {
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	padding: 5px;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.jbh-toast-icon svg { width: 18px; height: 18px; }
.jbh-toast-success .jbh-toast-icon { color: var(--jbh-notice-success); background: var(--jbh-notice-success-bg); }
.jbh-toast-error   .jbh-toast-icon { color: var(--jbh-notice-error);   background: var(--jbh-notice-error-bg); }
.jbh-toast-info    .jbh-toast-icon { color: var(--jbh-notice-info);    background: var(--jbh-notice-info-bg); }
.jbh-toast-warning .jbh-toast-icon { color: var(--jbh-notice-warning); background: var(--jbh-notice-warning-bg); }

/* Content */
.jbh-toast-body {
	flex: 1;
	min-width: 0;
}
.jbh-toast-title {
	font-weight: 700;
	font-size: 0.9rem;
	margin-bottom: 2px;
	color: var(--jbh-notice-text);
}
.jbh-toast-message {
	font-size: 0.825rem;
	color: var(--jbh-notice-muted);
	line-height: 1.45;
}
.jbh-toast-body a {
	color: var(--jbh-notice-success);
	text-decoration: underline;
	text-underline-offset: 2px;
	font-weight: 600;
	transition: opacity 0.2s ease;
}
.jbh-toast-body a:hover { opacity: 0.8; }

/* Stacked toast entrance — each subsequent toast slightly delayed */
.jbh-toast:nth-child(2) { animation-delay: 0.05s; }
.jbh-toast:nth-child(3) { animation-delay: 0.10s; }
.jbh-toast:nth-child(4) { animation-delay: 0.15s; }
.jbh-toast:nth-child(5) { animation-delay: 0.20s; }

/* Action button inside toast (e.g. "View Cart", "Undo") */
.jbh-toast-action {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin-top: 6px;
	padding: 4px 12px;
	border-radius: 6px;
	font-size: 0.8rem;
	font-weight: 600;
	cursor: pointer;
	border: 1px solid transparent;
	transition: all 0.2s ease;
}
.jbh-toast-success .jbh-toast-action {
	background: var(--jbh-notice-success-bg);
	color: var(--jbh-notice-success);
	border-color: rgba(42,157,143,0.20);
}
.jbh-toast-error .jbh-toast-action {
	background: var(--jbh-notice-error-bg);
	color: var(--jbh-notice-error);
	border-color: rgba(214,79,66,0.20);
}
.jbh-toast-info .jbh-toast-action {
	background: var(--jbh-notice-info-bg);
	color: var(--jbh-notice-info);
	border-color: rgba(59,130,246,0.20);
}
.jbh-toast-warning .jbh-toast-action {
	background: var(--jbh-notice-warning-bg);
	color: var(--jbh-notice-warning);
	border-color: rgba(245,158,11,0.20);
}
.jbh-toast-action:hover { filter: brightness(1.1); }

/* Close button */
.jbh-toast-close {
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: none;
	background: transparent;
	color: var(--jbh-notice-text);
	opacity: 0.45;
	cursor: pointer;
	border-radius: 6px;
	padding: 0;
	margin: -4px -6px -4px 0;
	transition: opacity 0.2s ease, background 0.2s ease;
}
.jbh-toast-close:hover {
	opacity: 1;
	background: rgba(127,127,127,0.12);
}
.jbh-toast-close svg {
	width: 14px;
	height: 14px;
}

/* ── Progress Bar ─────────────────────────────────────────────── */
.jbh-toast-progress {
	position: absolute;
	bottom: 0;
	left: 0;
	height: 3px;
	border-radius: 0 0 0 var(--jbh-notice-radius);
	will-change: width;
}
.jbh-toast-success .jbh-toast-progress { background: var(--jbh-notice-success); }
.jbh-toast-error   .jbh-toast-progress { background: var(--jbh-notice-error);   }
.jbh-toast-info    .jbh-toast-progress { background: var(--jbh-notice-info);    }
.jbh-toast-warning .jbh-toast-progress { background: var(--jbh-notice-warning); }

/* Pause progress on hover */
.jbh-toast:hover .jbh-toast-progress {
	animation-play-state: paused !important;
}

/* ── Animations ───────────────────────────────────────────────── */

/* Slide-in from bottom-right (default) */
@keyframes jbh-toast-in {
	from { opacity: 0; transform: translateX(24px) translateY(8px) scale(0.96); }
	to   { opacity: 1; transform: translateX(0)    translateY(0)   scale(1); }
}

/* Slide-in from bottom-left */
@keyframes jbh-toast-in-left {
	from { opacity: 0; transform: translateX(-24px) translateY(8px) scale(0.96); }
	to   { opacity: 1; transform: translateX(0)     translateY(0)   scale(1); }
}

/* Slide-in from top-right */
@keyframes jbh-toast-in-top {
	from { opacity: 0; transform: translateX(24px) translateY(-8px) scale(0.96); }
	to   { opacity: 1; transform: translateX(0)    translateY(0)    scale(1); }
}

/* Slide-in from top-left */
@keyframes jbh-toast-in-top-left {
	from { opacity: 0; transform: translateX(-24px) translateY(-8px) scale(0.96); }
	to   { opacity: 1; transform: translateX(0)     translateY(0)    scale(1); }
}

.jbh-toast-top-right  .jbh-toast { animation-name: jbh-toast-in-top; }
.jbh-toast-top-left   .jbh-toast { animation-name: jbh-toast-in-top-left; }
.jbh-toast-bottom-left .jbh-toast { animation-name: jbh-toast-in-left; }

/* Dismiss — slide out in reverse */
@keyframes jbh-toast-out {
	from { opacity: 1; transform: translateY(0)   scale(1); }
	to   { opacity: 0; transform: translateY(8px) scale(0.96); }
}
@keyframes jbh-toast-out-top {
	from { opacity: 1; transform: translateY(0)    scale(1); }
	to   { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

.jbh-toast.jbh-toast-dismissing {
	animation: jbh-toast-out 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}
.jbh-toast-top-right  .jbh-toast.jbh-toast-dismissing,
.jbh-toast-top-left   .jbh-toast.jbh-toast-dismissing {
	animation-name: jbh-toast-out-top;
}

/* Progress shrink (duration injected via inline style --jbh-toast-dur) */
@keyframes jbh-toast-progress-shrink {
	from { width: 100%; }
	to   { width: 0%;   }
}

.jbh-toast-progress {
	animation: jbh-toast-progress-shrink var(--jbh-toast-dur, 5s) linear forwards;
}


/* ================================================================
   C. ADMIN NOTICE STYLING (WP Dashboard)
   ================================================================
   Applied only when enable_admin_notice_styling is on.
   ================================================================ */

body.wp-admin .notice {
	font-family: var(--jbh-notice-font);
	border-radius: 10px !important;
	border: 1px solid rgba(127,127,127,0.15) !important;
	border-left-width: 4px !important;
	padding: 12px 20px !important;
	box-shadow: 0 2px 8px rgba(0,0,0,0.06);
	margin: 8px 0 !important;
	font-size: 0.875rem;
	line-height: 1.5;
}

body.wp-admin .notice-success {
	background: var(--jbh-notice-success-bg) !important;
	border-left-color: var(--jbh-notice-success) !important;
}
body.wp-admin .notice-error {
	background: var(--jbh-notice-error-bg) !important;
	border-left-color: var(--jbh-notice-error) !important;
}
body.wp-admin .notice-warning {
	background: var(--jbh-notice-warning-bg) !important;
	border-left-color: var(--jbh-notice-warning) !important;
}
body.wp-admin .notice-info {
	background: var(--jbh-notice-info-bg) !important;
	border-left-color: var(--jbh-notice-info) !important;
}

/* WP admin dark-mode compatibility (common admin dark-mode plugins) */
body.wp-admin.dark-mode .notice,
body.wp-admin[data-theme="dark"] .notice {
	background: rgba(30,30,30,0.90) !important;
	color: #e5e7eb !important;
}


/* ================================================================
   D. MOBILE RESPONSIVE
   ================================================================ */

@media (max-width: 600px) {
	.jbh-toast-container {
		left: 12px !important;
		right: 12px !important;
		bottom: 12px !important;
		top: auto !important;
		max-width: none;
		align-items: stretch !important;
	}

	.jbh-toast {
		min-width: 0;
		max-width: none;
		width: 100%;
		padding: 12px 16px 12px 14px;
		font-size: 0.825rem;
	}

	.jbh-toast-icon {
		width: 28px;
		height: 28px;
		padding: 4px;
	}
	.jbh-toast-icon svg { width: 16px; height: 16px; }

	/* On mobile, top-* positions still float at bottom for thumb reach */
	.jbh-toast-top-right,
	.jbh-toast-top-left {
		top: auto !important;
		bottom: 12px !important;
	}

	/* Full-width inline notices on mobile */
	.woocommerce-notices-wrapper .woocommerce-message,
	.woocommerce-notices-wrapper .woocommerce-info,
	.woocommerce-notices-wrapper .woocommerce-error {
		padding: 12px 16px !important;
		flex-wrap: wrap;
		gap: 8px !important;
	}
}


/* ================================================================
   E. REDUCED MOTION
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
	.jbh-toast {
		animation: none !important;
		opacity: 1;
		transform: none;
		transition: none !important;
	}
	.jbh-toast.jbh-toast-dismissing {
		animation: none !important;
		display: none;
	}
	.jbh-toast-progress {
		animation: none !important;
		width: 100%;
	}
	.jbh-toast:hover {
		transform: none;
	}
}


/* ================================================================
   F. FOCUS STYLES (keyboard navigation)
   ================================================================ */

.jbh-toast:focus-visible {
	outline: 2px solid var(--jbh-notice-success);
	outline-offset: 2px;
}
.jbh-toast-close:focus-visible {
	outline: 2px solid var(--jbh-notice-success);
	outline-offset: 1px;
	border-radius: 6px;
}
