/**
 * base.css - 基础样式系统
 * 包含：CSS变量、样式重置、通用工具类
 * 作者: ike
 * 日期: 2025-12-02
 */

/* ========================================
   1. CSS 变量系统
   ======================================== */

:root {
  /* ---------- 品牌色 ---------- */
  --hb-primary: #2f80ed;
  --hb-primary-hover: #1d6fd9;
  --hb-primary-light: rgba(47, 128, 237, 0.15);
  --hb-primary-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
  
  /* ---------- 背景色 ---------- */
  --hb-bg-body: #0b0f17;
  --hb-bg-surface: #0f1624;
  --hb-bg-elevated: #151f30;
  --hb-bg-card: rgba(15, 22, 36, 0.95);
  --hb-bg-overlay: rgba(0, 0, 0, 0.65);
  
  /* ---------- 文字色 ---------- */
  --hb-text-primary: #f8fafc;
  --hb-text-secondary: #e5e7eb;
  --hb-text-muted: #9ca3af;
  --hb-text-disabled: #6b7280;
  
  /* ---------- 边框色 ---------- */
  --hb-border-default: rgba(255, 255, 255, 0.06);
  --hb-border-hover: rgba(59, 130, 246, 0.35);
  --hb-border-active: rgba(47, 128, 237, 0.45);
  
  /* ---------- 状态色 ---------- */
  --hb-success: #10b981;
  --hb-success-light: rgba(16, 185, 129, 0.15);
  --hb-warning: #f59e0b;
  --hb-warning-light: rgba(245, 158, 11, 0.15);
  --hb-error: #ef4444;
  --hb-error-light: rgba(239, 68, 68, 0.15);
  --hb-info: #3b82f6;
  --hb-info-light: rgba(59, 130, 246, 0.15);
  
  /* ---------- 间距系统 ---------- */
  --hb-space-1: 4px;
  --hb-space-2: 8px;
  --hb-space-3: 12px;
  --hb-space-4: 16px;
  --hb-space-5: 20px;
  --hb-space-6: 24px;
  --hb-space-8: 32px;
  --hb-space-10: 40px;
  --hb-space-12: 48px;
  --hb-space-16: 64px;
  
  /* ---------- 圆角系统 ---------- */
  --hb-radius-sm: 8px;
  --hb-radius-md: 12px;
  --hb-radius-lg: 16px;
  --hb-radius-xl: 20px;
  --hb-radius-full: 9999px;
  
  /* ---------- 阴影系统 ---------- */
  --hb-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --hb-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --hb-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35);
  --hb-shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.45);
  --hb-shadow-primary: 0 4px 16px rgba(47, 128, 237, 0.35);
  
  /* ---------- 字体系统 ---------- */
  --hb-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --hb-font-size-xs: 11px;
  --hb-font-size-sm: 12px;
  --hb-font-size-base: 14px;
  --hb-font-size-md: 16px;
  --hb-font-size-lg: 18px;
  --hb-font-size-xl: 20px;
  --hb-font-size-2xl: 24px;
  --hb-font-size-3xl: 30px;
  
  /* ---------- 字重 ---------- */
  --hb-font-normal: 400;
  --hb-font-medium: 500;
  --hb-font-semibold: 600;
  --hb-font-bold: 700;
  --hb-font-extrabold: 800;
  
  /* ---------- 行高 ---------- */
  --hb-line-height-tight: 1.25;
  --hb-line-height-normal: 1.5;
  --hb-line-height-relaxed: 1.75;
  
  /* ---------- 过渡动画 ---------- */
  --hb-transition-fast: 0.15s ease;
  --hb-transition-normal: 0.2s ease;
  --hb-transition-slow: 0.3s ease;
  
  /* ---------- 层级系统 ---------- */
  --hb-z-dropdown: 50;
  --hb-z-sticky: 80;
  --hb-z-header: 90;
  --hb-z-modal-backdrop: 95;
  --hb-z-modal: 100;
  --hb-z-toast: 110;
  
  /* ---------- 布局变量 ---------- */
  --hb-header-height: 72px;
  --hb-header-height-scrolled: 68px;
  --hb-shell-padding: clamp(16px, 2vw, 32px);
  --hb-max-width: 1920px;
}

/* 滚动状态下的 header 高度 */
@media (max-width: 1199px) {
  :root {
    --hb-header-height: 68px;
  }
}

@media (max-width: 768px) {
  :root {
    --hb-header-height: 64px;
  }
}

/* ========================================
   2. 样式重置
   ======================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  font-family: var(--hb-font-family);
  font-size: var(--hb-font-size-base);
  font-weight: var(--hb-font-normal);
  line-height: var(--hb-line-height-normal);
  color: var(--hb-text-secondary);
  background-color: var(--hb-bg-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 菜单打开时禁止滚动 */
body.menu-open {
  overflow: hidden;
}

/* 链接重置 */
a {
  color: inherit;
  text-decoration: none;
  transition: color var(--hb-transition-normal);
}

a:hover,
a:focus {
  outline: none;
  text-decoration: none;
}

/* 按钮重置 */
button {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: var(--hb-transition-normal);
}

button:focus {
  outline: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* 表单元素重置 */
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-radius: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-shadow: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
}

select::-ms-expand {
  display: none;
}

/* 列表重置 */
ul,
ol {
  list-style: none;
}

/* 图片重置 */
img,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* 表格重置 */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* 选中文本样式 */
::selection {
  background: var(--hb-primary);
  color: var(--hb-text-primary);
  text-shadow: none;
}

::-moz-selection {
  background: var(--hb-primary);
  color: var(--hb-text-primary);
  text-shadow: none;
}

/* 占位符样式 */
::placeholder {
  color: var(--hb-text-muted);
  opacity: 1;
}

::-webkit-input-placeholder {
  color: var(--hb-text-muted);
}

::-moz-placeholder {
  color: var(--hb-text-muted);
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--hb-bg-elevated);
}

::-webkit-scrollbar-thumb {
  background: var(--hb-primary);
  border-radius: 6px;
  border: 2px solid var(--hb-bg-elevated);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--hb-primary-hover);
}

/* Firefox 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--hb-primary) var(--hb-bg-elevated);
}

/* 焦点可见性 */
:focus-visible {
  outline: 2px solid var(--hb-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ========================================
   3. 布局容器
   ======================================== */

/* 页面容器 */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Shell 容器 - 内容最大宽度限制 */
.page-shell {
  width: 100%;
  max-width: var(--hb-max-width);
  margin: 0 auto;
  padding-inline: var(--hb-shell-padding);
}

/* Header 占位符 */
.header-spacer {
  height: var(--hb-header-height);
  flex-shrink: 0;
}

/* 主内容区 */
main.page {
  flex: 1;
  padding-top: 0;
}

/* ========================================
   4. 通用工具类
   ======================================== */

/* ---------- 显示/隐藏 ---------- */
.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Flexbox ---------- */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.items-end {
  align-items: flex-end;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-start {
  justify-content: flex-start;
}

.justify-end {
  justify-content: flex-end;
}

.flex-1 {
  flex: 1;
}

.flex-shrink-0 {
  flex-shrink: 0;
}

.gap-1 { gap: var(--hb-space-1); }
.gap-2 { gap: var(--hb-space-2); }
.gap-3 { gap: var(--hb-space-3); }
.gap-4 { gap: var(--hb-space-4); }
.gap-5 { gap: var(--hb-space-5); }
.gap-6 { gap: var(--hb-space-6); }

/* ---------- Grid ---------- */
.grid {
  display: grid;
}

/* ---------- 文本 ---------- */
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-primary {
  color: var(--hb-text-primary);
}

.text-secondary {
  color: var(--hb-text-secondary);
}

.text-muted {
  color: var(--hb-text-muted);
}

.text-brand {
  color: var(--hb-primary);
}

.text-success {
  color: var(--hb-success);
}

.text-warning {
  color: var(--hb-warning);
}

.text-error {
  color: var(--hb-error);
}

.text-xs { font-size: var(--hb-font-size-xs); }
.text-sm { font-size: var(--hb-font-size-sm); }
.text-base { font-size: var(--hb-font-size-base); }
.text-md { font-size: var(--hb-font-size-md); }
.text-lg { font-size: var(--hb-font-size-lg); }
.text-xl { font-size: var(--hb-font-size-xl); }
.text-2xl { font-size: var(--hb-font-size-2xl); }

.font-normal { font-weight: var(--hb-font-normal); }
.font-medium { font-weight: var(--hb-font-medium); }
.font-semibold { font-weight: var(--hb-font-semibold); }
.font-bold { font-weight: var(--hb-font-bold); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 间距 ---------- */
.m-0 { margin: 0; }
.m-1 { margin: var(--hb-space-1); }
.m-2 { margin: var(--hb-space-2); }
.m-3 { margin: var(--hb-space-3); }
.m-4 { margin: var(--hb-space-4); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--hb-space-1); }
.mt-2 { margin-top: var(--hb-space-2); }
.mt-3 { margin-top: var(--hb-space-3); }
.mt-4 { margin-top: var(--hb-space-4); }
.mt-5 { margin-top: var(--hb-space-5); }
.mt-6 { margin-top: var(--hb-space-6); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--hb-space-1); }
.mb-2 { margin-bottom: var(--hb-space-2); }
.mb-3 { margin-bottom: var(--hb-space-3); }
.mb-4 { margin-bottom: var(--hb-space-4); }
.mb-5 { margin-bottom: var(--hb-space-5); }
.mb-6 { margin-bottom: var(--hb-space-6); }

.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0 { padding: 0; }
.p-1 { padding: var(--hb-space-1); }
.p-2 { padding: var(--hb-space-2); }
.p-3 { padding: var(--hb-space-3); }
.p-4 { padding: var(--hb-space-4); }
.p-5 { padding: var(--hb-space-5); }
.p-6 { padding: var(--hb-space-6); }

.py-3 { padding-top: var(--hb-space-3); padding-bottom: var(--hb-space-3); }
.py-4 { padding-top: var(--hb-space-4); padding-bottom: var(--hb-space-4); }
.py-5 { padding-top: var(--hb-space-5); padding-bottom: var(--hb-space-5); }
.py-6 { padding-top: var(--hb-space-6); padding-bottom: var(--hb-space-6); }

.px-3 { padding-left: var(--hb-space-3); padding-right: var(--hb-space-3); }
.px-4 { padding-left: var(--hb-space-4); padding-right: var(--hb-space-4); }
.px-5 { padding-left: var(--hb-space-5); padding-right: var(--hb-space-5); }
.px-6 { padding-left: var(--hb-space-6); padding-right: var(--hb-space-6); }

/* ---------- 宽高 ---------- */
.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

.min-h-screen {
  min-height: 100vh;
}

/* ---------- 圆角 ---------- */
.rounded-sm { border-radius: var(--hb-radius-sm); }
.rounded-md { border-radius: var(--hb-radius-md); }
.rounded-lg { border-radius: var(--hb-radius-lg); }
.rounded-xl { border-radius: var(--hb-radius-xl); }
.rounded-full { border-radius: var(--hb-radius-full); }

/* ---------- 阴影 ---------- */
.shadow-sm { box-shadow: var(--hb-shadow-sm); }
.shadow-md { box-shadow: var(--hb-shadow-md); }
.shadow-lg { box-shadow: var(--hb-shadow-lg); }
.shadow-xl { box-shadow: var(--hb-shadow-xl); }

/* ---------- 定位 ---------- */
.relative {
  position: relative;
}

.absolute {
  position: absolute;
}

.fixed {
  position: fixed;
}

.sticky {
  position: sticky;
}

.inset-0 {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* ---------- 溢出 ---------- */
.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.overflow-x-auto {
  overflow-x: auto;
}

.overflow-y-auto {
  overflow-y: auto;
}

/* ---------- 过渡 ---------- */
.transition {
  transition: all var(--hb-transition-normal);
}

.transition-fast {
  transition: all var(--hb-transition-fast);
}

.transition-slow {
  transition: all var(--hb-transition-slow);
}

/* ---------- 交互 ---------- */
.cursor-pointer {
  cursor: pointer;
}

.cursor-not-allowed {
  cursor: not-allowed;
}

.pointer-events-none {
  pointer-events: none;
}

.select-none {
  user-select: none;
}

/* ---------- 性能优化 ---------- */
.gpu {
  transform: translateZ(0);
  backface-visibility: hidden;
}

.contain-layout {
  contain: layout;
}

.contain-paint {
  contain: paint;
}

.contain-strict {
  contain: layout paint style;
}

/* ========================================
   5. 响应式工具类
   ======================================== */

/* 移动端隐藏 */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

/* 平板及以上显示 */
@media (min-width: 768px) {
  .hide-tablet-up {
    display: none !important;
  }
  
  .show-tablet-up {
    display: block;
  }
}

/* 桌面端显示 */
@media (min-width: 1024px) {
  .hide-desktop {
    display: none !important;
  }
  
  .show-desktop {
    display: block;
  }
}

/* ========================================
   6. 动画
   ======================================== */

/* 淡入 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.animate-fadeIn {
  animation: fadeIn var(--hb-transition-normal) ease forwards;
}

/* 淡入上移 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fadeInUp {
  animation: fadeInUp var(--hb-transition-slow) ease forwards;
}

/* 骨架屏闪烁 */
@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton {
  background: linear-gradient(120deg, var(--hb-bg-surface) 0%, var(--hb-bg-elevated) 40%, var(--hb-bg-surface) 80%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

/* 旋转加载 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* 减少动画（用户偏好设置） */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   7. 表单基础样式
   ======================================== */

/* 输入框基础 */
.input {
  width: 100%;
  padding: var(--hb-space-3) var(--hb-space-4);
  background: var(--hb-bg-elevated);
  border: 1px solid var(--hb-border-default);
  border-radius: var(--hb-radius-md);
  color: var(--hb-text-primary);
  font-size: var(--hb-font-size-base);
  transition: border-color var(--hb-transition-normal), box-shadow var(--hb-transition-normal);
}

.input:focus {
  border-color: var(--hb-primary);
  box-shadow: 0 0 0 3px var(--hb-primary-light);
}

.input::placeholder {
  color: var(--hb-text-muted);
}

.input:disabled {
  background: var(--hb-bg-surface);
  cursor: not-allowed;
  opacity: 0.6;
}

/* 输入框错误状态 */
.input.is-error {
  border-color: var(--hb-error);
}

.input.is-error:focus {
  box-shadow: 0 0 0 3px var(--hb-error-light);
}

/* ========================================
   8. 按钮基础样式
   ======================================== */

/* 按钮基础 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--hb-space-2);
  padding: var(--hb-space-3) var(--hb-space-5);
  font-size: var(--hb-font-size-base);
  font-weight: var(--hb-font-semibold);
  line-height: 1;
  border-radius: var(--hb-radius-md);
  transition: all var(--hb-transition-normal);
  white-space: nowrap;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 主要按钮 */
.btn-primary {
  background: var(--hb-primary-gradient);
  color: var(--hb-text-primary);
  border: none;
  box-shadow: var(--hb-shadow-primary);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(47, 128, 237, 0.45);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

/* 次要按钮 */
.btn-secondary {
  background: var(--hb-bg-elevated);
  color: var(--hb-text-secondary);
  border: 1px solid var(--hb-border-default);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--hb-bg-card);
  border-color: var(--hb-border-hover);
  color: var(--hb-text-primary);
}

/* 幽灵按钮 */
.btn-ghost {
  background: transparent;
  color: var(--hb-text-secondary);
  border: 1px solid var(--hb-border-default);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--hb-primary-light);
  border-color: var(--hb-primary);
  color: var(--hb-primary);
}

/* 文本按钮 */
.btn-text {
  background: transparent;
  color: var(--hb-primary);
  padding: var(--hb-space-2) var(--hb-space-3);
}

.btn-text:hover:not(:disabled) {
  background: var(--hb-primary-light);
}

/* 按钮尺寸 */
.btn-sm {
  padding: var(--hb-space-2) var(--hb-space-3);
  font-size: var(--hb-font-size-sm);
}

.btn-lg {
  padding: var(--hb-space-4) var(--hb-space-6);
  font-size: var(--hb-font-size-md);
}

/* 全宽按钮 */
.btn-block {
  width: 100%;
}

/* ========================================
   9. 卡片基础样式
   ======================================== */

.card {
  background: var(--hb-bg-card);
  border: 1px solid var(--hb-border-default);
  border-radius: var(--hb-radius-lg);
  overflow: hidden;
  transition: transform var(--hb-transition-normal), border-color var(--hb-transition-normal), box-shadow var(--hb-transition-normal);
}

.card:hover {
  border-color: var(--hb-border-hover);
}

.card-elevated {
  box-shadow: var(--hb-shadow-lg);
}

.card-elevated:hover {
  transform: translateY(-4px);
  box-shadow: var(--hb-shadow-xl);
}

/* ========================================
   10. 徽章样式
   ======================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--hb-space-1) var(--hb-space-2);
  font-size: var(--hb-font-size-xs);
  font-weight: var(--hb-font-semibold);
  line-height: 1;
  border-radius: var(--hb-radius-sm);
  white-space: nowrap;
}

.badge-primary {
  background: var(--hb-primary);
  color: var(--hb-text-primary);
}

.badge-success {
  background: var(--hb-success);
  color: var(--hb-text-primary);
}

.badge-warning {
  background: var(--hb-warning);
  color: var(--hb-bg-body);
}

.badge-error {
  background: var(--hb-error);
  color: var(--hb-text-primary);
}

.badge-info {
  background: var(--hb-info);
  color: var(--hb-text-primary);
}

.badge-outline {
  background: transparent;
  border: 1px solid currentColor;
}

