/* ==========================================================================
   style.css —— 积分商城全局样式（登录页 / 用户商城页 / 管理后台页共用）
   设计思路：简洁、卡片化、移动端优先（小屏自动单列，大屏自动多列）。
   ========================================================================== */

/* ---------- 全局变量 ---------- */
:root {
  --primary: #4f6ef7;
  --primary-dark: #3a55d9;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f3f5f9;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 16px rgba(0, 0, 0, .04);
  --sidebar-width: 230px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: rgba(79, 110, 247, .08); color: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-gray { background: #9ca3af; }
.btn-gray:hover { background: #6b7280; }

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

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 24px 0 14px;
  font-size: 18px;
  font-weight: 700;
}

.empty-tip {
  text-align: center;
  color: var(--text-light);
  padding: 34px 10px;
  font-size: 14px;
}

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-light); }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .12); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.form-hint { color: var(--text-light); font-size: 12px; margin-top: 4px; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  padding: 34px 30px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo { font-size: 46px; }
.login-brand h1 { font-size: 22px; margin-top: 6px; }
.login-brand p { color: var(--text-light); font-size: 13px; }
.login-tip {
  margin-top: 16px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-light);
  font-size: 12px;
  line-height: 1.8;
}

/* ---------- 用户端顶部导航 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .05);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar .brand { font-size: 18px; font-weight: 800; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.points-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #4b3400;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, .3);
}
.username-badge { color: var(--text-light); font-size: 14px; }

.page-container { max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }

/* ---------- 商品网格 ---------- */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.product-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform .15s, box-shadow .15s;
}
.product-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0, 0, 0, .1); }
.product-img-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #eef2f7;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.product-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.product-name { font-size: 16px; font-weight: 700; line-height: 1.4; }
.product-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.product-cost { color: var(--danger); font-weight: 800; font-size: 16px; }
.stock-badge {
  font-size: 12px;
  color: var(--success);
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 2px 10px;
  border-radius: 999px;
}
.stock-badge.out {
  color: var(--danger);
  background: #fef2f2;
  border-color: #fecaca;
}
.product-body .btn { margin-top: auto; }

/* ---------- 记录列表（用户端/管理端通用表格容器） ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data-table { width: 100%; border-collapse: collapse; background: #fff; min-width: 640px; }
table.data-table th,
table.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}
table.data-table th {
  background: #f9fafb;
  color: var(--text-light);
  font-weight: 600;
  font-size: 13px;
}
table.data-table tbody tr:hover { background: #fafbff; }
table.data-table td.wrap { white-space: normal; min-width: 180px; }
.mini-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; background: #eef2f7; }

/* ---------- 管理后台布局 ---------- */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-brand {
  padding: 20px 18px;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-nav { flex: 1; padding: 12px 0; display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 20px);
  margin: 0 10px;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d1d5db;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.sidebar-nav button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-nav button.active { background: var(--primary); color: #fff; }
.sidebar-bottom { padding: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }

.admin-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 22px 26px 46px;
  min-width: 0;
}
.admin-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.admin-topbar h1 { font-size: 22px; }
.admin-topbar-right { display: flex; align-items: center; gap: 12px; }

.tab-section { display: none; }
.tab-section.active { display: block; }

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { color: var(--text-light); font-size: 13px; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat-card.blue .stat-value { color: var(--primary); }
.stat-card.green .stat-value { color: var(--success); }
.stat-card.orange .stat-value { color: var(--warning); }
.stat-card.red .stat-value { color: var(--danger); }

/* 商品表单行 */
.product-form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.image-preview {
  width: 90px;
  height: 68px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #eef2f7;
}
.actions-cell { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-overlay.show { display: flex; }
.modal {
  width: 100%;
  max-width: 430px;
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 14px; }
.modal .form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- 实时通知 toast ---------- */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: #fff;
  border-left: 5px solid var(--primary);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.5;
  animation: toast-in .25s ease both;
  word-break: break-all;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.fade-out { animation: toast-out .3s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(30px); } }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .admin-layout { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .sidebar-brand { border-bottom: 0; padding: 12px 16px; white-space: nowrap; }
  .sidebar-nav { flex-direction: row; padding: 8px; overflow-x: auto; }
  .sidebar-nav button { width: auto; margin: 0 4px; white-space: nowrap; }
  .sidebar-bottom { border-top: 0; padding: 8px; }
  .admin-main { margin-left: 0; padding: 16px 14px 40px; }
  .product-form-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .topbar-inner { justify-content: center; text-align: center; }
  .page-container { padding-bottom: 30px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
  .product-body { padding: 10px; }
  .product-name { font-size: 14px; }
  .section-title { font-size: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 22px !important; }
  .modal { padding: 18px; }
}
