.ai-assistant-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1085;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

body.modal-open .ai-assistant-root {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
}

.ai-assistant-launcher {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(18, 52, 88, 0.14);
  border-radius: 18px;
  background: linear-gradient(135deg, #123458 0%, #1f5f97 100%);
  color: #fff;
  box-shadow: 0 16px 36px rgba(18, 52, 88, 0.24);
}

.ai-assistant-launcher:hover {
  color: #fff;
  transform: translateY(-1px);
}

.ai-assistant-launcher-icon {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.14);
  font-size: 1.1rem;
}

.ai-assistant-launcher-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.ai-assistant-launcher-text .small {
  color: rgba(255, 255, 255, 0.78);
}

.ai-assistant-panel {
  position: fixed;
  top: calc(var(--navbar-height) + 12px);
  right: 0;
  width: min(440px, calc(100vw - 20px));
  height: calc(100vh - var(--navbar-height) - 24px);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.28s ease;
  pointer-events: none;
}

.ai-assistant-panel.expanded {
  width: min(1180px, calc(100vw - 20px));
}

.ai-assistant-panel.open {
  transform: translateX(0);
  pointer-events: auto;
}

.ai-assistant-panel.collapsed {
  transform: translateX(calc(100% - 74px));
  pointer-events: auto;
}

.ai-assistant-shell {
  width: 100%;
  height: 100%;
  border-radius: 22px 0 0 22px;
  overflow: hidden;
  background: #f7f7f4;
  border-left: 1px solid rgba(18, 52, 88, 0.08);
}

.ai-assistant-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.9rem;
  background: linear-gradient(160deg, #123458 0%, #1f5f97 100%);
  color: #fff;
}

.ai-assistant-kicker {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 0.35rem;
}

.ai-assistant-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.ai-assistant-subtitle {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.78);
  margin-top: 0.25rem;
}

.ai-assistant-header-actions {
  display: inline-flex;
  gap: 0.45rem;
}

.ai-assistant-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.ai-assistant-icon-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.ai-assistant-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100% - 224px);
  background:
    radial-gradient(circle at top left, rgba(31, 95, 151, 0.08), transparent 28%),
    linear-gradient(180deg, #f9fafb 0%, #f1efec 100%);
}

.ai-assistant-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(18, 52, 88, 0.08);
}

.ai-assistant-toolbar-copy {
  font-size: 0.8rem;
  color: #607085;
  max-width: 280px;
}

.ai-assistant-history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.ai-history-empty {
  margin: auto;
  max-width: 290px;
  text-align: center;
  color: #6b7280;
}

.ai-history-empty-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 0.85rem;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(18, 52, 88, 0.1), rgba(31, 95, 151, 0.14));
  color: #123458;
  font-size: 1.5rem;
}

.ai-history-empty-title {
  font-weight: 700;
  color: #123458;
  margin-bottom: 0.35rem;
}

.ai-history-entry {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ai-history-entry.user {
  align-items: flex-end;
}

.ai-history-entry.assistant,
.ai-history-entry.action {
  align-items: stretch;
}

.ai-history-bubble {
  max-width: 92%;
  border-radius: 18px;
  padding: 0.8rem 0.95rem;
  box-shadow: 0 10px 26px rgba(18, 52, 88, 0.08);
}

.ai-history-entry.user .ai-history-bubble {
  background: #123458;
  color: #fff;
  border-bottom-right-radius: 6px;
}

.ai-history-entry.assistant .ai-history-bubble {
  background: #fff;
  color: #19324f;
  border: 1px solid rgba(18, 52, 88, 0.1);
  border-bottom-left-radius: 6px;
}

.ai-history-meta {
  font-size: 0.72rem;
  color: #738095;
  padding: 0 0.15rem;
}

.ai-response-card,
.ai-preview-card {
  background: #fff;
  border: 1px solid rgba(18, 52, 88, 0.12);
  border-radius: 18px;
  box-shadow: 0 16px 30px rgba(18, 52, 88, 0.08);
  overflow: hidden;
}

.ai-response-card-header,
.ai-preview-card-header {
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  border-bottom: 1px solid rgba(18, 52, 88, 0.08);
}

.ai-response-card-title,
.ai-preview-card-title {
  font-weight: 700;
  color: #123458;
}

.ai-response-card-subtitle,
.ai-preview-card-subtitle {
  font-size: 0.78rem;
  color: #6c7a8b;
  margin-top: 0.2rem;
}

.ai-card-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.32rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  background: #e8f0fa;
  color: #123458;
  white-space: nowrap;
}

.ai-response-card-body,
.ai-preview-card-body {
  padding: 0.9rem 1rem 1rem;
}

.ai-card-section-title {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #708096;
  margin-bottom: 0.55rem;
}

.ai-payload-list {
  display: grid;
  gap: 0.55rem;
}

.ai-payload-item {
  border: 1px solid rgba(18, 52, 88, 0.08);
  border-radius: 14px;
  background: #f8fafc;
  padding: 0.65rem 0.75rem;
}

.ai-payload-key {
  display: block;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7b8798;
  margin-bottom: 0.2rem;
}

.ai-payload-value {
  color: #173454;
  font-size: 0.9rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.ai-query-table-wrap {
  overflow-x: visible;
}

.ai-query-table {
  table-layout: fixed;
  width: 100%;
}

.ai-query-table th,
.ai-query-table td {
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

.ai-query-table th:last-child,
.ai-query-table td:last-child {
  width: 110px;
  white-space: nowrap;
}

.ai-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1rem;
}

.ai-assistant-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 1rem 0.9rem;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(18, 52, 88, 0.08);
  color: #4c5d72;
}

.ai-assistant-footer {
  padding: 0.95rem 1rem 1rem;
  border-top: 1px solid rgba(18, 52, 88, 0.08);
  background: #fff;
}

.ai-assistant-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5f6f83;
  margin-bottom: 0.45rem;
}

.ai-assistant-input {
  resize: none;
  min-height: 86px;
  border-radius: 16px;
  border-color: rgba(18, 52, 88, 0.14);
  box-shadow: none;
}

.ai-assistant-input:focus {
  border-color: rgba(31, 95, 151, 0.36);
  box-shadow: 0 0 0 0.2rem rgba(31, 95, 151, 0.12);
}

.ai-assistant-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.75rem;
}

.ai-assistant-hint {
  font-size: 0.76rem;
  color: #76859a;
}

.ai-assistant-send {
  min-width: 110px;
  border-radius: 12px;
  font-weight: 700;
}

.ai-validation-list {
  margin: 0.8rem 0 0;
  padding-left: 1rem;
  color: #a94442;
}

.ai-result-success {
  border-left: 4px solid #198754;
}

.ai-result-warning {
  border-left: 4px solid #d97706;
}

.ai-result-neutral {
  border-left: 4px solid #1f5f97;
}

@media (max-width: 991.98px) {
  .ai-assistant-panel {
    top: calc(var(--navbar-height) + 8px);
    width: min(100vw - 12px, 420px);
    height: calc(100vh - var(--navbar-height) - 16px);
  }

  .ai-assistant-panel.expanded {
    width: min(100vw - 12px, 980px);
  }

  .ai-assistant-root {
    right: 10px;
    bottom: 10px;
  }
}

@media (max-width: 767.98px) {
  .ai-assistant-launcher {
    padding: 0.8rem 0.9rem;
  }

  .ai-assistant-launcher-text .small {
    display: none;
  }

  .ai-assistant-panel {
    top: var(--navbar-height);
    width: 100vw;
    height: calc(100vh - var(--navbar-height));
    transform: translateX(100%);
  }

  .ai-assistant-panel.expanded {
    width: 100vw;
  }

  .ai-assistant-panel.open,
  .ai-assistant-panel.collapsed {
    transform: translateX(0);
  }

  .ai-assistant-shell {
    border-radius: 0;
  }

  .ai-assistant-header {
    padding-right: 0.85rem;
  }

  .ai-assistant-body {
    height: calc(100% - 234px);
  }
}
