/* ============================================================
   Sade Assistant widget — panel overlay layout
   Structure: fab > backdrop > drawer > header / body(stage + compose)
   Panels (history, memory) overlay the messages area; they never
   push the chat layout, so opening/closing causes zero reflow.
   ============================================================ */

.sade-assistant-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1047;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #4154f1 0%, #13b7ff 100%);
  box-shadow: 0 18px 45px rgba(65, 84, 241, 0.34);
  font-size: 1.45rem;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.sade-assistant.is-open .sade-assistant-fab {
  transform: scale(0.84);
  opacity: 0;
  pointer-events: none;
}

body:has(.sade-assistant.is-open) .back-to-top {
  opacity: 0;
  pointer-events: none;
}

.sade-assistant-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: none;
  background: rgba(10, 15, 32, 0.38);
  backdrop-filter: blur(3px);
}

.sade-assistant.is-open .sade-assistant-backdrop {
  display: block;
}

.sade-assistant-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1051;
  display: flex;
  width: min(720px, calc(100vw - 28px));
  flex-direction: column;
  background: color-mix(in srgb, var(--bs-body-bg, #fff) 94%, #eef3ff);
  border-left: 1px solid rgba(65, 84, 241, 0.16);
  box-shadow: -22px 0 55px rgba(10, 15, 32, 0.18);
  transform: translateX(105%);
  transition: transform 0.22s ease;
}

.sade-assistant.is-open .sade-assistant-drawer {
  transform: translateX(0);
}

/* ---------- Header ---------- */

.sade-assistant-header {
  display: flex;
  flex: 0 0 auto;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(65, 84, 241, 0.1), rgba(19, 183, 255, 0.04));
  border-bottom: 1px solid rgba(108, 117, 125, 0.14);
}

.sade-assistant-title {
  display: flex;
  min-width: 0;
  gap: 10px;
  align-items: center;
}

.sade-assistant-logo {
  display: grid;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, #4154f1, #13b7ff);
}

.sade-assistant-kicker {
  color: var(--bs-body-color, #212529);
  font-size: 0.92rem;
  font-weight: 800;
}

.sade-assistant-subtitle {
  display: block;
  color: #6c757d;
  font-size: 0.74rem;
}

.sade-assistant-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  align-items: center;
}

.sade-assistant-icon-btn {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--bs-secondary, #6c757d);
  background: transparent;
  font-size: 1rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.sade-assistant-icon-btn:hover {
  color: var(--bs-body-color, #212529);
  background: rgba(65, 84, 241, 0.09);
}

.sade-assistant-icon-btn.is-active {
  color: #4154f1;
  border-color: rgba(65, 84, 241, 0.34);
  background: rgba(65, 84, 241, 0.12);
}

.sade-assistant-send-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #4154f1, #5b7cfa);
  transition: filter 0.15s ease;
}

.sade-assistant-send-btn:hover {
  filter: brightness(1.08);
}

.sade-assistant-text-btn {
  border: 0;
  padding: 4px 8px;
  border-radius: 8px;
  color: #4154f1;
  background: transparent;
  font-size: 0.8rem;
}

.sade-assistant-text-btn:hover {
  background: rgba(65, 84, 241, 0.09);
}

/* ---------- Body: stage (chat + overlay panels) + compose ---------- */

.sade-assistant-body {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.sade-assistant-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sade-assistant-messages {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 18px;
  background: radial-gradient(circle at top left, rgba(65, 84, 241, 0.06), transparent 240px);
}

/* Overlay panels slide over the stage; the chat never reflows. */

.sade-assistant-sidebar,
.sade-assistant-memory-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  width: min(280px, 100%);
  flex-direction: column;
  padding: 12px 12px 14px;
  background: color-mix(in srgb, var(--bs-body-bg, #fff) 96%, #eef3ff);
  box-shadow: 0 14px 40px rgba(10, 15, 32, 0.16);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
}

.sade-assistant-sidebar {
  left: 0;
  border-right: 1px solid rgba(108, 117, 125, 0.14);
  border-radius: 0 16px 16px 0;
  transform: translateX(-14px);
}

.sade-assistant-memory-panel {
  right: 0;
  border-left: 1px solid rgba(108, 117, 125, 0.14);
  border-radius: 16px 0 0 16px;
  transform: translateX(14px);
}

.sade-assistant.show-history .sade-assistant-sidebar,
.sade-assistant.show-memory .sade-assistant-memory-panel {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.sade-assistant-side-head {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sade-assistant-side-head .sade-assistant-section-title {
  margin: 0;
}

.sade-assistant-side-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.sade-assistant-panel-close {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #6c757d;
  background: transparent;
}

.sade-assistant-panel-close:hover {
  color: var(--bs-body-color, #212529);
  background: rgba(108, 117, 125, 0.12);
}

.sade-assistant-side-note {
  flex: 0 0 auto;
  margin: -2px 0 10px;
  color: #6c757d;
  font-size: 0.76rem;
  line-height: 1.35;
}

.sade-assistant-section-title {
  margin: 0 0 8px;
  color: #6c757d;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- History list ---------- */

.sade-assistant-history {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.sade-assistant-history-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 12px;
}

.sade-assistant-chip {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--bs-body-color, #212529);
  background: transparent;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.sade-assistant-history-item:hover .sade-assistant-chip {
  background: rgba(65, 84, 241, 0.07);
}

.sade-assistant-history-item.is-active .sade-assistant-chip {
  color: #fff;
  background: linear-gradient(135deg, #4154f1, #5b7cfa);
  box-shadow: 0 10px 24px rgba(65, 84, 241, 0.18);
}

.sade-assistant-history-action {
  position: absolute;
  right: 6px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #dc3545;
  background: rgba(255, 255, 255, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.sade-assistant-history-action + .sade-assistant-history-action {
  right: 38px;
}

.sade-assistant-history-item:hover .sade-assistant-history-action,
.sade-assistant-history-action:focus {
  opacity: 1;
  pointer-events: auto;
}

.sade-assistant-history-action:hover {
  transform: scale(1.06);
  background: #fff;
}

.sade-assistant-history-item:hover .sade-assistant-chip,
.sade-assistant-history-item:focus-within .sade-assistant-chip {
  padding-right: 72px;
}

.sade-assistant-history-empty {
  color: #6c757d;
  padding: 10px 4px;
  font-size: 0.82rem;
}

/* ---------- Memory panel ---------- */

.sade-assistant-memory-body {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
}

.sade-assistant-memory-list {
  display: grid;
  flex: 1;
  min-height: 0;
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.sade-assistant-memory-item {
  display: grid;
  gap: 6px;
  padding: 9px 10px;
  border: 1px solid rgba(108, 117, 125, 0.16);
  border-radius: 12px;
  background: #fff;
}

.sade-assistant-memory-item.is-proposed {
  border-color: rgba(255, 193, 7, 0.34);
  background: rgba(255, 248, 226, 0.86);
}

.sade-assistant-memory-content {
  font-size: 0.86rem;
  line-height: 1.35;
}

.sade-assistant-memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sade-assistant-memory-meta,
.sade-assistant-memory-empty {
  color: #6c757d;
  font-size: 0.78rem;
}

.sade-assistant-memory-footer {
  display: flex;
  flex: 0 0 auto;
  justify-content: center;
  padding-top: 6px;
  border-top: 1px solid rgba(108, 117, 125, 0.12);
}

/* ---------- Empty state & suggestions ---------- */

.sade-assistant-empty {
  display: grid;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  padding: 20px;
  color: #6c757d;
  text-align: center;
}

.sade-assistant-empty-title {
  margin-bottom: 6px;
  color: var(--bs-body-color, #212529);
  font-size: 1.2rem;
  font-weight: 800;
}

.sade-assistant-suggestions {
  display: flex;
  max-width: 360px;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.sade-assistant-suggestion {
  border: 1px solid rgba(65, 84, 241, 0.18);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--bs-body-color, #212529);
  background: rgba(65, 84, 241, 0.06);
  font-size: 0.84rem;
}

.sade-assistant-suggestion:hover {
  background: rgba(65, 84, 241, 0.12);
}

/* ---------- Messages ---------- */

.sade-assistant-attachments,
.sade-assistant-message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.sade-assistant-attachment-chip,
.sade-assistant-message-attachments span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(65, 84, 241, 0.09);
  font-size: 0.78rem;
}

.sade-assistant-attachment-chip button {
  border: 0;
  background: transparent;
  color: #6c757d;
}

.sade-assistant-message {
  max-width: 86%;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.sade-assistant-message p,
.sade-assistant-message ul,
.sade-assistant-message pre,
.sade-assistant-message ol {
  margin: 0 0 0.55rem;
}

.sade-assistant-message p:last-child,
.sade-assistant-message ul:last-child,
.sade-assistant-message ol:last-child,
.sade-assistant-message pre:last-child {
  margin-bottom: 0;
}

.sade-assistant-message pre {
  overflow-x: auto;
  padding: 8px;
  border-radius: 10px;
  background: rgba(10, 15, 32, 0.08);
  white-space: pre;
}

.sade-assistant-message.is-user {
  margin-left: auto;
  color: #fff;
  background: linear-gradient(135deg, #4154f1, #13b7ff);
  border-bottom-right-radius: 5px;
}

.sade-assistant-message.is-assistant {
  margin-right: auto;
  background: var(--bs-tertiary-bg, #f6f7fb);
  border: 1px solid rgba(108, 117, 125, 0.14);
  border-bottom-left-radius: 5px;
}

.sade-assistant-message.is-error {
  border-color: rgba(220, 53, 69, 0.24);
  background: rgba(220, 53, 69, 0.06);
}

.sade-assistant-retry {
  display: block;
  width: max-content;
  margin-top: 8px;
}

.sade-assistant-error-code {
  margin-top: 6px;
  font-size: 0.76rem;
}

.sade-assistant-message.is-thinking {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  color: #6c757d;
}

.sade-assistant-thinking-icon {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  color: #4154f1;
  background: rgba(65, 84, 241, 0.11);
}

.sade-assistant-thinking-dots::after {
  content: '';
  display: inline-block;
  width: 1.2em;
  animation: sadeAssistantDots 1.2s steps(4, end) infinite;
}

@keyframes sadeAssistantDots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75%, 100% { content: '...'; }
}

.sade-assistant-tool {
  display: flex;
  width: max-content;
  max-width: 100%;
  gap: 6px;
  align-items: center;
  margin: 0 0 10px;
  padding: 6px 9px;
  border-radius: 999px;
  color: #6c757d;
  background: rgba(19, 183, 255, 0.1);
  font-size: 0.78rem;
}

.sade-assistant-tool[data-status='failed'] {
  color: #dc3545;
  background: rgba(220, 53, 69, 0.08);
}

.sade-assistant-tool.is-fallback {
  color: #6c757d;
  background: rgba(108, 117, 125, 0.08);
}

.sade-assistant-confirmation {
  max-width: 88%;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid rgba(220, 53, 69, 0.22);
  border-radius: 16px;
  background: rgba(220, 53, 69, 0.06);
}

.sade-assistant-confirmation-title {
  margin-bottom: 10px;
  font-weight: 700;
}

.sade-assistant-confirmation-actions {
  display: flex;
  gap: 8px;
}

.sade-assistant-confirmation.is-approved {
  border-color: rgba(25, 135, 84, 0.24);
  background: rgba(25, 135, 84, 0.08);
}

.sade-assistant-confirmation.is-rejected {
  border-color: rgba(108, 117, 125, 0.2);
  background: rgba(108, 117, 125, 0.08);
}

/* ---------- Compose ---------- */

.sade-assistant-compose {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(108, 117, 125, 0.16);
  background: color-mix(in srgb, var(--bs-body-bg, #fff) 92%, #eef3ff);
}

.sade-assistant-input-box {
  border: 1px solid rgba(108, 117, 125, 0.25);
  border-radius: 20px;
  padding: 10px;
  background: var(--bs-body-bg, #fff);
  box-shadow: 0 10px 28px rgba(10, 15, 32, 0.06);
}

.sade-assistant-compose textarea {
  width: 100%;
  min-height: 42px;
  max-height: 150px;
  overflow-y: auto;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: 6px 4px 8px;
  color: var(--bs-body-color, #212529);
  background: transparent;
  outline: none;
}

.sade-assistant-compose-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.sade-assistant-compose-model {
  flex: 1 1 auto;
  max-width: 260px;
  min-width: 150px;
}

.sade-assistant-compose-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.sade-assistant-compose-actions .sade-assistant-icon-btn {
  width: 38px;
  height: 38px;
  border-color: rgba(108, 117, 125, 0.18);
  border-radius: 999px;
}

.sade-assistant-compose-actions .btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
}

.sade-assistant-stop {
  width: auto;
  min-width: 74px !important;
  padding: 0 12px !important;
  font-size: 0.82rem;
}

.sade-assistant-model-select {
  width: 100%;
  min-width: 150px;
}

.sade-assistant-model-select .sade-searchable-select-input {
  height: 32px;
  border-radius: 999px;
  border-color: transparent;
  background: rgba(65, 84, 241, 0.08);
  font-size: 0.8rem;
}

.sade-assistant-model-select .sade-searchable-select-menu {
  top: auto;
  bottom: calc(100% + 6px);
  max-height: min(320px, 46vh);
  border-radius: 14px;
}

.sade-assistant-model-option-group {
  padding: 8px 11px 4px;
  color: #6c757d;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sade-assistant-model-option {
  display: block;
  width: 100%;
  border: 0;
  padding: 8px 11px;
  color: var(--bs-body-color, #212529);
  background: transparent;
  text-align: left;
  font-size: 0.84rem;
}

.sade-assistant-model-option:hover,
.sade-assistant-model-option:focus,
.sade-assistant-model-option.is-active {
  background: rgba(65, 84, 241, 0.1);
}

.sade-assistant-model-option[hidden],
.sade-assistant-model-option-group[hidden] {
  display: none;
}

/* ---------- Small screens ---------- */

@media (max-width: 575.98px) {
  .sade-assistant-fab {
    right: 16px;
    bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .sade-assistant-drawer {
    width: 100vw;
    max-height: 100dvh;
    border-left: 0;
  }

  .sade-assistant-header {
    padding: 10px 12px;
  }

  .sade-assistant-subtitle {
    display: none;
  }

  .sade-assistant-sidebar,
  .sade-assistant-memory-panel {
    width: 100%;
    border-radius: 0;
  }

  .sade-assistant-messages {
    padding: 14px;
  }

  .sade-assistant-message {
    max-width: 94%;
  }

  .sade-assistant-compose {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .sade-assistant-compose-model {
    min-width: 0;
  }
}
