/* 全局微调：PC 优先 */
body { margin: 0; font-family: -apple-system, "Segoe UI", Arial, "Microsoft YaHei", sans-serif; background: #f4f5f7; }
#app { min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #1d2b36; color: #fff; padding: 0 24px; height: 52px;
  position: sticky; top: 0; z-index: 100;
}
.topbar .brand { font-size: 16px; font-weight: 700; letter-spacing: .5px; margin-right: 32px; }
.topbar .el-menu { border-bottom: none; background: transparent; flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
/* 菜单在窄屏可横向滚动，不裁掉后面的项 */
.topbar .el-menu::-webkit-scrollbar { height: 4px; }
.topbar .el-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.28); border-radius: 2px; }
.topbar .el-menu--horizontal > .el-menu-item { flex: none; color: #b7c3cd; height: 52px; line-height: 52px; border-bottom: 2px solid transparent; }
.topbar .el-menu--horizontal > .el-menu-item.is-active { color: #fff; border-bottom-color: #409eff; background: transparent; }
.topbar .el-menu--horizontal > .el-menu-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.topbar .userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #dfe6ec; flex: none; }
/* 用户名下拉：整块可点，命中区域更大 */
.topbar .user-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px;
  border-radius: 16px; cursor: pointer; color: #fff; font-size: 13px; outline: none;
}
.topbar .user-chip:hover { background: rgba(255,255,255,.12); }
.topbar .user-chip .avatar {
  width: 22px; height: 22px; border-radius: 50%; background: #409eff; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex: none;
}
.topbar .user-chip .uname { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page { max-width: 1180px; margin: 20px auto 60px; padding: 0 24px; }
.card { background: #fff; border-radius: 8px; padding: 20px 22px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 16px; }
.card h3 { margin: 0 0 14px; font-size: 15px; color: #1d2b36; }
.card h3 small { color: #999; font-weight: 400; margin-left: 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 24px; }

/* 开单页表单网格：顶置标签、等宽列、自动换行 */
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 4px 20px; align-items: start; }
.fgrid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fgrid > .el-form-item { margin-bottom: 16px; min-width: 0; }
.fgrid .span-2 { grid-column: span 2; }
.fgrid .span-all { grid-column: 1 / -1; }
.fgrid .el-form-item__content { min-width: 0; }

.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.items-toolbar { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.items-toolbar .el-select { width: 320px; max-width: 100%; }

.items-wrap { overflow-x: auto; }
.item-row { display: grid; grid-template-columns: minmax(180px, 1.4fr) minmax(170px, 1.3fr) 150px 60px 150px 140px 40px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dashed #eee; min-width: 820px; }
.item-row:last-of-type { border-bottom: none; }
.item-head { font-size: 12px; color: #888; padding-bottom: 4px; }
.item-amount { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; padding: 0 12px; white-space: nowrap; }
.total-row { font-size: 14px; }
.total-row .total-label { text-align: right; color: #666; font-weight: 600; }
.total-row .total-val { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; text-align: right; padding-right: 12px; white-space: nowrap; }

.total-bar { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 14px; }
.total-bar .num { font-size: 18px; font-weight: 700; color: #d84a3a; }

.asset-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.asset-preview {
  width: 150px; height: 40px; flex: none; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #dcdfe6; border-radius: 4px; background: #fff; padding: 3px;
}
.asset-preview.tall { width: 88px; height: 64px; }
.asset-preview.empty { border-style: dashed; background: #fafafa; }
.asset-preview img, .asset-thumb { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-thumb { width: 100%; height: 100%; }
.asset-ph { font-size: 12px; color: #c0c4cc; }
.form-actions { padding-left: 260px; }
/* 大图预览：透明 PNG 需要白底，否则叠在深色遮罩上看不清 */
.el-image-viewer__img { background: #fff; border-radius: 4px; }

.op-btns { display: flex; gap: 4px; flex-wrap: nowrap; }
.op-btns .el-button + .el-button { margin-left: 0; }
.pager { display: flex; justify-content: flex-end; margin-top: 14px; overflow-x: auto; }
.logo-preview { max-height: 44px; max-width: 180px; border: 1px solid #eee; border-radius: 4px; padding: 4px; background: #fff; }

/* ================= 响应式 ================= */
@media (max-width: 1024px) {
  .fgrid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .page { padding: 0 14px; margin: 14px auto 40px; }
  .card { padding: 16px 14px; }
  .topbar { padding: 0 14px; }
  .topbar .brand { margin-right: 16px; }
  .topbar .userbox { gap: 6px; }
}

@media (max-width: 640px) {
  /* 顶栏两行：品牌+用户一行，菜单独占第二行；菜单项按内容宽度 space-around 分布，
     避免 Element Plus 水平菜单在贴满时因亚像素误差把末项折叠成 "…" */
  .topbar { flex-wrap: wrap; height: auto; min-height: 52px; padding: 8px 12px; gap: 6px 10px; }
  .topbar .brand { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 0; font-size: 15px; order: 1; }
  .topbar .userbox { order: 2; gap: 4px; }
  .topbar .userbox .el-tag { display: none; }  /* 徽标与菜单里的 Admin 重复，窄屏省空间 */
  .topbar .el-menu { flex: 1 1 100%; order: 3; min-width: 0; display: flex; justify-content: space-around; height: 40px; overflow: visible; }
  .topbar .el-menu--horizontal > .el-menu-item { flex: none; text-align: center; padding: 0 12px; height: 40px; line-height: 40px; }
  .topbar .userbox .el-button { padding: 4px 8px; }
  .userbox { font-size: 12px; }

  .fgrid, .fgrid.cols-3 { grid-template-columns: 1fr; }
  .fgrid .span-2 { grid-column: auto; }
  .grid2, .grid3 { grid-template-columns: 1fr; }

  .item-head { display: none; }
  .items-wrap { overflow-x: visible; }
  .item-row { grid-template-columns: 1fr; min-width: 0; gap: 8px; padding: 12px 0; }
  .item-row > .el-button { justify-self: end; }
  .item-row > .item-amount { text-align: left; padding: 0; }
  /* Total 行窄屏改两列：标签 + 金额 */
  .total-row { grid-template-columns: auto 1fr; }
  .total-row > div { grid-column: auto !important; }
  .total-row .total-label, .total-row .total-val { text-align: left; padding: 0; }
  .total-row > div:empty, .total-row > div:first-child:empty { display: none; }

  .card h3 { font-size: 14px; }
  .card h3 small { display: block; margin: 4px 0 0; }
  .total-bar { justify-content: stretch; }
  .total-bar .el-button { width: 100%; }

  /* 左标签表单在窄屏改为上下结构 */
  .el-form-item__label { width: auto !important; float: none !important; display: block; text-align: left; padding: 0 0 4px; line-height: 1.4; }
  .el-form-item__content { margin-left: 0 !important; }
  .form-actions { padding-left: 0; }
  .el-dialog, .el-message-box { width: 94vw !important; max-width: 94vw; }
}
