/* Embayu — AI Handbook Assistant */
#embayu-ai .eai-panel[hidden],
#embayu-ai .eai-fbwrap[hidden],
#embayu-ai .eai-fblink[hidden],
#embayu-ai .eai-fb[hidden] { display: none !important; }

#embayu-ai {
	position: fixed; right: 0; top: auto; bottom: 120px;
	z-index: 9998; font-family: inherit;
}

#embayu-ai .eai-fab {
	display: inline-flex; align-items: center; justify-content: center;
	background: #3f7a00; color: #fff;
	border: 1px solid rgba(255, 255, 255, .22); border-right: 0;
	border-radius: 8px 0 0 8px;
	padding: 0; width: 38px; height: 46px;
	min-width: 38px; min-height: 46px;
	line-height: 1;
	box-shadow: -2px 0 10px rgba(16, 24, 32, .14); cursor: pointer; opacity: .72;
	transition: opacity .18s ease;
}
#embayu-ai .eai-fab .eai-spark { display: block; width: 19px; height: 19px; }
#embayu-ai .eai-sr {
	position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
#embayu-ai .eai-fab:hover { background: #356800; opacity: 1; }
#embayu-ai .eai-fab:focus-visible { outline: 3px solid #bae878; outline-offset: -3px; }
#embayu-ai .eai-fab:focus-visible { outline: 3px solid #bae878; outline-offset: 2px; }

#embayu-ai .eai-panel {
	position: fixed; right: 10px; top: 50%; transform: translateY(-50%);
	width: min(380px, calc(100vw - 32px));
	background: #fff; border: 1px solid #d9d6cd; border-radius: 14px; overflow: hidden;
	box-shadow: 0 18px 48px rgba(16, 24, 32, .26); display: flex; flex-direction: column;
	max-height: min(72vh, 560px);
}

#embayu-ai .eai-head {
	display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
	background: #22262a; color: #f2efe8; padding: .8rem .9rem;
}
#embayu-ai .eai-head strong { display: block; font-size: .95rem; }
#embayu-ai .eai-head small { display: block; color: #cfcabc; font-size: .64rem; line-height: 1.3; margin-top: .12rem; letter-spacing: .01em; text-wrap: balance; }
#embayu-ai .eai-close {
	background: transparent; border: 0; color: #f2efe8; font-size: 1.5rem; line-height: 1;
	cursor: pointer; padding: 0 .2rem; min-width: 32px; min-height: 32px;
}
#embayu-ai .eai-close:hover { color: #bae878; }

#embayu-ai .eai-log { padding: .85rem .9rem; overflow-y: auto; flex: 1 1 auto; background: #f7f6f2; }
#embayu-ai .eai-msg { margin: 0 0 .7rem; font-size: .87rem; line-height: 1.5; }
#embayu-ai .eai-msg.eai-q {
	background: #eef4e6; color: #101820; border-radius: 10px 10px 2px 10px;
	padding: .5rem .7rem; margin-left: 18%; font-weight: 600;
}
#embayu-ai .eai-msg.eai-a {
	background: #fff; color: #2c3540; border: 1px solid #e3e0d7; border-radius: 10px 10px 10px 2px;
	padding: .6rem .75rem; margin-right: 6%;
}
#embayu-ai .eai-msg.eai-a a { color: #3f7a00; text-decoration: underline; }
#embayu-ai .eai-src { margin: .45rem 0 0; padding: .45rem 0 0; border-top: 1px dashed #d9d6cd; font-size: .76rem; color: #55606b; }
#embayu-ai .eai-src a { color: #3b5a74; text-decoration: underline; }
#embayu-ai .eai-think { color: #55606b; font-style: italic; }

#embayu-ai .eai-form { display: flex; gap: .45rem; padding: .6rem .7rem; border-top: 1px solid #e3e0d7; background: #fff; }
#embayu-ai .eai-input {
	flex: 1 1 auto; border: 1px solid #c9c5ba; border-radius: 8px; padding: .5rem .6rem;
	font-size: .86rem; color: #101820; min-height: 40px;
}
#embayu-ai .eai-input:focus { outline: 2px solid #3f7a00; outline-offset: 1px; border-color: #3f7a00; }
#embayu-ai .eai-send {
	background: #3b5a74; color: #fff; border: 0; border-radius: 8px; padding: .5rem .85rem;
	font-size: .84rem; font-weight: 600; cursor: pointer; min-height: 40px;
}
#embayu-ai .eai-send:hover { background: #2f4a60; }
#embayu-ai .eai-send[disabled] { opacity: .55; cursor: default; }

@media (max-width: 480px) {
	#embayu-ai { right: 0; top: auto; bottom: 96px; }
	#embayu-ai .eai-fab { width: 34px; height: 42px; min-width: 34px; min-height: 42px; }
	#embayu-ai .eai-fab .eai-spark { width: 17px; height: 17px; }
	#embayu-ai .eai-panel {
		right: 8px; left: 8px; width: auto; top: 8px; bottom: auto;
		transform: none; max-height: calc(100dvh - 24px);
	}
}
@media (prefers-reduced-motion: reduce) {
	#embayu-ai * { transition: none !important; animation: none !important; }
}

/* --- Borang cadangan / maklum balas --- */
#embayu-ai .eai-fbwrap { border-top: 1px solid #e3e0d7; background: #fff; }
#embayu-ai .eai-fblink {
	display: block; width: 100%; text-align: left; background: #f2f0ea; border: 0;
	color: #3b5a74; font-size: .78rem; font-weight: 600; padding: .55rem .9rem; cursor: pointer;
	min-height: 40px; text-decoration: underline;
}
#embayu-ai .eai-fblink:hover { background: #e9e6dd; color: #2f4a60; }
#embayu-ai .eai-fb { padding: .7rem .9rem .8rem; }
#embayu-ai .eai-fbnote { margin: 0 0 .55rem; font-size: .74rem; color: #55606b; line-height: 1.4; }
#embayu-ai .eai-fb label { display: block; margin-bottom: .45rem; }
#embayu-ai .eai-fbl { display: block; font-size: .72rem; color: #3f4a54; font-weight: 600; margin-bottom: .15rem; }
#embayu-ai .eai-fb input,
#embayu-ai .eai-fb textarea {
	width: 100%; box-sizing: border-box; border: 1px solid #c9c5ba; border-radius: 7px;
	padding: .42rem .5rem; font-size: .82rem; color: #101820; font-family: inherit;
}
#embayu-ai .eai-fb input:focus,
#embayu-ai .eai-fb textarea:focus { outline: 2px solid #3f7a00; outline-offset: 1px; border-color: #3f7a00; }
#embayu-ai .eai-fbact { display: flex; gap: .5rem; margin-top: .3rem; }
#embayu-ai .eai-fbsend {
	background: #3f7a00; color: #fff; border: 0; border-radius: 7px; padding: .45rem .85rem;
	font-size: .8rem; font-weight: 600; cursor: pointer; min-height: 38px;
}
#embayu-ai .eai-fbsend:hover { background: #356800; }
#embayu-ai .eai-fbcancel {
	background: #fff; color: #3f4a54; border: 1px solid #c9c5ba; border-radius: 7px;
	padding: .45rem .8rem; font-size: .8rem; cursor: pointer; min-height: 38px;
}
#embayu-ai .eai-fbstatus { margin: .45rem 0 0; font-size: .76rem; }
#embayu-ai .eai-fbstatus.ok { color: #2f6b00; }
#embayu-ai .eai-fbstatus.err { color: #9c2b20; }

/* --- Pautan "Tak tepat?" di bawah setiap jawapan --- */
#embayu-ai .eai-dispute {
	display: inline-block; margin-top: .45rem; padding: 0;
	background: none; border: 0; border-top: 1px dashed #d9d6cd; width: 100%;
	text-align: left; color: #6b6a63; font-size: .7rem; text-decoration: underline;
	cursor: pointer; min-height: 26px; padding-top: .35rem;
}
#embayu-ai .eai-dispute:hover { color: #9c2b20; }

/* --- Sembang baharu, cap masa, cadangan, cuba semula --- */
#embayu-ai .eai-head-act { display: flex; align-items: center; gap: .15rem; }
#embayu-ai .eai-new {
	background: transparent; border: 0; color: #cfcabc; cursor: pointer;
	min-width: 32px; min-height: 32px; border-radius: 6px; display: inline-flex;
	align-items: center; justify-content: center;
}
#embayu-ai .eai-new:hover { color: #bae878; background: rgba(255,255,255,.08); }

#embayu-ai .eai-time {
	display: block; margin-top: .3rem; font-size: .64rem; color: #8a8578;
	font-variant-numeric: tabular-nums;
}
#embayu-ai .eai-q .eai-time { text-align: right; }

#embayu-ai .eai-welcome { margin: 0 0 .8rem; }
#embayu-ai .eai-welcome p {
	margin: 0 0 .6rem; font-size: .87rem; line-height: 1.5; color: #2c3540;
	background: #fff; border: 1px solid #e3e0d7; border-radius: 10px; padding: .6rem .75rem;
}
#embayu-ai .eai-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
#embayu-ai .eai-chip {
	/* !important kerana tema menetapkan "button { color:#fff !important }" untuk semua butang */
	background: #eef4e6; color: #2f5c00 !important; border: 1px solid #cfe0bb; border-radius: 999px;
	padding: .38rem .7rem; font-size: .74rem; cursor: pointer; min-height: 32px; text-align: left;
}
#embayu-ai .eai-chip:hover { background: #e2eed3; border-color: #9fd06a; }

#embayu-ai .eai-retry {
	margin-top: .45rem; background: #fff; color: #3b5a74; border: 1px solid #c9c5ba;
	border-radius: 7px; padding: .3rem .6rem; font-size: .74rem; cursor: pointer; min-height: 30px;
}
#embayu-ai .eai-retry:hover { background: #f2f0ea; }
#embayu-ai .eai-fail { background: #fdf3f2 !important; border-color: #e8c9c5 !important; }

#embayu-ai .eai-msg.eai-a strong { font-weight: 700; color: #101820; }
#embayu-ai .eai-src-many { margin-top: .5rem; padding-top: .4rem; border-top: 1px dashed #d9d6cd; }
#embayu-ai .eai-src-many summary {
	cursor: pointer; font-size: .74rem; color: #55606b; font-weight: 600; list-style: none;
}
#embayu-ai .eai-src-many summary::-webkit-details-marker { display: none; }
#embayu-ai .eai-src-many summary::before { content: "▸ "; color: #3f7a00; }
#embayu-ai .eai-src-many[open] summary::before { content: "▾ "; }
#embayu-ai .eai-src-many a {
	display: block; font-size: .73rem; line-height: 1.35; margin-top: .3rem; color: #3b5a74;
}

/* --- Kebolehbacaan jawapan --- */
#embayu-ai .eai-msg.eai-a { line-height: 1.58; font-size: .88rem; }
#embayu-ai .eai-msg.eai-a p { margin: 0 0 .55rem; }
#embayu-ai .eai-msg.eai-a p:last-of-type { margin-bottom: .2rem; }
#embayu-ai .eai-msg.eai-a ul,
#embayu-ai .eai-msg.eai-a ol { margin: .35rem 0 .6rem; padding-left: 1.15rem; }
#embayu-ai .eai-msg.eai-a li { margin: 0 0 .3rem; padding-left: .1rem; }
#embayu-ai .eai-msg.eai-a ul li::marker { color: #3f7a00; }
#embayu-ai .eai-msg.eai-a ol li::marker { color: #3b5a74; font-weight: 700; }
#embayu-ai .eai-q { font-size: .86rem; }

/* --- gerakan FAB (1.0.71): lebih jelas, ada sandaran tanpa gerakan --- */
@keyframes eai-breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50%      { transform: scale(1.07) translateY(-2px); }
}
@keyframes eai-nudge {
  0%, 84%, 100% { transform: rotate(0deg); }
  87%           { transform: rotate(-5deg); }
  90%           { transform: rotate(5deg); }
  93%           { transform: rotate(-3deg); }
  96%           { transform: rotate(0deg); }
}
@keyframes eai-halo {
  0%, 70%, 100% { box-shadow: -2px 0 10px rgba(16,24,32,.14), 0 0 0 0 rgba(159,208,106,.55); }
  80%           { box-shadow: -2px 0 10px rgba(16,24,32,.14), 0 0 0 9px rgba(159,208,106,0); }
}
@keyframes eai-ripple {
  from { transform: scale(.75); opacity: .55; }
  to   { transform: scale(2.4);  opacity: 0; }
}
@keyframes eai-enter {
  from { transform: translateX(26px); opacity: 0; }
  to   { transform: translateX(0);    opacity: .72; }
}
@keyframes eai-glow-soft {
  0%, 100% { opacity: .72; }
  50%      { opacity: 1; }
}

#embayu-ai .eai-fab {
  position: relative;
  will-change: transform, opacity;
  animation:
    eai-enter .5s ease-out 1,
    eai-breathe 3.4s ease-in-out .5s infinite,
    eai-halo 7s ease-out .5s infinite;
}
#embayu-ai .eai-fab .eai-spark {
  animation: eai-nudge 9s ease-in-out 1s infinite;
}
#embayu-ai .eai-fab::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid #9fd06a;
  opacity: 0;
  pointer-events: none;
}
#embayu-ai .eai-fab.eai-tap::after { animation: eai-ripple .62s ease-out; }

#embayu-ai .eai-welcome p {
  transition: opacity .2s ease, transform .2s ease;
}
#embayu-ai .eai-welcome p.eai-fading { opacity: .12; transform: translateY(-2px); }

/* Pengguna yang menetapkan "kurangkan gerakan": tiada gerakan, tetapi masih
   ada nadi cahaya supaya butang tidak nampak mati. */
@media (prefers-reduced-motion: reduce) {
  #embayu-ai .eai-fab {
    animation: eai-glow-soft 3.2s ease-in-out infinite !important;
  }
  #embayu-ai .eai-fab .eai-spark { animation: none !important; }
  #embayu-ai .eai-fab.eai-tap::after { animation: none !important; }
  #embayu-ai .eai-welcome p { transition: none; }
}


/* --- gerakan panel + mesej (1.0.72) --- */
@keyframes eai-panel-in {
  from { opacity: 0; transform: translateY(16px) scale(.982); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes eai-panel-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(10px) scale(.99); }
}
@keyframes eai-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#embayu-ai #eai-panel:not([hidden]) {
  animation: eai-panel-in .28s cubic-bezier(.2, .85, .3, 1) both;
  transform-origin: bottom right;
}
#embayu-ai #eai-panel.eai-closing {
  animation: eai-panel-out .17s ease-in both;
}
#embayu-ai .eai-msg { animation: eai-rise .28s ease-out both; }
#embayu-ai .eai-welcome p { animation: eai-rise .36s ease-out 40ms both; }
#embayu-ai .eai-chip { animation: eai-rise .3s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  #embayu-ai #eai-panel:not([hidden]) { animation: none; }
  #embayu-ai #eai-panel.eai-closing { animation: none; }
  #embayu-ai .eai-msg,
  #embayu-ai .eai-welcome p,
  #embayu-ai .eai-chip { animation: none; }
}


/* --- pautan sumber: sorotan perenggan yang dituju (1.0.73) --- */
@keyframes eai-hit-flash {
  0%   { background-color: rgba(255, 224, 110, .90); box-shadow: 0 0 0 10px rgba(255, 224, 110, .45); }
  65%  { background-color: rgba(255, 224, 110, .55); box-shadow: 0 0 0 10px rgba(255, 224, 110, .18); }
  100% { background-color: rgba(255, 224, 110, 0);   box-shadow: 0 0 0 0 rgba(255, 224, 110, 0); }
}
.eai-hit {
  animation: eai-hit-flash 6s ease-out both;
  border-radius: 6px;
  scroll-margin-top: 96px;
}
@media (prefers-reduced-motion: reduce) {
  .eai-hit { animation: none; outline: 3px solid rgba(255, 200, 40, .85); outline-offset: 4px; }
}
