/* ========================================
   云笺 - Cloud Notes - Styles
   ======================================== */

/* --- CSS Variables --- */
#yunjian-root {
  --yj-primary: #6366f1;
  --yj-primary-light: #818cf8;
  --yj-primary-dark: #4f46e5;
  --yj-primary-bg: #eef2ff;
  --yj-danger: #ef4444;
  --yj-success: #10b981;
  --yj-bg: #f1f5f9;
  --yj-white: #ffffff;
  --yj-text: #1e293b;
  --yj-text-light: #64748b;
  --yj-text-lighter: #94a3b8;
  --yj-border: #e2e8f0;
  --yj-border-focus: #a5b4fc;
  --yj-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --yj-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --yj-shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 4px 10px -6px rgba(0, 0, 0, 0.06);
  --yj-shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.18), 0 8px 16px -8px rgba(0, 0, 0, 0.08);
  --yj-radius: 14px;
  --yj-radius-sm: 8px;
  --yj-radius-xs: 6px;
  --yj-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --yj-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  font-family: var(--yj-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--yj-text);
  -webkit-font-smoothing: antialiased;
}

#yunjian-root *,
#yunjian-root *::before,
#yunjian-root *::after {
  box-sizing: border-box;
}

/* --- Toggle Button --- */
#yunjian-toggle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--yj-primary), var(--yj-primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--yj-shadow-lg);
  transition: transform var(--yj-transition), box-shadow var(--yj-transition), opacity var(--yj-transition);
  z-index: 2;
  padding: 0;
  outline: none;
}

#yunjian-toggle:hover {
  transform: scale(1.08);
  box-shadow: var(--yj-shadow-xl);
}

#yunjian-toggle:active {
  transform: scale(0.96);
}

#yunjian-toggle svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Panel --- */
#yunjian-panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 390px;
  height: 560px;
  background: var(--yj-white);
  border-radius: var(--yj-radius);
  box-shadow: var(--yj-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  transition: opacity var(--yj-transition), transform var(--yj-transition);
}

#yunjian-root.yunjian-open #yunjian-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#yunjian-root.yunjian-open #yunjian-toggle {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

/* --- Panel Header --- */
#yunjian-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--yj-primary), var(--yj-primary-dark));
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}

#yunjian-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#yunjian-header-title .yj-icon {
  width: 20px;
  height: 20px;
  opacity: 0.9;
}

#yunjian-header-count {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.18);
  padding: 2px 10px;
  border-radius: 20px;
}

#yunjian-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--yj-transition);
  padding: 0;
  line-height: 1;
  outline: none;
}

#yunjian-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* --- Message List --- */
#yunjian-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--yj-bg);
  padding: 12px 14px;
  scroll-behavior: smooth;
}

#yunjian-messages::-webkit-scrollbar {
  width: 5px;
}

#yunjian-messages::-webkit-scrollbar-track {
  background: transparent;
}

#yunjian-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

#yunjian-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

#yunjian-messages-inner {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 100%;
  justify-content: flex-end;
}

/* --- Load More --- */
#yunjian-load-more {
  text-align: center;
  padding: 8px 0 14px;
  flex-shrink: 0;
}

#yunjian-load-more button {
  background: var(--yj-white);
  border: 1px solid var(--yj-border);
  border-radius: 20px;
  padding: 6px 20px;
  font-size: 12px;
  color: var(--yj-text-light);
  cursor: pointer;
  transition: all var(--yj-transition);
  outline: none;
  font-family: var(--yj-font);
}

#yunjian-load-more button:hover {
  color: var(--yj-primary);
  border-color: var(--yj-primary-light);
  background: var(--yj-primary-bg);
}

/* --- Empty State --- */
#yunjian-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--yj-text-lighter);
  text-align: center;
  flex: 1;
}

#yunjian-empty .yj-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

#yunjian-empty p {
  margin: 0;
  font-size: 13px;
  line-height: 1.8;
}

/* --- Message Bubble --- */
.yunjian-msg {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  align-items: flex-start;
}

.yunjian-msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
}

.yunjian-msg-body {
  flex: 1;
  min-width: 0;
}

.yunjian-msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
  padding-left: 2px;
}

.yunjian-msg-nickname {
  font-size: 13px;
  font-weight: 600;
  color: var(--yj-text);
}

.yunjian-msg-time {
  font-size: 11px;
  color: var(--yj-text-lighter);
}

.yunjian-msg-bubble {
  display: inline-block;
  background: var(--yj-white);
  border-radius: 4px 14px 14px 14px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--yj-text);
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--yj-shadow-sm);
  max-width: 100%;
}

/* --- Reply Bubble --- */
.yunjian-msg-reply {
  margin-top: 6px;
  padding: 8px 12px;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  border-radius: 4px 12px 12px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: #4338ca;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--yj-shadow-sm);
  max-width: 100%;
  position: relative;
}

.yunjian-msg-reply::before {
  content: '站长回复';
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #6366f1;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}

/* --- Input Area --- */
#yunjian-input-area {
  border-top: 1px solid var(--yj-border);
  padding: 10px 14px;
  background: var(--yj-white);
  flex-shrink: 0;
  position: relative;
}

.yunjian-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.yunjian-input-row:last-child {
  margin-bottom: 0;
}

.yunjian-input-row input,
.yunjian-input-row textarea {
  font-family: var(--yj-font);
  font-size: 13px;
  border: 1px solid var(--yj-border);
  border-radius: var(--yj-radius-xs);
  padding: 7px 10px;
  outline: none;
  transition: border-color var(--yj-transition), box-shadow var(--yj-transition);
  color: var(--yj-text);
  background: var(--yj-white);
}

.yunjian-input-row input:focus,
.yunjian-input-row textarea:focus {
  border-color: var(--yj-border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}

.yunjian-input-row input::placeholder,
.yunjian-input-row textarea::placeholder {
  color: var(--yj-text-lighter);
}

#yunjian-nickname {
  flex: 1;
  min-width: 0;
}

#yunjian-email {
  flex: 1;
  min-width: 0;
}

#yunjian-email.yj-invalid {
  border-color: var(--yj-danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.08);
}

#yunjian-email.yj-valid {
  border-color: var(--yj-success);
}

#yunjian-message {
  flex: 1;
  resize: none;
  min-height: 36px;
  max-height: 100px;
}

#yunjian-emoji-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--yj-border);
  border-radius: var(--yj-radius-xs);
  background: var(--yj-white);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--yj-transition);
  padding: 0;
  outline: none;
  line-height: 1;
}

#yunjian-emoji-btn:hover {
  background: var(--yj-primary-bg);
  border-color: var(--yj-border-focus);
}

#yunjian-captcha-img {
  height: 36px;
  border-radius: var(--yj-radius-xs);
  border: 1px solid var(--yj-border);
  cursor: pointer;
  flex-shrink: 0;
}

#yunjian-captcha-input {
  width: 80px;
  flex-shrink: 0;
  text-align: center;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#yunjian-submit {
  padding: 0 18px;
  height: 36px;
  border: none;
  border-radius: var(--yj-radius-xs);
  background: linear-gradient(135deg, var(--yj-primary), var(--yj-primary-dark));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--yj-transition);
  outline: none;
  font-family: var(--yj-font);
  white-space: nowrap;
  flex-shrink: 0;
}

#yunjian-submit:hover {
  background: linear-gradient(135deg, var(--yj-primary-dark), var(--yj-primary-dark));
  box-shadow: var(--yj-shadow);
}

#yunjian-submit:active {
  transform: scale(0.97);
}

#yunjian-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* --- Emoji Picker --- */
#yunjian-emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 14px;
  width: 300px;
  background: var(--yj-white);
  border: 1px solid var(--yj-border);
  border-radius: var(--yj-radius-sm);
  box-shadow: var(--yj-shadow-lg);
  z-index: 10;
  display: none;
}

#yunjian-emoji-picker.yj-visible {
  display: block;
}

.yunjian-emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--yj-border);
  padding: 4px 6px 0;
  gap: 2px;
}

.yunjian-emoji-tab {
  padding: 6px 10px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  border-radius: 6px 6px 0 0;
  transition: background var(--yj-transition);
  outline: none;
  line-height: 1;
}

.yunjian-emoji-tab:hover {
  background: var(--yj-bg);
}

.yunjian-emoji-tab.yj-active {
  background: var(--yj-bg);
}

.yunjian-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.yunjian-emoji-grid button {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 20px;
  border-radius: 6px;
  transition: background var(--yj-transition);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  line-height: 1;
}

.yunjian-emoji-grid button:hover {
  background: var(--yj-primary-bg);
}

/* --- Notification Toast --- */
#yunjian-toast {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: var(--yj-text);
  color: #fff;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 13px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 15;
  max-width: 90%;
  text-align: center;
  word-break: break-word;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

#yunjian-toast.yj-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#yunjian-toast.yj-error {
  background: var(--yj-danger);
}

/* --- Responsive --- */
@media (max-width: 480px) {
  #yunjian-root {
    bottom: 0;
    right: 0;
    left: 0;
  }

  #yunjian-toggle {
    bottom: 20px;
    right: 20px;
  }

  #yunjian-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    bottom: 0;
  }

  #yunjian-root.yunjian-open #yunjian-toggle {
    display: none;
  }

  #yunjian-emoji-picker {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 50vh;
  }

  .yunjian-emoji-grid {
    max-height: 40vh;
  }
}

/* --- Loading Spinner --- */
.yj-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--yj-border);
  border-top-color: var(--yj-primary);
  border-radius: 50%;
  animation: yj-spin 0.6s linear infinite;
}

@keyframes yj-spin {
  to { transform: rotate(360deg); }
}

/* --- Fade-in for new messages --- */
.yunjian-msg.yj-new {
  animation: yj-fade-in 0.35s ease-out;
}

@keyframes yj-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
