/* ===========================================================
   Design System — shadcn/ui inspired for 菜鸟驿站 Admin
   Based on: ui/app/globals.css + shadcn component patterns
   =========================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --bg: #f8f9fc;
  --bg-card: #ffffff;
  --bg-muted: #f1f3f8;
  --bg-accent: #e8f5f0;
  --bg-primary: #eef2ff;

  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-primary: #4f46e5;
  --text-on-primary: #ffffff;
  --text-accent: #0d9488;

  --border: #e5e7eb;
  --border-light: #f0f0f5;
  --focus-ring: rgba(79, 70, 229, 0.25);

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-accent: #0d9488;
  --color-accent-hover: #0f766e;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-info: #3b82f6;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px 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 16px 40px rgba(0,0,0,0.16);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;

  --sidebar-w: 240px;
  --header-h: 60px;

  --transition: 0.2s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
  width: 40px; height: 40px;
  background: var(--color-primary);
  color: var(--text-on-primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.sidebar-logo-text {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-section {
  padding: 8px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}
.sidebar-item:hover {
  background: var(--bg-muted);
}
.sidebar-item.active {
  background: var(--bg-primary);
  color: var(--color-primary);
  font-weight: 600;
}
.sidebar-item .icon { width: 20px; text-align: center; font-size: 16px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ---------- Main Content ---------- */
.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-header-title {
  font-size: 18px;
  font-weight: 600;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-primary);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

/* ---------- Page Content ---------- */
.page-content {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 6px;
}

.page-header p {
  color: var(--text-muted);
  margin: 0;
  font-size: 14px;
}

/* ---------- Navigation / Module Buttons ---------- */
.module-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  background: var(--bg-card);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.module-nav button {
  padding: 9px 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.module-nav button:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.module-nav button.active {
  background: var(--color-primary);
  color: var(--text-on-primary);
}

/* ---------- Tab Buttons ---------- */
.tab-bar {
  display: flex;
  gap: 2px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
  padding: 0;
}

.tab-btn {
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--text);
}

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

/* ---------- Stats Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* backward compat: colored accent variants */
.stat-card.blue { border-left: 4px solid var(--color-primary); }
.stat-card.green { border-left: 4px solid var(--color-success); }
.stat-card.orange { border-left: 4px solid var(--color-warning); }
.stat-card.purple { border-left: 4px solid #7c3aed; }

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-icon-badge {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.stat-icon-badge.blue { background: var(--bg-primary); color: var(--color-primary); }
.stat-icon-badge.green { background: #e8f5e9; color: var(--color-success); }
.stat-icon-badge.orange { background: #fff3e0; color: var(--color-warning); }
.stat-icon-badge.purple { background: #f3e8ff; color: #7c3aed; }

.stat-trend {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.stat-trend.up { background: #e8f5e9; color: var(--color-success); }
.stat-trend.down { background: #fce4ec; color: var(--color-danger); }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Wallet Card ---------- */
.wallet-card {
  background: linear-gradient(135deg, var(--color-primary), #7c3aed);
  color: var(--text-on-primary);
  border-radius: var(--radius-xl);
  padding: 28px;
  margin-bottom: 24px;
}

.wallet-card .wallet-label {
  font-size: 13px;
  opacity: 0.85;
}

.wallet-card .wallet-balance {
  font-size: 38px;
  font-weight: 700;
  margin: 8px 0;
}

.wallet-card .wallet-meta {
  display: flex;
  gap: 28px;
  margin-top: 16px;
}

.wallet-card .wallet-meta-item .meta-value {
  font-size: 18px;
  font-weight: 600;
}
.wallet-card .wallet-meta-item .meta-label {
  font-size: 12px;
  opacity: 0.75;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); }

.btn-primary { background: var(--color-primary); color: var(--text-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow); }

.btn-secondary { background: var(--bg-muted); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

.btn-success { background: var(--color-success); color: var(--text-on-primary); }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--color-danger); color: var(--text-on-primary); }
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-muted); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }

/* Primary color variant */
.btn[class*="primary"] { background: var(--color-primary); color: #fff; }

/* ---------- Tables ---------- */
.table-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }

.table-header {
  padding: 16px 20px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
}
.table-header .table-title { font-size: 15px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--bg-muted);
  font-weight: 600;
  text-align: left;
  padding: 11px 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--bg-muted); }

/* ---------- Form Elements ---------- */
input, select, textarea {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  transition: all var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
}

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

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
  outline: none;
}

/* ---------- Search / Action Bars ---------- */
.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.action-bar input,
.action-bar select {
  min-width: 140px;
}

.action-bar .spacer {
  flex: 1;
}

/* ---------- Status Badges ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge.active,
.status-badge.success,
.status-active {
  background: #e8f5e9;
  color: var(--color-success);
  border: 1px solid #c8e6c9;
}

.status-badge.inactive,
.status-badge.danger,
.status-inactive {
  background: #fce4ec;
  color: var(--color-danger);
  border: 1px solid #ffcdd2;
}

.status-badge.warning,
.status-warning {
  background: #fff3e0;
  color: var(--color-warning);
  border: 1px solid #ffe0b2;
}

/* ---------- Action Buttons (table row) ---------- */
.action-btn {
  padding: 5px 12px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}
.action-btn.edit { background: var(--bg-primary); color: var(--color-primary); }
.action-btn.edit:hover { background: var(--color-primary); color: var(--text-on-primary); }
.action-btn.delete { background: #fce4ec; color: var(--color-danger); }
.action-btn.delete:hover { background: var(--color-danger); color: var(--text-on-primary); }

/* ---------- Pagination ---------- */
.pagination-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}
.pagination-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ---------- Loading ---------- */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* ---------- Modals ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.active { display: flex; }

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 0;
  width: 540px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-header .close-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.modal-header .close-btn:hover {
  background: var(--color-danger);
  color: var(--text-on-primary);
}

.modal-body {
  padding: 24px;
}

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

/* ---------- Section Separator ---------- */
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 28px 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Helper Classes ---------- */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .app-sidebar { display: none; }
  .app-main { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
