/* MG Aiva 1.0.0: chat widget. Matches the mirror-glass theme (Stone/White/Ink palette, Helvetica, square black buttons). */
.mg-aiva {
	--aiva-ink: var(--wp--preset--color--contrast, #111);
	--aiva-base: var(--wp--preset--color--base, #eae7e1);
	--aiva-surface: var(--wp--preset--color--surface, #fff);
	--aiva-muted: var(--wp--preset--color--muted, #4a473f);
	--aiva-subtle: var(--wp--preset--color--subtle, #6a665e);
	--aiva-line: var(--wp--preset--color--line, #d3cec5);
	--aiva-alert: var(--wp--preset--color--alert, #8f4a30);
	--aiva-font: var(--wp--preset--font-family--sans, "Helvetica Neue", Helvetica, Arial, system-ui, -apple-system, "Segoe UI", sans-serif);
	position: fixed; right: calc(20px + env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 99990;
	font-family: var(--aiva-font); font-size: 15px; line-height: 1.45; color: var(--aiva-ink);
	-webkit-font-smoothing: antialiased;
}
.mg-aiva :where(*, *::before, *::after) { box-sizing: border-box; }
.mg-aiva :where(button, input, textarea) { font: inherit; color: inherit; }
.mg-aiva :focus-visible { outline: 2px solid var(--aiva-ink); outline-offset: 2px; }
.mg-aiva__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; }
.mg-aiva__hp { position: absolute; left: -10000px; width: 1px; height: 1px; opacity: 0; }

/* Launcher */
.mg-aiva__launcher {
	display: inline-flex; align-items: center; gap: .55rem; margin-left: auto;
	padding: .8rem 1.15rem; border: 1px solid var(--aiva-ink); border-radius: 0;
	background: var(--aiva-ink); color: var(--aiva-surface) !important; cursor: pointer;
	font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
	box-shadow: 0 6px 24px rgba(17, 17, 17, .18); transition: background .15s ease;
}
.mg-aiva__launcher:hover { background: var(--aiva-muted); border-color: var(--aiva-muted); }
.mg-aiva__launcher:focus-visible { outline-color: var(--aiva-ink); outline-offset: 3px; }
.mg-aiva.is-open .mg-aiva__launcher { display: none; }

/* Panel */
.mg-aiva__panel {
	display: flex; flex-direction: column; width: 380px; height: min(640px, calc(100vh - 40px));
	background: var(--aiva-surface); border: 1px solid var(--aiva-line);
	box-shadow: 0 18px 50px rgba(17, 17, 17, .22);
}
.mg-aiva__panel[hidden] { display: none; }
/* Logged in: keep the floating panel clear of the WP admin bar (32px, 46px under 783px). */
body.admin-bar .mg-aiva__panel { height: min(640px, calc(100vh - 72px)); }
@media (max-width: 782px) {
	body.admin-bar .mg-aiva__panel { height: min(640px, calc(100vh - 86px)); }
}
.mg-aiva__head { display: flex; align-items: center; gap: .7rem; padding: .85rem .9rem .85rem 1rem; background: var(--aiva-base); border-bottom: 1px solid var(--aiva-line); }
.mg-aiva__avatar { flex: 0 0 34px; height: 34px; display: grid; place-items: center; background: var(--aiva-ink); color: var(--aiva-surface); font-weight: 700; letter-spacing: .04em; }
.mg-aiva__titles { flex: 1; min-width: 0; }
.mg-aiva__title { margin: 0 !important; font-size: 16px !important; font-weight: 700; line-height: 1.2 !important; letter-spacing: 0; text-transform: none; color: var(--aiva-ink); }
.mg-aiva__sub { margin: 0 !important; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--aiva-muted); letter-spacing: .06em; text-transform: uppercase; }
.mg-aiva__head-actions { display: flex; align-items: center; gap: .15rem; }
.mg-aiva__icon-btn { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 .4rem; background: transparent; border: 0; cursor: pointer; color: var(--aiva-ink); }
.mg-aiva__icon-btn:hover { background: rgba(17, 17, 17, .07); }
.mg-aiva__link-btn { background: none; border: 0; padding: .45rem .4rem; cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; color: var(--aiva-muted); white-space: nowrap; }
.mg-aiva__link-btn:hover { color: var(--aiva-ink); }
.mg-aiva__link-btn[hidden] { display: none; }

/* Messages */
.mg-aiva__log { flex: 1 1 0; min-height: 96px; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; overscroll-behavior: contain; scroll-behavior: smooth; }
.mg-aiva__msg { max-width: 88%; padding: .6rem .8rem; border: 1px solid var(--aiva-line); overflow-wrap: anywhere; }
.mg-aiva__msg p { margin: 0; white-space: pre-line; }
.mg-aiva__msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.mg-aiva__msg--aiva { align-self: flex-start; background: var(--aiva-base); border-color: var(--aiva-base); }
.mg-aiva__msg--customer { align-self: flex-end; background: var(--aiva-surface); border-color: var(--aiva-ink); }
.mg-aiva__products { list-style: none; margin: .55rem 0 0; padding: 0; display: grid; gap: .35rem; }
.mg-aiva__products li { background: var(--aiva-surface); padding: .45rem .6rem; font-size: 14px; }
.mg-aiva__products a { font-weight: 600; }
.mg-aiva__products span { color: var(--aiva-muted); }
.mg-aiva__summary { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: .6rem 0 0; padding: .6rem; background: var(--aiva-surface); font-size: 14px; }
.mg-aiva__summary dt { color: var(--aiva-muted); }
.mg-aiva__summary dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.mg-aiva__typing { display: flex; gap: 4px; padding: 0 1rem .4rem; }
.mg-aiva__typing[hidden] { display: none; }
.mg-aiva__typing span { width: 6px; height: 6px; background: var(--aiva-subtle); border-radius: 50%; animation: mg-aiva-dot 1s infinite ease-in-out; }
.mg-aiva__typing span:nth-child(2) { animation-delay: .15s; }
.mg-aiva__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes mg-aiva-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Quick replies and uploads */
.mg-aiva__actions { flex: 0 0 auto; padding: 0 1rem; max-height: 46%; overflow-y: auto; }
.mg-aiva__actions:empty { display: none; }
.mg-aiva__chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: .25rem 0 .7rem; }
.mg-aiva__chip {
	display: inline-flex; align-items: center; min-height: 38px; padding: .45rem .8rem; cursor: pointer;
	background: var(--aiva-surface); color: var(--aiva-ink); border: 1px solid var(--aiva-ink); border-radius: 0;
	font-size: 14px; line-height: 1.2; text-align: left;
}
.mg-aiva__chip:hover { background: var(--aiva-base); }
.mg-aiva__chip--primary { background: var(--aiva-ink); color: var(--aiva-surface); }
.mg-aiva__chip--primary:hover { background: var(--aiva-muted); border-color: var(--aiva-muted); }
.mg-aiva__files { list-style: none; margin: 0 0 .4rem; padding: 0; display: grid; gap: .45rem; }
.mg-aiva__file { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .2rem .5rem; padding: .45rem .55rem; border: 1px solid var(--aiva-line); font-size: 13px; }
.mg-aiva__fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-aiva__frm { min-width: 28px; height: 28px; font-size: 18px; }
.mg-aiva__bar { grid-column: 1; height: 4px; background: var(--aiva-base); overflow: hidden; }
.mg-aiva__bar span { display: block; height: 100%; width: 0; background: var(--aiva-ink); transition: width .2s linear; }
.mg-aiva__fstate { color: var(--aiva-muted); font-size: 12px; }
.mg-aiva__note { margin: 0 0 .5rem; font-size: 13px; color: var(--aiva-alert); }
.mg-aiva__note:empty { display: none; }

/* Input */
.mg-aiva__form { flex: 0 0 auto; display: flex; align-items: flex-end; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--aiva-line); margin: 0; }
.mg-aiva .mg-aiva__input { flex: 1; width: auto; height: 42px; min-height: 42px !important; max-height: 140px; margin: 0; resize: none; box-shadow: none; padding: .6rem .7rem; border: 1px solid var(--aiva-line); border-radius: 0; background: var(--aiva-surface); font-size: 15px; line-height: 1.35; }
.mg-aiva .mg-aiva__input:focus { border-color: var(--aiva-ink); outline: none; box-shadow: inset 0 0 0 1px var(--aiva-ink); }
.mg-aiva__send { min-height: 42px; padding: 0 1rem; background: var(--aiva-ink); color: var(--aiva-surface); border: 1px solid var(--aiva-ink); border-radius: 0; cursor: pointer; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.mg-aiva__send:hover { background: var(--aiva-muted); border-color: var(--aiva-muted); }
.mg-aiva__gdpr { margin: 0 !important; padding: 0 1rem .7rem; font-size: 12px; color: var(--aiva-muted); }
.mg-aiva__gdpr a { color: inherit; text-decoration: underline; }

/* Mobile: full screen panel, compact launcher, 16px input so iOS does not zoom. */
@media (max-width: 600px) {
	.mg-aiva { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
	.mg-aiva__launcher { padding: .75rem 1rem; }
	.mg-aiva { right: calc(12px + env(safe-area-inset-right, 0px)); }
	.mg-aiva.is-open { inset: 0; right: 0; bottom: 0; }
	/* Full screen, anchored top and bottom (no 100vh, which iOS measures under its toolbars),
	   padded for the notch / home indicator / landscape insets. */
	.mg-aiva__panel {
		position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: auto; height: auto;
		border: 0; box-shadow: none;
		padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
	}
	/* Logged in: start below the WP admin bar (46px under 783px) instead of under it. */
	body.admin-bar .mg-aiva__panel { top: 46px; top: var(--aiva-bar, 46px); height: auto; padding-top: 0; }
	.mg-aiva__msg { max-width: 92%; }
	.mg-aiva .mg-aiva__input { font-size: 16px; }
	.mg-aiva__actions { max-height: 42%; }
	html.mg-aiva-locked, html.mg-aiva-locked body { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) {
	.mg-aiva__log { scroll-behavior: auto; }
	.mg-aiva__typing span, .mg-aiva__bar span, .mg-aiva__launcher { animation: none; transition: none; }
}
@media print { .mg-aiva { display: none !important; } }
.mg-aiva__chip[aria-disabled="true"] { opacity: .7; cursor: progress; }
/* 1.0.6: never switch off the keyboard's auto-capitalisation or correction. */
.mg-aiva .mg-aiva__input { text-transform: none; }
