/*
 * 元启 - 公共样式
 * 响应式设计：移动端优先，适配 PC/平板/手机
 */

/* ========== CSS 变量 ========== */
:root {
  /* 颜色变量 */
  --primary: #000000;
  --primary-hover: #333333;
  --secondary: #666666;
  --accent: #2563EB;
  --body-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --border: #E5E7EB;
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;

  /* 布局变量 */
  --sidebar-width: 256px;
  --sidebar-width-collapsed: 0px;
  --header-height: 64px;

  /* 过渡 */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
}

/* ========== 基础重置 ========== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== 响应式断点 ========== */

/* 移动端基础样式（默认） */
.site-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.site-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
  z-index: 50;
}

.site-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.site-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--card-bg);
  flex-shrink: 0;
}

.site-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* ========== 侧边栏 Logo 区 ========== */
.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-icon {
  font-size: 28px;
}

.sidebar-logo-text {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ========== 汉堡菜单按钮 ========== */
.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.menu-toggle:hover {
  background: #F3F4F6;
  color: var(--primary);
}

/* ========== 遮罩层（移动端） ========== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* ========== 导航链接 ========== */
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.nav-link:hover {
  background: #F9FAFB;
  color: var(--text-primary);
}

.nav-link.active {
  background: #F9FAFB;
  color: var(--primary);
  font-weight: 500;
}

.nav-link i {
  width: 20px;
  text-align: center;
}

/* ========== 用户菜单 ========== */
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition-fast);
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.user-menu:hover {
  background: #F3F4F6;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a1a1a 0%, #4a4a4a 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== 按钮样式 ========== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  background: #FFFFFF;
  color: var(--text-primary);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  border-color: var(--primary);
  background: #F9FAFB;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: #EF4444;
  color: white;
}

.btn-danger:hover {
  background: #DC2626;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: #F3F4F6;
  color: var(--text-primary);
}

.btn-icon.danger:hover {
  background: #FEF2F2;
  color: #DC2626;
}

/* ========== 输入框样式 ========== */
.input-field {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: all var(--transition-fast);
  outline: none;
}

.input-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

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

/* ========== 卡片样式 ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: all var(--transition-fast);
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ========== 文件网格（响应式） ========== */
.file-grid {
  display: grid;
  gap: 16px;
  /* 自适应列数：最小 160px，最大自动填充 */
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.file-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.file-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border-color: #D1D5DB;
}

.file-card-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.file-card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.file-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* 文件列表视图 */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.file-list-item:hover {
  background: #F9FAFB;
  border-color: #D1D5DB;
}

.file-list-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.file-list-info {
  flex: 1;
  min-width: 0;
}

.file-list-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-list-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.file-list-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ========== 表格样式（响应式） ========== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: #F9FAFB;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tr:hover {
  background: #F9FAFB;
}

/* ========== 模态框样式 ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 512px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ========== 通知 Toast ========== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 14px 20px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
  animation: slideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid #10B981;
}

.toast.error {
  border-left: 4px solid #EF4444;
}

.toast.warning {
  border-left: 4px solid #F59E0B;
}

.toast-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: #10B981; }
.toast.error .toast-icon { color: #EF4444; }
.toast.warning .toast-icon { color: #F59E0B; }

.toast-message {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

@keyframes slideIn {
  from {
    transform: translateX(calc(100% + 20px));
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ========== 加载动画 ========== */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
  color: var(--text-muted);
}

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-state-icon {
  font-size: 64px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state-desc {
  font-size: 14px;
  color: var(--text-muted);
}

/* ========== 工具类 ========== */
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 600; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ========== 响应式断点：平板 (641px - 1024px) ========== */
@media (min-width: 641px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }

  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .site-header {
    padding: 0 12px;
  }

  .site-content {
    padding: 12px;
  }
}

/* ========== 响应式断点：PC (>1024px) ========== */
@media (min-width: 1025px) {
  .site-sidebar.mobile {
    transform: translateX(calc(-1 * var(--sidebar-width)));
  }

  .site-sidebar.mobile.open {
    transform: translateX(0);
  }

  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* ========== 响应式断点：手机 (<=768px) ========== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 256px;
  }

  /* 移动端侧边栏默认隐藏 */
  .site-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  .site-sidebar.open {
    transform: translateX(0);
  }

  .site-header {
    padding: 0 12px;
  }

  .site-content {
    padding: 12px;
  }

  /* 文件网格：2 列 */
  .file-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .file-card {
    padding: 12px;
  }

  .file-card-icon {
    font-size: 36px;
  }

  .file-card-name {
    font-size: 12px;
  }

  /* 模态框全宽 */
  .modal {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    height: 100%;
  }

  /* Toast 全宽 */
  .toast {
    left: 16px;
    right: 16px;
    max-width: none;
  }

  /* 按钮组垂直排列 */
  .btn-group {
    flex-direction: column;
  }

  .btn-group .btn {
    width: 100%;
  }

  /* 表格卡片化 */
  .data-table th,
  .data-table td {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* 隐藏次要列 */
  .data-table .hide-mobile {
    display: none;
  }
}

/* ========== 打印样式 ========== */
@media print {
  .site-sidebar,
  .site-header,
  .btn,
  .modal-overlay {
    display: none !important;
  }

  .site-main,
  .site-content {
    overflow: visible;
    height: auto;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
