/* ==========================================================================
   Star OS / PopOS Desktop - AI Conversational Agent Widget
   Tailored for Liquid Crystal Glassmorphism & Cyber Deep-Space Theme
   ========================================================================== */

:root {
  --sa-accent: #00f0ff;
  --sa-accent-rgb: 0, 240, 255;
  --sa-accent-blue: #38bdf8;
  --sa-accent-purple: #c084fc;
  --sa-bg-window: rgba(8, 14, 28, 0.88);
  --sa-bg-header: rgba(14, 24, 48, 0.92);
  --sa-bg-card: rgba(18, 28, 54, 0.65);
  --sa-border: rgba(0, 240, 255, 0.22);
  --sa-border-hover: rgba(0, 240, 255, 0.55);
  --sa-text-bright: #ffffff;
  --sa-text-main: #f1f5f9;
  --sa-text-muted: #94a3b8;
  --sa-text-dim: #64748b;
  --sa-glow: 0 0 24px rgba(0, 240, 255, 0.25);
  --sa-radius-win: 1.25rem;
  --sa-radius-bubble: 1rem;
  --sa-radius-btn: 0.625rem;
}

/* 1. 悬浮胶囊召唤按钮 */
.star-agent-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1.35rem;
  border-radius: 9999px;
  background: var(--sa-bg-window);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--sa-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15), var(--sa-glow);
  color: var(--sa-text-bright);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
}

.star-agent-toggle:hover {
  transform: translateY(-3px) scale(1.04);
  border-color: var(--sa-border-hover);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.7), 0 0 28px rgba(var(--sa-accent-rgb), 0.45);
}

.star-agent-toggle:active {
  transform: translateY(0) scale(0.98);
}

.star-agent-toggle-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sa-accent);
  position: relative;
}

.star-agent-toggle-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px rgba(var(--sa-accent-rgb), 0.6));
}

.star-agent-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sa-accent);
  box-shadow: 0 0 8px var(--sa-accent);
}

.star-agent-pulse::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid rgba(var(--sa-accent-rgb), 0.7);
  animation: saRadarPing 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes saRadarPing {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* 2. 对话主窗口 (大尺寸、支持拖动、开阔视野) */
.star-agent-window {
  position: fixed;
  top: calc(50vh - 360px);
  left: calc(50vw - 270px);
  width: 540px;
  max-width: calc(100vw - 2.5rem);
  height: 720px;
  max-height: calc(100vh - 5.5rem);
  background: var(--sa-bg-window);
  backdrop-filter: blur(28px) saturate(200%);
  -webkit-backdrop-filter: blur(28px) saturate(200%);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-win);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.82), inset 0 1px 0 rgba(255, 255, 255, 0.15), var(--sa-glow);
  z-index: 9995;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--sa-text-main);
  box-sizing: border-box;
}

.star-agent-window.open {
  opacity: 1;
  pointer-events: auto;
}

/* 窗口头部：作为拖拽把手 */
.star-agent-header {
  padding: 1.05rem 1.35rem;
  background: var(--sa-bg-header);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  cursor: grab;
  touch-action: none;
}

.star-agent-header:active,
.star-agent-header.dragging,
body.sa-dragging-active {
  cursor: grabbing !important;
  user-select: none !important;
}

.star-agent-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none; /* 确保拖拽手柄不被内部文字中断 */
}

.star-agent-logo-badge {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sa-accent);
  background: transparent !important;
  border: none !important;
  filter: drop-shadow(0 0 8px rgba(var(--sa-accent-rgb), 0.65));
}

.star-agent-logo-badge svg {
  width: 22px;
  height: 22px;
}

.star-agent-title-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.star-agent-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--sa-text-bright);
  letter-spacing: -0.01em;
}

.star-agent-subtitle {
  font-size: 11.5px;
  color: var(--sa-accent);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.star-agent-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.star-agent-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: default;
}

.star-agent-header-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: transparent !important;
  border: 1px solid transparent !important;
  color: var(--sa-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.star-agent-header-btn:hover {
  background: rgba(var(--sa-accent-rgb), 0.12) !important;
  color: var(--sa-accent) !important;
  border-color: rgba(var(--sa-accent-rgb), 0.3) !important;
  box-shadow: 0 0 10px rgba(var(--sa-accent-rgb), 0.25);
}

/* 消息滚动区 */
.star-agent-body {
  flex: 1;
  padding: 1.2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  scroll-behavior: smooth;
}

.star-agent-body::-webkit-scrollbar {
  width: 4px;
}

.star-agent-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* 消息气泡 */
.star-agent-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 0.4rem;
  animation: saFadeIn 0.25s ease-out;
}

@keyframes saFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.star-agent-msg.user {
  align-self: flex-end;
}

.star-agent-msg.assistant {
  align-self: flex-start;
}

.star-agent-bubble {
  padding: 0.95rem 1.25rem;
  font-size: 15px;
  line-height: 1.7;
  border-radius: var(--sa-radius-bubble);
  box-sizing: border-box;
  word-break: break-word;
}

.star-agent-msg.user .star-agent-bubble {
  background: rgba(0, 240, 255, 0.14) !important;
  color: #e0faff !important;
  border: 1px solid rgba(0, 240, 255, 0.32) !important;
  font-weight: 500;
  border-bottom-right-radius: 0.25rem;
  box-shadow: 0 4px 18px rgba(0, 240, 255, 0.15) !important;
}

.star-agent-msg.assistant .star-agent-bubble {
  background: rgba(14, 22, 42, 0.65) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  color: var(--sa-text-main);
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
}

.star-agent-bubble p {
  margin: 0 0 0.65rem 0;
}

.star-agent-bubble p:last-child {
  margin-bottom: 0;
}

.star-agent-bubble code {
  background: rgba(0, 0, 0, 0.4);
  padding: 0.2rem 0.45rem;
  border-radius: 0.3rem;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13.5px;
  color: var(--sa-accent);
}

.star-agent-bubble pre {
  background: rgba(0, 0, 0, 0.55);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.65rem 0;
}

.star-agent-bubble pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
}

/* 推荐快捷问题容器 */
.star-agent-presets {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.star-agent-preset-btn {
  text-align: left;
  padding: 0.55rem 1rem;
  border-radius: 9999px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.2);
  color: #7df4ff;
  font-size: 13.5px;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  user-select: none;
}

.star-agent-preset-btn:hover {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--sa-border-hover);
  transform: translateX(4px);
  color: #ffffff;
}

/* 引用博文卡片列表：通透极光指示细线，鼠标指针与悬浮动画 */
.star-agent-sources {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.star-agent-sources-label {
  font-size: 12.5px;
  color: var(--sa-text-dim);
  font-family: ui-monospace, monospace;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.star-agent-source-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0 0.45rem 0.85rem !important;
  border-radius: 0 !important;
  background: transparent !important;
  border: none !important;
  border-left: 2px solid rgba(var(--sa-accent-rgb), 0.45) !important;
  text-decoration: none !important;
  text-decoration-line: none !important;
  border-bottom: none !important;
  box-shadow: none !important;
  color: var(--sa-text-muted) !important;
  font-size: 13.5px;
  cursor: pointer !important;
  transition: all 0.2s ease;
}

.star-agent-source-card:hover {
  background: rgba(0, 240, 255, 0.06) !important;
  border-left-color: var(--sa-accent) !important;
  color: #ffffff !important;
  transform: translateX(3px);
}

.star-agent-source-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 82%;
}

.star-agent-source-arrow {
  font-size: 12.5px;
  color: var(--sa-accent);
  flex-shrink: 0;
}

/* 打字思考中动画 */
.star-agent-thinking {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.6rem 0.95rem;
}

.star-agent-thinking span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sa-accent);
  animation: saBounce 1.2s infinite ease-in-out both;
}

.star-agent-thinking span:nth-child(1) { animation-delay: -0.32s; }
.star-agent-thinking span:nth-child(2) { animation-delay: -0.16s; }

@keyframes saBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* 底部输入框区 */
.star-agent-footer {
  padding: 0.95rem 1.25rem;
  background: var(--sa-bg-header);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.star-agent-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  background: rgba(10, 16, 32, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 1.25rem;
  padding: 0.45rem 0.6rem 0.45rem 1rem;
  transition: all 0.25s ease;
}

.star-agent-input-wrap:focus-within {
  border-color: var(--sa-border-hover);
  box-shadow: 0 0 14px rgba(var(--sa-accent-rgb), 0.3);
}

.star-agent-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--sa-text-bright);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 110px;
  min-height: 28px;
  padding: 0.25rem 0;
}

.star-agent-textarea::placeholder {
  color: var(--sa-text-dim);
}

.star-agent-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00f0ff 0%, #0099ff 100%);
  border: none;
  color: #030a16;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 8px rgba(0, 240, 255, 0.4);
}

.star-agent-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(0, 240, 255, 0.6);
}

.star-agent-send-btn:active {
  transform: scale(0.92);
}

.star-agent-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.star-agent-send-btn svg {
  width: 17px;
  height: 17px;
}

@media (max-width: 640px) {
  .star-agent-toggle {
    bottom: 1.25rem;
    right: 1.25rem;
    padding: 0.65rem 1rem;
    font-size: 13px;
  }
  .star-agent-window {
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
  }
}

/* Dock 菜单专属图标与悬浮位置 */
.star-agent-dock-item {
  position: relative;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: none !important;
  cursor: pointer;
  outline: none;
}

.star-agent-dock-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sa-accent);
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.25s ease;
}

.star-agent-dock-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px rgba(var(--sa-accent-rgb), 0.5));
}

.star-agent-dock-item:hover .star-agent-dock-icon {
  transform: scale(1.18);
  color: #ffffff;
  filter: drop-shadow(0 0 10px var(--sa-accent));
}

.star-agent-dock-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sa-accent);
  box-shadow: 0 0 6px var(--sa-accent);
}

/* Dock 模式窗口协同，由拖动与居中控制器统筹位置，不强行覆盖 left/transform */
.star-agent-window.dock-mode {
  /* 继承统一尺寸与自由拖拽坐标系 */
}
