:root {
  --primary: #ff884d;
  --primary-hover: #ff9a66;
  --primary-dark: #e86535;
  --sidebar-bg: #001529;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 136, 77, 0.18);
  --sidebar-text: rgba(255, 255, 255, 0.72);
  --sidebar-text-active: #fff;
  --sidebar-group: rgba(255, 255, 255, 0.38);
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f0f2f5;
  --card: #fff;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --info: #8c8c8c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 16px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

.admin-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo__icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(145deg, #ffb07d, #ff884d);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-logo__text {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  letter-spacing: 0.04em;
}

.sidebar-nav { padding: 12px 0 24px; flex: 1; }

.sidebar-group {
  padding: 16px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-group);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  margin: 2px 8px;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar-link.is-active {
  background: var(--sidebar-active);
  color: var(--primary);
  font-weight: 500;
}

/* ── Main area ── */
.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-title { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; }
.topbar-breadcrumb { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.topbar-btn {
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 6px;
  color: var(--text);
  transition: border-color 0.15s;
}

.topbar-btn:hover { border-color: var(--primary); color: var(--primary); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.topbar-user__avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffb07d, #ff884d);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.topbar-logout { color: var(--primary); margin-left: 4px; font-size: 13px; }
.topbar-logout:hover { text-decoration: underline; }

.content { padding: 20px 24px 32px; flex: 1; }

/* ── Page card (list / form container) ── */
.page-card,
.table-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.page-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-card__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.page-card__desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.page-back {
  display: inline-block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  transition: color 0.15s;
}

.page-back:hover { color: var(--primary); }

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.table-toolbar h2 { margin: 0; font-size: 18px; font-weight: 600; }

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.4;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(145deg, #ffb07d 0%, #ff884d 52%, #e86535 100%);
  color: #fff;
  border: none;
}

.btn-default {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-muted { background: #f3f4f6; color: #4b5563; border: 1px solid var(--border); }

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

.btn-text {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 4px 8px;
}

.btn-text--danger { color: var(--danger); }
.btn-text:hover { background: rgba(255, 136, 77, 0.08); border-radius: 4px; opacity: 1; }
.btn-text--danger:hover { background: rgba(255, 77, 79, 0.08); }

.inline-form { display: inline; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }

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

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  background: #fafafa;
  white-space: nowrap;
}

.data-table tbody tr:hover { background: #fafafa; }

.table-empty {
  text-align: center !important;
  color: var(--muted);
  padding: 40px 14px !important;
}

.col-actions { white-space: nowrap; width: 1%; }

.table-thumb {
  width: 56px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  vertical-align: middle;
}

/* ── Tags / badges ── */
.tag,
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.6;
}

.tag--success, .badge-success { background: #f6ffed; color: var(--success); border: 1px solid #b7eb8f; }
.tag--info, .badge-muted { background: #fafafa; color: var(--info); border: 1px solid #d9d9d9; }
.tag--warning, .badge-warning { background: #fffbe6; color: var(--warning); border: 1px solid #ffe58f; }
.tag--danger, .badge-danger { background: #fff2f0; color: var(--danger); border: 1px solid #ffccc7; }

/* ── Forms ── */
.admin-form { max-width: 860px; }

.admin-form__grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
}

.form-field--full { grid-column: 1 / -1; }

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

.form-required { color: var(--danger); margin-left: 2px; }

.form-control,
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-control:focus,
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 136, 77, 0.15);
}

.form-control[readonly] { background: #f9fafb; color: var(--muted); cursor: not-allowed; }

.form-field textarea,
.form-control[type="textarea"] { min-height: 96px; resize: vertical; }

.form-hint,
.field-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.form-footer,
.form-actions {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* ── Image uploader ── */
.image-uploader { max-width: 360px; }

.image-uploader__preview {
  width: 100%;
  height: 160px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 10px;
}

.image-uploader__preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-uploader__preview.is-empty span { color: var(--muted); font-size: 13px; }

.image-uploader__preview.is-loading { opacity: 0.6; }

.image-uploader__actions { display: flex; gap: 8px; align-items: center; }

.image-uploader__file { display: none; }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid transparent;
}

.alert-success { background: #f6ffed; color: #389e0d; border-color: #b7eb8f; }
.alert-error { background: #fff2f0; color: #cf1322; border-color: #ffccc7; }

/* ── Pagination ── */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }

.pagination-item {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--card);
  transition: all 0.15s;
}

.pagination-item:hover { border-color: var(--primary); color: var(--primary); }
.pagination-item.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Dashboard ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card__label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-card__value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-card__icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-card--blue .stat-card__icon { background: #fff7e6; }
.stat-card--green .stat-card__icon { background: #f6ffed; }
.stat-card--orange .stat-card__icon { background: #fff7e6; }
.stat-card--red .stat-card__icon { background: #fff2f0; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
}

.chart-box { width: 100%; height: 280px; }

/* ── User management ── */
.user-manage-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.user-empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 14px;
}

.user-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  overflow: hidden;
}

.user-card__main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.user-card__identity {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
}

.user-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(145deg, #ffb07d, #ff884d);
  position: relative;
}

.user-avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-avatar__fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.user-card__info { min-width: 0; flex: 1; }

.user-card__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.user-card__name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.user-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.user-card__meta b { color: var(--text); font-weight: 600; }

.user-card__openid {
  font-family: Consolas, Monaco, monospace;
  font-size: 11px;
}

.user-card__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.user-card__form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.user-card__form--inline .user-card__input-num {
  width: 56px;
  padding: 5px 8px;
  font-size: 13px;
}

.user-slots-table { margin: 0; background: var(--card); }
.user-slots-table th { font-size: 12px; }
.user-slots-table td { font-size: 13px; }

.user-slot-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.user-slot-actions__select {
  width: auto;
  min-width: 120px;
  padding: 5px 8px;
  font-size: 12px;
}

.tag--danger {
  background: #fff2f0;
  color: var(--danger);
  border: 1px solid #ffccc7;
}

@media (max-width: 768px) {
  .user-card__main { flex-direction: column; }
  .user-card__toolbar { width: 100%; }
}

/* ── Legacy user slots (deprecated) ── */
.slot-user-card {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.slot-user-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.slot-user-head select,
.slot-user-head input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.login-card {
  width: 400px;
  background: var(--card);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card p { margin: 0 0 24px; text-align: center; color: var(--muted); font-size: 13px; }
.login-error { background: #fff2f0; color: var(--danger); padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; border: 1px solid #ffccc7; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--card);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .admin-form__grid,
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
