/* ==========================================================================
   AI CHAT WIDGET — Asisten Informasi Pendidikan Matematika FKIP ULM
   ========================================================================== */

.pm-chat-launcher {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 8px;
  border: none;
  border-radius: 9999px;
  background: var(--color-terracotta, #D57F52);
  color: #FFFFFF;
  font-family: var(--font-heading, 'Space Grotesk', sans-serif);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(213, 127, 82, 0.45);
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}
.pm-chat-launcher:hover { transform: translateY(-3px); background: var(--color-terracotta-hover, #BF6E43); }
.pm-chat-launcher:focus-visible { outline: 3px solid rgba(213,127,82,0.45); outline-offset: 3px; }
.pm-chat-launcher-icon {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.pm-chat-launcher-avatar {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.pm-chat-launcher-icon::after {
  content: '';
  position: absolute; top: -1px; right: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #4ADE80; border: 2px solid var(--color-terracotta, #D57F52);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.6);
}
.pm-chat-launcher-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.pm-chat-launcher-text small { font-size: 0.68rem; font-weight: 600; opacity: 0.88; }
.pm-chat-launcher.is-hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }

/* Panel */
.pm-chat-panel {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1001;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg-card, #FAF6EF);
  border: 1px solid rgba(54, 68, 51, 0.14);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(28, 36, 26, 0.28);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom left;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease, width 0.24s ease, height 0.24s ease, left 0.24s ease, bottom 0.24s ease, border-radius 0.24s ease;
  font-family: var(--font-body, -apple-system, 'Segoe UI', sans-serif);
}
.pm-chat-panel.is-open { opacity: 1; transform: none; pointer-events: auto; }
.pm-chat-panel.is-fullscreen {
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
  z-index: 1200;
}
.pm-chat-panel.is-fullscreen .pm-chat-header {
  padding: 16px max(24px, calc((100vw - 880px) / 2));
}
.pm-chat-panel.is-fullscreen .pm-chat-body {
  padding: 24px max(24px, calc((100vw - 880px) / 2)) 16px;
}
.pm-chat-panel.is-fullscreen .pm-chat-footer {
  padding: 14px max(24px, calc((100vw - 880px) / 2)) 18px;
}

.pm-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 14px 18px;
  background: linear-gradient(135deg, #1B3529 0%, var(--color-forest, #283325) 100%);
  color: #FFFFFF;
  flex-shrink: 0;
}
.pm-chat-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}
.pm-chat-avatar-img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.pm-chat-title { flex: 1; min-width: 0; }
.pm-chat-title strong { display: block; font-family: var(--font-heading, sans-serif); font-size: 0.98rem; }
.pm-chat-title span { display: flex; align-items: center; gap: 6px; font-size: 0.74rem; opacity: 0.85; }
.pm-chat-title span::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #4ADE80; }
.pm-chat-hbtn {
  width: 32px; height: 32px; border-radius: 10px; border: none;
  background: rgba(255,255,255,0.12); color: #FFFFFF; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease;
}
.pm-chat-hbtn:hover { background: rgba(255,255,255,0.24); }

.pm-chat-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}

/* Mascot Welcome Card */
.pm-chat-welcome-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px;
  background: #FFFFFF;
  border: 1px solid rgba(54, 68, 51, 0.12);
  border-radius: 18px;
  box-shadow: 0 6px 20px rgba(40, 51, 37, 0.07);
  margin-bottom: 2px;
}
.pm-chat-welcome-mascot {
  width: 76px;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.12));
  transition: transform 0.25s ease;
}
.pm-chat-welcome-mascot:hover {
  transform: scale(1.06) rotate(-2deg);
}
.pm-chat-welcome-body {
  flex: 1;
  min-width: 0;
}
.pm-chat-welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(213, 127, 82, 0.14);
  color: var(--color-terracotta, #D57F52);
  font-size: 0.68rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.pm-chat-welcome-title {
  font-family: var(--font-heading, sans-serif);
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--color-forest, #283325);
  margin-bottom: 4px;
}
.pm-chat-welcome-desc {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-dark, #262E23);
  opacity: 0.9;
}

.pm-chat-msg { display: flex; gap: 8px; max-width: 100%; align-items: flex-end; }
.pm-chat-msg.user { justify-content: flex-end; }
.pm-chat-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #FFFFFF;
  border: 1.5px solid rgba(54, 68, 51, 0.14);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  flex-shrink: 0;
  overflow: hidden;
  margin-bottom: 2px;
}
.pm-chat-msg-avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.pm-chat-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.pm-chat-msg.bot .pm-chat-bubble {
  background: #FFFFFF;
  color: var(--text-dark, #262E23);
  border: 1px solid rgba(54, 68, 51, 0.1);
  border-bottom-left-radius: 4px;
}
.pm-chat-msg.user .pm-chat-bubble {
  background: var(--color-forest, #283325);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.pm-chat-bubble p { margin: 0 0 6px; }
.pm-chat-bubble p:last-child { margin-bottom: 0; }
.pm-chat-bubble ul, .pm-chat-bubble ol { margin: 4px 0 6px; padding-left: 18px; }
.pm-chat-bubble li { margin-bottom: 3px; }
.pm-chat-bubble a { color: var(--color-terracotta, #D57F52); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.pm-chat-bubble strong { font-weight: 700; color: inherit; }

.pm-chat-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pm-chat-source {
  display: inline-flex; align-items: center; gap: 5px;
  max-width: 100%;
  padding: 4px 10px; border-radius: 9999px;
  background: rgba(114, 138, 116, 0.12);
  color: var(--color-forest, #283325) !important;
  font-size: 0.72rem; font-weight: 700; text-decoration: none !important;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pm-chat-source:hover { background: rgba(114, 138, 116, 0.24); }

.pm-chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 4px; }
.pm-chat-chip {
  border: 1px solid rgba(213, 127, 82, 0.35);
  background: rgba(213, 127, 82, 0.08);
  color: #A85A2F;
  border-radius: 9999px;
  padding: 6px 12px;
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer; text-align: left;
  transition: background 0.15s ease;
  font-family: inherit;
}
.pm-chat-chip:hover { background: rgba(213, 127, 82, 0.18); }
.pm-chat-chip.is-link { border-color: rgba(114,138,116,0.4); background: rgba(114,138,116,0.1); color: var(--color-forest, #283325); text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }

.pm-chat-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.pm-chat-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-moss, #728A74);
  animation: pmChatDot 1.2s infinite ease-in-out;
}
.pm-chat-typing i:nth-child(2) { animation-delay: 0.15s; }
.pm-chat-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pmChatDot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.pm-chat-footer {
  flex-shrink: 0;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(54, 68, 51, 0.1);
  background: var(--bg-card-subtle, #F3EBDD);
}
.pm-chat-form { display: flex; align-items: flex-end; gap: 8px; }
.pm-chat-input {
  flex: 1;
  resize: none;
  min-height: 42px; max-height: 110px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(54, 68, 51, 0.18);
  background: #FFFFFF;
  color: var(--text-dark, #262E23);
  font-family: inherit; font-size: 0.88rem; line-height: 1.4;
  outline: none;
}
.pm-chat-input:focus { border-color: var(--color-terracotta, #D57F52); box-shadow: 0 0 0 3px rgba(213,127,82,0.15); }
.pm-chat-send {
  width: 42px; height: 42px; border-radius: 12px; border: none;
  background: var(--color-terracotta, #D57F52); color: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.pm-chat-send:hover { background: var(--color-terracotta-hover, #BF6E43); }
.pm-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.pm-chat-disclaimer { margin: 7px 2px 0; font-size: 0.68rem; color: var(--text-muted, #586655); text-align: center; line-height: 1.4; }
.pm-chat-disclaimer a { color: inherit; font-weight: 700; }

/* Dark mode */
[data-theme="dark"] .pm-chat-panel { background: #1C231B; border-color: rgba(255,255,255,0.08); }
[data-theme="dark"] .pm-chat-welcome-card { background: #262F25; border-color: rgba(255,255,255,0.08); }
[data-theme="dark"] .pm-chat-welcome-title { color: #E9EDE6; }
[data-theme="dark"] .pm-chat-welcome-desc { color: #C4CEC0; }
[data-theme="dark"] .pm-chat-msg-avatar { background: #262F25; border-color: rgba(255,255,255,0.12); }
[data-theme="dark"] .pm-chat-msg.bot .pm-chat-bubble { background: #262F25; color: #E9EDE6; border-color: rgba(255,255,255,0.06); }
[data-theme="dark"] .pm-chat-msg.user .pm-chat-bubble { background: var(--color-terracotta, #D57F52); }
[data-theme="dark"] .pm-chat-footer { background: #171D16; border-color: rgba(255,255,255,0.06); }
[data-theme="dark"] .pm-chat-input { background: #262F25; color: #E9EDE6; border-color: rgba(255,255,255,0.1); }
[data-theme="dark"] .pm-chat-source,
[data-theme="dark"] .pm-chat-chip.is-link { color: #DCE6D8 !important; background: rgba(114,138,116,0.22); }
[data-theme="dark"] .pm-chat-chip { color: #F2B48F; }
[data-theme="dark"] .pm-chat-disclaimer { color: #9AA696; }

/* Mobile: compact launcher pill + full screen sheet */
@media (max-width: 640px) {
  .pm-chat-launcher {
    left: 12px;
    bottom: 14px;
    height: 40px;
    padding: 4px 12px 4px 5px;
    gap: 7px;
    font-size: 0.78rem;
    box-shadow: 0 6px 18px rgba(213, 127, 82, 0.38);
  }
  .pm-chat-launcher-icon {
    width: 30px;
    height: 30px;
    border-width: 1.5px;
  }
  .pm-chat-launcher-icon::after {
    width: 8px;
    height: 8px;
    border-width: 1.5px;
  }
  .pm-chat-launcher-text {
    white-space: nowrap;
  }
  .pm-chat-launcher-text small {
    display: none;
  }
}

@media (max-width: 560px) {
  .pm-chat-panel {
    left: 0; right: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 88vh; max-height: 88vh;
    border-radius: 22px 22px 0 0;
  }
  .pm-chat-panel.is-fullscreen {
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

@media print { .pm-chat-launcher, .pm-chat-panel { display: none !important; } }

