/* =========================================================
   ASISTEN & BOTTOM SHEET CSS (FINAL)
   ========================================================= */

/* --- 1. BOTTOM SHEET OVERLAY --- */
.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: flex;
  align-items: flex-end;
}

.bottom-sheet-overlay.muncul {
  opacity: 1;
  visibility: visible;
}

/* --- 2. BOTTOM SHEET CONTENT (Area yang ditarik) --- */
.bottom-sheet-content {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-2, #10141d);
  border-radius: 28px 28px 0 0;
  padding: 12px 24px calc(32px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  min-height: min(72vh, 34rem);
  max-height: calc(92vh - env(safe-area-inset-top, 0px));
  overflow: hidden;

  /* Transform dikontrol via JS untuk snap/momentum/spring */
  transform: translateY(100%);
  will-change: transform;

  /* Pointer/touch */
  touch-action: none;
}

/* Handle abu-abu di atas modal */
.drag-handle {
  width: 40px;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  margin: 0 auto 20px;
  cursor: grab;
}

.sheet-header h3 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  color: #fff;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 0.5rem;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  text-align: left;
  color: #fff;
  transition: transform 0.2s ease, background 0.2s ease;
  will-change: transform;
}

.sheet-item:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.08);
}

.sheet-icon {
  font-size: 1.5rem;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

.sheet-text strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.sheet-text p {
  margin: 0;
  font-size: 0.85rem;
  color: #aaa6b9; /* var(--muted) */
}

/* --- 3. MODAL AI --- */
.ai-modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: stretch;
  padding: 0;
  background: rgba(7, 7, 10, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 35000;
}

.ai-modal-overlay.muncul {
  opacity: 1;
  visibility: visible;
}

.ai-modal-content {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(64, 224, 208, 0.08), transparent 34%),
    linear-gradient(180deg, #10141d 0%, #0b1017 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  box-shadow: none;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
}

.ai-modal-overlay.muncul .ai-modal-content {
  transform: translateY(0) scale(1);
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 0;
  padding: calc(clamp(14px, 2.2vw, 18px) + env(safe-area-inset-top, 0px)) clamp(14px, 2.2vw, 18px) clamp(12px, 2vw, 14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(16, 20, 29, 0.86);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.ai-header:active {
  cursor: grabbing;
}

.ai-modal-content.ai-swipe-closing {
  transition: none;
}

.ai-header h3 {
  margin: 0;
  font-size: 1.08rem;
  color: #fff;
}

.ai-kicker {
  margin: 0 0 6px;
  color: #74f0e5;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: bold;
}

.close-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  flex-shrink: 0;
}

.ai-desc {
  flex-shrink: 0;
  font-size: 0.9rem;
  color: #aeb7c6;
  line-height: 1.5;
  margin: clamp(10px, 2vw, 14px) clamp(12px, 2vw, 16px) clamp(8px, 1.4vw, 10px);
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2vw, 14px);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
}

.ai-response-box {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding:
    0
    clamp(12px, 2vw, 16px)
    calc(96px + env(safe-area-inset-bottom, 0px))
    clamp(12px, 2vw, 16px);
  background: transparent;
  border: none;
  border-radius: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

.ai-response-box::-webkit-scrollbar {
  width: 6px;
}

.ai-response-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

.ai-text-result {
  display: none;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #f5f1e8;
}

.ai-textarea {
  position: absolute;
  left: clamp(12px, 2vw, 16px);
  right: calc(52px + clamp(12px, 2vw, 16px) + 10px + clamp(12px, 2vw, 16px));
  bottom: calc(clamp(12px, 2vw, 16px) + env(safe-area-inset-bottom, 0px));
  min-height: 52px;
  max-height: 52px;
  height: 52px;
  padding: 0 16px;
  background: #708090;
  border: none;
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  resize: none;
  margin: 0;
  outline: none;
  box-sizing: border-box;
  line-height: 52px;
  z-index: 3;
}

.ai-textarea::placeholder {
  color: rgba(255, 255, 255, 0.42);
  line-height: normal;
}

.ai-textarea:focus {
  border-color: #40e0d0;
  box-shadow: 0 0 0 3px rgba(64, 224, 208, 0.15);
  line-height: normal;
}

.w-full {
  position: absolute;
  right: clamp(1rem, 2vw, 1.4rem);
  bottom: calc(clamp(12px, 2vw, 16px) + env(safe-area-inset-bottom, 0px));
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  margin: 0;
  border: none;
  border-radius: 50%;
  font-size: 0;
  background: linear-gradient(135deg, #A9A9A9, #696979);
  box-shadow: none !important
  z-index: 4;
}

.w-full::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-46%, -52%);
  background-color: black;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M21.8 2.2a1 1 0 0 0-1.04-.23l-18 7a1 1 0 0 0 .08 1.89l7.17 2.39 2.39 7.17a1 1 0 0 0 .9.68h.06a1 1 0 0 0 .92-.78l7-18a1 1 0 0 0-.48-1.14ZM13.7 17.1l-1.53-4.59a1 1 0 0 0-.63-.63L6.95 10.35l10.93-4.25Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M21.8 2.2a1 1 0 0 0-1.04-.23l-18 7a1 1 0 0 0 .08 1.89l7.17 2.39 2.39 7.17a1 1 0 0 0 .9.68h.06a1 1 0 0 0 .92-.78l7-18a1 1 0 0 0-.48-1.14ZM13.7 17.1l-1.53-4.59a1 1 0 0 0-.63-.63L6.95 10.35l10.93-4.25Z'/%3E%3C/svg%3E");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.w-full[disabled] {
  opacity: 0.72;
  cursor: wait;
}

.w-full[disabled]::before {
  content: "";
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #052021;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Ccircle cx='5' cy='12' r='2'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Ccircle cx='19' cy='12' r='2'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Ccircle cx='5' cy='12' r='2'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Ccircle cx='19' cy='12' r='2'/%3E%3C/svg%3E");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

@media (max-width: 640px) {
  .ai-modal-overlay {
    padding: 0;
    align-items: stretch;
  }

  .ai-modal-content {
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .ai-textarea {
    min-height: 50px;
    max-height: 50px;
    padding: 14px 15px;
    right: calc(50px + 0.75rem + 0.5rem + 0.75rem);
  }

  .w-full {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
  }
}

@media (min-width: 641px) and (max-width: 1024px) {
  .ai-modal-content {
    width: 100%;
    height: 100dvh;
  }
}

/* Loader asli disembunyikan, diganti bubble loader */
.ai-loader {
  display: none;
  gap: 6px;
  justify-content: center;
  padding: 10px 0;
}

.ai-loader span {
  width: 8px;
  height: 8px;
  background: #40e0d0;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.ai-loader span:nth-child(1) { animation-delay: -0.32s; }
.ai-loader span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Bubble chat thread */
.ai-chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-chat-row {
  display: flex;
  width: 100%;
}

.ai-chat-row.is-ai {
  justify-content: flex-start;
}

.ai-chat-row.is-user {
  justify-content: flex-end;
}

.ai-chat-bubble {
  position: relative;
  max-width: 84%;
  padding: 12px 14px 18px;
  font-size: 0.95rem;
  line-height: 1.58;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  overflow-wrap: break-word;
  animation: aiBubbleIn 180ms ease;
}

.ai-chat-bubble.is-ai {
  color: #f3f8fa;
  background: linear-gradient(180deg, #17363b, #122a2f);
  border: 1px solid rgba(64, 224, 208, 0.12);
  border-radius: 18px 18px 18px 8px;
}

.ai-chat-bubble.is-user {
  color: #ffffff;
  background: linear-gradient(180deg, #222833, #1a1f27);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px 18px 8px 18px;
}

.ai-chat-text {
  word-break: break-word;
}

.ai-chat-time {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 0.66rem;
  color: rgba(255, 255, 255, 0.52);
}

.ai-chat-bubble .ai-loader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
}

.ai-chat-bubble .ai-loader span {
  width: 8px;
  height: 8px;
  background: #7df0e7;
  border-radius: 50%;
  animation: aiTyping 1.1s infinite ease-in-out;
}

.ai-chat-bubble .ai-loader span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-chat-bubble .ai-loader span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes aiTyping {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@keyframes aiBubbleIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- 4. Handle kecil di atas kapsul (tap / swipe up hint) --- */
.dock-handle-btn {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + 64px);
  transform: translateX(-50%);
  width: 92px;
  height: 22px;
  border: none;
  background: transparent;
  padding: 0;
  z-index: 29000;
}

.dock-handle-btn::before {
  content: "";
  display: block;
  width: 46px;
  height: 5px;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.dock-handle-btn:active::before {
  transform: scaleX(0.92);
  background: rgba(255, 255, 255, 0.28);
}
