:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --ink: #22302a;
  --ink-muted: #75817a;
  --line: #e2e8e3;
  --brand: #1d5c48;
  --brand-deep: #14352c;
  --brand-bright: #2e8b6a;
  --danger: #b3452f;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input { font: inherit; }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-deep);
}

.login-shell { width: min(360px, calc(100vw - 40px)); }

.login-card {
  background: var(--panel);
  padding: 36px 32px 32px;
  border-radius: 3px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-brand strong { display: block; font-size: 17px; letter-spacing: 0.02em; }
.login-brand small { color: var(--ink-muted); font-size: 11px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  border-radius: 3px;
}

.field { display: block; margin-bottom: 16px; }
.field span { display: block; margin-bottom: 6px; color: var(--ink-muted); font-size: 12px; }
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  background: #fff;
  font: inherit;
  transition: border-color 0.15s;
}
.field input:focus,
.field select:focus { border-color: var(--brand); }

.form-error { margin: -4px 0 12px; color: var(--danger); font-size: 12px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 2px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-bright); }
.login-submit { width: 100%; padding: 11px; }

/* ---------- 后台骨架 ---------- */
.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 228px;
  display: flex;
  flex-direction: column;
  background: var(--brand-deep);
  color: #dce7e1;
  padding: 20px 14px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand-copy strong { display: block; font-size: 15px; }
.brand-copy small { color: #8fa89d; font-size: 10px; }

.nav-caption { margin: 26px 8px 8px; color: #6e857b; font-size: 10px; letter-spacing: 0.14em; }

.main-nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 2px;
  color: #b9c9c1;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-icon { width: 18px; text-align: center; }

.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }
.password-link {
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: transparent;
  color: #cfe6d9;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.password-link:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.05);
  text-align: left;
}
.profile:hover { background: rgba(255, 255, 255, 0.1); }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 2px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
}
.profile-copy { flex: 1; min-width: 0; }
.profile-copy strong { display: block; font-size: 13px; }
.profile-copy small { color: #8fa89d; font-size: 10px; }
.logout-icon { color: #8fa89d; }

.main-area { margin-left: 228px; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.breadcrumbs { color: var(--ink-muted); font-size: 13px; }
.breadcrumbs strong { color: var(--ink); font-weight: 500; }
.crumb-sep { margin: 0 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink-muted);
  font-size: 11px;
}
.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: #39c187; }

.content-wrap { padding: 28px 32px 36px; width: 100%; max-width: 1480px; margin: 0 auto; }

.page-heading { margin-bottom: 22px; }
.eyebrow { color: var(--brand-bright); font-size: 11px; letter-spacing: 0.12em; }
.page-heading h1 { font-size: 22px; font-weight: 600; margin: 4px 0; }
.heading-note { color: var(--ink-muted); font-size: 13px; }

.data-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.panel-heading { padding: 16px 20px 0; }
.panel-heading h2 { font-size: 15px; font-weight: 600; }
.panel-heading p { color: var(--ink-muted); font-size: 12px; }

.db-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 18px 20px 20px;
}
.db-item { display: grid; gap: 4px; min-width: 0; }
.db-item small { color: var(--ink-muted); font-size: 11px; }
.db-item strong { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.db-item strong.ok { color: var(--brand-bright); }
.db-item strong.bad { color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  padding: 9px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 2px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 业务模块 ---------- */
.table-scroll { overflow-x: auto; padding: 14px 20px 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 10px; color: var(--ink-muted); font-size: 11px; font-weight: 500; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #eef2ee; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.empty { text-align: center; color: var(--ink-muted); padding: 26px; }
#sites-table td { white-space: nowrap; }
td.money, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.pos { color: var(--brand-bright); }
.money.neg { color: var(--danger); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 2px; background: #eef1ee; color: var(--ink-muted); font-size: 11px; white-space: nowrap; }
.tag.ok { background: #e3f2ea; color: #237a52; }
.tag.warn { background: #fdf2e2; color: #b07918; }
.tag.bad { background: #fae9e4; color: var(--danger); }

td.actions { white-space: nowrap; }
.link { color: var(--brand-bright); padding: 2px 6px; font-size: 12px; }
.link:hover { text-decoration: underline; }

.select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 2px; background: #fff; font: inherit; }
.button-sm { padding: 5px 12px; font-size: 12px; }
textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 2px; font: inherit; resize: vertical; }

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(16, 30, 26, 0.45); }
.modal[hidden] { display: none; }
.modal-card { width: min(720px, calc(100vw - 32px)); background: var(--panel); border-radius: 3px; padding: 24px 24px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal-card h3 { font-size: 16px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal .form-error { margin: 10px 0 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .field { margin-bottom: 14px; }
.form-grid .field.full { grid-column: 1 / -1; }

/* 商品必填字段配置器 */
.field-config { border: 1px solid var(--line); border-radius: 3px; padding: 10px; background: rgba(0, 0, 0, 0.04); }
.field-config-header { display: grid; grid-template-columns: 160px 1fr 80px 1fr 60px; gap: 8px; font-size: 11px; color: var(--ink-muted); margin-bottom: 6px; padding: 0 2px; }
.field-config-row { display: grid; grid-template-columns: 160px 1fr 80px 1fr 60px; gap: 8px; align-items: center; margin-bottom: 8px; }
.field-config-row select, .field-config-row input { width: 100%; }
.field-config-row .fc-req { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.field-config-row .fc-del { padding: 4px 8px; font-size: 12px; background: transparent; border: 1px solid var(--line); cursor: pointer; color: var(--danger); }
.field-config > button[data-fc-add] { margin-top: 4px; padding: 6px 10px; font-size: 12px; cursor: pointer; background: transparent; border: 1px dashed var(--line); border-radius: 3px; }

.cred-box { display: grid; gap: 10px; }
.cred-box small { display: block; color: var(--ink-muted); font-size: 11px; margin-bottom: 2px; }
.cred-box code { display: block; padding: 8px 10px; background: #f2f6f3; border: 1px solid var(--line); border-radius: 2px; font-size: 12px; user-select: all; }
.hint-text { color: var(--ink-muted); font-size: 12px; margin-top: 6px; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }

/* 订单管理：筛选栏与订单详情 */
#page-orders .db-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); padding-bottom: 0; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 20px 0; }
.filter-bar select,
.filter-bar input {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fff;
  font: inherit;
  outline: none;
}
.filter-bar input { flex: 1 1 220px; min-width: 180px; }
.filter-bar select:focus,
.filter-bar input:focus { border-color: var(--brand); }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; margin-bottom: 18px; }
.detail-item { display: grid; gap: 3px; min-width: 0; }
.detail-item small { color: var(--ink-muted); font-size: 11px; }
.detail-item strong { font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.detail-subtitle { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.modal-actions .button[hidden] { display: none; }

.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font: inherit;
  resize: vertical;
  outline: none;
}
.field textarea:focus { border-color: var(--brand); }
.hint { color: var(--ink-muted); font-size: 12px; }

/* ---------- 响应式适配 ---------- */
html { -webkit-text-size-adjust: 100%; }

.mobile-menu { display: none; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink); font-size: 16px; flex: none; }
.sidebar-mask { display: none; }

/* 平板：侧栏收起为抽屉 */
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 70; width: 240px; transform: translateX(-100%); transition: transform 0.22s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 14px 0 45px rgba(0, 0, 0, 0.35); }
  .sidebar-mask { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(16, 30, 26, 0.45); }
  .sidebar-mask[hidden] { display: none; }
  .mobile-menu { display: grid; }
  .main-area { margin-left: 0; }
  .topbar { padding: 12px 16px; gap: 12px; }
  .content-wrap { padding: 20px 16px; }
  .db-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #page-orders .db-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding-bottom: 6px; }
}

/* 手机：单列布局、加大字体与触控区 */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .topbar { padding: 10px 12px; }
  .breadcrumbs { font-size: 12px; }
  .status-pill { font-size: 10px; padding: 3px 8px; }
  .content-wrap { padding: 16px 12px; }
  .page-heading { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
  .page-heading h1 { font-size: 20px; }
  .heading-note { font-size: 12px; }
  .panel-heading { padding: 14px 14px 0; }
  .table-scroll { padding: 10px 12px 14px; }
  table { font-size: 12px; }
  th { font-size: 11px; padding: 8px; }
  td { padding: 9px 8px; }
  .filter-bar { padding: 12px 14px 0; gap: 8px; }
  .filter-bar input { flex: 1 1 100%; min-width: 0; }
  .filter-bar select { flex: 1 1 calc(50% - 4px); }
  .filter-bar .button { flex: 1 1 calc(50% - 4px); }
  .db-grid { gap: 12px; padding: 14px; }
  .db-item strong { font-size: 13px; }
  .detail-grid { grid-template-columns: 1fr; gap: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  /* 弹窗适配小屏 */
  .modal { padding: 12px; align-items: flex-end; }
  .modal-card { width: 100%; max-height: 92vh; overflow-y: auto; padding: 18px 16px 14px; }
  /* 必填字段配置器：小屏堆叠 */
  .field-config-header { display: none; }
  .field-config-row { grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 3px; background: #fff; }
  .field-config-row .fc-del { justify-self: end; }
  /* iOS 输入框聚焦防缩放：字号 >= 16px */
  .field input, .field textarea, .modal-card input, .modal-card select, .modal-card textarea, .filter-bar input, .filter-bar select, .select { font-size: 16px; }
  .button { min-height: 40px; }
  .button-sm { min-height: 34px; }
  .modal-actions .button { flex: 1; }
  .toast { left: 12px; right: 12px; bottom: 16px; transform: translateY(20px); text-align: center; }
  .toast.visible { transform: translateY(0); }
}

/* 小屏手机 */
@media (max-width: 420px) {
  .db-grid { gap: 10px; }
  .db-item strong { font-size: 12px; }
  .page-heading .button { width: 100%; }
  .login-card { padding: 28px 20px 24px; }
}
