/* =========================================================================
   Floating support chat.
   Scoped under #msat-chat-root so it cannot inherit or leak theme styles.
   ====================================================================== */

#msat-chat-root {
	--c-navy: #0f2a56;
	--c-navy-deep: #0a1d3d;
	--c-gold: #d9a441;
	--c-gold-light: #f0cd86;
	--c-line: #e3e7ee;
	--c-muted: #5b6675;
	--c-ink: #16202e;
	--c-ease: cubic-bezier(.16, 1, .3, 1);

	position: fixed;
	right: clamp(1rem, 3vw, 1.75rem);
	bottom: clamp(1rem, 3vw, 1.75rem);
	z-index: 9999;
	font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.55;
}

#msat-chat-root *,
#msat-chat-root *::before,
#msat-chat-root *::after { box-sizing: border-box; }

.screen-reader-only {
	position: absolute !important;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0 0 0 0);
	white-space: nowrap; border: 0;
}

/* -------------------------------------------------------------------------
   Button
   ---------------------------------------------------------------------- */

.msat-fab {
	position: relative;
	display: grid;
	place-items: center;
	width: 58px;
	height: 58px;
	margin-left: auto;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--c-navy) 0%, var(--c-navy-deep) 100%);
	color: #fff;
	cursor: pointer;
	box-shadow:
		0 2px 4px rgb(10 29 61 / 18%),
		0 8px 18px rgb(10 29 61 / 24%),
		0 18px 40px rgb(10 29 61 / 20%),
		inset 0 1px 0 rgb(255 255 255 / 18%);
	transition: transform .28s var(--c-ease), background-color .2s ease, box-shadow .28s var(--c-ease);
}
.msat-fab:hover {
	background: var(--c-navy-deep);
	transform: translateY(-2px);
	box-shadow: 0 6px 18px rgb(15 42 86 / 32%), 0 16px 40px rgb(15 42 86 / 26%);
}
.msat-fab:active { transform: translateY(0); }
.msat-fab:focus-visible { outline: 3px solid var(--c-gold); outline-offset: 3px; }

/* A single gold ring that pulses twice, then stops. Enough to notice,
   not enough to annoy. */
.msat-fab::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--c-gold);
	opacity: 0;
	animation: msat-ring 2.6s var(--c-ease) 1.2s 2;
}

@keyframes msat-ring {
	0%   { transform: scale(1); opacity: .65; }
	100% { transform: scale(1.5); opacity: 0; }
}

/* Icon swap: chat turns into a cross when open. */
.msat-fab__icon {
	grid-area: 1 / 1;
	transition: opacity .2s ease, transform .28s var(--c-ease);
}
.msat-fab__icon--close { opacity: 0; transform: rotate(-90deg) scale(.7); }
#msat-chat-root.is-open .msat-fab__icon--chat { opacity: 0; transform: rotate(90deg) scale(.7); }
#msat-chat-root.is-open .msat-fab__icon--close { opacity: 1; transform: rotate(0) scale(1); }
#msat-chat-root.is-open .msat-fab::after { animation: none; }

/* -------------------------------------------------------------------------
   Panel
   ---------------------------------------------------------------------- */

.msat-panel {
	position: absolute;
	right: 0;
	bottom: 72px;
	width: min(370px, calc(100vw - 2rem));
	max-height: min(600px, calc(100dvh - 7rem));
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: rgb(255 255 255 / 82%);
	backdrop-filter: saturate(180%) blur(22px);
	-webkit-backdrop-filter: saturate(180%) blur(22px);
	border: 1px solid rgb(255 255 255 / 70%);
	border-radius: 18px;
	box-shadow:
		0 2px 4px rgb(10 29 61 / 7%),
		0 12px 26px rgb(10 29 61 / 10%),
		0 34px 70px rgb(10 29 61 / 16%),
		inset 0 1px 0 rgb(255 255 255 / 80%);
	opacity: 0;
	transform: translateY(12px) scale(.98);
	transform-origin: bottom right;
	transition: opacity .24s var(--c-ease), transform .28s var(--c-ease);
}
.msat-panel.is-visible { opacity: 1; transform: translateY(0) scale(1); }

.msat-panel__head {
	display: flex;
	align-items: flex-start;
	gap: 1rem;
	padding: 1.05rem 1.15rem;
	background: linear-gradient(145deg, var(--c-navy), var(--c-navy-deep));
	color: #fff;
}
.msat-panel__title { margin: 0; font-size: 1rem; font-weight: 600; }
.msat-panel__intro { margin: .2rem 0 0; font-size: .82rem; color: rgb(255 255 255 / 75%); }

.msat-panel__close {
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	width: 30px; height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgb(255 255 255 / 12%);
	color: #fff;
	cursor: pointer;
	transition: background-color .18s ease;
}
.msat-panel__close:hover { background: rgb(255 255 255 / 22%); }

/* Log */
.msat-panel__log {
	flex: 1 1 auto;
	min-height: 140px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 1.1rem;
	background: rgb(247 249 252 / 70%);
	display: flex;
	flex-direction: column;
	gap: .6rem;
	scrollbar-width: thin;
}
.msat-log__empty { margin: auto; text-align: center; color: var(--c-muted); font-size: .88rem; }

.msat-msg {
	max-width: 85%;
	padding: .6rem .8rem;
	border-radius: 14px;
	font-size: .9rem;
	animation: msat-in .3s var(--c-ease) both;
}
@keyframes msat-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

.msat-msg--visitor {
	align-self: flex-end;
	background: linear-gradient(140deg, var(--c-navy), var(--c-navy-deep));
	color: #fff;
	box-shadow: 0 1px 2px rgb(10 29 61 / 14%), 0 4px 12px rgb(10 29 61 / 14%);
	border-bottom-right-radius: 5px;
}
.msat-msg--admin {
	align-self: flex-start;
	background: rgb(255 255 255 / 86%);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	color: var(--c-ink);
	border: 1px solid rgb(255 255 255 / 80%);
	box-shadow: var(--c-shadow, 0 1px 2px rgb(10 29 61 / 6%));
	border-bottom-left-radius: 5px;
}

.msat-msg__text { word-wrap: break-word; overflow-wrap: anywhere; }
.msat-msg__img { display: block; max-width: 100%; border-radius: 9px; margin-bottom: .4rem; }
.msat-msg__time { display: block; margin-top: .25rem; font-size: .68rem; opacity: .65; }

/* Form */
.msat-panel__form { padding: .8rem; border-top: 1px solid var(--c-line); background: #fff; }
.msat-panel__identity { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .5rem; }
/* A plain display rule beats the browser's own [hidden] styling, so the
   attribute silently stops working. This puts it back. */
.msat-panel__identity[hidden] { display: none; }

.msat-input,
.msat-textarea {
	width: 100%;
	padding: .55rem .7rem;
	font: inherit;
	font-size: .88rem;
	color: var(--c-ink);
	background: #f7f9fc;
	border: 1px solid var(--c-line);
	border-radius: 10px;
	transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.msat-input:focus,
.msat-textarea:focus {
	outline: none;
	background: #fff;
	border-color: var(--c-gold);
	box-shadow: 0 0 0 3px rgb(217 164 65 / 20%);
}

.msat-panel__row { display: flex; align-items: flex-end; gap: .45rem; }

.msat-textarea {
	flex: 1 1 auto;
	min-height: 40px;
	max-height: 120px;
	resize: none;
	line-height: 1.45;
}

.msat-attach,
.msat-send {
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	border-radius: 10px;
	cursor: pointer;
	border: 1px solid var(--c-line);
	background: #f7f9fc;
	color: var(--c-muted);
	transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .18s var(--c-ease);
}
.msat-attach:hover { color: var(--c-navy); border-color: var(--c-navy); }

.msat-send { background: var(--c-gold); border-color: var(--c-gold); color: var(--c-navy-deep); }
.msat-send:hover { background: var(--c-gold-light); border-color: var(--c-gold-light); }
.msat-send:active { transform: scale(.94); }

.is-sending .msat-send { opacity: .6; pointer-events: none; }

.msat-attach-preview { position: relative; display: inline-block; margin-bottom: .5rem; }
.msat-attach-preview img { max-height: 76px; width: auto; border-radius: 9px; display: block; }
.msat-attach-remove {
	position: absolute;
	top: -7px; right: -7px;
	width: 22px; height: 22px;
	display: grid; place-items: center;
	padding: 0;
	font-size: 15px;
	line-height: 1;
	color: #fff;
	background: var(--c-navy);
	border: 2px solid #fff;
	border-radius: 50%;
	cursor: pointer;
}

/* Honeypot: off-screen, never display:none -- bots skip hidden fields. */
.msat-hp {
	position: absolute !important;
	left: -9999px;
	width: 1px; height: 1px;
	opacity: 0;
}

.msat-status { margin: .5rem 0 0; min-height: 1.1em; font-size: .78rem; color: var(--c-muted); }
.msat-status.is-error { color: #b32d2e; }

/* -------------------------------------------------------------------------
   Small screens: fill the viewport, like a messaging app
   ---------------------------------------------------------------------- */

@media (max-width: 480px) {
	.msat-panel {
		position: fixed;
		inset: auto 0 0 0;
		width: 100%;
		max-height: 86dvh;
		border-radius: 18px 18px 0 0;
		border-bottom: 0;
		transform-origin: bottom center;
	}
	.msat-panel__identity { grid-template-columns: 1fr; }
}

@media (prefers-reduced-transparency: reduce) {
	.msat-panel, .msat-msg--admin { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background: #fff !important; }
	.msat-panel__log { background: #f7f9fc !important; }
}

@media (prefers-reduced-motion: reduce) {
	.msat-fab, .msat-fab__icon, .msat-panel, .msat-msg, .msat-send {
		transition-duration: .01ms !important;
		animation: none !important;
	}
	.msat-fab::after { animation: none !important; }
}

/* -------------------------------------------------------------------------
   Contact form

   Same endpoint and same inbox as the floating widget, so it is styled
   alongside it rather than in the theme.
   ---------------------------------------------------------------------- */

.msat-contact {
	max-width: 620px;
	margin-top: 1.5rem;
}

.msat-contact__row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0 1rem;
}

.msat-contact__field { margin: 0 0 1rem; }

.msat-contact__field label {
	display: block;
	margin-bottom: .35rem;
	font-size: .82rem;
	font-weight: 700;
	color: var(--navy, #0f2a56);
}

.msat-contact__field input,
.msat-contact__field textarea {
	width: 100%;
	padding: .8rem .9rem;
	border: 1px solid var(--line, #e3e1dc);
	border-radius: 12px;
	background: #fff;
	font-family: inherit;
	font-size: 1rem;              /* 16px minimum, or iOS zooms on focus */
	line-height: 1.5;
	color: var(--ink, #16202e);
	transition: border-color .18s ease, box-shadow .18s ease;
}

.msat-contact__field textarea { resize: vertical; min-height: 140px; }

.msat-contact__field input:focus,
.msat-contact__field textarea:focus {
	outline: none;
	border-color: var(--gold, #d9a441);
	box-shadow: 0 0 0 3px rgb(217 164 65 / 22%);
}

/* The honeypot. Hidden from people without display:none, which some
   bots check for. */
.msat-contact__hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.msat-contact__note {
	margin: 0 0 1rem;
	padding: .8rem 1rem;
	border-radius: 12px;
	font-size: .9rem;
	font-weight: 600;
	line-height: 1.5;
}

.msat-contact__note[hidden] { display: none; }

.msat-contact__note.is-good {
	border: 1px solid rgb(27 127 140 / 40%);
	background: rgb(27 127 140 / 10%);
	color: #11606b;
}

.msat-contact__note.is-bad {
	border: 1px solid rgb(179 45 46 / 40%);
	background: rgb(179 45 46 / 7%);
	color: #a32627;
}

.msat-contact__small {
	margin: .85rem 0 0;
	font-size: .82rem;
	color: var(--muted, #5b6675);
}

@media (max-width: 600px) {
	.msat-contact__row { grid-template-columns: 1fr; }
	.msat-contact__go { width: 100%; justify-content: center; }
}
