/* ─── 全局重置 ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sidebar-width: 220px;
  --header-height: 56px;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --border: #e0e0e0;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.app-hidden {
  display: none !important;
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(145deg, #e9f5ed, #f5f7f9);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 36px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(30, 41, 59, 0.14);
}

.auth-logo { text-align: center; font-size: 52px; }
.auth-card h1 { margin-top: 8px; text-align: center; font-size: 24px; }
.auth-card p { margin: 6px 0 26px; color: var(--text-muted); text-align: center; }
.auth-card label { display: block; margin: 14px 0 6px; font-weight: 500; }
.auth-submit { width: 100%; margin-top: 20px; padding: 10px; }
.auth-error { min-height: 21px; margin-top: 12px; color: var(--danger); }

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

.sidebar-user button {
  border: 0;
  color: rgba(255, 255, 255, 0.7);
  background: transparent;
  cursor: pointer;
}

/* ─── 布局 ─── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ─── 侧边栏 ─── */
.sidebar {
  width: var(--sidebar-width);
  background: #1e293b;
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.sidebar-header .sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: all 0.2s;
  gap: 10px;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-left-color: var(--primary);
}

.nav-item .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* ─── 主内容区 ─── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

/* ─── 页面标题 ─── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.page-header .actions {
  display: flex;
  gap: 8px;
}

/* ─── 卡片 ─── */
.card {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 20px;
  margin-bottom: 16px;
}

/* ─── 按钮 ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: #f5f5f5;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover {
  background: #218838;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

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

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ─── 表格 ─── */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th,
table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table th {
  background: #f8f9fa;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
}

table tr:hover {
  background: #f8f9ff;
}

table td.actions {
  white-space: nowrap;
}
table td.actions .btn {
  margin-right: 4px;
}

/* ─── 表单 ─── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.form-group .required::after {
  content: " *";
  color: var(--danger);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
  outline: none;
  background: #fff;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.form-control-sm {
  padding: 4px 8px;
  font-size: 13px;
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── 搜索框 ─── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.search-bar .form-control {
  width: 260px;
}

.search-bar .form-control-sm {
  width: 180px;
}

/* ─── 分页 ─── */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination-info {
  font-size: 13px;
}

.pagination-buttons {
  display: flex;
  gap: 4px;
}

.pagination-buttons button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.pagination-buttons button:hover:not(:disabled) {
  background: #f0f0f0;
}

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

.pagination-buttons button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ─── 图片预览 ─── */
.image-preview {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.image-preview-lg {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.preview-card {
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.preview-del {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: #dc3545;
  color: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.preview-del:hover {
  background: #c82333;
}

.preview-label {
  position: absolute;
  top: -8px;
  left: -8px;
  padding: 2px 8px;
  background: #1a73e8;
  color: #fff;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.preview-label.cover {
  background: #28a745;
}

.preview-label.cover-hint {
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.2s;
}

.preview-card:hover .cover-hint {
  opacity: 1;
}

.add-card {
  width: 200px;
  height: 200px;
  border: 2px dashed #ddd;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
}

.add-card:hover {
  border-color: #1a73e8;
}

.add-icon {
  font-size: 36px;
  color: #ccc;
}

.add-text {
  font-size: 13px;
  color: #999;
  margin-top: 4px;
}

.add-card-empty {
  width: 100%;
  height: 160px;
}
.add-card-empty .add-icon { font-size: 48px; }
.add-card-empty .add-text { font-size: 15px; }

/* 放大按钮 */
.zoom-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.preview-card:hover .zoom-btn { opacity: 1; }
.zoom-btn:hover { background: rgba(0,0,0,0.7); }

/* 图片灯箱 */
.image-lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.image-preview-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ─── 状态标签 ─── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success {
  background: #d4edda;
  color: #155724;
}

.badge-warning {
  background: #fff3cd;
  color: #856404;
}

.badge-danger {
  background: #f8d7da;
  color: #721c24;
}

.badge-info {
  background: #d1ecf1;
  color: #0c5460;
}

.badge-secondary {
  background: #e2e3e5;
  color: #383d41;
}

/* ─── 弹窗 ─── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  min-width: 400px;
  max-width: 600px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ─── Toast 消息 ─── */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateX(120%);
  transition: transform 0.3s ease;
}

.toast.show {
  transform: translateX(0);
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

.toast-warning {
  background: var(--warning);
  color: #333;
}

/* ─── 树形分类 ─── */
.category-tree {
  list-style: none;
}

.category-tree ul {
  list-style: none;
}

.category-tree .cat-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  cursor: default;
  border-radius: 6px;
  transition: background 0.15s;
}

.category-tree .cat-node:hover {
  background: #f5f7ff;
}

.category-tree .cat-node.level-1 {
  padding-left: 4px;
}

.category-tree .cat-node.level-2 {
  padding-left: 32px;
}

.category-tree .cat-node.level-3 {
  padding-left: 60px;
}

.category-tree .cat-toggle {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #999;
  cursor: pointer;
  border-radius: 3px;
  flex-shrink: 0;
}

.category-tree .cat-toggle:hover {
  background: #e0e0e0;
  color: #333;
}

.category-tree .cat-toggle.empty {
  visibility: hidden;
}

.category-tree .cat-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.category-tree .cat-name {
  font-size: 14px;
  font-weight: 500;
}

.category-tree .cat-name.editing {
  border: 2px solid #1a73e8;
  border-radius: 4px;
  padding: 2px 6px;
  outline: none;
  background: #fff;
  min-width: 120px;
}

.category-tree .level-3 .cat-name {
  font-size: 13px;
  color: var(--text-secondary);
}

.category-tree .cat-count {
  font-size: 12px;
  color: #999;
  flex-shrink: 0;
}

.category-tree .cat-count.warn {
  color: var(--warning);
}

.category-tree .cat-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.category-tree .cat-actions button {
  font-size: 11px;
  padding: 2px 8px;
}

.category-tree .cat-children.collapsed {
  display: none;
}

/* 拖拽排序辅助 */
.category-tree .sort-btn {
  font-size: 11px;
  padding: 2px 6px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 3px;
  cursor: pointer;
  color: #666;
}

.category-tree .sort-btn:hover {
  background: #e0e0e0;
}

.category-tree .sort-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ─── 空状态 ─── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ─── 响应式 ─── */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-header h1,
  .sidebar-header .sub,
  .nav-item span {
    display: none;
  }
  .main-content {
    margin-left: 60px;
    padding: 16px;
  }
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
  .search-bar .form-control {
    width: 100%;
  }
}
