/*
 * Songbrocade Mobile-First Design System
 * 移动优先响应式设计
 */

:root {
  /* 品牌色彩 */
  --primary: #B41E2E;
  --primary-light: #D63447;
  --primary-dark: #8B1621;
  --secondary: #3A6A57;
  --accent: #EADBB7;
  
  /* 中性色 */
  --text-primary: #000000;   /* 所有文字统一纯黑 */
  --text-secondary: #000000;
  --text-tertiary: #000000;
  --bg-primary: #FFFFFF;     /* 页面/卡片背景统一白色 */
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #FFFFFF;
  --border: rgba(0,0,0,0.15); /* 仅用黑色透明度做边框 */
  
  /* 语义色彩 */
  --success: #22C55E;
  --warning: #F59E0B;
  --error: #EF4444;
  --info: #3B82F6;
  
  /* 间距系统 (基于 4px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  
  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  
  /* 阴影 */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 12px 40px rgba(0, 0, 0, 0.16);
  
  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
  --font-serif: 'Georgia', 'Noto Serif SC', serif;
  
  /* 字号 (移动优先) */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;
  
  /* 过渡 */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Z-index */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-toast: 1060;
}

/* 深色模式下也保持白底黑字，避免整页反色导致视觉疲劳 */
@media (prefers-color-scheme: dark) {
  :root {
    --text-primary: #000000;
    --text-secondary: #000000;
    --text-tertiary: #000000;
    --bg-primary: #FFFFFF;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #FFFFFF;
    --border: rgba(0,0,0,0.15);
  }
}

/* 重置和基础样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* 响应式容器 (移动优先) */
.container {
  width: 100%;
  max-width: 100%;
  padding: var(--space-4);
  margin: 0 auto;
}

/* 平板 */
@media (min-width: 768px) {
  .container {
    max-width: 768px;
    padding: var(--space-6);
  }
}

/* 桌面 */
@media (min-width: 1024px) {
  .container {
    max-width: 1024px;
    padding: var(--space-8);
  }
}

/* 大屏 */
@media (min-width: 1280px) {
  .container {
    max-width: 1200px;
  }
}

/* 页头 */
header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  box-shadow: var(--shadow-sm);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  gap: var(--space-3);
  flex-wrap: wrap;
}

header h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  line-height: 1.2;
}

@media (min-width: 768px) {
  .header-content {
    padding: var(--space-5) var(--space-6);
  }
  
  header h1 {
    font-size: var(--text-2xl);
  }
}

/* 导航 */
nav {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

nav a {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
}

nav a:hover,
nav a:active {
  background: var(--bg-tertiary);
  color: var(--primary);
}

@media (min-width: 768px) {
  nav {
    gap: var(--space-3);
  }
  
  nav a {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-base);
  }
}

/* 卡片组件 */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  transition: var(--transition);
}

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

.card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
  line-height: 1.3;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.card-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: var(--space-3);
}

@media (min-width: 768px) {
  .card {
    padding: var(--space-6);
    border-radius: var(--radius-xl);
  }
  
  .card-title {
    font-size: var(--text-xl);
  }
  
  .card-desc {
    font-size: var(--text-base);
  }
}

/* 按钮系统 (移动友好：44px 最小触摸面积) */
.btn,
button:not(.unstyled) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

/* 主按钮 */
.btn-primary,
button:not([class*="btn-"]):not(.unstyled) {
  background: var(--primary);
  color: white;
}

.btn-primary:hover,
.btn-primary:active,
button:not([class*="btn-"]):not(.unstyled):hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* 次级按钮 */
.btn-secondary {
  background: var(--bg-primary);
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-secondary:hover,
.btn-secondary:active {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
}

/* 成功按钮 */
.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #16A34A;
  transform: translateY(-1px);
}

/* 警告按钮 */
.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:hover {
  background: #D97706;
  transform: translateY(-1px);
}

/* 按钮尺寸 */
.btn-sm {
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.btn-lg {
  min-height: 52px;
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-lg);
}

.btn-block {
  display: flex;
  width: 100%;
}

/* 表单控件 (移动优先) */
.form-group {
  margin-bottom: var(--space-4);
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  line-height: 1.5;
  /* 白底黑字，贴近纸张阅读体验 */
  color: #000000 !important;
  background: #FFFFFF !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(180, 30, 46, 0.1);
}

input::placeholder,
textarea::placeholder {
  /* 白色背景上的placeholder使用中等灰色，确保可读性 */
  color: #999999 !important;
  opacity: 1;
}

/* Disabled状态 - 保持白色背景，但降低对比度 */
input:disabled,
textarea:disabled,
select:disabled {
  background: #E5E7EB !important; /* 比正常态略浅，仍为灰底 */
  color: #4B5563 !important;
  cursor: not-allowed;
  opacity: 0.7;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

select {
  /* 使用深色箭头图标，在白色背景上清晰可见 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-8);
}

/* 复选框和单选框 */
input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  margin-right: var(--space-2);
  cursor: pointer;
}

/* 网格系统 */
.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Flex 布局 */
.flex {
  display: flex;
}

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

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

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

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

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

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

/* 徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

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

.badge-secondary {
  background: var(--secondary);
  color: white;
}

.badge-success {
  background: var(--success);
  color: white;
}

.badge-warning {
  background: var(--warning);
  color: white;
}

.badge-info {
  background: var(--info);
  color: white;
}

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

/* 状态消息 */
.status-message {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
  display: none;
}

.status-message.show {
  display: block;
}

.status-message.success {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #BBF7D0;
}

.status-message.error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
}

.status-message.warning {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
}

.status-message.info {
  background: #DBEAFE;
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

/* 钱包地址显示 */
.wallet-address {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-family: monospace;
  color: var(--text-secondary);
}

.wallet-btn {
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.wallet-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* 加载动画 */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* 日志输出 */
.log,
pre.log {
  background: #0F172A;
  color: #E2E8F0;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: var(--text-sm);
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: var(--space-4) 0;
}

/* 分隔线 */
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: var(--space-6) 0;
}

/* 链接 */
a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* 标题 */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

@media (min-width: 768px) {
  h1 { font-size: var(--text-4xl); }
  h2 { font-size: var(--text-3xl); }
  h3 { font-size: var(--text-2xl); }
}

/* 段落 */
p {
  margin-bottom: var(--space-4);
  line-height: 1.7;
  color: var(--text-secondary);
}

/* 列表 */
ul, ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

li {
  margin-bottom: var(--space-2);
  line-height: 1.6;
}

/* 工具类 */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* 隐藏类 */
.hidden {
  display: none !important;
}

.mobile-only {
  display: block;
}

.desktop-only {
  display: none;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
  
  .desktop-only {
    display: block;
  }
}

/* 模态框 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-6);
}

/* Tab 标签页 */
.tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: var(--space-3) var(--space-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  min-height: 44px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* 底部导航 (移动端) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  z-index: var(--z-fixed);
  display: flex;
  justify-content: space-around;
  padding: var(--space-2) 0;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  min-width: 60px;
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: var(--text-xs);
  transition: var(--transition);
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-icon {
  font-size: 24px;
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* 浮动操作按钮 (FAB) */
.fab {
  position: fixed;
  bottom: 80px;
  right: var(--space-4);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  z-index: var(--z-fixed);
  transition: var(--transition);
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl);
}

@media (min-width: 768px) {
  .fab {
    bottom: var(--space-6);
    right: var(--space-6);
  }
}

/* 卡片网格 */
.card-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-6);
  }
}

/* 渐变背景 */
.gradient-bg {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

/* 触摸反馈 */
@media (hover: none) and (pointer: coarse) {
  .btn:active,
  button:active,
  .tab-btn:active,
  .bottom-nav-item:active {
    opacity: 0.8;
    transform: scale(0.98);
  }
}

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

/* 打印样式 */
@media print {
  .no-print {
    display: none !important;
  }
}

/* 骨架屏加载动画 */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--border) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Section 分段 */
.section {
  margin-bottom: var(--space-8);
}

.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.section-icon {
  font-size: var(--text-2xl);
}

.section-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

@media (min-width: 768px) {
  .section-title {
    font-size: var(--text-2xl);
  }
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-4);
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-text {
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}

/* 滚动条优化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* 页脚 */
footer {
  margin-top: var(--space-12);
  padding: var(--space-8) 0;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

@media (max-width: 767px) {
  footer {
    padding-bottom: 80px; /* 为底部导航留出空间 */
  }
}

/* 面包屑导航 */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.breadcrumb-separator {
  color: var(--text-tertiary);
}

/* Toast 通知 */
.toast {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-toast);
  font-size: var(--text-sm);
  max-width: calc(100% - var(--space-8));
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (min-width: 768px) {
  .toast {
    max-width: 400px;
  }
}
