/* 统一 UI 设计系统（现代简约 / 响应式 / 触摸友好）
   仅前端样式：不依赖后端、不影响接口与数据库 */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: rgba(17, 24, 39, 0.10);
  --text: #0f172a;
  --muted: rgba(15, 23, 42, 0.65);
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 10px 30px rgba(0,0,0,0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --ring: 0 0 0 4px rgba(79, 70, 229, 0.14);
}

/* 全局基础（只对 body.ui 生效，避免影响非接入页面） */
body.ui {
  margin: 0;
  background: var(--bg) !important;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.ui * { box-sizing: border-box; min-width: 0; }
body.ui a { color: var(--primary); text-decoration: none; }
body.ui a:hover { text-decoration: underline; }

body.ui button,
body.ui input,
body.ui textarea,
body.ui select {
  font: inherit;
}

body.ui img, body.ui canvas, body.ui svg { max-width: 100%; height: auto; }

/* 可访问性：键盘焦点清晰 */
body.ui :focus { outline: none; }
body.ui :focus-visible { box-shadow: var(--ring); border-radius: 10px; }

/* 通用卡片/容器（给现有页面的 .card/.container 提供统一底色与边框） */
body.ui .card,
body.ui .modal-content,
body.ui .chat-window,
body.ui .pane-right,
body.ui .mind-container,
body.ui .json-panel {
  border: 1px solid var(--border);
}

body.ui .card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* 通用按钮：给现有的 .btn-action/.btn-primary/.btn-secondary 等降噪统一 */
body.ui .btn-primary,
body.ui .btn-submit,
body.ui .send-btn,
body.ui .btn-upload,
body.ui .btn-action.btn-primary {
  background: var(--primary) !important;
}

body.ui .btn-success,
body.ui .btn-action.btn-success {
  background: var(--success) !important;
}

body.ui .btn-warning,
body.ui .btn-action.btn-warning {
  background: var(--warning) !important;
}

/* 统一阴影与圆角（避免不同页面“风格不一”） */
body.ui .header,
body.ui header {
  background: var(--surface) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-sm) !important;
  border-bottom: 1px solid var(--border);
}

/* 统一导航链接（兼容 dashboard/mindmap 等页面的 .nav-link） */
body.ui .nav-link {
  color: var(--text) !important;
  background: transparent !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
}
body.ui .nav-link:hover {
  text-decoration: none !important;
  border-color: rgba(79, 70, 229, 0.35) !important;
  box-shadow: var(--shadow-sm) !important;
}

/* 统一页面背景：去掉强渐变造成的“花” */
body.ui[data-page="dashboard"],
body.ui[data-page="mindmap"],
body.ui[data-page="login"],
body.ui[data-page="register"],
body.ui[data-page="gl"],
body.ui[data-page="flashcard"] {
  background: var(--bg) !important;
}

/* mindmap 页面：之前标题用白字，这里统一为深色 */
body.ui[data-page="mindmap"] .pane-title { color: var(--text) !important; text-shadow: none !important; }
body.ui[data-page="mindmap"] .book-summary { color: var(--muted) !important; background: var(--surface) !important; }

/* gl 页面：从深色统一为浅色风格（保留结构，不改功能） */
body.ui[data-page="gl"] {
  color: var(--text) !important;
}
body.ui[data-page="gl"] .chat-wrapper {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-md) !important;
}
body.ui[data-page="gl"] .chat-header,
body.ui[data-page="gl"] .tabs {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
body.ui[data-page="gl"] .chat-subtitle { color: var(--muted) !important; }
body.ui[data-page="gl"] .tab {
  color: var(--muted) !important;
}
body.ui[data-page="gl"] .tab:hover {
  background: rgba(79, 70, 229, 0.08) !important;
  color: var(--text) !important;
}
body.ui[data-page="gl"] .tab.active {
  background: rgba(79, 70, 229, 0.12) !important;
  color: var(--primary) !important;
}
body.ui[data-page="gl"] .tab-content { background: var(--surface) !important; }
body.ui[data-page="gl"] .chat-messages { background: var(--bg) !important; }
body.ui[data-page="gl"] .message-row.bot .message-bubble {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
body.ui[data-page="gl"] .chat-input-area { background: var(--surface) !important; }
body.ui[data-page="gl"] .chat-textarea { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
body.ui[data-page="gl"] .upload-card {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
}
body.ui[data-page="gl"] .json-preview {
  background: #0b1220 !important;
  color: #e5e7eb !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
}

/* flashcard 页面：ElementPlus 下适配背景与容器 */
body.ui[data-page="flashcard"] .header {
  background: var(--surface) !important;
  color: var(--text) !important;
}
body.ui[data-page="flashcard"] .header a {
  color: var(--text) !important;
}
body.ui[data-page="flashcard"] .el-card {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
}
body.ui[data-page="flashcard"] .el-card.is-always-shadow,
body.ui[data-page="flashcard"] .el-card.is-hover-shadow:hover {
  box-shadow: var(--shadow-sm) !important;
}

/* 溢出保护：长文本不撑破布局 */
body.ui .message-bubble,
body.ui .json-panel,
body.ui .subject-name,
body.ui .item-title,
body.ui .card-title {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* 动画偏好：减少动态 */
@media (prefers-reduced-motion: reduce) {
  body.ui * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* 触摸设备：确保可点区域 >= 44px */
@media (hover: none) and (pointer: coarse) {
  body.ui button,
  body.ui .nav-link,
  body.ui .btn-action,
  body.ui .btn-submit,
  body.ui .send-btn {
    min-height: 44px;
  }
  body.ui input,
  body.ui textarea {
    font-size: 16px;
  }
}

/* =======================
   Auth（login/register）
   ======================= */
body.ui[data-page="login"],
body.ui[data-page="register"] {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

body.ui[data-page="login"] .auth-container,
body.ui[data-page="register"] .auth-container {
  width: 100%;
  max-width: 420px;
}

body.ui[data-page="login"] .auth-card,
body.ui[data-page="register"] .auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 32px;
}

body.ui[data-page="login"] .auth-logo,
body.ui[data-page="register"] .auth-logo {
  text-align: center;
  margin-bottom: 18px;
}

body.ui[data-page="login"] .auth-logo-icon,
body.ui[data-page="register"] .auth-logo-icon {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 10px 25px rgba(79, 70, 229, 0.25);
  margin-bottom: 10px;
}

body.ui[data-page="register"] .auth-logo-icon {
  background: linear-gradient(135deg, var(--success), #22c55e);
  box-shadow: 0 10px 25px rgba(22, 163, 74, 0.20);
}

body.ui[data-page="login"] .auth-title,
body.ui[data-page="register"] .auth-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
}

body.ui[data-page="login"] .auth-subtitle,
body.ui[data-page="register"] .auth-subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

body.ui[data-page="login"] .auth-error,
body.ui[data-page="register"] .auth-error {
  margin: 14px 0 18px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.08);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.20);
  font-size: 14px;
}

body.ui[data-page="login"] .auth-form .form-group,
body.ui[data-page="register"] .auth-form .form-group {
  margin-bottom: 16px;
}

body.ui[data-page="login"] .auth-form label,
body.ui[data-page="register"] .auth-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

body.ui[data-page="login"] .auth-form .input-wrapper,
body.ui[data-page="register"] .auth-form .input-wrapper {
  position: relative;
}

body.ui[data-page="login"] .auth-form input,
body.ui[data-page="register"] .auth-form input {
  width: 100%;
  padding: 12px 14px 12px 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}

body.ui[data-page="login"] .auth-form input:focus,
body.ui[data-page="register"] .auth-form input:focus {
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: var(--ring);
}

body.ui[data-page="login"] .auth-form .input-icon,
body.ui[data-page="register"] .auth-form .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: rgba(15, 23, 42, 0.45);
  pointer-events: none;
}

body.ui[data-page="login"] .auth-form .password-toggle,
body.ui[data-page="register"] .auth-form .password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: rgba(15, 23, 42, 0.55);
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
}

body.ui[data-page="login"] .auth-form .password-toggle:hover,
body.ui[data-page="register"] .auth-form .password-toggle:hover {
  background: rgba(79, 70, 229, 0.08);
  color: var(--text);
}

body.ui[data-page="login"] .auth-form .password-toggle img,
body.ui[data-page="register"] .auth-form .password-toggle img {
  width: 18px;
  height: 18px;
  display: block;
}

body.ui[data-page="login"] .auth-form .btn-submit,
body.ui[data-page="register"] .auth-form .btn-submit {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.18);
}

body.ui[data-page="register"] .auth-form .btn-submit {
  box-shadow: 0 10px 20px rgba(22, 163, 74, 0.14);
}

body.ui[data-page="login"] .auth-divider,
body.ui[data-page="register"] .auth-divider {
  position: relative;
  text-align: center;
  margin: 18px 0;
  color: rgba(15, 23, 42, 0.45);
  font-size: 12px;
}
body.ui[data-page="login"] .auth-divider::before,
body.ui[data-page="register"] .auth-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
}
body.ui[data-page="login"] .auth-divider span,
body.ui[data-page="register"] .auth-divider span {
  position: relative;
  padding: 0 10px;
  background: var(--surface);
}

body.ui[data-page="login"] .auth-footer,
body.ui[data-page="register"] .auth-footer {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* 登录/注册：按钮内加载小转圈 */
body.ui .loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: -3px;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* 注册页：密码强度/匹配提示（保持现有 JS 不变） */
body.ui[data-page="register"] .password-strength {
  margin-top: 8px;
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
body.ui[data-page="register"] .password-strength-bar {
  height: 100%;
  width: 0%;
  transition: width 0.2s ease, background 0.2s ease;
}
body.ui[data-page="register"] .strength-weak { width: 33%; background: var(--danger); }
body.ui[data-page="register"] .strength-medium { width: 66%; background: var(--warning); }
body.ui[data-page="register"] .strength-strong { width: 100%; background: var(--success); }

body.ui[data-page="register"] .password-hint,
body.ui[data-page="register"] .password-match {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
body.ui[data-page="register"] .match-success { color: var(--success); }
body.ui[data-page="register"] .match-error { color: var(--danger); }

/* =======================
   Workflow steps（dashboard）
   ======================= */
body.ui .workflow-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
body.ui .workflow-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
body.ui .workflow-step .num {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: var(--primary);
}
body.ui .workflow-step .label {
  font-size: 13px;
  font-weight: 700;
}
body.ui .workflow-step .hint {
  font-size: 12px;
  color: var(--muted);
}
body.ui .workflow-step a { text-decoration: none !important; }

/* 通用搜索框（mindmap/flashcard 等可复用） */
body.ui .ui-search {
  width: 260px;
  max-width: 45vw;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
body.ui .ui-search::placeholder { color: rgba(15, 23, 42, 0.45); }
body.ui .ui-search:focus { box-shadow: var(--ring); border-color: rgba(79, 70, 229, 0.45); }

/* =======================
   Empty state（通用空状态）
   ======================= */
body.ui .empty-state {
  padding: 28px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px dashed rgba(15, 23, 42, 0.18);
  text-align: center;
  color: var(--muted);
}
body.ui .empty-icon {
  font-size: 42px;
  line-height: 1;
  margin-bottom: 10px;
}
body.ui .empty-text {
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  margin-bottom: 6px;
}
body.ui .empty-hint {
  font-size: 13px;
  color: var(--muted);
}

/* =======================
   Loading overlay（全屏/局部 Loading）
   ======================= */
body.ui .ui-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.30);
  backdrop-filter: blur(6px);
}
body.ui .ui-loading-overlay.open { display: flex; }
body.ui .ui-loading-card {
  width: min(520px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 18px 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
body.ui .ui-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(79, 70, 229, 0.22);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ui-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
body.ui .ui-loading-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 700;
}
body.ui .ui-loading-subtext {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* 流式处理步骤提示 */
body.ui .ui-loading-steps {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

body.ui .streaming-steps-container {
  text-align: left;
}

body.ui .streaming-step-current {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  padding: 8px 12px;
  background: rgba(79, 70, 229, 0.08);
  border-radius: 10px;
  margin-bottom: 8px;
  animation: pulse-step 1.5s ease-in-out infinite;
}

@keyframes pulse-step {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

body.ui .streaming-step-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

body.ui .streaming-step-done {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 8px;
  background: rgba(22, 163, 74, 0.06);
  border-radius: 6px;
  border-left: 2px solid var(--success);
}

/* =======================
   Toast（轻量提示）
   ======================= */
body.ui .ui-toast-stack {
  position: fixed;
  right: 14px;
  top: 14px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
body.ui .ui-toast {
  pointer-events: none;
  width: min(420px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 12px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
body.ui .ui-toast .icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex: 0 0 auto;
  margin-top: 1px;
}
body.ui .ui-toast.info .icon { background: var(--primary); }
body.ui .ui-toast.success .icon { background: var(--success); }
body.ui .ui-toast.warning .icon { background: var(--warning); }
body.ui .ui-toast.error .icon { background: var(--danger); }
body.ui .ui-toast .msg {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  font-weight: 600;
}

/* =======================
   Modal（通用模态框基础，不覆盖已有结构）
   ======================= */
body.ui .modal {
  position: fixed;
  inset: 0;
  z-index: 1800;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(5px);
}
body.ui .modal.open { display: flex; }
body.ui .modal-content {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
body.ui .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
body.ui .modal-title { font-weight: 900; color: var(--text); }
body.ui .modal-close {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
body.ui .modal-close:hover { color: var(--text); box-shadow: var(--shadow-sm); }
body.ui .modal-body { padding: 18px; }
body.ui .modal-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* =======================
   AppHeader（可选：后续模板逐步迁移使用）
   ======================= */
body.ui .app-header {
  position: sticky;
  top: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
body.ui .app-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
body.ui .app-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.18);
  flex: 0 0 auto;
}
body.ui .app-title {
  font-size: 15px;
  font-weight: 900;
  color: var(--text);
  line-height: 1.2;
}
body.ui .app-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
body.ui .app-header__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}


