/* ============================================================
   AI TUTOR PANEL — style clean / macOS-like (putih/abu, rounded, shadow)
   ============================================================ */

:root {
  --ai-bg: #ffffff;
  --ai-bg-soft: #f5f6f8;
  --ai-border: #e5e7eb;
  --ai-text: #1f2430;
  --ai-text-soft: #6b7280;
  --ai-accent: #3b82f6;
  --ai-accent-soft: #eff4ff;
  --ai-user-bubble: #3b82f6;
  --ai-user-text: #ffffff;
  --ai-ai-bubble: #f2f3f5;
  --ai-shadow: 0 8px 40px rgba(17, 24, 39, 0.16);
  --ai-radius: 16px;
}

/* ---------- overlay ---------- */
.ai-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  z-index: 9998;
}
.ai-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* ---------- panel / drawer ---------- */
.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 100vw;
  background: var(--ai-bg);
  box-shadow: var(--ai-shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--ai-text);
  border-left: 1px solid var(--ai-border);
}
.ai-panel.open {
  transform: translateX(0);
}

/* ---------- header ---------- */
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ai-border);
  flex: 0 0 auto;
}
.ai-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.ai-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.ai-close {
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--ai-text-soft);
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}
.ai-close:hover {
  background: var(--ai-bg-soft);
  color: var(--ai-text);
}

/* ---------- tabs ---------- */
.ai-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--ai-bg-soft);
  border-bottom: 1px solid var(--ai-border);
  flex: 0 0 auto;
}
.ai-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--ai-text-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.ai-tab:hover {
  color: var(--ai-text);
}
.ai-tab.is-active {
  background: var(--ai-bg);
  color: var(--ai-accent);
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.1);
}

/* ---------- quick actions ---------- */
.ai-actions {
  display: none;
  gap: 8px;
  padding: 10px 14px 2px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.ai-action-btn {
  border: 1px solid var(--ai-border);
  background: var(--ai-accent-soft);
  color: var(--ai-accent);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ai-action-btn:hover:not(:disabled) {
  background: #e2ecff;
}
.ai-action-btn:active:not(:disabled) {
  transform: scale(0.97);
}
.ai-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- chat area ---------- */
.ai-chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.ai-chat::-webkit-scrollbar {
  width: 8px;
}
.ai-chat::-webkit-scrollbar-thumb {
  background: #d5d8dd;
  border-radius: 8px;
}

/* ---------- messages ---------- */
.ai-msg {
  display: flex;
  max-width: 100%;
}
.ai-msg-user {
  justify-content: flex-end;
}
.ai-msg-ai {
  justify-content: flex-start;
}
.ai-bubble {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}
.ai-msg-user .ai-bubble {
  background: var(--ai-user-bubble);
  color: var(--ai-user-text);
  border-bottom-right-radius: 5px;
}
.ai-msg-ai .ai-bubble {
  background: var(--ai-ai-bubble);
  color: var(--ai-text);
  border-bottom-left-radius: 5px;
}
.ai-bubble-error {
  background: #fef2f2 !important;
  color: #b91c1c !important;
  border: 1px solid #fecaca;
}

/* markdown ringan */
.ai-bubble strong { font-weight: 680; }
.ai-bubble em { font-style: italic; }
.ai-bubble .ai-ul,
.ai-bubble .ai-ol {
  margin: 6px 0;
  padding-left: 20px;
}
.ai-bubble .ai-ul li,
.ai-bubble .ai-ol li {
  margin: 2px 0;
}
.ai-bubble .ai-code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.ai-msg-user .ai-bubble .ai-code {
  background: rgba(255, 255, 255, 0.22);
}
.ai-bubble .ai-pre {
  background: #1f2430;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12.5px;
}
.ai-bubble .ai-pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

/* ---------- empty state ---------- */
.ai-empty {
  margin: auto;
  text-align: center;
  color: var(--ai-text-soft);
  padding: 24px 18px;
}
.ai-empty-icon {
  font-size: 34px;
  margin-bottom: 10px;
}
.ai-empty-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--ai-text);
  margin-bottom: 6px;
}
.ai-empty-sub {
  font-size: 13px;
  line-height: 1.55;
}

/* ---------- typing indicator ---------- */
.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ai-text-soft);
  font-size: 13px;
}
.ai-dots {
  display: inline-flex;
  gap: 3px;
}
.ai-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-text-soft);
  display: inline-block;
  animation: ai-bounce 1.2s infinite ease-in-out;
}
.ai-dots i:nth-child(2) { animation-delay: 0.15s; }
.ai-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- input bar ---------- */
.ai-inputbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--ai-border);
  background: var(--ai-bg);
}
.ai-input {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  font-family: inherit;
  color: var(--ai-text);
  background: var(--ai-bg-soft);
  resize: none;              /* auto-grow via JS, bukan handle manual */
  overflow-y: auto;
  max-height: 140px;
  min-height: 22px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ai-input:focus {
  border-color: var(--ai-accent);
  background: var(--ai-bg);
}
.ai-input::placeholder {
  color: #9aa1ac;
}
.ai-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--ai-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.ai-send:hover:not(:disabled) {
  background: #2f6fe0;
}
.ai-send:active:not(:disabled) {
  transform: scale(0.94);
}
.ai-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- toast ---------- */
.ai-toast {
  position: absolute;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1f2430;
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  max-width: 90%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}
.ai-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- mobile: full width ---------- */
@media (max-width: 480px) {
  .ai-panel {
    width: 100vw;
    border-left: none;
  }
  .ai-bubble {
    max-width: 90%;
  }
}
