/* ==========================================
   คุณศิลา — AI Companion (latest UX)
   FAB bottom-right → expand chat panel
   ========================================== */

#sila-root {
  font-family: Sarabun, sans-serif;
}

/* ── Floating expanded panel ── */
#sila-sheet {
  position: fixed;
  z-index: 500;
  display: none;
  flex-direction: column;
  background: #0f0a1e;
  border: 1px solid rgba(201, 168, 76, 0.2);
  box-shadow: 0 16px 48px rgba(15, 10, 30, 0.55);
  font-family: Sarabun, sans-serif;
  /* Desktop / tablet: float above FAB */
  right: 16px;
  bottom: 84px;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  border-radius: 18px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}

#sila-sheet.sila-sheet-open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

@media (max-width: 767px) {
  #sila-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(78vh, 640px);
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform: translateY(100%);
    transform-origin: bottom center;
  }
  #sila-sheet.sila-sheet-open {
    transform: translateY(0);
  }
}

#sila-sheet-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}
@media (max-width: 767px) {
  #sila-sheet-handle { display: block; }
}

/* ── Header ── */
#sila-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  background: linear-gradient(135deg, #1a0a3e, #0f0a1e);
  border-bottom: 1px solid rgba(201, 168, 76, 0.12);
  flex-shrink: 0;
}

#sila-ava,
.sila-ava,
#sila-sheet-ava {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #c9a84c);
  border: 2px solid rgba(201, 168, 76, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}

#sila-ava img,
.sila-ava img,
#sila-sheet-ava img,
#sila-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

#sila-name,
#sila-sheet-name {
  font-size: 13px;
  font-weight: 700;
  color: #e9d5a1;
}
#sila-status,
#sila-sheet-status {
  font-size: 10px;
  color: #22c55e;
}

#sila-sheet-close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
#sila-sheet-close:hover {
  color: rgba(255, 255, 255, 0.7);
}

/* ── Messages ── */
#sila-msgs,
#sila-sheet-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
#sila-msgs::-webkit-scrollbar {
  width: 4px;
}
#sila-msgs::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.sila-bubble-sila {
  background: rgba(124, 58, 237, 0.18);
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 10px 10px 10px 2px;
  padding: 9px 11px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.65;
  max-width: 90%;
  white-space: pre-wrap;
  word-break: break-word;
}

.sila-bubble-user {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px 10px 2px 10px;
  padding: 9px 11px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.65;
  max-width: 82%;
  align-self: flex-end;
  word-break: break-word;
}

.sila-typing {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: rgba(124, 58, 237, 0.12);
  border-radius: 10px 10px 10px 2px;
  align-self: flex-start;
  width: fit-content;
}
.sila-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  animation: silaBounceDot 1.2s infinite;
}
.sila-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.sila-typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes silaBounceDot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

.sila-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
  flex-shrink: 0;
}
.sila-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-family: Sarabun, sans-serif;
  cursor: pointer;
}
.sila-chip:hover,
.sila-chip.is-on {
  border-color: rgba(201, 168, 76, 0.45);
  color: #e9d5a1;
  background: rgba(201, 168, 76, 0.12);
}
.sila-chip:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Input ── */
#sila-input-row,
#sila-sheet-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

#sila-inp,
#sila-sheet-inp {
  flex: 1;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  font-family: Sarabun, sans-serif;
  outline: none;
}
#sila-inp::placeholder,
#sila-sheet-inp::placeholder {
  color: rgba(255, 255, 255, 0.3);
}
#sila-inp:focus,
#sila-sheet-inp:focus {
  border-color: rgba(124, 58, 237, 0.5);
}

#sila-send,
#sila-sheet-send {
  width: 40px;
  height: 40px;
  background: #7c3aed;
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
#sila-send:hover,
#sila-sheet-send:hover {
  background: #6d28d9;
}
#sila-send:disabled,
#sila-sheet-send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── FAB (always) ── */
#sila-fab-wrap {
  display: flex;
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 300;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#sila-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #4c1d95);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.55);
  border: 2px solid rgba(201, 168, 76, 0.35);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  animation: silaFloat 3s ease-in-out infinite;
  transition: transform 0.2s, box-shadow 0.2s;
}
#sila-root.sila-open #sila-fab {
  animation: none;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
}
#sila-fab:active {
  transform: scale(0.93);
}
@keyframes silaFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

#sila-tooltip {
  background: #1a0a3e;
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 10px 10px 2px 10px;
  padding: 9px 12px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  max-width: 210px;
  line-height: 1.55;
  opacity: 0;
  transition: opacity 0.4s;
  font-family: Sarabun, sans-serif;
  pointer-events: none;
}

/* ── Overlay ── */
#sila-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 400;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
#sila-overlay.sila-overlay-show {
  opacity: 1;
  pointer-events: all;
}
@media (min-width: 768px) {
  #sila-overlay {
    background: transparent;
  }
}
