:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #eff6ff;
  --text: #1f2937;
  --text-soft: #475569;
  --muted: #7b8798;
  --border: #e6eaf0;
  --border-strong: #d7dde6;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0ea5e9;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-md: 0 12px 30px rgba(16, 24, 40, .10);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 238px;
  --transition: .18s ease;
  --hover: #fbfcfe;
  --topbar-bg: rgba(255, 255, 255, .94);
  --ok-bg: #e9f9ef;
  --ok-text: #188a48;
  --pending-bg: #fff5e6;
  --pending-text: #c05621;
  --fail-bg: #fdecec;
  --fail-text: #c62828;
  --gray-bg: #f1f3f6;
  --gray-text: #667085;
  --blue-bg: #e8f3ff;
  --blue-text: #2167c4;
  --flash-ok-bg: #eaf7ee;
  --flash-ok-text: #166534;
  --flash-ok-border: #ccebd5;
  --flash-err-bg: #fdecec;
  --flash-err-text: #b42318;
  --flash-err-border: #f5cccc;
  --stripe: #fafbfd;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(59, 130, 246, .06), transparent 34%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

a {
  color: var(--primary-dark);
}

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.sidebar .brand {
  height: 68px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .01em;
  border-bottom: 1px solid var(--border);
}

.sidebar .brand a {
  color: var(--text);
  text-decoration: none;
}

.sidebar .menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
}

.sidebar .menu a,
.sidebar .menu .grp-head {
  display: flex;
  align-items: center;
  min-height: 40px;
  margin: 2px 0;
  padding: 0 14px;
  border-radius: 9px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 14px;
  border-left: none;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.sidebar .menu a:hover,
.sidebar .menu .grp-head:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.sidebar .menu a.active {
  background: var(--surface-blue);
  color: var(--primary-dark);
  font-weight: 600;
}

/* 顶层主标签链接（无子标签：仪表盘/订单管理/商品列表等）：
   与分组头同为主标签层级，字重/颜色与有子标签的主标签(.grp-head)保持一致，
   右侧放与箭头同列的淡色圆点作主标签标识，与缩进小字、无标识的子标签区分开 */
.sidebar .menu > a {
  position: relative;
  font-weight: 600;
  color: var(--text);
}
.sidebar .menu > a::after {
  content: "";
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted);
  flex: none;
  margin-left: auto;
}

.sidebar .menu a.sub {
  padding-left: 30px;
  font-size: 13px;
}

.sidebar .menu .grp-head {
  cursor: pointer;
  justify-content: space-between;
  user-select: none;
}

.sidebar .menu .grp-head.cur {
  color: var(--text);
}

.sidebar .menu .grp-head .arrow {
  font-size: 10px;
  color: var(--muted);
  transition: transform .18s ease;
}

.sidebar .menu .grp-head.open .arrow {
  transform: rotate(90deg);
}

.sidebar .menu .grp-items {
  display: none;
  margin: 2px 0 4px;
}

.sidebar .menu .grp-items.open {
  display: block;
}

.sidebar .side-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.sidebar .side-foot a {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}

.sidebar .side-foot a:hover {
  color: var(--danger);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 30px 42px;
}

.container {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px 18px 40px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 17px;
  line-height: 1.35;
  color: var(--text);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.page-head h2 {
  margin: 0;
  font-size: 20px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform .06s ease, opacity var(--transition);
}

.btn:hover {
  opacity: .92;
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .22);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-gray {
  background: #64748b;
  color: #fff;
}

.btn-warn {
  background: var(--warning);
  color: #fff;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 7px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .14);
  background: var(--surface);
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

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

.form-row {
  margin-bottom: 14px;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.flash-ok,
.flash-error {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
}

.flash-ok {
  background: var(--flash-ok-bg);
  color: var(--flash-ok-text);
  border: 1px solid var(--flash-ok-border);
}

.flash-error {
  background: var(--flash-err-bg);
  color: var(--flash-err-text);
  border: 1px solid var(--flash-err-border);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
}

.b-pending {
  background: var(--pending-bg);
  color: var(--pending-text);
}

.b-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.b-fail {
  background: var(--fail-bg);
  color: var(--fail-text);
}

.b-gray {
  background: var(--gray-bg);
  color: var(--gray-text);
}

.b-blue {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
}

.stat .num {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.15;
}

.stat .lab {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

.num-pending {
  color: #d97706;
}

.num-total {
  color: #2563eb;
}

.num-today {
  color: #16a34a;
}

.num-success {
  color: #16a34a;
}

.num-fail {
  color: #dc2626;
}

.sumbar {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-soft);
}

.sumbar .v {
  color: var(--primary-dark);
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-soft);
  margin-right: 6px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.chip b {
  color: var(--primary-dark);
  margin-left: 5px;
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.chip.active b {
  color: #fff;
}

.table-tip {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 11px;
}

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

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

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

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

.cell-main {
  font-weight: 600;
}

.cell-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.cell-sub.red {
  color: var(--danger);
}

.cell-sub.green {
  color: var(--success);
}

.cell-sub.orange {
  color: var(--warning);
}

/* 统一分页栏：共N条靠左，其余控件一行对齐靠右；窄屏自动换行 */
.pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 14px;
  font-size: 13px;
}

.pager-total {
  color: var(--text-soft);
  margin-right: auto;
}

.pager form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pager select,
.pager-jump input[type="number"] {
  width: auto;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.pager-jump input[type="number"] {
  width: 56px;
  text-align: center;
}

.pager .btn {
  min-height: 0;
  height: 30px;
  padding: 0 10px;
}

.pager-btns {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pager-btns a,
.pager-btns .is-current,
.pager-btns .is-disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text-soft);
  text-align: center;
  text-decoration: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.pager-btns a:hover {
  background: var(--surface-soft);
  color: var(--primary-dark);
  border-color: var(--primary);
}

.pager-btns .is-current {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  cursor: default;
}

.pager-btns .is-disabled {
  color: var(--muted);
  opacity: .5;
  cursor: not-allowed;
  background: none;
}

.pager-ellipsis {
  padding: 0 2px;
  color: var(--muted);
}

.down-reason {
  color: var(--danger);
  font-size: 12px;
  margin-top: 3px;
  word-break: break-all;
  cursor: help;
}

.login-wrap {
  max-width: 410px;
  margin: 10vh auto;
}

.login-wrap .card {
  padding: 26px;
}

.order-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 22px;
  transition: .2s;
}

.switch .slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}

.switch input:checked + .slider {
  background: var(--success);
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

.mobile-topbar {
  display: none;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 900px) {
  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 14px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
  }

  .mobile-topbar .mobile-brand {
    flex: 1;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: 16px;
  }

  .menu-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
  }

  .layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    width: min(82vw, 300px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-md);
    z-index: 90;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(15, 23, 42, .38);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.nav-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    padding: 18px 14px 34px;
  }

  .container {
    padding: 16px 14px 32px;
  }

  .card {
    padding: 16px 14px;
    border-radius: 13px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat {
    padding: 14px;
  }

  .stat .num {
    font-size: 23px;
  }

  .btn {
    min-height: 42px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px;
  }
}

/* ============ 侧边栏折叠菜单：主次层次区分 ============ */
.sidebar .menu .grp-head {
  font-weight: 600;
  color: var(--text);
}

.sidebar .menu .grp-head.open,
.sidebar .menu .grp-head.cur {
  background: var(--surface-soft);
  color: var(--text);
}

.sidebar .menu .grp-head .arrow {
  color: var(--muted);
}

.sidebar .menu .grp-head.open .arrow,
.sidebar .menu .grp-head.cur .arrow {
  color: var(--primary);
}

.sidebar .menu .grp-items {
  position: relative;
}

.sidebar .menu .grp-items.open::before {
  content: "";
  position: absolute;
  left: 21px;
  top: 5px;
  bottom: 5px;
  width: 1px;
  background: var(--border);
}

.sidebar .menu a.sub {
  color: var(--muted);
  padding-left: 38px;
  min-height: 38px;
}

.sidebar .menu a.sub:hover {
  color: var(--text);
}

.sidebar .menu a.sub.active {
  color: var(--primary-dark);
  font-weight: 600;
  background: var(--surface-blue);
}

@media (max-width: 540px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .card h2 {
    font-size: 16px;
  }

  .sumbar {
    gap: 10px;
  }

  .pager {
    line-height: 2;
  }
}

@media (max-width: 900px) {
  .table-wrap {
    margin: 0 -14px;
    width: calc(100% + 28px);
    padding: 0 14px;
    border-radius: 0;
  }

  .table-scroll {
    min-width: 760px;
  }

  .table-stack thead {
    display: none;
  }

  .table-stack,
  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
    width: 100%;
  }

  .table-stack tr {
    margin-bottom: 12px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-xs);
  }

  .table-stack td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    text-align: right;
  }

  .table-stack td:last-child {
    border-bottom: none;
  }

  .table-stack td::before {
    content: attr(data-label);
    flex-shrink: 0;
    min-width: 76px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
  }

  .table-kv tr {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  .table-kv tr:last-child {
    border-bottom: none;
  }

  .table-kv th,
  .table-kv td {
    display: block;
    width: 100%;
    padding: 3px 0;
    border-bottom: none;
    text-align: left;
  }

  .table-kv th {
    background: none;
    color: var(--muted);
    font-size: 12px;
  }

  .table-kv td {
    color: var(--text);
    padding-bottom: 8px;
  }

  [id$="-modal"] {
    padding: 12px;
  }

  [id$="-modal"] > div:not([id$="-modal-mask"]) {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 auto !important;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    border-radius: 13px;
  }

  dialog#role-dialog {
    width: calc(100% - 24px);
    max-width: 420px;
    margin: auto;
  }

  .uo-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .uo-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .uo-sync-row {
    flex-direction: column;
    gap: 14px;
  }

  .uo-sync-item {
    width: 100%;
    min-width: 0;
  }

  .uo-checks {
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .uo-filter {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .uo-filter-item {
    width: 100%;
    min-width: 0;
    align-items: stretch;
  }

  .uo-filter-item > label {
    width: auto;
  }

  .uo-filter-item input[type="text"],
  .uo-filter-item input[type="date"],
  .uo-filter-item select {
    width: 100%;
    min-width: 0;
  }

  #f-dates {
    width: 100%;
  }

  #f-dates input[type="date"] {
    flex: 1;
    min-width: 0;
  }

  .uo-modal-box {
    width: calc(100% - 24px);
  }
}

@media (max-width: 540px) {
  .uo-stats {
    grid-template-columns: 1fr;
  }
}

/* ============ 组件补充（主题变量化） ============ */
.col-resizer {
  background: var(--primary);
}

th:hover .col-resizer {
  opacity: 1;
}

/* ---- 表格列宽/列设置工具条（base.html 全局注入） ---- */
.table-ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.table-ctl .tsp {
  flex: 1;
}

.colw-set {
  position: relative;
  display: inline-block;
}

.colw-pop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 150px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d1d6dd);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
}

.colw-pop.open {
  display: block;
}

.colw-pop .pop-ops {
  display: flex;
  gap: 10px;
  padding: 2px 2px 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border, #eceff3);
}

.colw-pop .pop-ops a {
  font-size: 12px;
  color: var(--primary, #2563eb);
  cursor: pointer;
}

.colw-pop label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  margin: 0;
  font-size: 12px;
  color: var(--text, #333);
  cursor: pointer;
}

.colw-pop input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* 固定列宽模式：内容超出列宽即裁剪——长串不再把列顶宽（拖不窄根因），拖一列不再牵动其他列 */
table.colw-fixed {
  table-layout: fixed;
}

table.colw-fixed th,
table.colw-fixed td {
  overflow: hidden;
}

table.colw-fixed th {
  text-overflow: ellipsis;
}

/* 移动端堆叠模式不受固定列宽影响：恢复自动布局，解除 JS 设置的 inline min-width */
@media (max-width: 900px) {
  table.colw-fixed {
    table-layout: auto;
    min-width: 0 !important;
  }

  table.colw-fixed th,
  table.colw-fixed td {
    overflow: visible;
  }
}

body.colw-dragging {
  cursor: col-resize;
}

body.colw-dragging * {
  cursor: col-resize !important;
  user-select: none !important;
}

.dtpicker-pop {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-md);
}

.dtpicker-head .nav-btn {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.dtpicker-head .nav-btn:hover {
  background: var(--surface-soft);
}

.dtpicker-wd {
  color: var(--muted);
}

.dtpicker-day:hover {
  background: var(--surface-soft);
}

.dtpicker-day.selected {
  background: var(--primary);
  color: #fff;
}

.dtpicker-day.other {
  color: var(--muted);
}

.dtpicker-title {
  color: var(--text);
}

/* ============ 主题选择器 ============ */
.theme-picker {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.theme-picker .tp-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 9px;
}

.theme-picker .tp-label b {
  font-weight: 600;
  color: var(--text-soft);
}

.theme-picker .tp-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.theme-picker .tp-opt {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  position: relative;
  padding: 0;
  background-clip: padding-box;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.theme-picker .tp-opt:hover {
  transform: scale(1.12);
}

.theme-picker .tp-opt:active {
  transform: scale(.96);
}

.theme-picker .tp-opt.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.theme-picker .tp-opt[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 9px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 20;
  pointer-events: none;
}

/* ============ 主题：Haze 现代（借鉴 DashboardPack Haze Dashboard） ============ */
html[data-theme="haze"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --surface-blue: #f2f0ff;
  --text: #1a1a1e;
  --text-soft: #3f3f46;
  --muted: #71717a;
  --border: #e7e7ea;
  --border-strong: #d7d7dc;
  --primary: #6d5df6;
  --primary-dark: #5846e8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0ea5e9;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .05);
  --shadow-md: 0 14px 32px rgba(0, 0, 0, .10);
  --radius: 10px;
  --radius-sm: 7px;
  --hover: #fafafa;
  --topbar-bg: rgba(255, 255, 255, .92);
}

html[data-theme="haze"] body {
  background:
    radial-gradient(circle at 12% -10%, rgba(109, 93, 246, .07), transparent 34%),
    var(--bg);
}

/* ============ 主题：深色 ============ */
html[data-theme="dark"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #eff6ff;
  --text: #1f2937;
  --text-soft: #475569;
  --muted: #7b8798;
  --border: #e6eaf0;
  --border-strong: #d7dde6;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0ea5e9;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-md: 0 12px 30px rgba(16, 24, 40, .10);
  --radius: 12px;
  --radius-sm: 8px;
  --hover: #fbfcfe;
  --topbar-bg: rgba(255, 255, 255, .94);
  --ok-bg: #e9f9ef;
  --ok-text: #188a48;
  --pending-bg: #fff5e6;
  --pending-text: #c05621;
  --fail-bg: #fdecec;
  --fail-text: #c62828;
  --gray-bg: #f1f3f6;
  --gray-text: #667085;
  --blue-bg: #e8f3ff;
  --blue-text: #2167c4;
  --flash-ok-bg: #eaf7ee;
  --flash-ok-text: #166534;
  --flash-ok-border: #ccebd5;
  --flash-err-bg: #fdecec;
  --flash-err-text: #b42318;
  --flash-err-border: #f5cccc;
  --stripe: #fafbfd;
}

html[data-theme="dark"] body {
  background: var(--bg);
}

html[data-theme="dark"] .mobile-topbar {
  background: var(--topbar-bg);
}

html[data-theme="dark"] .sidebar-overlay {
  background: rgba(15, 23, 42, .40);
}

html[data-theme="dark"] .sidebar {
  --surface: #1e293b;
  --surface-soft: #263449;
  --surface-blue: #1f2a45;
  --text: #e5eaf3;
  --text-soft: #b7c3d6;
  --muted: #8b9bb0;
  --border: #2c3b54;
  --border-strong: #3c4e6c;
  --primary: #60a5fa;
  --primary-dark: #93c5fd;
  --hover: #243450;
  background: #1e293b;
  color: #e5eaf3;
}

/* ============ 主题：Tabler 清爽 ============ */
html[data-theme="tabler"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #eef4fb;
  --text: #1d273b;
  --text-soft: #475569;
  --muted: #6b7a90;
  --border: #e5e9f0;
  --border-strong: #d3dae3;
  --primary: #206bc4;
  --primary-dark: #1a569c;
  --success: #2fb344;
  --danger: #d63939;
  --warning: #f59f00;
  --info: #4299e1;
  --shadow-xs: 0 1px 2px rgba(30, 41, 59, .05);
  --shadow-sm: 0 4px 12px rgba(30, 41, 59, .06);
  --shadow-md: 0 14px 30px rgba(30, 41, 59, .12);
  --radius: 8px;
  --radius-sm: 6px;
  --hover: #f8fafc;
  --topbar-bg: rgba(255, 255, 255, .95);
}

html[data-theme="tabler"] body {
  background: var(--bg);
}

/* ============ 主题：翡翠绿 ============ */
html[data-theme="emerald"] {
  --bg: #f5faf7;
  --surface: #ffffff;
  --surface-soft: #f7fbf9;
  --surface-blue: #e9f7f0;
  --text: #1f2937;
  --text-soft: #475569;
  --muted: #6b7280;
  --border: #e3ebe7;
  --border-strong: #d0dcd5;
  --primary: #059669;
  --primary-dark: #047857;
  --success: #10b981;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0ea5e9;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-md: 0 14px 32px rgba(16, 24, 40, .10);
  --radius: 12px;
  --radius-sm: 8px;
  --hover: #f7fbf9;
  --topbar-bg: rgba(255, 255, 255, .94);
}

html[data-theme="emerald"] body {
  background:
    radial-gradient(circle at 12% -10%, rgba(5, 150, 105, .06), transparent 34%),
    var(--bg);
}

/* ============ 主题：紫罗兰 ============ */
html[data-theme="violet"] {
  --bg: #f9f7fc;
  --surface: #ffffff;
  --surface-soft: #faf8fd;
  --surface-blue: #f3eefe;
  --text: #231d3c;
  --text-soft: #4a4365;
  --muted: #746c8f;
  --border: #e8e3f1;
  --border-strong: #d7d0e5;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0ea5e9;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-md: 0 14px 32px rgba(16, 24, 40, .10);
  --radius: 14px;
  --radius-sm: 9px;
  --hover: #faf8fd;
  --topbar-bg: rgba(255, 255, 255, .94);
}

html[data-theme="violet"] body {
  background:
    radial-gradient(circle at 12% -10%, rgba(124, 58, 237, .06), transparent 34%),
    var(--bg);
}

/* ============ 全局组件细节优化 ============ */
/* 侧边栏菜单：激活态左侧指示条 */
.sidebar .menu a,
.sidebar .menu .grp-head {
  position: relative;
}

.sidebar .menu a::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
  transform: translateY(-50%) scaleY(0);
  transition: transform .18s ease;
}

.sidebar .menu a.active::before {
  transform: translateY(-50%) scaleY(1);
}

/* 表格斑马纹，提升长表格可读性 */
tbody tr:nth-child(even) td {
  background: var(--stripe);
}

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

/* 分页器按钮化 */
.pager a {
  display: inline-block;
  min-width: 30px;
  padding: 4px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text-soft);
  text-align: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.pager a:hover {
  background: var(--surface-soft);
  color: var(--primary-dark);
  border-color: var(--primary);
}

/* 键盘导航焦点可见性 */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 输入控件 hover 反馈 */
input[type="text"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="date"]:hover,
textarea:hover,
select:hover {
  border-color: var(--border-strong);
}

/* 移动端触控目标放大 */
@media (max-width: 900px) {
  .sidebar .menu a,
  .sidebar .menu .grp-head {
    min-height: 46px;
    border-radius: 10px;
    margin: 3px 0;
  }

  .theme-picker .tp-opt {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .theme-picker .tp-options {
    gap: 10px;
  }

  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 38px;
    padding: 7px 13px;
  }

  .pager a {
    min-width: 36px;
    padding: 7px 11px;
  }
}

/* ============ 大气化：整体字号与留白提升 ============ */
body {
  font-size: 15px;
}

.sidebar .brand {
  font-size: 18px;
}

.sidebar .menu a,
.sidebar .menu .grp-head {
  font-size: 15px;
  min-height: 46px;
  padding: 0 16px;
}

.sidebar .menu a.sub {
  font-size: 14px;
  min-height: 40px;
}

.main {
  padding: 32px 36px 48px;
}

.card {
  padding: 24px 26px;
  margin-bottom: 22px;
}

.card h2 {
  font-size: 19px;
  margin-bottom: 18px;
}

.page-head h2 {
  font-size: 24px;
}

.stat {
  padding: 20px 22px;
}

.stat .num {
  font-size: 32px;
}

.stat .lab {
  font-size: 13px;
}

.stat-grid {
  gap: 18px;
}

table {
  font-size: 14px;
}

th,
td {
  padding: 12px 14px;
}

.btn {
  font-size: 14px;
  min-height: 42px;
  padding: 9px 18px;
}

.btn-sm {
  font-size: 13px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  font-size: 14px;
  padding: 10px 13px;
}

.badge {
  font-size: 13px;
  padding: 4px 12px;
}

.toolbar {
  gap: 14px;
  margin-bottom: 16px;
}

label {
  font-size: 14px;
}

.chip {
  font-size: 13px;
}

/* 移动端保持紧凑，避免放大后溢出 */
@media (max-width: 900px) {
  body {
    font-size: 14px;
  }

  .main {
    padding: 20px 16px 36px;
  }

  .card {
    padding: 18px 16px;
    margin-bottom: 16px;
  }

  .card h2 {
    font-size: 17px;
    margin-bottom: 14px;
  }

  .page-head h2 {
    font-size: 21px;
  }

  .stat {
    padding: 15px;
  }

  .stat .num {
    font-size: 26px;
  }

  .stat-grid {
    gap: 11px;
  }

  table {
    font-size: 13px;
  }

  th,
  td {
    padding: 10px 11px;
  }

  .btn {
    min-height: 44px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px;
  }
}

/* ============ 窄屏卡片式列表（订单/商品/设备页共用；各页媒体查询隐藏对应表格） ============ */
.mobile-cards { display: none; }

.ocard {
  border: 1px solid var(--border, #d1d6dd);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface, #fff);
}

.ocard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ocard-head .badge { flex: none; }
.ocard-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ocard-no { font-size: 12px; word-break: break-all; margin-top: 2px; }
.ocard-grid { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin-top: 8px; font-size: 13px; }
.ocard-grid .k { color: var(--muted, #8a94a3); white-space: nowrap; }
.ocard-grid .v { word-break: break-all; text-align: right; }
.ocard-grid .v .badge { margin-left: 4px; }
.ocard-reason { margin-top: 6px; font-size: 12px; color: #c0392b; word-break: break-all; }
.ocard-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border, #e5e9f0); font-size: 12px; }
.ocard-foot .ops { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

@media (max-width: 700px) {
  .mobile-cards { display: block; }
}

/* ===================== 仪表盘 v2（业务整合版） ===================== */
.dash-hero {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.dash-hero .dash-kpi .num { font-size: 26px; }

.dh-ok { color: var(--success); }
.dh-fail { color: var(--danger); }
.dh-sep { color: var(--muted); margin: 0 2px; font-weight: 400; }

.dash-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.dash-main .card { margin-bottom: 0; }

/* 近7日趋势：纯 CSS 柱状图（无图表库依赖） */
.dash-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  min-height: 100px;
  padding-top: 8px;
}

.dash-bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }

.dash-bar {
  width: 100%;
  max-width: 42px;
  min-height: 3px;
  background: linear-gradient(180deg, var(--primary) 0%, #93c5fd 100%);
  border-radius: 5px 5px 2px 2px;
  transition: height .3s ease;
}

.dash-bar-col:hover .dash-bar { filter: brightness(1.12); }

.dash-bar-num { font-size: 12px; font-weight: 600; color: var(--primary-dark); margin-top: 4px; min-height: 15px; }
.dash-bar-label { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }

/* 订单总览四联块（可点跳对应筛选） */
.dash-order-sum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.dos-item {
  display: block;
  text-align: center;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  background: var(--surface-soft);
  transition: border-color var(--transition), background var(--transition);
}

.dos-item:hover { border-color: var(--primary); background: var(--surface-blue); }

.dos-num { font-size: 22px; font-weight: 700; }
.dos-lab { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 业务模块状态卡 */
.dash-mods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.dmod {
  display: block;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  text-decoration: none;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.dmod:hover { border-color: var(--primary); box-shadow: var(--shadow-xs); }

.dmod-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.dmod-name { font-weight: 600; color: var(--text); font-size: 14px; }
.dmod-body { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--text-soft); margin-top: 6px; }

@media (max-width: 1100px) {
  .dash-hero { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .dash-main { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .dash-hero { grid-template-columns: 1fr 1fr; }
  .dash-order-sum { grid-template-columns: repeat(2, 1fr); }
  .dash-mods { grid-template-columns: 1fr; }
}

/* ===================== 窄屏统一适配（≤700px） =====================
   所有筛选/搜索工具栏、批量编辑表单、大表隐藏规则集中在这里（外链 CSS 首帧生效，
   页面底部的内联 <style> 会导致手机端首帧旧排版闪烁，禁止再往页面里加移动布局规则）。 */

@media (max-width: 700px) {
  /* 筛选工具栏：两列 grid，替代 flex wrap 的不可控收缩 */
  .toolbar form {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px 8px;
    align-items: end;
  }

  .toolbar form > * { width: auto !important; min-width: 0; }

  .toolbar form select,
  .toolbar form input[type=text] { width: 100% !important; }

  .toolbar form > button[type=submit],
  .toolbar form > a.btn { height: 38px; align-self: end; }

  /* 快捷日期按钮组：弹性换行，不强制一行塞满 6 个——按内容宽度排，
     塞得下就撑满一行、塞不下自然换成整齐的两行，字号保持可读 */
  .toolbar form .quick-range {
    grid-column: 1 / -1;
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    background: #eef1f6;
    border-radius: 10px;
    padding: 6px;
  }

  .toolbar form .quick-range .btn {
    flex: 1 1 88px;   /* 基准 88px，行内平分拉伸 */
    max-width: 130px; /* 防末行少量按钮被拉过宽 */
    min-height: 32px;
    padding: 0 6px;
    font-size: 12.5px;
    border: none;
    border-radius: 7px;
    background: var(--surface);
    color: var(--text-soft); /* btn-gray 是白字，背景被换成白色后必须补深色文字 */
    box-shadow: 0 1px 2px rgba(16, 24, 40, .08);
    margin: 0;
  }

  .toolbar form .quick-range .btn:hover { color: var(--primary-dark); }
  .toolbar form .quick-range .btn:active { background: var(--primary); color: #fff; }

  /* 创建/添加表单（m-grid）：首个字段与提交按钮整行，其余字段两列对齐，
     替代 flex 换行的参差排布（标签折行导致输入框高低不齐） */
  form.m-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px 8px;
    align-items: end;
  }

  form.m-grid > * { width: auto !important; min-width: 0; }
  form.m-grid > div:first-child { grid-column: 1 / -1; }
  form.m-grid > button[type=submit] { grid-column: 1 / -1; height: 40px; }
  form.m-grid label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* 商品卡片底部操作行：4 个按钮（禁用/启用+编辑+验证配置+下单配置）一行四等分 */
  .gcard .ocard-foot {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    align-items: center;
  }

  .gcard .ocard-foot form,
  .gcard .ocard-foot .ops { display: contents; }

  .gcard .ocard-foot .btn { width: 100%; padding: 0 2px; font-size: 12.5px; }

  /* 批量编辑表单（商品/下单商品）：标题整行 + 字段两列 */
  #g-batch-form,
  #dg-batch-form {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px 8px;
    align-items: end;
  }

  #g-batch-form > div:first-child,
  #dg-batch-form > div:first-child {
    grid-column: 1 / -1;
    padding-bottom: 0 !important;
  }

  #g-batch-form > div:not(:first-child),
  #dg-batch-form > div:not(:first-child) { min-width: 0; }

  #g-batch-form > button,
  #dg-batch-form > button { height: 38px; }

  /* 卡片列表页：隐藏桌面大表与列宽工具条（.mobile-cards 在上方 700px 块里显示） */
  .table-wrap.hide-m,
  table.hide-m { display: none; }
  .table-ctl { display: none; }

  #goods-table { display: none; }
  #devices-table { display: none; }

  /* 弹窗：说明文字收紧、设备列表限高，避免首屏全被说明占满 */
  .modal-box p.muted { font-size: 12px; margin: 6px 0; line-height: 1.5; }
  #dev-list { max-height: 34vh !important; }
}
