/* Alliance Smart Chat — front-end widget
   Hardened & fully scoped under #alliance-chat-root so host themes can't bleed in.
   Unique class prefix: aesw-  */

#alliance-chat-root {
	--ac-accent: #FF7A00;
	--ac-accent-2: #ff9836;
	--ac-bg: #14161c;
	--ac-surface: #1c1f27;
	--ac-surface-2: #242833;
	--ac-text: #f3f5f8;
	--ac-muted: #9aa3b0;
	--ac-border: rgba(255,255,255,.10);
	--ac-user-text: #ffffff;
	--ac-radius: 18px;
	--ac-bubble-radius: 16px;
	--ac-shadow: 0 24px 60px -12px rgba(0,0,0,.55);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	line-height: 1.5;
}

#alliance-chat-root.aesw-light {
	--ac-bg: #ffffff;
	--ac-surface: #f6f7f9;
	--ac-surface-2: #eceef2;
	--ac-text: #11151c;
	--ac-muted: #6b7280;
	--ac-border: rgba(0,0,0,.10);
	--ac-shadow: 0 24px 60px -12px rgba(20,30,50,.25);
}

/* ---- Reset: neutralize inherited theme styles INSIDE the widget only ---- */
#alliance-chat-root, #alliance-chat-root * { box-sizing: border-box; }
#alliance-chat-root button,
#alliance-chat-root input,
#alliance-chat-root textarea,
#alliance-chat-root select {
	font-family: inherit !important;
	font-size: 14px;
	letter-spacing: normal !important;
	text-transform: none !important;
	text-shadow: none !important;
	box-shadow: none !important;
	outline: none !important;
	-webkit-appearance: none !important;
	-moz-appearance: none !important;
	appearance: none !important;
	margin: 0 !important;
	min-height: 0 !important;
	min-width: 0 !important;
	max-width: none !important;
	line-height: normal !important;
	text-align: left;
	float: none !important;
	transition: none;
}
#alliance-chat-root button { border: none; background: none; cursor: pointer; height: auto; width: auto; }
#alliance-chat-root a { text-decoration: none !important; box-shadow: none !important; border: none !important; }
#alliance-chat-root p { margin: 0; padding: 0; }
#alliance-chat-root img { max-width: 100%; height: auto; box-shadow: none !important; border: none !important; border-radius: inherit; }
#alliance-chat-root svg { vertical-align: middle; }

/* ---- Launcher ---- */
#alliance-chat-root .aesw-launcher {
	position: fixed !important; bottom: 24px !important; right: 24px !important; left: auto !important; z-index: 999998 !important;
	display: flex; align-items: center; gap: 10px;
	background: linear-gradient(135deg, var(--ac-accent), var(--ac-accent-2)) !important;
	color: var(--ac-user-text, #fff) !important;
	padding: 14px 20px 14px 16px !important; border-radius: 999px !important;
	font-size: 15px !important; font-weight: 600; letter-spacing: .2px;
	box-shadow: 0 12px 30px -6px rgba(255,122,0,.45) !important;
	transition: transform .18s ease, box-shadow .18s ease !important;
}
#alliance-chat-root .aesw-launcher:hover { transform: translateY(-2px) scale(1.02); }
#alliance-chat-root .aesw-launcher svg { width: 24px; height: 24px; }
#alliance-chat-root .aesw-launcher .aesw-pulse {
	position: absolute; top: -3px; right: -3px; width: 14px; height: 14px;
	background: #22c55e; border-radius: 50%; border: 2px solid #fff; animation: aesw-pulse 2s infinite;
}
@keyframes aesw-pulse { 0%{box-shadow:0 0 0 0 rgba(34,197,94,.6)} 70%{box-shadow:0 0 0 10px rgba(34,197,94,0)} 100%{box-shadow:0 0 0 0 rgba(34,197,94,0)} }

/* ---- Panel ---- */
#alliance-chat-root .aesw-panel {
	position: fixed !important; bottom: 24px !important; right: 24px !important; left: auto !important; z-index: 999999 !important;
	width: 384px; max-width: calc(100vw - 32px);
	height: 620px; max-height: calc(100vh - 48px);
	background: var(--ac-bg) !important; color: var(--ac-text) !important;
	border: 1px solid var(--ac-border) !important; border-radius: 22px !important;
	box-shadow: var(--ac-shadow) !important;
	display: flex; flex-direction: column; overflow: hidden;
	transform: translateY(16px) scale(.98); opacity: 0; pointer-events: none;
	transition: transform .22s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}
#alliance-chat-root .aesw-panel.aesw-open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }

/* ---- Header ---- */
#alliance-chat-root .aesw-head {
	padding: 16px 18px; display: flex; align-items: center; gap: 12px;
	background: linear-gradient(135deg, rgba(255,122,0,.16), rgba(255,122,0,.02));
	border-bottom: 1px solid var(--ac-border); position: relative;
}
#alliance-chat-root .aesw-avatar {
	width: 42px; height: 42px; border-radius: 12px; flex: 0 0 auto;
	background: linear-gradient(135deg,var(--ac-accent),var(--ac-accent-2));
	display: flex; align-items: center; justify-content: center;
	color: var(--ac-user-text,#fff); font-weight: 700; font-size: 18px; overflow: hidden;
}
#alliance-chat-root .aesw-avatar img { width: 100%; height: 100%; object-fit: cover; }
#alliance-chat-root .aesw-titles { min-width: 0; flex: 1; }
#alliance-chat-root .aesw-title { font-weight: 700; font-size: 15px; line-height: 1.2; color: var(--ac-text); }
#alliance-chat-root .aesw-sub { font-size: 12px; color: var(--ac-muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
#alliance-chat-root .aesw-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: 0 0 auto; }
#alliance-chat-root .aesw-close { background: transparent !important; color: var(--ac-text) !important; opacity: .7; font-size: 22px !important; line-height: 1 !important; padding: 4px !important; }
#alliance-chat-root .aesw-close:hover { opacity: 1; }
#alliance-chat-root .aesw-newchat { background: transparent !important; color: var(--ac-text) !important; opacity: .65; border: none; cursor: pointer; padding: 4px !important; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: opacity .2s, background .2s; margin-right: 2px; }
#alliance-chat-root .aesw-newchat svg { width: 18px; height: 18px; pointer-events: none; }
#alliance-chat-root .aesw-newchat:hover { opacity: 1; background: rgba(255,255,255,.08) !important; }

/* ---- Messages ---- */
#alliance-chat-root .aesw-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
#alliance-chat-root .aesw-body::-webkit-scrollbar { width: 8px; }
#alliance-chat-root .aesw-body::-webkit-scrollbar-thumb { background: var(--ac-surface-2); border-radius: 8px; }

#alliance-chat-root .aesw-msg { max-width: 82%; padding: 11px 14px; border-radius: var(--ac-bubble-radius,16px); font-size: 14px; line-height: 1.5; word-wrap: break-word; animation: aesw-in .25s ease; }
#alliance-chat-root .aesw-msg p { margin: 0 0 6px; }
#alliance-chat-root .aesw-msg p:last-child { margin: 0; }
@keyframes aesw-in { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }
#alliance-chat-root .aesw-msg.bot { align-self: flex-start; background: var(--ac-surface); color: var(--ac-text); border: 1px solid var(--ac-border); border-bottom-left-radius: 4px; }
#alliance-chat-root .aesw-msg.agent { align-self: flex-start; background: var(--ac-surface-2); color: var(--ac-text); border: 1px solid var(--ac-accent); border-bottom-left-radius: 4px; }
#alliance-chat-root .aesw-msg.user { align-self: flex-end; background: linear-gradient(135deg,var(--ac-accent),var(--ac-accent-2)); color: var(--ac-user-text,#fff); border-bottom-right-radius: 4px; }
#alliance-chat-root .aesw-msg .aesw-attach img { max-width: 100%; border-radius: 10px; margin-top: 6px; }

/* ---- Typing ---- */
#alliance-chat-root .aesw-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: var(--ac-surface); border-radius: 16px; border: 1px solid var(--ac-border); }
#alliance-chat-root .aesw-typing span { width: 7px; height: 7px; background: var(--ac-muted); border-radius: 50%; animation: aesw-bounce 1.2s infinite; }
#alliance-chat-root .aesw-typing span:nth-child(2){animation-delay:.15s}
#alliance-chat-root .aesw-typing span:nth-child(3){animation-delay:.3s}
@keyframes aesw-bounce { 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-5px);opacity:1} }

/* ---- Quick chips ---- */
#alliance-chat-root .aesw-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 6px; }
#alliance-chat-root .aesw-chip { background: var(--ac-surface) !important; border: 1px solid var(--ac-border) !important; color: var(--ac-text) !important; padding: 8px 13px !important; border-radius: 999px !important; font-size: 13px !important; cursor: pointer; transition: all .15s; }
#alliance-chat-root .aesw-chip:hover { border-color: var(--ac-accent) !important; color: var(--ac-accent) !important; }

/* ---- Inline forms ---- */
#alliance-chat-root .aesw-form { align-self: stretch; background: var(--ac-surface); border: 1px solid var(--ac-border); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 9px; animation: aesw-in .25s ease; }
#alliance-chat-root .aesw-form h4 { margin: 0 0 2px !important; font-size: 14px !important; color: var(--ac-text); }
#alliance-chat-root .aesw-form label { font-size: 12px; color: var(--ac-muted); display: block; }
#alliance-chat-root .aesw-form input,
#alliance-chat-root .aesw-form select,
#alliance-chat-root .aesw-form textarea {
	width: 100% !important; background: var(--ac-bg) !important; color: var(--ac-text) !important;
	border: 1px solid var(--ac-border) !important; border-radius: 10px !important; padding: 10px 12px !important; font-size: 14px !important;
}
#alliance-chat-root .aesw-form input:focus,
#alliance-chat-root .aesw-form select:focus,
#alliance-chat-root .aesw-form textarea:focus { border-color: var(--ac-accent) !important; }
#alliance-chat-root .aesw-form .aesw-submit { background: linear-gradient(135deg,var(--ac-accent),var(--ac-accent-2)) !important; color: var(--ac-user-text,#fff) !important; padding: 12px !important; border-radius: 12px !important; font-weight: 700; cursor: pointer; font-size: 14px !important; width: 100% !important; }
#alliance-chat-root .aesw-form .aesw-submit:hover { filter: brightness(1.06); }
#alliance-chat-root .aesw-form .aesw-err { color: #ff6b6b; font-size: 12px; }
#alliance-chat-root .aesw-uprow { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
#alliance-chat-root .aesw-uplabel { display:inline-flex; align-items:center; gap:6px; cursor:pointer; font-size:13px; color:var(--ac-accent); }
#alliance-chat-root .aesw-thumbs { display:flex; gap:6px; flex-wrap:wrap; }
#alliance-chat-root .aesw-thumbs img { width:46px; height:46px; object-fit:cover; border-radius:8px; }

/* ---- Footer input ---- */
#alliance-chat-root .aesw-foot { border-top: 1px solid var(--ac-border); padding: 12px; }
#alliance-chat-root .aesw-inputrow { display: flex; align-items: flex-end; gap: 8px; background: var(--ac-surface) !important; border: 1px solid var(--ac-border) !important; border-radius: 14px !important; padding: 6px 6px 6px 12px !important; }
#alliance-chat-root .aesw-inputrow.aesw-focus { border-color: var(--ac-accent) !important; }
#alliance-chat-root .aesw-inputrow textarea {
	flex: 1; resize: none !important; border: none !important; background: transparent !important; color: var(--ac-text) !important;
	font-size: 14px !important; max-height: 110px; padding: 6px 0 !important; box-shadow: none !important; width: auto !important;
}
#alliance-chat-root .aesw-iconbtn { background: transparent !important; color: var(--ac-muted) !important; padding: 6px !important; display:flex; }
#alliance-chat-root .aesw-iconbtn:hover { color: var(--ac-accent) !important; }
#alliance-chat-root .aesw-send {
	background: linear-gradient(135deg,var(--ac-accent),var(--ac-accent-2)) !important; color: var(--ac-user-text,#fff) !important;
	width: 38px !important; height: 38px !important; min-width: 38px !important; border-radius: 11px !important;
	display: flex !important; align-items: center; justify-content: center; flex: 0 0 auto; padding: 0 !important;
}
#alliance-chat-root .aesw-send:hover { filter: brightness(1.08); }
#alliance-chat-root .aesw-send svg { width: 18px; height: 18px; }
#alliance-chat-root .aesw-foot-meta { display: flex; justify-content: space-between; align-items:center; margin-top: 8px; font-size: 11px; color: var(--ac-muted); }
#alliance-chat-root .aesw-foot-meta a { color: var(--ac-muted) !important; }
#alliance-chat-root .aesw-foot-meta a:hover { color: var(--ac-accent) !important; }
#alliance-chat-root .aesw-human-btn { background:transparent !important; color: var(--ac-muted) !important; cursor:pointer; font-size:11px !important; }
#alliance-chat-root .aesw-human-btn:hover { color: var(--ac-accent) !important; }

/* ---- Left placement option ---- */
#alliance-chat-root.aesw-left .aesw-launcher { right: auto !important; left: 24px !important; }
#alliance-chat-root.aesw-left .aesw-panel { right: auto !important; left: 24px !important; }

@media (max-width: 480px) {
	#alliance-chat-root .aesw-panel { right: 8px !important; left: auto !important; bottom: 8px !important; height: calc(100vh - 16px); width: calc(100vw - 16px); border-radius: 18px !important; }
	#alliance-chat-root .aesw-launcher { bottom: 16px !important; right: 16px !important; }
	#alliance-chat-root .aesw-launcher span.aesw-launcher-text { display: none; }
	#alliance-chat-root.aesw-left .aesw-launcher { left: 16px !important; right: auto !important; }
	#alliance-chat-root.aesw-left .aesw-panel { left: 8px !important; right: 8px !important; }
}
