:root[data-theme="dark"] {
  --bg: #090d16;
  --card-bg: #111726;
  --card-border: #1e293b;
  --omnibar-bg: #0d1322;
  --omnibar-border: #2a374f;
  --hover-bg: #1a233a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-sub: #64748b;
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  --primary-glow: rgba(14, 165, 233, 0.25);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --badge-bg: #141b2b;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --omnibar-bg: #f1f5f9;
  --omnibar-border: #cbd5e1;
  --hover-bg: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --text-sub: #64748b;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.2);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --badge-bg: #f1f5f9;
  --shadow: 0 4px 16px -2px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { overflow-x: hidden; max-width: 100vw; }
body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.brand-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.2; }
.brand-subtitle { font-size: 11px; color: var(--text-sub); }

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--omnibar-bg);
  border: 1px solid var(--card-border);
  padding: 3px;
  border-radius: 8px;
}
.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  background: var(--card-bg);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nav-btn {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--hover-bg);
  border: 1px solid var(--card-border);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.nav-btn:hover { color: var(--text); border-color: var(--primary); }

main {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* 门禁卡片 */
.gate-wrap {
  min-height: 60vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}
.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}
.gate-title { font-size: 18px; font-weight: 700; color: var(--text); }
.gate-desc { font-size: 13px; color: var(--text-sub); line-height: 1.5; }
.gate-input {
  height: 42px;
  background: var(--omnibar-bg);
  border: 1px solid var(--omnibar-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 0 14px;
  outline: none;
  text-align: center;
  transition: border-color 0.15s ease;
}
.gate-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

/* 控制栏 */
.omnibar-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.omnibar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 260px;
}
.select-storage {
  height: 36px;
  background: var(--omnibar-bg);
  border: 1px solid var(--omnibar-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
  padding: 0 10px;
  outline: none;
  cursor: pointer;
}
.select-storage:focus { border-color: var(--primary); }

.status-badge {
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--badge-bg);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

/* 拖拽上传 */
.dropzone-card {
  background: var(--card-bg);
  border: 2px dashed var(--card-border);
  border-radius: 12px;
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  box-shadow: var(--shadow);
}
.dropzone-card:hover, .dropzone-card.dragover {
  border-color: var(--primary);
  background: var(--omnibar-bg);
  box-shadow: 0 0 0 4px var(--primary-glow);
}
.dropzone-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dropzone-icon svg { width: 34px; height: 34px; stroke-width: 1.8; fill: none; stroke: currentColor; }
.dropzone-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.dropzone-sub { font-size: 12.5px; color: var(--text-sub); }
.file-input { display: none; }

.quick-chips-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.chip {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--hover-bg);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
}

/* 按钮通用 */
.btn {
  height: 34px;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px var(--primary-glow); }
.btn.secondary { background: var(--hover-bg); color: var(--text); border: 1px solid var(--card-border); font-weight: 500; }
.btn.secondary:hover { border-color: var(--primary); filter: none; }
.btn.danger { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); font-weight: 500; }
.btn.danger:hover { background: var(--danger); color: #fff; filter: none; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 11.5px; }
.btn.copied { background: var(--success) !important; color: #fff !important; border: none !important; }

/* 提示栏 */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
  align-items: center;
  gap: 8px;
}
.alert.error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.25); color: #f87171; display: flex; }
.alert.info { background: rgba(14, 165, 233, 0.12); border: 1px solid rgba(14, 165, 233, 0.25); color: var(--primary); display: flex; }
.alert.success { background: rgba(16, 185, 129, 0.12); border: 1px solid rgba(16, 185, 129, 0.25); color: #34d399; display: flex; }

/* 队列卡片 */
.queue-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  gap: 12px;
}
.queue-panel.active { display: flex; }

/* 全局总体进度条 */
.global-progress-wrap {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px 16px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}
.global-progress-wrap.active { display: flex; }
.global-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}
.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--hover-bg);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #6366f1);
  border-radius: 3px;
  transition: width 0.15s ease;
  width: 0%;
}

/* 单任务进度条 */
.queue-progress-bar {
  width: 100%;
  height: 4px;
  background: var(--hover-bg);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.queue-progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.1s ease;
}
.queue-progress-fill.error { background: var(--danger); }
.queue-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 3px;
}
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 12px;
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--omnibar-bg);
  border: 1px solid var(--omnibar-border);
  border-radius: 8px;
  padding: 10px 12px;
}
.queue-thumb { width: 50px; height: 50px; border-radius: 6px; object-fit: cover; background: #000; flex-shrink: 0; cursor: zoom-in; }
.queue-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.queue-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* 图库 */
.gallery-panel { display: none; flex-direction: column; gap: 16px; }
.gallery-toolbar {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow);
}
.search-input {
  width: 240px;
  height: 34px;
  background: var(--omnibar-bg);
  border: 1px solid var(--omnibar-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
  padding: 0 10px;
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.gallery-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
.gallery-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.gallery-cover {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #060910;
  overflow: hidden;
  position: relative;
  cursor: zoom-in;
}
.gallery-cover img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.25s ease; }
.gallery-card:hover .gallery-cover img { transform: scale(1.04); }
.gallery-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}
.gallery-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.gallery-title { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.gallery-sub { font-size: 11px; color: var(--text-sub); display: flex; justify-content: space-between; }
.gallery-btns { display: flex; gap: 6px; margin-top: 4px; }

/* 批量控制条 */
.batch-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  border-radius: 30px;
  padding: 8px 18px;
  display: none;
  align-items: center;
  gap: 12px;
  z-index: 1000;
}
.batch-bar.active { display: flex; }
.batch-text { font-size: 12.5px; font-weight: 500; color: var(--text); }

/* 灯箱 */
.lightbox {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 24px;
}
.lightbox.active { display: flex; }
.lightbox img { max-width: 90vw; max-height: 85vh; object-fit: contain; border-radius: 6px; box-shadow: 0 12px 48px rgba(0,0,0,0.8); }
.lightbox-close { position: absolute; top: 20px; right: 24px; background: none; border: none; color: #fff; font-size: 26px; cursor: pointer; }

/* 后台分开排版卡片 */
.admin-panel { display: none; flex-direction: column; gap: 20px; }
.admin-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.admin-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.admin-card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.admin-card-desc { font-size: 12px; color: var(--text-sub); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text); }
.form-group small { font-size: 11.5px; color: var(--text-sub); line-height: 1.4; }
.form-group input, .form-group select {
  height: 38px;
  background: var(--omnibar-bg);
  border: 1px solid var(--omnibar-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 0 12px;
  outline: none;
  transition: border-color 0.15s ease;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* 存储池横向拖动容器 (禁止竖向叠加) */
.storage-table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--omnibar-bg);
}
.storage-table {
  width: 100%;
  min-width: 680px; /* 确保在小屏下保持单行，通过手指横向划动 */
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}
.storage-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--text-sub);
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
}
.storage-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text);
  vertical-align: middle;
}
.storage-table tr:last-child td {
  border-bottom: none;
}
.storage-actions-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.storage-tag-active {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* 模态弹窗系统 (用于添加/编辑 R2 存储桶) */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  z-index: 9999;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 16px;
}
.modal-overlay.active { display: flex; }

/* 全局悬浮 Toast 提示 (解决移动端滚动看不到顶部报错的问题) */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  animation: toastIn 0.2s ease forwards;
  text-align: center;
}
.toast.info { border-color: var(--primary); color: var(--primary); }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: #f87171; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--text); }
.modal-close-btn {
  background: none; border: none; color: var(--text-sub); font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close-btn:hover { color: var(--text); }
.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--card-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--card-bg);
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
}

/* 移动端深度优化：防溢出与弹性排版 */
@media (max-width: 768px) {
  header { padding: 4px 0; }
  .header-inner {
    padding: 8px 12px;
    flex-wrap: wrap; /* 移动端自然折行，绝不横向挤爆 */
    gap: 8px;
    justify-content: space-between;
  }
  .brand { order: 1; }
  .header-actions { order: 2; gap: 6px; }
  .nav-tabs {
    order: 3;
    width: 100%; /* Tab 在移动端独占第二行，居中展示 */
    justify-content: center;
    margin-top: 4px;
    padding: 3px;
    gap: 4px;
  }
  .nav-tab {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 13px;
    min-height: 36px;
  }
  .nav-btn {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 34px;
  }
  .btn {
    min-height: 38px;
  }
  .btn.sm {
    min-height: 30px;
  }

  main { padding: 12px 10px; gap: 14px; }
  
  .gate-wrap { min-height: 48vh; padding: 10px; }
  .gate-card { padding: 22px 16px; max-width: 100%; border-radius: 12px; }
  .gate-input { font-size: 16px; }

  .omnibar-card { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; }
  .omnibar-left { min-width: 100%; }
  .select-storage { width: 100%; }

  .dropzone-card { padding: 32px 14px; }
  .quick-chips-row { gap: 6px; }
  .chip { font-size: 11px; padding: 3px 8px; }

  .gallery-toolbar { padding: 10px 12px; }
  .search-input { width: 100%; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .gallery-body { padding: 8px 10px; }
  .gallery-btns .btn { flex: 1; padding: 0 4px; }

  .batch-bar { width: 92%; max-width: 380px; justify-content: space-between; padding: 8px 12px; }
  .batch-bar .batch-text { font-size: 11px; }
  .batch-bar .btn { font-size: 11px; padding: 0 6px; }

  .admin-card { padding: 16px 14px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-group input, .form-group select { font-size: 16px; }
}
