:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-subtle: #f8f9fc;
  --border: #e5e7f0;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --primary: #5b4bff;
  --primary-hover: #4a3be8;
  --primary-soft: #eeecff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 4px 16px rgba(17, 24, 39, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, #ebe8ff 0%, #f5f6fa 45%, #eef2ff 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 16px 40px rgba(17, 24, 39, 0.08);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6d5dfc, #9d6bff);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark.sm {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 16px;
}

/* Form & Buttons */
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field input, .input, .select {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input { height: 40px; font-size: 14px; }
.field input:focus, .input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 75, 255, 0.12);
}

.form-error {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; height: 42px; font-size: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-subtle); border-color: #d1d5db; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: #eef0f6; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.danger-text { color: var(--danger); }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-subtle); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-dot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; opacity: 0.55; }
.nav-item.active .nav-dot { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.admin-badge { padding: 0 6px 10px; }
.admin-name { font-weight: 600; font-size: 13px; }
.admin-meta { font-size: 12px; color: var(--muted); }
.sidebar-actions { display: flex; gap: 6px; }

/* Main area */
.main-area {
  padding: 24px 28px 40px;
  max-width: 1440px;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.topbar h2 { margin: 0; font-size: 22px; font-weight: 700; }
.topbar p { margin: 4px 0 0; }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Filter & Table */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.filter-bar .input { min-width: 220px; }
.filter-bar .input-date { min-width: 142px; }

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  margin-bottom: 10px;
}
.chip-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f1f6;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #fafbfe; }
.data-table tbody tr:last-child td { border-bottom: none; }
.empty-cell { text-align: center; padding: 36px 14px !important; color: var(--muted); }
.col-actions { text-align: right; white-space: nowrap; }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }

/* User cell */
.user-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 99px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-neutral { background: #eef0f6; color: var(--text-secondary); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-group { display: flex; flex-wrap: wrap; gap: 4px; }

/* Thumbs */
.thumb-row { display: flex; align-items: center; gap: 6px; }
.thumb {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: #f3f4f6;
}
.thumb-more {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
}
.page-btns { display: flex; gap: 8px; }

/* Drawer */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.36);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}
.drawer {
  width: min(560px, 96vw);
  height: 100%;
  background: var(--surface);
  box-shadow: -12px 0 36px rgba(17, 24, 39, 0.14);
  display: flex;
  flex-direction: column;
}
.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 { margin: 0; font-size: 17px; }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.icon-btn:hover { color: var(--text); }
.drawer-body {
  padding: 20px 22px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail-section h4 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.kv-label { font-size: 11px; color: var(--muted); }
.kv-value { font-size: 13px; font-weight: 500; margin-top: 2px; word-break: break-all; }

.drawer-action-bar { display: flex; flex-wrap: wrap; gap: 8px; }

.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.photo-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-subtle);
}
.photo-card img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.photo-meta { padding: 6px 8px; font-size: 11px; color: var(--muted); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(17, 24, 39, 0.2);
}
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.lightbox-wrap { position: relative; max-width: 92vw; max-height: 90vh; }
.lightbox-wrap img { max-width: 92vw; max-height: 88vh; border-radius: 10px; display: block; box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 34px;
  height: 34px;
  border-radius: 99px;
  border: none;
  background: #fff;
  color: #111;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main-area { padding: 18px 16px 32px; }
}
