/* SmartAssistant — floating coach in every authenticated view */

.smart-assistant {
  position: fixed;
  z-index: 90;
  bottom: 24px;
  right: 24px;
  font-family: "Inter", sans-serif;
}

.app-shell:has(.sa-panel) .smart-assistant {
  position: fixed;
  z-index: 50;
  bottom: auto;
  right: 0;
  top: 0;
  flex-shrink: 0;
}

.sa-fab {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: #111;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}

.sa-fab:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .28);
}

.sa-fab img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: contain;
  z-index: 2;
}

.sa-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(17, 17, 17, .35);
  animation: sa-pulse 2s ease-in-out infinite;
  z-index: 1;
}

@keyframes sa-pulse {
  0%, 100% { transform: scale(1); opacity: .5; }
  50% { transform: scale(1.18); opacity: 0; }
}

.sa-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #FFF;
  border-left: 1px solid #E5E5E5;
  overflow: hidden;
  flex-shrink: 0;
}

.sa-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: #111;
  color: #F4F3EF;
}

.sa-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sa-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #F4F3EF;
}

.sa-avatar img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.sa-title strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

.sa-title small {
  display: block;
  font-size: 11px;
  color: rgba(244, 243, 239, .65);
}

.sa-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: rgba(244, 243, 239, .12);
  color: #F4F3EF;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.sa-close:hover {
  background: rgba(244, 243, 239, .22);
}

.sa-messages {
  flex: 1 1 auto;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #FAFAFA;
}

.sa-welcome {
  padding: 12px 14px;
  border-radius: 16px;
  background: #F4F3EF;
  color: #555;
  font-size: 13px;
  line-height: 1.55;
}

.sa-message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 88%;
}

.sa-message.user {
  align-items: flex-end;
  align-self: flex-end;
}

.sa-bubble {
  padding: 12px 15px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
}

.sa-bubble p { margin: 0 0 8px; }
.sa-bubble p:last-child { margin-bottom: 0; }
.sa-bubble h1, .sa-bubble h2, .sa-bubble h3, .sa-bubble h4 { margin: 10px 0 6px; font-weight: 700; line-height: 1.3; }
.sa-bubble h1 { font-size: 16px; }
.sa-bubble h2 { font-size: 15px; }
.sa-bubble h3 { font-size: 14px; }
.sa-bubble h4 { font-size: 13px; }
.sa-bubble ul, .sa-bubble ol { margin: 6px 0; padding-left: 20px; }
.sa-bubble li { margin: 3px 0; }
.sa-bubble strong { font-weight: 700; }
.sa-bubble em { font-style: italic; }
.sa-bubble a { color: #111; text-decoration: underline; }
.sa-bubble code { background: rgba(0,0,0,.06); padding: 2px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; }
.sa-bubble pre { background: #f5f5f5; padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.sa-bubble pre code { background: none; padding: 0; }
.sa-bubble blockquote { border-left: 3px solid #ddd; margin: 8px 0; padding-left: 12px; color: #777; }
.sa-bubble hr { border: 0; border-top: 1px solid #eee; margin: 10px 0; }
.sa-bubble table { border-collapse: collapse; margin: 8px 0; }
.sa-bubble th, .sa-bubble td { border: 1px solid #ddd; padding: 6px 10px; font-size: 12px; }

.sa-message.assistant .sa-bubble {
  background: #FFF;
  color: #111;
  border: 1px solid #E5E5E5;
  border-top-left-radius: 4px;
}

.sa-message.user .sa-bubble {
  background: #111;
  color: #F4F3EF;
  border-top-right-radius: 4px;
}

.sa-time {
  font-size: 10px;
  color: #999;
}

.sa-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.sa-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #888;
  animation: sa-dot 1.2s ease-in-out infinite;
}

.sa-typing span:nth-child(2) { animation-delay: .15s; }
.sa-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes sa-dot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.sa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #ECECEC;
  background: #FFF;
}

.sa-chip {
  padding: 7px 12px;
  border: 1px solid #E5E5E5;
  border-radius: 999px;
  background: #FFF;
  color: #111;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s ease;
}

.sa-chip:hover {
  background: #F4F3EF;
  border-color: #111;
}

.sa-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid #ECECEC;
  background: #FFF;
}

.sa-input input {
  flex: 1 1 auto;
  height: 42px;
  padding: 0 14px;
  border: 1px solid #E5E5E5;
  border-radius: 12px;
  outline: none;
  font-size: 13px;
  background: #FAFAFA;
}

.sa-input input:focus {
  border-color: #111;
  background: #FFF;
}

.sa-input button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: #111;
  color: #F4F3EF;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.sa-input button:disabled {
  background: #E5E5E5;
  color: #999;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .smart-assistant {
    bottom: 84px;
    right: 16px;
  }

  .app-shell:has(.sa-panel) .smart-assistant {
    position: fixed;
    bottom: 84px;
    right: 16px;
    z-index: 90;
  }

  .sa-fab {
    width: 52px;
    height: 52px;
  }

  .sa-fab img {
    width: 28px;
    height: 28px;
  }

  .sa-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 88px;
    top: auto;
    width: auto;
    height: 70vh;
    border-radius: 18px;
  }

  .app-main.assistant-open { margin-right: 0; }
}
