:root {
  --sidebar-width: 220px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* ice-blue 默认 */
  --color-primary: #0284c7;
  --color-primary-light: #e0f2fe;
  --color-primary-hover: #0369a1;
  --color-primary-subtle: rgba(2, 132, 199, 0.08);

  --color-purple: #7c3aed;
  --color-purple-light: #f3e8ff;
  --color-purple-hover: #6d28d9;

  --sidebar-bg: rgba(15, 23, 42, 0.95);
  --sidebar-text: #e2e8f0;
  --sidebar-text-muted: #94a3b8;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(2, 132, 199, 0.25);
  --sidebar-width: 220px;

  --bg: #f0f4f8;
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.35);
  --glass-shadow: 0 8px 32px rgba(31, 38, 135, 0.10);
  --glass-blur: 14px;

  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --glass-bg: rgba(30, 41, 59, 0.85);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.30);
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --sidebar-bg: rgba(2, 6, 23, 0.97);
  --color-primary-subtle: rgba(2, 132, 199, 0.15);
}

[data-color="purple"] {
  --color-primary: #7c3aed;
  --color-primary-light: #f3e8ff;
  --color-primary-hover: #6d28d9;
  --color-primary-subtle: rgba(124, 58, 237, 0.08);
  --sidebar-active: rgba(124, 58, 237, 0.25);
}
[data-color="purple"][data-theme="dark"] {
  --color-primary-subtle: rgba(124, 58, 237, 0.15);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }

/* ── Layout ── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-width);
  background: var(--sidebar-bg); backdrop-filter: blur(16px);
  z-index: 100; display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.04);
  transition: background var(--transition);
}
.sidebar-brand {
  padding: 22px 20px 14px; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-brand h1 { font-size: 19px; font-weight: 700; color: #fff; margin: 0; letter-spacing: -0.3px; }
.sidebar-brand h1 span { color: var(--color-primary); transition: color var(--transition); }
.sidebar-brand small { font-size: 13px; color: var(--sidebar-text-muted); display: block; margin-top: 3px; }
.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; padding: 9px 20px; gap: 12px;
  color: var(--sidebar-text); text-decoration: none; transition: all 0.15s;
  cursor: pointer; border-left: 3px solid transparent; font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--sidebar-active); color: #fff; border-left-color: #fff;
}
.nav-item i { width: 20px; font-size: 15px; text-align: center; }

.sidebar-toggle { display: none; }

.main-wrap { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.page-header {
  background: var(--glass-bg); backdrop-filter: var(--glass-blur);
  padding: 14px 28px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  transition: background var(--transition), border var(--transition);
}
.page-header h2 { font-size: 17px; font-weight: 600; color: var(--text); margin: 0; }
.page-header-actions { display: flex; align-items: center; gap: 6px; }
.page-body { padding: 22px 28px 8px; flex: 1; }

/* ── Theme Toggle ── */
.theme-toggle {
  display: flex; align-items: center; gap: 2px;
  background: var(--border-light); border-radius: var(--radius-full);
  padding: 2px; border: 1px solid var(--border);
}
.theme-toggle button {
  border: none; background: transparent; color: var(--text-muted);
  width: 30px; height: 28px; border-radius: var(--radius-full);
  cursor: pointer; font-size: 13px; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle button.active { background: var(--color-primary); color: #fff; }
.theme-toggle button:not(.active):hover { color: var(--text); }

.color-toggle-btn {
  border: none; background: transparent; color: var(--text-muted);
  width: 30px; height: 28px; border-radius: var(--radius-full);
  cursor: pointer; font-size: 13px; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.color-toggle-btn.active { background: var(--color-primary); color: #fff; }
.color-toggle-btn:not(.active):hover { color: var(--text); }

/* ── Template Tags ── */
.tpl-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; background: var(--border-light);
}
.tpl-tag.ready { background: var(--success-bg); color: var(--success); }
.tpl-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Components ── */
.card-glass {
  background: var(--glass-bg); backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-lg); border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow); padding: 20px;
  transition: background var(--transition), border var(--transition), box-shadow var(--transition);
}
.card-glass-sm { padding: 14px; border-radius: var(--radius-md); }

/* Buttons */
.btn-base {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 0.2s;
  font-family: var(--font); line-height: 1.4;
  white-space: nowrap;
}
.btn-base:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-base:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-outline {
  background: transparent; color: var(--text); border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-subtle); }
.btn-ghost {
  background: transparent; color: var(--text-secondary); border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--color-primary-subtle); color: var(--color-primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Table */
.table-glass {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table-glass thead { position: sticky; top: 0; z-index: 5; }
.table-glass th {
  padding: 10px 14px; text-align: left; font-weight: 600; color: var(--text-secondary);
  font-size: 12px; white-space: nowrap; background: var(--bg);
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.3px;
}
.table-glass td { padding: 12px 14px; border-bottom: 1px solid var(--border-light); vertical-align: middle; line-height: 1.5; }
.table-glass tr.row-even { background: transparent; }
.table-glass tr.row-odd { background: rgba(0,0,0,0.02); }
[data-theme="dark"] .table-glass tr.row-odd { background: rgba(255,255,255,0.02); }
.table-glass tr:hover { background: var(--color-primary-subtle); }
.table-glass tr.selected-row { background: var(--color-primary-subtle); }
.table-glass tr { cursor: pointer; }
.table-glass td:first-child { text-align: center; }
.table-glass td:nth-child(2),
.table-glass td:nth-child(4),
.table-glass td:nth-child(5),
.table-glass td:nth-child(6),
.table-glass td:nth-child(7),
.table-glass td:nth-child(8) { font-size: 12px; color: var(--text-secondary); }

/* Badge */
.badge-base {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--border); color: var(--text-muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
  animation: modalFadeIn 0.2s ease;
}
.modal-content {
  background: var(--glass-bg); backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-lg); border: 1px solid var(--glass-border);
  box-shadow: 0 24px 48px rgba(0,0,0,0.2); padding: 24px;
  min-width: 360px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  animation: modalScaleIn 0.25s ease;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }

@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalScaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* Progress */
.progress-glass {
  height: 6px; background: var(--border); border-radius: var(--radius-full); overflow: hidden;
}
.progress-glass-bar {
  height: 100%; background: var(--color-primary); border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* Form */
.form-glass {
  width: 100%; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--glass-bg); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-family: var(--font);
  transition: border var(--transition);
}
.form-glass:focus { outline: none; border-color: var(--color-primary); }
select.form-glass { cursor: pointer; }

/* Log Box */
.log-box {
  background: #1e293b; color: #e2e8f0; font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px; padding: 12px 14px; border-radius: var(--radius-md);
  max-height: 300px; overflow-y: auto; white-space: pre-wrap; line-height: 1.6;
}
.log-box .log-info { color: #60a5fa; }
.log-box .log-warn { color: #f59e0b; }
.log-box .log-error { color: #ef4444; }
.log-box .log-success { color: #22c55e; }

/* Stat Card */
.stat-card {
  display: flex; align-items: center; gap: 14px;
}
.stat-card .icon {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff; flex-shrink: 0;
}
.stat-card .info h3 { font-size: 22px; font-weight: 700; margin: 0; color: var(--text); }
.stat-card .info p { margin: 1px 0 0; color: var(--text-muted); font-size: 12px; }

/* Toast */
.toast-container { position: fixed; bottom: 16px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 6px; }
.toast {
  padding: 10px 16px; border-radius: var(--radius-md); font-size: 13px;
  backdrop-filter: var(--glass-blur); border: 1px solid var(--glass-border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); animation: toastIn 0.25s ease;
  display: flex; align-items: center; gap: 8px;
}
.toast-success { background: rgba(22, 163, 74, 0.9); color: #fff; }
.toast-danger { background: rgba(220, 38, 38, 0.9); color: #fff; }
.toast-warning { background: rgba(245, 158, 11, 0.9); color: #fff; }
.toast-info { background: var(--glass-bg); color: var(--text); }
.toast .toast-close { margin-left: auto; background: none; border: none; color: inherit; opacity: 0.6; cursor: pointer; padding: 2px 4px; }
.toast .toast-close:hover { opacity: 1; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-danger { color: var(--danger); }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── 响应式 ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -220px;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: flex; }
  .main-wrap { margin-left: 0 !important; padding: 12px !important; }
  .page-header { flex-direction: column; gap: 8px; align-items: flex-start; }
  .page-header-actions { flex-wrap: wrap; }
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px !important; }
  #img-layout { flex-direction: column; height: auto; }
  .flex.gap-4 { flex-direction: column; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr !important; }
}
