#dify-widget-root {
  --dw-primary: #3b82f6;
  --dw-bg: #ffffff;
  --dw-panel-bg: #f4f4f5;
  --dw-border: #e4e4e7;
  --dw-text: #18181b;
  --dw-muted: #71717a;
  font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
}

#dify-widget-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10050;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#dify-widget-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.5);
}

#dify-widget-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 120px));
  z-index: 10049;
  display: none;
  flex-direction: column;
  background: var(--dw-bg);
  color: var(--dw-text);
  border: 1px solid var(--dw-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
}

#dify-widget-panel.is-open {
  display: flex;
}

.dw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--dw-border);
}

.dw-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.dw-header-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(145deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 1px solid #bbf7d0;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dw-header-icon i {
  font-size: 17px;
  color: #10b981;
}

.dw-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.dw-subtitle {
  font-size: 11px;
  color: var(--dw-muted);
}

.dw-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dw-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #059669;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dw-icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--dw-border);
  border-radius: 10px;
  background: #f4f4f5;
  color: var(--dw-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dw-icon-btn:hover {
  background: #e4e4e7;
}

#dify-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--dw-bg);
}

#dify-widget-messages::-webkit-scrollbar {
  width: 5px;
}

#dify-widget-messages::-webkit-scrollbar-thumb {
  background: #d4d4d8;
  border-radius: 8px;
}

.dw-msg-row {
  display: flex;
  margin-bottom: 12px;
  animation: dwFadeIn 0.2s ease;
}

.dw-msg-row.user {
  justify-content: flex-end;
}

.dw-msg-row.bot {
  justify-content: flex-start;
}

.dw-bubble {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.dw-bubble.user {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}

.dw-bubble.bot {
  background: var(--dw-panel-bg);
  border: 1px solid var(--dw-border);
  border-radius: 16px 16px 16px 4px;
}

.dw-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.dw-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a1a1aa;
  animation: dwBounce 1.2s infinite ease-in-out;
}

.dw-typing span:nth-child(2) { animation-delay: 0.15s; }
.dw-typing span:nth-child(3) { animation-delay: 0.3s; }

.dw-input-area {
  border-top: 1px solid var(--dw-border);
  padding: 10px;
  background: var(--dw-bg);
}

.dw-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f4f4f5;
  border: 1px solid var(--dw-border);
  border-radius: 14px;
  padding: 6px;
}

#dify-widget-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--dw-text);
  font-size: 14px;
  line-height: 1.4;
  max-height: 96px;
  min-height: 36px;
  padding: 6px 8px;
}

#dify-widget-send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: var(--dw-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

#dify-widget-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes dwFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes dwBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ========== ÀúÊ·¼ÇÂ¼µ¯´° ========== */
.dw-history-modal {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.dw-history-modal.is-open {
  display: flex;
}

.dw-history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.dw-history-dialog {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid var(--dw-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
}

.dw-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--dw-border);
  background: #ffffff;
}

.dw-history-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--dw-text);
}

.dw-history-title i {
  color: #60a5fa;
}

.dw-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 180px;
  max-height: 360px;
}

.dw-history-list::-webkit-scrollbar {
  width: 5px;
}

.dw-history-list::-webkit-scrollbar-thumb {
  background: #d4d4d8;
  border-radius: 8px;
}

.dw-history-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #fafafa;
  color: var(--dw-text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dw-history-item:hover {
  background: #f4f4f5;
  border-color: #d4d4d8;
}

.dw-history-item-main {
  min-width: 0;
  flex: 1;
}

.dw-history-item-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dw-history-item:hover .dw-history-item-name {
  color: #2563eb;
}

.dw-history-item-time {
  font-size: 11px;
  color: var(--dw-muted);
  margin-top: 2px;
}

.dw-history-item-tag {
  flex-shrink: 0;
  font-size: 10px;
  color: #059669;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: 999px;
  padding: 2px 8px;
}

.dw-history-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--dw-border);
}

.dw-history-clear {
  border: none;
  background: transparent;
  color: #f87171;
  font-size: 12px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.dw-history-clear:hover {
  background: rgba(248, 113, 113, 0.12);
}

.dw-history-close-btn {
  border: 1px solid var(--dw-border);
  background: #f4f4f5;
  color: var(--dw-text);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 10px;
}

.dw-history-close-btn:hover {
  background: #e4e4e7;
}

.dw-history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 16px;
  color: var(--dw-muted);
  font-size: 13px;
  text-align: center;
}

.dw-history-empty i {
  font-size: 28px;
  opacity: 0.55;
}

.dw-history-error {
  color: #dc2626;
}

.dw-history-success {
  color: #059669;
}

.dw-history-tip {
  margin: 0;
  font-size: 11px;
  color: var(--dw-muted);
}

.dw-history-retry {
  margin-top: 8px;
  border: none;
  background: transparent;
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  font-size: 12px;
}

.dw-history-loading-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 12px;
  color: var(--dw-muted);
  font-size: 13px;
}
